Ecriture dans l'annuaire à l'aide de ldap3
This commit is contained in:
parent
a0f7cb7a3d
commit
bf60d65925
|
@ -47,11 +47,10 @@ def ldap_max_uidnumber():
|
|||
l.search(search_base = base,
|
||||
search_filter = '(uid=*)',
|
||||
search_scope = scope,
|
||||
attributes = ALL_ATTRIBUTES)
|
||||
attributes = 'uidNumber')
|
||||
|
||||
max_uidnumber = 0
|
||||
for entry in l.response:
|
||||
#max_uidnumber = max_uidnumber+" <br><br> "+str(entry['attributes']['uidNumber'])
|
||||
if entry['attributes']['uidNumber'] > max_uidnumber:
|
||||
max_uidnumber = entry['attributes']['uidNumber']
|
||||
|
||||
|
@ -59,5 +58,36 @@ def ldap_max_uidnumber():
|
|||
|
||||
return max_uidnumber
|
||||
|
||||
def ldap_add_entry(form):
|
||||
return "TODO"
|
||||
def ldap_add_entry(id):
|
||||
# uid and uidNumber on-the-fly production:
|
||||
uidNumber = ldap_max_uidnumber()+1
|
||||
#uid = ldap_craft_uid(id)
|
||||
|
||||
# The to-be-added entry DN.
|
||||
# the "dn: " prefix musn't appear here:
|
||||
dn = 'uid='+id['nameid']+","+base
|
||||
|
||||
objectClass = ['inetOrgPerson', 'organizationalPerson', 'person', 'posixAccount', 'top']
|
||||
# All the entry attributes can be defind in a dictionary as below:
|
||||
addmod = {}
|
||||
addmod['cn'] = id['prenom']+" "+id['nom']
|
||||
addmod['uid'] = id['nameid']
|
||||
addmod['uidNumber'] = str(uidNumber)
|
||||
addmod['gidNumber'] = '1000'
|
||||
addmod['sn'] = id['nom']
|
||||
addmod['homeDirectory'] = "/home/"+id['nameid']
|
||||
|
||||
# From here we get an addModlist intelligible to python-ldap:
|
||||
#ldif = modlist.addModlist(addmod)
|
||||
l = ldap_init()
|
||||
|
||||
# Do not forget the entry DN:
|
||||
ret = l.add(dn, objectClass, addmod)
|
||||
|
||||
ldap_terminate(l)
|
||||
|
||||
# Temporary debug output
|
||||
return str(dn)+"\n"+str(addmod)+"\n"+str(ret)
|
||||
#return str(addmod)
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.views.generic import View, UpdateView, CreateView
|
|||
|
||||
# Add library search path entry?
|
||||
from passerelle import utils
|
||||
from .utils import get_form_entry, ldap_max_uidnumber
|
||||
from .utils import get_form_entry, ldap_add_entry
|
||||
|
||||
#TODO
|
||||
# derive csv connector
|
||||
|
@ -28,12 +28,13 @@ def wcs(request, slug="", wcs_entry_id=0):
|
|||
#return HttpResponse(str(wcs_entry_id))
|
||||
#return HttpResponse(str(json.dumps(json_response)))
|
||||
|
||||
#dict = json.loads(json_response)
|
||||
dict = json.loads(json_response)
|
||||
#return HttpResponse(str(dict['fields']))
|
||||
|
||||
#return HttpResponse(str("foo"))
|
||||
#res = ldap_init() #OK
|
||||
res = ldap_max_uidnumber()
|
||||
#res = ldap_max_uidnumber()
|
||||
res = ldap_add_entry(dict['fields'])
|
||||
return HttpResponse(str(res))
|
||||
|
||||
class LDAPView(View, SingleObjectMixin):
|
||||
|
|
Reference in New Issue