Changeset 2756 for trunk/server/common
- Timestamp:
- Feb 26, 2016, 2:48:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/common/oursrc/whoisd/whoisd.tac
r1742 r2756 3 3 from twisted.protocols import basic 4 4 import ldap, ldap.filter 5 import os, sys, pwd, glob5 import pwd 6 6 7 7 class WhoisProtocol(basic.LineReceiver): … … 19 19 class WhoisFactory(protocol.ServerFactory): 20 20 protocol = WhoisProtocol 21 def __init__(self, vhostDir, ldap_URL, ldap_base, keyFile): 22 self.vhostDir = vhostDir 21 def __init__(self, ldap_URL, ldap_base, keyFile): 23 22 self.ldap_URL = ldap_URL 24 23 self.ldap = ldap.initialize(self.ldap_URL) 25 24 self.ldap_base = ldap_base 26 self.vhosts = {}27 if vhostDir:28 self.rescanVhosts()29 25 self.key = file(keyFile).read() 30 def rescanVhosts(self):31 newVhosts = {}32 for f in glob.iglob(os.path.join(self.vhostDir, "*.conf")):33 locker = os.path.splitext(os.path.basename(f))[0]34 newVhosts.update(self.parseApacheConf(file(f)))35 self.vhosts = newVhosts36 self.vhostTime = os.stat(self.vhostDir).st_mtime37 def parseApacheConf(self, f):38 vhosts = {}39 hostnames = []40 locker = None41 docroot = None42 for l in f:43 parts = l.split()44 if not parts: continue45 command = parts.pop(0)46 if command in ("ServerName", "ServerAlias"):47 hostnames.extend(parts)48 elif command in ("SuExecUserGroup",):49 locker = parts[0]50 elif command in ("DocumentRoot",):51 docroot = parts[0]52 elif command == "</VirtualHost>":53 d = {'locker': locker, 'apacheDocumentRoot': docroot, 'apacheServerName': hostnames[0]}54 for h in hostnames: vhosts[h] = d55 hostnames = []56 locker = None57 docroot = None58 return vhosts59 26 def canonicalize(self, vhost): 60 27 vhost = vhost.lower().rstrip(".") … … 84 51 def getWhois(self, vhost): 85 52 vhost = self.canonicalize(vhost) 86 info = self.vhosts.get(vhost)53 info = None 87 54 tries = 0 88 55 while (tries < 3) and not info: … … 104 71 105 72 application = service.Application('whois', uid=99, gid=99) 106 factory = WhoisFactory( None,73 factory = WhoisFactory( 107 74 "ldap://localhost", "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu", "/etc/whoisd-password") 108 75 internet.TCPServer(43, factory).setServiceParent(
Note: See TracChangeset
for help on using the changeset viewer.