Esthetic fixes
This commit is contained in:
parent
e64bcd1fac
commit
d78359ca69
1 changed files with 41 additions and 20 deletions
61
json2ldap.py
61
json2ldap.py
|
@ -1,35 +1,56 @@
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
from ldap3 import Server, Connection, ALL
|
from ldap3 import Server, Connection, ALL
|
||||||
|
|
||||||
basedn = 'dc=nantes,dc=omero-fbi,dc=fr'
|
BASEDN = 'dc=nantes,dc=omero-fbi,dc=fr'
|
||||||
usersdn = 'cn=users,'+basedn
|
USERSDN = 'cn=users,'+BASEDN
|
||||||
|
|
||||||
serv = Server('10.54.3.60', get_info=ALL) # define an unsecure LDAP server, requesting info on DSE and schema
|
|
||||||
|
|
||||||
|
serv = Server('10.54.3.60', get_info=ALL)
|
||||||
conn = Connection(serv, user='cn=admin,dc=nantes,dc=omero-fbi,dc=fr', password='Jps55Sk8An9y2nVL')
|
conn = Connection(serv, user='cn=admin,dc=nantes,dc=omero-fbi,dc=fr', password='Jps55Sk8An9y2nVL')
|
||||||
|
|
||||||
if not conn.bind():
|
if not conn.bind():
|
||||||
print('error in bind', conn.result)
|
print('error in bind', conn.result)
|
||||||
|
|
||||||
data_file="user.json"
|
def adduser():
|
||||||
|
with open(DATA_FILE, "r", encoding="utf8") as file:
|
||||||
|
json_user = json.load(file)
|
||||||
|
|
||||||
with open(data_file, "r") as file:
|
ldap_full_username = json_user["params"]["attributes"]["uid"]
|
||||||
json_user = json.load(file)
|
ldap_full_passwd = json_user["params"]["attributes"]["userPassword"]
|
||||||
|
ldap_givenname = json_user["params"]["attributes"]["givenName"]
|
||||||
|
ldap_surname = json_user["params"]["attributes"]["sn"]
|
||||||
|
ldap_cn = json_user["params"]["attributes"]["cn"]
|
||||||
|
ldap_homedir = json_user["params"]["attributes"]["homeDirectory"]
|
||||||
|
ldap_mail = json_user["params"]["attributes"]["mail"]
|
||||||
|
ldap_uid_number = json_user["params"]["attributes"]["uidNumber"]
|
||||||
|
ldap_gid_number = json_user["params"]["attributes"]["gidNumber"]
|
||||||
|
ldap_user_dn = 'uid=' + ldap_full_username + ',' + USERSDN
|
||||||
|
|
||||||
|
conn.add(
|
||||||
|
ldap_user_dn,
|
||||||
|
[
|
||||||
|
'inetOrgPerson',
|
||||||
|
'posixAccount',
|
||||||
|
'person',
|
||||||
|
'top'
|
||||||
|
],
|
||||||
|
{
|
||||||
|
'sn': ldap_surname,
|
||||||
|
'gidNumber': ldap_gid_number,
|
||||||
|
'uidNumber': ldap_uid_number,
|
||||||
|
'mail': ldap_mail,
|
||||||
|
'homeDirectory': ldap_homedir,
|
||||||
|
'userPassword': ldap_full_passwd,
|
||||||
|
'givenName': ldap_givenname,
|
||||||
|
'uid': ldap_full_username,
|
||||||
|
'cn': ldap_cn
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
ldap_full_username = json_user["params"]["attributes"]["uid"]
|
for arg in sys.argv[1:]:
|
||||||
ldap_full_passwd = json_user["params"]["attributes"]["userPassword"]
|
print(arg)
|
||||||
ldap_givenname = json_user["params"]["attributes"]["givenName"]
|
DATA_FILE = arg
|
||||||
ldap_surname = json_user["params"]["attributes"]["sn"]
|
adduser()
|
||||||
ldap_cn = json_user["params"]["attributes"]["cn"]
|
|
||||||
ldap_homedir = json_user["params"]["attributes"]["homeDirectory"]
|
|
||||||
ldap_mail = json_user["params"]["attributes"]["mail"]
|
|
||||||
ldap_uid_number = json_user["params"]["attributes"]["uidNumber"]
|
|
||||||
ldap_gid_number = json_user["params"]["attributes"]["gidNumber"]
|
|
||||||
ldap_user_dn = 'uid=' + ldap_full_username + ',' + usersdn
|
|
||||||
|
|
||||||
conn.add(ldap_user_dn, ['inetOrgPerson', 'posixAccount', 'person', 'top'], {'sn': ldap_surname, 'gidNumber': ldap_gid_number, 'uidNumber': ldap_uid_number, 'mail': ldap_mail, 'homeDirectory': ldap_homedir, 'userPassword': ldap_full_passwd, 'givenName': ldap_givenname, 'uid': ldap_full_username, 'cn': ldap_cn})
|
|
||||||
|
|
||||||
print(conn.result)
|
print(conn.result)
|
||||||
conn.unbind()
|
conn.unbind()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue