Commit 910cb4ff authored by Recteur LP's avatar Recteur LP

Add Settings HTML Template

parent 55b60726
......@@ -6,6 +6,7 @@ import ldif
import sys
import urllib
import hashlib
import pyrmin
######## Custom LDAP / AD module #########
__name__ = "LDAP Authentification"
......@@ -20,16 +21,15 @@ class ldapauth2():
def __init__(self, config):
# Get Auth method in config file if none set go to simgle user mode
if config:
if 'ldap' in config:
if 'server' not in config['ldap']:
returnerror("No ldap server in config")
elif 'port' not in config['ldap']:
returnerror("No ldap port in 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['ldap']['server'] + ':' + self.config['ldap']['port'])
self.ld.protocol_version = config['ldap']['version']
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['ldap']['user'], self.config['ldap']['password'])
self.ld.simple_bind_s(self.config['user'], self.config['password'])
def __del__(self):
try:
......@@ -38,7 +38,7 @@ class ldapauth2():
pass
def __getresults(self, filter):
results = self.ld.search_s(self.config['ldap']['basedn'],ldap.SCOPE_SUBTREE,filter)
results = self.ld.search_s(self.config['basedn'],ldap.SCOPE_SUBTREE,filter)
return results
def __getgroup(self, group):
......@@ -60,19 +60,23 @@ class ldapauth2():
mail = str(attrs.get('mail')[0]).decode('utf-8').lower()
gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(mail).hexdigest() + "?"
gravatar_url += urllib.urlencode({'d':"identicon", 's':str(50)})
isadmin = False
admins = self.getusersfromgroup("memberOf=" + self.config['ldap']['admin'])
for admin in admins:
if name.lower() == admin['name'].lower():
isadmin = True
break
admins = []
for group in self.config['admin']:
admins = self.getusersfromgroup("memberOf=" + group)
for admin in admins:
pyrmin.log.debug(admin)
if 'name' in admin and name.lower() == admin['name'].lower():
isadmin = True
break
if isadmin:
break
return {
"name": name,
"isauth": True,
"isadmin": isadmin,
"auth": True,
"admin": isadmin,
"division": attrs.get('division', [ 'Guest' ])[0].decode("utf-8"),
"displayName": attrs.get('displayName', [ 'Guest' ])[0].decode("utf-8"),
"mobile": attrs.get('otherMobile', [ '' ])[0],
......
<div class="form-group">
<label for="exampleInputEmail1">Authentification module</label>
<input type="text" class="form-control" id="auth" value="{{ config.auth_module }}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">LDAP Username</label>
<input type="text" class="form-control" id="username" value="{{ config.ldap.user }}">
</div>
<div class="form-group">
<label for="exampleInputPassword1">LDAP Password</label>
<input type="password" class="form-control" id="password" value="{{ config.ldap.password }}">
</div>
<div class="form-group">
<label for="exampleInputFile">Admin Group</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
<p class="help-block">Example block-level help text here.</p>
</div>
\ No newline at end of file
{% import 'core/templates/form_macros.html' as forms %}
{{ forms.input('server', label="LDAP Server", value=config.server) }}
{{ forms.input('port', label="LDAP Port", value=config.port) }}
{{ forms.input('version', label="Protocol Version", value=config.version) }}
{{ forms.input('user', label="LDAP Username", value=config.user) }}
{{ forms.input('password', label="LDAP Password", value=config.password, type='password') }}
{{ forms.input('basedn', label="BASE DN", value=config.basedn) }}
{{ forms.input('admin', label="Admin Group", value=config.admin) }}
\ 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