2011-02-18 18:12:09 -05:00
|
|
|
#!/usr/bin/python2
|
|
|
|
"""
|
|
|
|
hs.py - hokie stalker module
|
2011-08-31 14:05:47 -04:00
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
2011-02-18 18:12:09 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
import ldap
|
2011-09-22 14:17:27 -04:00
|
|
|
from urllib.parse import quote as urlquote
|
2011-02-18 18:12:09 -05:00
|
|
|
|
|
|
|
LDAP_URI = "ldap://directory.vt.edu"
|
2011-08-31 14:05:47 -04:00
|
|
|
RESULTS_URL = "http://search.vt.edu/search/people.html?q={0}"
|
|
|
|
PERSON_URL = "http://search.vt.edu/search/person.html?person={0:d}"
|
2011-02-18 18:12:09 -05:00
|
|
|
|
|
|
|
l = ldap.initialize(LDAP_URI)
|
|
|
|
|
|
|
|
"""Search LDAP using the argument as a query. Argument must be a valid LDAP query."""
|
|
|
|
def search(query):
|
2011-08-31 14:05:47 -04:00
|
|
|
result = l.search_s('ou=People,dc=vt,dc=edu', ldap.SCOPE_SUBTREE, query)
|
|
|
|
if len(result) <= 0:
|
|
|
|
return False
|
2011-02-18 18:12:09 -05:00
|
|
|
|
2011-08-31 14:05:47 -04:00
|
|
|
return result
|
2011-02-18 18:12:09 -05:00
|
|
|
|
|
|
|
def hs(phenny, input):
|
2011-08-31 14:05:47 -04:00
|
|
|
""".hs <pid/name/email> - Search for someone on Virginia Tech People Search."""
|
|
|
|
|
|
|
|
q = input.group(2)
|
|
|
|
if q is None:
|
|
|
|
return
|
|
|
|
q = q.strip()
|
|
|
|
results = RESULTS_URL.format(urlquote(q))
|
|
|
|
|
|
|
|
try:
|
2011-09-14 20:29:42 -04:00
|
|
|
s = search('(|(uupid={0})(mail={0})(cn={0}))'.format(q))
|
2011-08-31 14:05:47 -04:00
|
|
|
if not s:
|
2011-09-14 20:27:29 -04:00
|
|
|
s = search('(|(uupid=*{0}*)(mail=*{0}*)(cn=*{1}*))'.format(q, '*'.join(q.split(' '))))
|
2011-08-31 14:05:47 -04:00
|
|
|
except ldap.FILTER_ERROR:
|
|
|
|
phenny.reply('Filter error; try to avoid injection attacks in the future please.')
|
|
|
|
return
|
|
|
|
except ldap.SIZELIMIT_EXCEEDED:
|
|
|
|
phenny.reply('Too many results to display here; check out {0}'.format(results))
|
|
|
|
return
|
|
|
|
except ldap.TIMELIMIT_EXCEEDED:
|
|
|
|
phenny.reply('Time limit exceeded; check out {0}'.format(results))
|
|
|
|
return
|
|
|
|
|
|
|
|
if s:
|
|
|
|
if len(s) >1:
|
|
|
|
phenny.reply("Multiple results found; try {0}".format(results))
|
|
|
|
else:
|
|
|
|
for dh, entry in s:
|
|
|
|
person = PERSON_URL.format(int(entry['uid'][0]))
|
|
|
|
phenny.reply("{0} - {1}".format(entry['cn'][0], person))
|
|
|
|
else:
|
|
|
|
phenny.reply("No results found")
|
2011-02-18 18:12:09 -05:00
|
|
|
hs.rule = (['hs'], r'(.*)')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-09-22 14:17:27 -04:00
|
|
|
print(__doc__.strip())
|
2011-02-18 18:12:09 -05:00
|
|
|
|