From 0a29297ea9315ce99adfea00104eae3fb608d10e Mon Sep 17 00:00:00 2001 From: FSRVI Date: Thu, 30 Sep 2021 01:52:51 +0200 Subject: [PATCH] shitty code der aus dem ldap user importiert und ihnen eine random pw gibt --- main.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 487c38f..dc93429 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ import ldap import toml import sys - +import secrets +import string def init_ldap(server, user, pw): con = ldap.initialize(server) @@ -15,6 +16,22 @@ if __name__ == '__main__': pw = sys.argv[3] con = init_ldap(server, user, pw) result = con.search_s('dc=beuth-hochschule,dc=de', - ldap.SCOPE_SUBTREE, - '|(title=Mechatronik Bachelor)(title=Mechatronik Master)', - ['cn']) + ldap.SCOPE_SUBTREE, + '(|(title=Mechatronik Bachelor)(title=Mechatronik Master))', + ['uid']) + mtnrs = [matnr[1]['uid'][0].decode("utf-8") for matnr in result[:-3]] + + pw = [] + for i in range(len(mtnrs)): + alphabet = string.ascii_lowercase + string.digits + password = ''.join(secrets.choice(alphabet) for i in range(8)) + userdict = dict() + userdict["passwd"] = password + userdict["roles"] = ["default/internal", "open/internal"] + userdict["priority"] = 0 + pw.append(userdict) + + + with open("users.toml", "w") as f: + toml.dump(dict(zip(mtnrs, pw)), f) +