source: trunk/server/fedora/config/etc/httpd/vhosts.d/reify-vhost.py @ 1119

Last change on this file since 1119 was 978, checked in by geofft, 13 years ago
undo miscommit
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/python
2#
3# Converts an apacheConfig record from LDAP, as used by mod_vhost_ldap,
4# into a <VirtualHost> record as used in an Apache conf.d directory.
5# Useful for adding things like SSL server certs that mod_vhost_ldap
6# doesn't support.
7#
8# Usage:
9# scripts# cd /etc/httpd/vhosts.d
10# scripts# ./reify-vhost.py geofft > geofft.conf
11# scripts# service httpd graceful
12#
13# Geoffrey Thomas <geofft@mit.edu>, 2008, public domain.
14
15import ldap
16import ldap.filter
17import pwd
18import sys
19
20ll = ldap.initialize("ldapi://%2fvar%2frun%2fdirsrv%2fslapd-scripts.socket/")
21ll.simple_bind_s("", "")
22
23host = sys.argv[1]
24
25r = ll.search_s(
26    "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu",
27    ldap.SCOPE_SUBTREE,
28    ldap.filter.filter_format(
29            "(&(objectClass=apacheConfig)" +
30            "(|(apacheServerName=%s)" +
31            "(apacheServerAlias=%s)))",
32           [host, host]))
33if len(r) != 0:
34    user = pwd.getpwuid(int(r[0][1]['apacheSuexecUid'][0]))
35    print """# do not trailing-slash DocumentRoot
36
37<VirtualHost *:80>
38        ServerName %(servername)s
39        ServerAlias %(serveralias)s
40        DocumentRoot %(docroot)s
41        Alias /~%(uname)s %(homedir)s/web_scripts
42        SuExecUserGroup %(uname)s %(uname)s
43        Include conf.d/vhosts-common.conf
44</VirtualHost>
45
46<IfModule ssl_module>
47        <VirtualHost *:443>
48                ServerName %(servername)s
49                ServerAlias %(serveralias)s
50                DocumentRoot %(docroot)s
51                Alias /~%(uname)s %(homedir)s/web_scripts
52                SuExecUserGroup %(uname)s %(uname)s
53                Include conf.d/vhosts-common-ssl.conf
54                SSLCertificateFile /etc/pki/tls/certs/%(hname)s.pem
55        </VirtualHost>
56        <VirtualHost *:444>
57                ServerName %(servername)s
58                ServerAlias %(serveralias)s
59                DocumentRoot %(docroot)s
60                Alias /~%(uname)s %(homedir)s/web_scripts
61                SuExecUserGroup %(uname)s %(uname)s
62                Include conf.d/vhosts-common-ssl.conf
63                Include conf.d/vhosts-common-ssl-cert.conf
64                SSLCertificateFile /etc/pki/tls/certs/%(hname)s.pem
65        </VirtualHost>
66</IfModule>""" % {
67    'servername': r[0][1]['apacheServerName'][0],
68    'serveralias': r[0][1]['apacheServerAlias'][0],
69    'docroot': r[0][1]['apacheDocumentRoot'][0],
70    'uname': user[0],
71    'homedir': user[5],
72    'hname': host
73}
74
75# vim: set ts=4 sw=4 et:
Note: See TracBrowser for help on using the repository browser.