1Ocsinventory::Agent::MoUdsOueclrseisCn:ov:neAtnprtaiocbrhuyet::e::dAVghPeoensrttl:s::DM:ooCcdouummlmeeonsnt:(a:3tA)ipoanche::Vhosts::Common(3)
2
3
4

NAME

6       Apache::Vhosts::Common - Lib for common operations in vhosts inventory
7

DESCRIPTION

9       This package is meant to contain common functions used by OCS modules
10       for Apache virtualhosts.
11
12       For example, we could have two OCS modules:
13
14       ApacheVhostsPackaged
15           which would deal with packaged apache setups
16
17       ApacheVhostsCompiled
18           which would deal with compiled apache versions
19
20       At different times, these modules still would need to do the same
21       things, such as parsing apache configuration files, reading and
22       extracting information from a vhost dump, reading a x509 certificate
23       with openssl, ...
24
25       To avoid code duplication, the specific modules can call the functions
26       contained in this common package.
27
28   Exports
29       The module exports the following functions:
30
31       "readVhostsDump"
32       "readVhostConfFile"
33
34   readVhostsDump()
35       Return an array of hashes with the virtualhosts found thanks to
36       Apache's vhosts dump ("httpd -S" command).
37
38       Return type
39
40       The function returns a reference to an array of hashes.
41
42       Process
43
44       The function's workflow is as follows:
45
46       1.  Open "httpd -S" command output, with the current configuration file
47
48       2.  Read dump line by line to match IP-based or name-based virtualhost
49           information (both types of lines should be recognized):
50
51            port 80 namevhost mynamevhost.fr (/etc/httpd/.../10-mynamevhost.conf:50)
52            10.0.0.1:80 myvhost myipvhost.fr (/etc/httpd/.../20-myipvhost.conf:1)
53
54       3.  Create a hash with the virtualhost's data
55
56           We put the following attributes in it:
57
58            (string) computedname, (int) port, (string) srvname,
59            (string) vhostfile, (string) vhostline, (string) docroot, (bool) ssl
60
61           At this stage we do not know docroot or ssl, so they are
62           "/nonexistent" and false (0), respectively.
63
64       4.  Push the vhost hash to the array.
65
66       Return example
67
68        [
69          {
70            'computedname' => "[httpd] myvhost.fr:80",
71            'port' => 80,
72            'srvname' => 'myvhost.fr',
73            'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf',
74            'vhostline' => 1,
75            'docroot' => '/nonexistent',
76            'ssl' => 0
77          },
78          {
79            'computedname' => "[httpd] myvhost.fr:443",
80            'port' => 443,
81            'srvname' => 'myvhost.fr',
82            'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf',
83            'vhostline' => 20,
84            'docroot' => '/nonexistent',
85            'ssl' => 0
86          }
87        ]
88
89       Calling
90
91           my $vhosts = readVhostsDump($httpd_bin, $httpd_conf_file, $logger);
92
93       Parameter: $httpd_bin (string)
94           Path to the httpd binary to execute (for example:
95           "/usr/sbin/httpd").  Specific options (such as "-D" parameters) may
96           be added to the string.
97
98       Parameter: $httpd_conf_file (string)
99           Path to the main httpd configuration file (for example:
100           "/etc/httpd/conf/httpd.conf").
101
102       Parameter: $logger (reference to OCS logger instance)
103           To make use of OCS logging capabilities within the function.
104
105   readVhostConfFile()
106       Enhance a virtualhost's information with elements found when parsing
107       the vhost's configuration file.
108
109       Return type
110
111       The function returns nothing.
112
113       It only operates on the (referenced) vhost hash it got in parameter.
114
115       Process
116
117       The function must read the apache configuration file in which the vhost
118       gets defined (<VirtualHost> block).
119
120       The path to the particular configuration file and the line number of
121       the vhost declaration are known in the "vhostfile" and "vhostline"
122       attributes, thanks to the vhost dump.
123
124       The function's process, for the given vhost, is as follows:
125
126       1.  Open the configuration file at "vhostfile"
127
128       2.  Read line by line, waiting to be at correct line number
129           ("vhostline") to start searching for information.
130
131       3.  Search for the following information in the <VirtualHost> and
132           enhance the given vhost hash with:
133
134           •   docroot (string)
135
136               the value of the "DocumentRoot" directive
137
138           •   ssl (bool)
139
140               we turn it to true if we find a "SSLEngine on" directive
141
142           •   sslcertpath (string)
143
144               value of the "SSLCertificateFile" directive, if such a
145               directive is present
146
147       4.  File reading stops when we find the "</VirtualHost>" closing block
148           (in case multiple vhosts are declared in the same configuration
149           file).
150
151       Calling
152
153           foreach my $vhost (@$vhosts) # Generally
154           {
155               readVhostConfFile($vhost, $httpd_basedir);
156           }
157
158       Parameter: $vhost (reference to hash)
159           The virtualhost hash to enhance.
160
161       Parameter: $httpd_basedir (string)
162           The path to base directory of httpd, in case we encounter a
163           relative path in "SSLCertificateFile" and need to complete it.
164
165           IMPORTANT: the given path is expected to end with a slash '/', for
166           example:
167
168               "/etc/httpd/"
169
170
171
172perl v5.32.1           Ocsinventor2y0:2:1A-g0e1n-t2:6:Modules::Apache::Vhosts::Common(3)
Impressum