2
# Sean Feole 2012, LDAP Query
18
def delete(self, widget, event=None):
22
def configfile(self, configlocation):
24
print ("Using Config File at: %s" % configlocation)
26
myfile = open(configlocation, "r").readlines()
28
configcheck = scaninit.find("Insert Host Address")
31
print("Please Configure the config.txt file")
34
self.init = scaninit.split("=")[1].strip().strip("\"")
37
self.bind = scanbind.split("\"")[1]
39
scanpasswd = myfile[7]
40
self.passwd = scanpasswd.split("=")[1].strip().strip("\"")
42
scanbasedn = myfile[8]
43
self.basedn = scanbasedn.split("\"")[1]
45
def searchstring(self, name):
49
print ("Searching For: %s" % self.name)
53
init = "%s" % self.init
54
bind = "%s" % self.bind
55
passwd = "%s" % self.passwd
56
basedn = "%s" % self.basedn
57
searchstring = "%s" % self.name
59
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
60
window.connect("delete_event", self.delete)
61
window.set_border_width(10)
63
table = gtk.Table(3, 6, False)
66
notebook = gtk.Notebook()
67
notebook.set_tab_pos(gtk.POS_LEFT)
68
notebook.set_scrollable(True)
69
notebook.set_current_page(1)
70
table.attach(notebook, 0, 6, 0, 1)
73
self.show_border = True
77
l = ldap.initialize(init)
78
l.protocol_version = ldap.VERSION3
79
l.bind_s(bind, passwd)
80
except ldap.LDAPError:
81
print ("Error Binding to Ldap Server")
85
searchScope = ldap.SCOPE_SUBTREE
86
retrieveAttributes = None
87
searchFilter = "cn=*%s*" % searchstring
89
ldap_result_id = l.search(baseDN, searchScope, searchFilter,
94
result_type, result_data = l.result(ldap_result_id, 0)
96
print ("No Additional Entries to Parse")
99
if result_type == ldap.RES_SEARCH_ENTRY:
101
for number in result_set:
103
result_set.append(result_data)
104
for i in range(len(result_set)):
105
for entry in result_set[i]:
106
#Find Each Entry, If the Entry does
107
#not exist then default "Not Found"
110
name = entry[1]['cn'][0]
113
if 'title' in entry[1]:
114
title = entry[1]['title'][0]
117
if 'mail' in entry[1]:
118
email = entry[1]['mail'][0]
121
if 'telephoneNumber' in entry[1]:
122
telephone = entry[1]['telephoneNumber'][0]
124
telephone = "Not Found"
125
if 'mobile' in entry[1]:
126
mobile = entry[1]['mobile'][0]
130
org = entry[1]['ou'][0]
133
if 'launchpadID' in entry[1]:
134
launchpad = entry[1]['launchpadID'][0]
136
launchpad = "Not Found"
137
if 'mozillaNickname' in entry[1]:
138
irc = entry[1]['mozillaNickname'][0]
141
jpeg = entry[1]['jpegPhoto'][0]
143
myinfo = "\nName: %s\nTitle: %s\nOrg: %s\nPhone: %s\
144
\nMobile: %s\nEmail: %s\nLaunchpad: %s\nIRC: %s"\
145
% (name, title, org, telephone, mobile, email,
148
jpegnew = Image.open(StringIO.StringIO(jpeg))
149
jpegnew.save("/tmp/image.jpg", "JPEG")
152
image.set_from_file("/tmp/image.jpg")
155
bufferf = "%s" % (myinfo)
156
bufferl = "%s" % (name)
159
frame.set_border_width(10)
160
frame.set_size_request(500, 300)
163
bodywin = gtk.HBox(False, 0)
167
label = gtk.Label(bufferf)
168
bodywin.pack_end(image, False, False, 0)
169
bodywin.pack_end(label, True, True, 0)
172
label = gtk.Label(bufferl)
173
notebook.append_page(frame, label)
176
#Create the Bottom Buttons
177
button = gtk.Button("close")
178
button.connect("clicked", self.delete)
179
table.attach(button, 0, 1, 1, 2)
182
button = gtk.Button("next page")
183
button.connect("clicked", lambda w: notebook.next_page())
184
table.attach(button, 1, 2, 1, 2)
187
button = gtk.Button("prev page")
188
button.connect("clicked", lambda w: notebook.prev_page())
189
table.attach(button, 2, 3, 1, 2)
199
parser = argparse.ArgumentParser()
200
parser.add_argument('-s', '--searchstring',
201
help="Name of the Individual to search", required=True)
202
#parser.add_argument('-c', '--config',
203
# help="Location of the config file", required=True)
204
args = parser.parse_args()
206
args.config = "/etc/lquery/config.txt"
208
ldap.configfile('%s' % args.config)
209
ldap.searchstring('%s' % args.searchstring)
210
print(ldap.displayme())
215
if __name__ == "__main__":