apache2 configuration file parser and query tool
Project description
a2conf is utility and python module to work with apache2 config files
Testing environment:
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com # .... OUR TEST SITE ....
ServerAlias www.example.com 1.example.com 2.example.com
DirectoryIndex index.html index.htm default.htm index.php
Options -Indexes +FollowSymLinks
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example
ServerName example.com # .... OUR TEST SITE ....
ServerAlias www.example.com 1.example.com 2.example.com secure.example.com
DirectoryIndex index.html index.htm default.htm index.php
Options -Indexes +FollowSymLinks
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
a2conf.py
Examples
Just smart grep
$ ./a2conf.py -i /etc/apache2/sites-enabled/example.conf --cmd ServerName Serveralias
ServerName example.com
ServerAlias www.example.com 1.example.com 2.example.com
ServerName example.com
ServerAlias www.example.com 1.example.com 2.example.com secure.example.com
$ ./a2conf.py -i /etc/apache2/sites-enabled/example.conf --cmd SSLCertificateFile
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
Only arguments (one line, space-separated, non-unique):
./a2conf.py -i /etc/apache2/sites-enabled/example.conf --cmd ServerName Serveralias --args
example.com www.example.com 1.example.com 2.example.com example.com www.example.com 1.example.com 2.example.com secure.example.com
Unique arguments:
$ ./a2conf.py -i /etc/apache2/sites-enabled/example.conf --cmd ServerName Serveralias --uargs
www.example.com secure.example.com 2.example.com example.com 1.example.com
Filtering sections
./a2conf.py -i /etc/apache2/sites-enabled/example.conf --cmd servername serveralias --filter sslengine on
ServerName example.com
ServerAlias www.example.com 1.example.com 2.example.com secure.example.com
Can add --neg
(--negative
) to invert filtering
Per-vhost info
$ bin/a2conf -i /etc/apache2/sites-enabled/example.conf --cmd servername serveralias --uargs --vhost '{vhostargs} {args}'
*:80 example.com www.example.com example.com 1.example.com 2.example.com
*:443 example.com www.example.com 1.example.com 2.example.com secure.example.com
You can get list of all available tokens with -v
.
Node class
Properties and methods
raw - text line as-is, with all spaces, tabs and with comments
cmd - cmd ('ServerName') without args or None (if section)
section - section (e.g. 'VirtualHost')
args - one text line args to cmd or section. for vhost args could be '*:80', for ServerAlias: 'example.com example.org'
Structure
For container sections (VirtualHost) attr content is not None. For usual lines (ServerName) content is None
content - list of child nodes or None
children() - return generator for all children nodes (e.g. for VirtualHost node). Generator is empty if no children
Limitations
Any 'Include*' directives are not supported for now.
Examples
Reading
#!/usr/bin/env python3
import a2conf
root = a2conf.Node(name='#root')
root.read_file('/etc/apache2/sites-available/example.conf')
def recdump(node, prefix=""):
if node.section:
print(prefix, "SECTION", node.section, "ARGS", node.args, "CONTENT", len(node.content))
else:
print(prefix, repr(node.cmd), repr(node.args))
for ch in node.children():
recdump(ch, prefix+" ")
recdump(root)
Output:
None None
SECTION VirtualHost ARGS *:80 CONTENT 5
'DocumentRoot' '/var/www/example'
'ServerName' 'example.com'
'ServerAlias' 'www.example.com 1.example.com 2.example.com'
'DirectoryIndex' 'index.html index.htm default.htm index.php'
'Options' '-Indexes +FollowSymLinks'
SECTION VirtualHost ARGS *:443 CONTENT 9
'DocumentRoot' '/var/www/example'
'ServerName' 'example.com'
'ServerAlias' 'www.example.com 1.example.com 2.example.com'
'DirectoryIndex' 'index.html index.htm default.htm index.php'
'Options' '-Indexes +FollowSymLinks'
'SSLEngine' 'On'
'SSLCertificateFile' '/etc/letsencrypt/live/example.com/fullchain.pem'
'SSLCertificateKeyFile' '/etc/letsencrypt/live/example.com/privkey.pem'
'SSLCertificateChainFile' '/etc/letsencrypt/live/example.com/chain.pem'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file a2conf-0.1.1.tar.gz
.
File metadata
- Download URL: a2conf-0.1.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75cdb01ba8bbeea08b9599d1ece120128395e597fbb6cc0931f800467f086b24 |
|
MD5 | 78d0616f7f5ad2128fb9026b0c6de83d |
|
BLAKE2b-256 | 563188ada0d62efd234c1d8d05ffdf4b54f8e599308f6fa53d9ad057158962df |