Given a path X or a copy of the apache vhosts configuration file, how would I parse that file using PHP?
E.g. Given a variable containing a string that has the contents of an Apache vhosts configuration, how would I get a list of hosted domains/subdomains alias?
For example, given:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact@tomjn.com
DocumentRoot "/srv/www/localhost/
ServerName 127.0.0.1
ServerAlias localhost
CustomLog "/srv/www/logs/localhost-access_log.log" combined
ErrorLog "/srv/www/logs/localhost-error_log.log"
<Directory "/srv/www/localhost">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact@tomjn.com
DocumentRoot "/srv/www/2.7.localhost.com/
ServerName 2.7.localhost.com
ServerAlias 2.7.localhost.com
CustomLog "/srv/www/logs/2.7.localhost.com-access_log.log" combined
ErrorLog "/srv/www/logs/2.7.localhost.com-error_log.log"
<Directory "/srv/www/2.7.localhost.com">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
How would I get this output:
- localhost
- 2.7.localhost.com
Here's something very close written in Python: