3 # Show some reports from the ldap database
4 # Call with nokey to generate a missing key report
5 # Call with noforward to generate a missing .forward report
7 import re, time, ldap, getopt, sys;
8 from userdir_ldap import *;
10 def ShowDups(Attrs,Len):
12 if x[1].has_key("keyFingerPrint") == 0:
16 for I in x[1]["keyFingerPrint"]:
20 for I in x[1]["keyFingerPrint"]:
22 print "%s: %s" % (EmailAddress(x),I);
24 # Main program starts here
26 (options, arguments) = getopt.getopt(sys.argv[1:], "")
27 for (switch, val) in options:
31 print "Connecting to LDAP directory";
33 # Connect to the ldap server
34 l = ldap.open(LDAPServer);
35 l.simple_bind_s("","");
37 if arguments[0] == "nokey":
38 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(!(keyFingerPrint=*))",\
39 ["uid","cn","sn","emailForward","comment"]);
42 print "Key Missing:",EmailAddress(x);
43 if GetAttr(x,"emailForward") != "":
44 print " ->",GetAttr(x,"emailForward");
45 if GetAttr(x,"comment") != "":
46 print " :",GetAttr(x,"comment");
48 if arguments[0] == "noforward":
49 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(!(emailForward=*))",\
50 ["uid","cn","sn","emailForward","comment"]);
53 print "No Forward:",EmailAddress(x);
55 if arguments[0] == "badpriv":
56 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(!(keyFingerPrint=*))(privateSub=*))",\
57 ["uid","cn","sn","privateSub"]);
60 print EmailAddress(x)+": "+GetAttr(x,"privateSub");
62 if arguments[0] == "nopriv":
63 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(keyFingerPrint=*)(!(privateSub=*)))",\
64 ["uid","cn","sn","privateSub"]);
67 print " ",EmailAddress(x)+": "+GetAttr(x,"privateSub");
69 if arguments[0] == "keymap":
70 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
71 ["uid","cn","sn","keyFingerPrint"]);
74 if x[1].has_key("keyFingerPrint"):
75 for I in x[1]["keyFingerPrint"]:
76 print "%s: %s" % (EmailAddress(x),I);
78 if arguments[0] == "devcount":
79 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(keyFingerPrint=*)(gidNumber=800))",\
84 print "There are",Count,"developers as of",time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()));
86 if arguments[0] == "echelon":
87 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,\
88 "(&(|(activity-pgp=*)(activity-from=*))(&(keyFingerPrint=*)(gidNumber=800)))",\
89 ["activity-pgp","activity-from"]);
94 if x[1].has_key("activity-pgp"):
95 PGPCount = PGPCount + 1;
96 print "Echelon has seen",Count,"developers, with",PGPCount,"PGP confirms as of",time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()));
98 if arguments[0] == "missing":
99 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,\
100 "(&(!(|(activity-pgp=*)(activity-from=*)))(&(keyFingerPrint=*)(gidNumber=800)))",\
101 ["uid","cn","sn","mn"]);
104 print EmailAddress(x);
106 if arguments[0] == "keystat":
107 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyFingerPrint=*",\
112 if x[1].has_key("keyFingerPrint"):
113 KeyCount = KeyCount + 1;
114 for I in x[1]["keyFingerPrint"]:
116 GPGCount = GPGCount + 1;
118 print "There are",KeyCount,"accounts with PGP2/5 keys and",GPGCount,"of them have PGP5 keys";
120 if arguments[0] == "multikeys":
121 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
122 ["uid","cn","sn","keyFingerPrint"]);
126 print "--- PGP Keys ---"
128 print "--- GPG Keys ---"