mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Init function complete
This commit is contained in:
parent
bf5126af26
commit
516102d913
2 changed files with 51 additions and 2 deletions
38
yunohost.py
38
yunohost.py
|
@ -12,6 +12,8 @@ import ldap.modlist as modlist
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import getpass
|
import getpass
|
||||||
|
if not __debug__:
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def colorize(astr, color):
|
def colorize(astr, color):
|
||||||
|
@ -262,8 +264,9 @@ class YunoHostLDAP:
|
||||||
if result:
|
if result:
|
||||||
result_list = []
|
result_list = []
|
||||||
for dn, entry in result:
|
for dn, entry in result:
|
||||||
if 'dn' in attrs:
|
if attrs != None:
|
||||||
entry['dn'] = [dn]
|
if 'dn' in attrs:
|
||||||
|
entry['dn'] = [dn]
|
||||||
result_list.append(entry)
|
result_list.append(entry)
|
||||||
return result_list
|
return result_list
|
||||||
else:
|
else:
|
||||||
|
@ -293,6 +296,37 @@ class YunoHostLDAP:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def update(self, rdn, attr_dict, new_rdn=False):
|
||||||
|
"""
|
||||||
|
Modify LDAP entry
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
rdn -- DN without domain
|
||||||
|
attr_dict -- Dictionnary of attributes/values to add
|
||||||
|
new_rdn -- New RDN for modification
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Boolean | YunoHostError
|
||||||
|
|
||||||
|
"""
|
||||||
|
dn = rdn + ',' + self.base
|
||||||
|
actual_entry = self.search(base=dn, attrs=None)
|
||||||
|
if actual_entry[0]['userPassword']:
|
||||||
|
del actual_entry[0]['userPassword']
|
||||||
|
ldif = modlist.modifyModlist(actual_entry[0], attr_dict)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if new_rdn:
|
||||||
|
self.conn.rename_s(dn, new_rdn)
|
||||||
|
dn = new_rdn + ',' + self.base
|
||||||
|
|
||||||
|
self.conn.modify_ext_s(dn, ldif)
|
||||||
|
except:
|
||||||
|
raise YunoHostError(169, _('An error occured during LDAP entry update'))
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def validate_uniqueness(self, value_dict):
|
def validate_uniqueness(self, value_dict):
|
||||||
"""
|
"""
|
||||||
Check uniqueness of values
|
Check uniqueness of values
|
||||||
|
|
|
@ -13,3 +13,18 @@ def tools_init(args, connections):
|
||||||
|
|
||||||
for rdn, attr_dict in ldap_map['childs'].items():
|
for rdn, attr_dict in ldap_map['childs'].items():
|
||||||
yldap.add(rdn, attr_dict)
|
yldap.add(rdn, attr_dict)
|
||||||
|
|
||||||
|
admin_dict = {
|
||||||
|
'cn': 'admin',
|
||||||
|
'uid': 'admin',
|
||||||
|
'description': 'LDAP Administrator',
|
||||||
|
'gidNumber': '1007',
|
||||||
|
'uidNumber': '1007',
|
||||||
|
'homeDirectory': '/home/admin',
|
||||||
|
'loginShell': '/bin/bash',
|
||||||
|
'objectClass': ['organizationalRole', 'posixAccount', 'simpleSecurityObject']
|
||||||
|
}
|
||||||
|
|
||||||
|
yldap.update('cn=admin', admin_dict)
|
||||||
|
|
||||||
|
return { 'Success' : _("LDAP successfully initialized") }
|
||||||
|
|
Loading…
Add table
Reference in a new issue