#!/usr/bin/env python # -*- mode: python -*- # Show some reports from the ldap database # Call with nokey to generate a missing key report # Call with noforward to generate a missing .forward report import string, re, time, ldap, getopt, sys; from userdir_ldap import *; def ShowDups(Attrs,Len): for x in Attrs: if x[1].has_key("keyfingerprint") == 0: continue; Count = 0; for I in x[1]["keyfingerprint"]: if len(I) == Len: Count = Count + 1; if Count > 1: for I in x[1]["keyfingerprint"]: if len(I) == Len: print "%s: %s" % (EmailAddress(x),I); # Main program starts here # Process options (options, arguments) = getopt.getopt(sys.argv[1:], "") for (switch, val) in options: if (switch == '-a'): DoAdd = 1; print "Connecting to LDAP directory"; # Connect to the ldap server l = ldap.open(LDAPServer); l.simple_bind_s("",""); if arguments[0] == "nokey": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(!(keyfingerprint=*))",\ ["uid","cn","sn","emailforward","comment"]); Attrs.sort(); for x in Attrs: print "Key Missing:",EmailAddress(x); if GetAttr(x,"emailforward") != "": print " ->",GetAttr(x,"emailforward"); if GetAttr(x,"comment") != "": print " :",GetAttr(x,"comment"); if arguments[0] == "noforward": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(!(emailforward=*))",\ ["uid","cn","sn","emailforward","comment"]); Attrs.sort(); for x in Attrs: print "No Forward:",EmailAddress(x); if arguments[0] == "badpriv": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(!(keyfingerprint=*))(privatesub=*))",\ ["uid","cn","sn","privatesub"]); Attrs.sort(); for x in Attrs: print EmailAddress(x)+": "+GetAttr(x,"privatesub"); if arguments[0] == "nopriv": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(keyfingerprint=*)(!(privatesub=*)))",\ ["uid","cn","sn","privatesub"]); Attrs.sort(); for x in Attrs: print " ",EmailAddress(x)+": "+GetAttr(x,"privatesub"); if arguments[0] == "keymap": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\ ["uid","cn","sn","keyfingerprint"]); Attrs.sort(); for x in Attrs: if x[1].has_key("keyfingerprint"): for I in x[1]["keyfingerprint"]: print "%s: %s" % (EmailAddress(x),I); if arguments[0] == "devcount": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(keyfingerprint=*)(gidnumber=800))",\ ["uid"]); Count = 0; for x in Attrs: Count = Count + 1; print "There are",Count,"developers as of",time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time())); if arguments[0] == "multikeys": Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\ ["uid","cn","sn","keyfingerprint"]); Attrs.sort(); print "--- PGP Keys ---" ShowDups(Attrs,32); print "--- GPG Keys ---" ShowDups(Attrs,40);