libreschool-client-manager/root/etc/ansible/library/nethserver-accounts

27 lines
804 B
Plaintext
Raw Normal View History

#!/usr/bin/env python3
# consider refactoring this script in perl: maybe we can improve the speed
# by not calling nethserver scripts (which BTW are wrappers for LDAP queries)
import os
import json
# users list
cmd = os.popen('/usr/libexec/nethserver/list-users -s -A')
userslist = json.loads(cmd.read())
for u in userslist:
cmd = os.popen('/usr/libexec/nethserver/list-user-membership -s -A "' + u + '"')
userslist[u]['groups'] = json.loads(cmd.read())
# groups list
cmd = os.popen('/usr/libexec/nethserver/list-groups -s')
groupslist = json.loads(cmd.read())
for g in groupslist:
cmd = os.popen('/usr/libexec/nethserver/list-group-members -s "' + g + '"')
groupslist[g]['members'] = json.loads(cmd.read())
# data return
print(json.dumps({"groups":groupslist,"users":userslist}))