-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_from_netids.py
104 lines (74 loc) · 2.61 KB
/
dump_from_netids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
import os
import sys
import ldap
import getpass
import traceback
import pprint
def main():
SERVER = 'ldap://authldap.gwu.edu:389'
DN = 'ou=people,dc=gwu,dc=edu'
user = "uid=%s,ou=people,dc=gwu,dc=edu"
passwd = None
uid = None
try:
admin_uid = raw_input("Please enter your netid: ")
user = user % admin_uid
passwd = getpass.getpass("Please enter your ldap password: ")
netidFile = sys.argv[1]
f = open(netidFile, "r")
l = ldap.initialize(SERVER)
l.simple_bind_s(user, passwd)
print "NetID,\t\tGWID,\t\tLastName,\t\tFirstName,\tEmail,\tStatus,\tisFaculty,\tisStaff,\tisWage,\tisStudent,\tisAlum,\tuidNumber\n"
for uid in f:
searchFilter = "uid=%s" % uid.strip()
#print searchFilter
try:
rIndex = l.search(DN, ldap.SCOPE_SUBTREE, searchFilter, ["GWid", "uid", "sn", "givenName", "mail", "gwStatus", "GWaccType",])
result_type, result_data = l.result(rIndex)
if (result_data == []):
pprint.pprint("Error getting data for filter=%s" % searchFilter, stream=sys.stderr)
continue
result = result_data[0][1]
account_types = result['GWaccType']
except:
pprint.pprint("Error getting data for filter=%s" % searchFilter, stream=sys.stderr)
#set the values for the account type
isStaff = False
isFac = False
isStudent = False
isAlum = False
isWage = False
isAffiliate = False
uidNumber = None
for aType in account_types:
try:
if aType.find("staff") >= 0:
isStaff = True
elif aType.find("faculty") >= 0:
isFac = True
elif aType.find("student") >= 0:
isStudent = True
elif aType.find("alumni") >= 0:
isAlum = True
elif aType.find("wage") >= 0:
isWage = True
else:
pprint.pprint("UNKNOWN ACCOUNT TYPE: %s" % aType.strip(), stream=sys.stderr)
except KeyError:
traceback.print_exc(file=sys.stderr)
continue
except:
traceback.print_exc(file=sys.stderr)
continue
try:
print "%s,\t%s,\t%s,\t%s,\t%s,\t%s,\t%s,\t%s,\t%s,\t%s,\t%s" % (result['GWid'][0].strip(), result['uid'][0].strip(), result['sn'][0].strip(), result['givenName'][0].strip(), result['mail'][0].strip(),result['gwStatus'][0].strip(), isFac, isStaff, isWage, isStudent, isAlum,)
except KeyError:
continue
except getpass.GetPassWarning:
print "meh"
except:
traceback.print_exc(file=sys.stderr)
sys.exit(-1)
if __name__=="__main__":
main()