def main(arguments): try: if len(arguments) < 3: raise ldap_common.UserError("503 Missing mode or search term") elif len(arguments) > 3: raise ldap_common.UserError("503 Too many arguments") mode = arguments[1] search = arguments[2] if mode == "email": user_filter = "(userprincipalname=%s)" % search elif mode == "name": user_filter = "(cn=%s)" % search else: raise ldap_common.UserError("503 Invalid search mode: " + mode) result = ldap_common.ldap_search(search, user_filter) result = ldap_common.parse_ldap_result(result) print "200 OK" print "distinguished name:", result["distinguished_name"] print "display_name:", result["display_name"] print "given name:", result["given_name"] print "surname:", result["surname"] print "email:", result["email"] print "last bad login:"******"last_bad_login"] print "last logon:", result["last_logon"] print "last password set:", result["last_password_set"] print "user created on:", result["user_created_on"] print "terminated:", result["terminated"] print "member of:" for group in result["member_of"]: print "\t", group print "Online Admin permission:", result["permissions"]["is_woa"] print "Online Platform permission:", result["permissions"]["is_wop"] print "Online MEX permission:", result["permissions"]["is_onlinemex"] print "Online Interlocutor permission:", result["permissions"]["is_interlocutor"] print "Online Lead permission:", result["permissions"]["is_woa_lead"] print "OGI permission:", result["permissions"]["is_ogi"] print "Customer Care permission:", result["permissions"]["is_cc"] print "Customer Care Lead permission:", result["permissions"]["is_cc_lead"] except ldap_common.UserError as e: print e except Exception as e: print "500 %s\n%s" % (e, traceback.format_exc())
def main(arguments): try: if len(arguments) < 2: raise ldap_common.UserError('503 Missing username') elif len(arguments) == 2: user = arguments[1] #password = arguments[2] else: raise ldap_common.UserError('503 Too many arguments') result = ldap_common.ldap_search(user, '(userprincipalname=%s)' % user) result = ldap_common.parse_ldap_result(result) #if ldap_common.ldap_auth(result['distinguished_name'], password): # result["correct_password"] = True # result["validation_cookie"] = 'currently_super_duper_secret_incredibly_strong_password' #else: # result["correct_password"] = False print '200 OK' print json.dumps(result) except ldap_common.UserError as e: print e except Exception as e: print '500 %s\n%s\n%s' % (e, str(type(e)), traceback.format_exc())