-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.py
120 lines (93 loc) · 3.79 KB
/
plugin.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
###
# Copyright (c) 2012, Andrew Smillie
# All rights reserved.
#
#
###
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import time as epoch
import os, sys, ldap
class GeekSoc(callbacks.Plugin):
"""Add the help for "@plugin help GeekSoc" here
This should describe *how* to use this plugin."""
threaded = True
def __init__(self, irc):
super(GeekSoc, self).__init__(irc)
def userinfo(self, irc, msg, args, name):
"""<username>
Return information on a given username.
"""
user = name
day = int(epoch.time()/(60*60*24))
try:
l = ldap.open("ldap.geeksoc.org")
l.protocol_version = ldap.VERSION3
except ldap.LDAPError, e:
irc.reply('Error getting info for user: "%s"' % name)
return
baseDN = "ou=People, dc=geeksoc, dc=org"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "uid={0}".format(user)
try:
results = l.search_s(baseDN, searchScope, searchFilter, retrieveAttributes)
if (len(results) == 0):
irc.reply('User "%s" doesn\'t exist' % name)
return
for dn, entry in results:
name = entry['cn'][0]
email = entry['mail'][0]
studentNo = entry['studentNumber'][0] if 'studentNumber' in entry else "N/A"
expiry = entry['shadowExpire'][0] if 'shadowExpire' in entry else "999999"
paid = entry['hasPaid'][0] if 'hasPaid' in entry else "N/A"
status = "Active"
if (paid == "FALSE"):
status = "Active (Not Paid)"
if int(expiry) <= day+60:
status = "Expiring (in %s days)" % (int(expiry)-day)
if int(expiry) <= day:
status = "Expired (%s days ago)" % (day-int(expiry))
if int(expiry) == 1:
status = "Admin disabled"
string = ( "User: %s, Name: %s, Email: %s, Student Number: %s, Status: %s" % (user, name, email, studentNo, status) )
irc.reply(string.encode('utf-8'))
baseDN = "ou=Groups, dc=geeksoc, dc=org"
searchFilter = "(memberUid=*)"
results = l.search_s(baseDN, ldap.SCOPE_SUBTREE, searchFilter)
groups = ''
for dn, entry in results:
if user in entry['memberUid']:
groups += entry['cn'][0] + ' '
irc.reply("Groups: " + groups)
except ldap.LDAPError, e:
irc.reply(e)
userinfo = wrap(userinfo, ['text'])
def group(self, irc, msg, args, name):
"""<group>
Return information on a given group.
"""
group = name
try:
l = ldap.open("ldap.geeksoc.org")
l.protocol_version = ldap.VERSION3
except ldap.LDAPError, e:
irc.reply('Error getting info for user: "%s"' % name)
return
baseDN = "cn=%s,ou=Groups, dc=geeksoc, dc=org" %(group)
searchFilter = "(memberUid=*)"
try:
results = l.search_s(baseDN, ldap.SCOPE_SUBTREE, searchFilter)
string = ''
for dn, entry in results:
for u in entry['memberUid']:
string += u + ' '
irc.reply("Group: %s, Members: %s" % (group, string))
except ldap.LDAPError, e:
irc.reply(e)
group = wrap(group, ['text'])
Class = GeekSoc
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: