Commit be34ce46 authored by Recteur LP's avatar Recteur LP

pyrmin v 0.3.0

parent 910cb4ff
......@@ -8,28 +8,27 @@ import urllib
import hashlib
import pyrmin
######## Custom LDAP / AD module #########
###################################
__name__ = "LDAP Authentification"
__description__ = "Module to authenticate user to ldap for python 2.x"
__version__ = "0.1"
__pyrmin_version__ = "0.2"
__description__ = "Module to authenticate user with Active Directory Server"
__version__ = "0.2.0"
__pyrmin_version__ = "0.3.0"
__namespace__ = "ldapauth2"
###################################
class ldapauth2():
class auth():
"LDAP auth module"
def __init__(self, config):
# Get Auth method in config file if none set go to simgle user mode
if config:
if 'server' not in config:
pyrmin.returnerror("No ldap server in config")
elif 'port' not in config:
pyrmin.returnerror("No ldap port in config")
self.config = config
self.ld = ldap.initialize('ldap://' + self.config['server'] + ':' + self.config['port'])
self.ld.protocol_version = config['version']
self.ld.set_option(ldap.OPT_REFERRALS, 0)
self.ld.simple_bind_s(self.config['user'], self.config['password'])
self.config = config
pyrmin.log.debug(config)
if 'server' not in self.config:
pyrmin.returnerror("No ldap server in config")
elif 'port' not in self.config:
pyrmin.returnerror("No ldap port in config")
self.ld = ldap.initialize('ldap://' + self.config['server'] + ':' + self.config['port'])
self.ld.protocol_version = self.config['version']
self.ld.set_option(ldap.OPT_REFERRALS, 0)
self.ld.simple_bind_s(self.config['user'], self.config['password'])
def __del__(self):
try:
......@@ -52,7 +51,7 @@ class ldapauth2():
users.append({ "name": attrs.get('sAMAccountName', [ 'Guest' ])[0], "uid": attrs.get('uidNumber', [ 'None' ])[0] })
return users
def getuserinfo(self, name):
def get(self, name):
filter = "(&(cn=" + name + ")(!(objectClass=computer)))"
for dn,attrs in self.__getresults(filter):
if dn and attrs:
......@@ -74,13 +73,13 @@ class ldapauth2():
break
return {
"name": name,
"username": name,
"auth": True,
"admin": isadmin,
"division": attrs.get('division', [ 'Guest' ])[0].decode("utf-8"),
"displayName": attrs.get('displayName', [ 'Guest' ])[0].decode("utf-8"),
"displayname": attrs.get('displayName', [ 'Guest' ])[0].decode("utf-8"),
"mobile": attrs.get('otherMobile', [ '' ])[0],
"company": attrs.get('company', [ '' ])[0].decode("utf-8"),
"mail": mail,
"img_url": gravatar_url
"img": gravatar_url
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment