"""
base_dn = 'o=lul'
search_scope = ldap.SCOPE_SUBTREE
+ results = []
+ attributes = None
try:
result_id = con.search(base_dn, search_scope, ldap_filter, attributes)
res = create_evergreen_user(auth, user)
if res:
update_ldap_barcode(con, user)
+ results.append(res)
if ARGS.push_barcode:
if user.barcode:
continue
except ldap.LDAPError, exc:
print >> sys.stderr, exc
+ return results
+
def get_barcode(auth, uid):
"""
Retrieve the barcode for a user from Evergreen based on their user ID
create_stat_cats(egau, user)
print("Created: %s with barcode %s" % (egau.usrname(), user.barcode))
- return user.barcode
+ return egau.usrname(), user.barcode
def update_ldap_barcode(con, user):
"""
"""
Process LDAP users created since a given date
"""
+
+ ldap_filter = None
+
attributes = [
'lulLibraryBarcode', 'createTimestamp', 'lulAffiliation',
'lulStudentLevel', 'lulPrimaryAffiliation', 'cn', 'mail',
)
if not ldap_filter:
return
- find_ldap_users(con, ldap_filter, attributes, auth)
+ return find_ldap_users(con, ldap_filter, attributes, auth)
def parse_args():
"""
args = parser.parse_args()
return args
-def main():
+def main(args=None):
"""
Set up connections and run code
"""
+ results = []
global ARGS
global AUTHTOKEN
ARGS = parse_args()
+ # override parsed args with anything that was passed in
+ if args:
+ ARGS = args
+
# Set the host for our requests
osrf.gateway.GatewayRequest.setDefaultHost(ARGS.eg_host)
con = ldap.initialize(ARGS.ldap_server)
con.set_option(ldap.OPT_REFERRALS, 0)
con.simple_bind_s(ARGS.ldap_user, ARGS.ldap_password)
- ldap_query(con, AUTHTOKEN)
+ results = ldap_query(con, AUTHTOKEN)
except ldap.LDAPError, exc:
print >> sys.stderr, "Could not connect: " + exc.message['info']
finally:
con.unbind()
+ return results
+
# UDATA = {
# 'mail': ['dan@example.com'],
# 'givenName': ['Dan'],
--- /dev/null
+ldap_osrf_sync
\ No newline at end of file
--- /dev/null
+$def with (uid, users)
+<html>
+<head>
+<title>Laurentian LDAP->Conifer account creation</title>
+<style>
+:invalid {
+ border-color: #e88;
+ -webkit-box-shadow: 0 0 5px rgba(255, 0, 0, .8);
+ -moz-box-shadow: 0 0 5px rbba(255, 0, 0, .8);
+ -o-box-shadow: 0 0 5px rbba(255, 0, 0, .8);
+ -ms-box-shadow: 0 0 5px rbba(255, 0, 0, .8);
+ box-shadow:0 0 5px rgba(255, 0, 0, .8);
+}
+</style>
+</head>
+<body>
+<h1>Laurentian LDAP->Conifer account creation</h1>
+$if uid:
+ $if len(users):
+ $for user, barcode in users:
+ <p>Created <strong>$user</strong> with barcode
+ <strong>$barcode</strong> for user ID <tt>$uid</tt></p>
+ $else:
+ <p>Tried to create user with ID # $uid, but we either could not find a
+ match, or it may already exist in Conifer.</p>
+
+<h2>Create an account</h2>
+<form action="/">
+ <label>Laurentian ID: <input type="number" name="uid"></label>
+ <input type="submit">
+</form>
+<h3>About this form</h3>
+<p>This form takes a Laurentian student or employee ID (normally 7 digits) as
+input, checks the LDAP directory for a match, and then attempts to create an
+account in Conifer with a new barcode that will then be pushed back into the
+LDAP directory.</p>
+</body>
+</html>
--- /dev/null
+#!/usr/bin/env python
+"A simple Web UI based on the web.py framework"
+
+import web
+import ldap_osrf_sync
+
+render = web.template.render('templates/')
+
+urls = (
+ '/(.*)', 'Index'
+)
+
+class Index:
+ "Adds a user based on their user ID"
+
+ def __init__(self):
+ self.args = LDAP_ARGS()
+
+ def GET(self, uid):
+ "Handle GET requests"
+
+ users = []
+
+ i = web.input(uid=None)
+
+ if i.uid:
+ uid = i.uid
+
+ if uid:
+ self.args.uid(uid)
+ users = ldap_osrf_sync.main(self.args)
+
+ return render.index(uid, users)
+
+class LDAP_ARGS:
+ def __init__(self):
+ self.ldap_server = ldap_osrf_sync.credentials.LDAP_HOST
+ self.ldap_user = ldap_osrf_sync.credentials.LDAP_DN
+ self.ldap_password = ldap_osrf_sync.credentials.LDAP_PW
+ self.eg_host = ldap_osrf_sync.credentials.OSRF_HOST
+ self.eg_user = ldap_osrf_sync.credentials.OSRF_USER
+ self.eg_password = ldap_osrf_sync.credentials.OSRF_PW
+ self.eg_workstation = ldap_osrf_sync.credentials.OSRF_WORK_OU
+ self.find_eg_user = None
+ self.dump_ldap = None
+ self.create_users = None
+ self.push_barcode = None
+ self.query_id = None
+ self.query_cn = None
+ self.query_sn = None
+ self.query_date = None
+
+ def uid(self, uid):
+ self.query_id = uid
+
+if __name__ == "__main__":
+ app = web.application(urls, globals())
+ app.run()