Changeset 627 for server/common/oursrc/whoisd
- Timestamp:
- Feb 3, 2008, 5:46:34 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/common/oursrc/whoisd/whoisd.tac
r528 r627 2 2 from twisted.internet import protocol, reactor, defer 3 3 from twisted.protocols import basic 4 import os, sys, glob 4 import ldap, ldap.filter 5 import os, sys, pwd, glob 5 6 6 7 class WhoisProtocol(basic.LineReceiver): … … 13 14 class WhoisFactory(protocol.ServerFactory): 14 15 protocol = WhoisProtocol 15 def __init__(self, vhostDir ):16 def __init__(self, vhostDir, ldap_URL, ldap_base): 16 17 self.vhostDir = vhostDir 18 self.ldap_URL = ldap_URL 19 self.ldap = ldap.initialize(self.ldap_URL) 20 self.ldap_base = ldap_base 17 21 self.vhosts = {} 18 22 self.rescanVhosts() … … 40 44 docroot = parts[0] 41 45 elif command == "</VirtualHost>": 42 d = {'locker': locker, ' docroot': docroot, 'canonical': hostnames[0]}46 d = {'locker': locker, 'apacheDocumentRoot': docroot, 'apacheServerName': hostnames[0]} 43 47 for h in hostnames: vhosts[h] = d 44 48 hostnames = [] … … 53 57 # else: 54 58 # return vhost + ".mit.edu" 59 def searchLDAP(self, vhost): 60 results = self.ldap.search_s(self.ldap_base, ldap.SCOPE_SUBTREE, 61 ldap.filter.filter_format( 62 '(|(apacheServername=%s)(apacheServerAlias=%s))', (vhost,)*2)) 63 if len(results) >= 1: 64 result = results[0] 65 attrs = result[1] 66 for attr in ('apacheServerName','apacheDocumentRoot', 'apacheSuexecUid', 'apacheSuexecGid'): 67 attrs[attr] = attrs[attr][0] 68 user = pwd.getpwuid(int(attrs['apacheSuexecUid'])) 69 if user: 70 attrs['locker'] = user.pw_name 71 else: 72 attrs['locker'] = None 73 return attrs 74 else: 75 return None 55 76 def getWhois(self, vhost): 56 77 vhost = self.canonicalize(vhost) 57 78 info = self.vhosts.get(vhost) 79 if not info: 80 info = self.searchLDAP(vhost) 58 81 if info: 59 82 ret = "Hostname: %s\nAlias: %s\nLocker: %s\nDocument Root: %s" % \ 60 (info[' canonical'], vhost, info['locker'], info['docroot'])83 (info['apacheServerName'], vhost, info['locker'], info['apacheDocumentRoot']) 61 84 else: 62 85 ret = "No such hostname" … … 64 87 65 88 application = service.Application('whois', uid=99, gid=99) 66 factory = WhoisFactory("/etc/httpd/vhosts.d") 89 factory = WhoisFactory("/etc/httpd/vhosts.d", 90 "ldap://localhost", "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu") 67 91 internet.TCPServer(43, factory).setServiceParent( 68 92 service.IServiceCollection(application))
Note: See TracChangeset
for help on using the changeset viewer.