Ocsinventory::Agent::Modules::Apache::Vhosts::Common(3pm) | User Contributed Perl Documentation | Ocsinventory::Agent::Modules::Apache::Vhosts::Common(3pm) |
Apache::Vhosts::Common - Lib for common operations in vhosts inventory
This package is meant to contain common functions used by OCS modules for Apache virtualhosts.
For example, we could have two OCS modules:
At different times, these modules still would need to do the same things, such as parsing apache configuration files, reading and extracting information from a vhost dump, reading a x509 certificate with openssl, ...
To avoid code duplication, the specific modules can call the functions contained in this common package.
The module exports the following functions:
Return an array of hashes with the virtualhosts found thanks to Apache's vhosts dump ("httpd -S" command).
Return type
The function returns a reference to an array of hashes.
Process
The function's workflow is as follows:
port 80 namevhost mynamevhost.fr (/etc/httpd/.../10-mynamevhost.conf:50) 10.0.0.1:80 myvhost myipvhost.fr (/etc/httpd/.../20-myipvhost.conf:1)
We put the following attributes in it:
(string) computedname, (int) port, (string) srvname, (string) vhostfile, (string) vhostline, (string) docroot, (bool) ssl
At this stage we do not know docroot or ssl, so they are "/nonexistent" and false (0), respectively.
Return example
[ { 'computedname' => "[httpd] myvhost.fr:80", 'port' => 80, 'srvname' => 'myvhost.fr', 'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf', 'vhostline' => 1, 'docroot' => '/nonexistent', 'ssl' => 0 }, { 'computedname' => "[httpd] myvhost.fr:443", 'port' => 443, 'srvname' => 'myvhost.fr', 'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf', 'vhostline' => 20, 'docroot' => '/nonexistent', 'ssl' => 0 } ]
Calling
my $vhosts = readVhostsDump($httpd_bin, $httpd_conf_file, $logger);
Enhance a virtualhost's information with elements found when parsing the vhost's configuration file.
Return type
The function returns nothing.
It only operates on the (referenced) vhost hash it got in parameter.
Process
The function must read the apache configuration file in which the vhost gets defined (<VirtualHost> block).
The path to the particular configuration file and the line number of the vhost declaration are known in the "vhostfile" and "vhostline" attributes, thanks to the vhost dump.
The function's process, for the given vhost, is as follows:
the value of the "DocumentRoot" directive
we turn it to true if we find a "SSLEngine on" directive
value of the "SSLCertificateFile" directive, if such a directive is present
Calling
foreach my $vhost (@$vhosts) # Generally { readVhostConfFile($vhost, $httpd_basedir); }
IMPORTANT: the given path is expected to end with a slash '/', for example:
"/etc/httpd/"
2020-09-14 | perl v5.30.3 |