From e2b84b2da0a7155a452adb227935d8b767565842 Mon Sep 17 00:00:00 2001 From: IDEZ Ugo Date: Wed, 6 Oct 2021 09:31:21 +0200 Subject: [PATCH] Dernierexos --- sio2/sisr/python/creatusr | 33 +++++++++++++++++++++++++++++ sio2/sisr/python/passusr.py | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 sio2/sisr/python/creatusr create mode 100755 sio2/sisr/python/passusr.py diff --git a/sio2/sisr/python/creatusr b/sio2/sisr/python/creatusr new file mode 100755 index 0000000..45dec5b --- /dev/null +++ b/sio2/sisr/python/creatusr @@ -0,0 +1,33 @@ +#!/usr/bin/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login + res = os.system ("getent passwd "+login) + if res != 0: + passw = "pwgen 4 1" + os.system (cmd) + mdp = string(os.system ("pwgen 4 1")) + os.system ("echo "+login+mdp+"|chpasswd") + os.system ("echo "+login+mdp+" > "+filename+".pwd") + else: + print ("Utilisateur "+login+" déjà éxistant") + os.system ("sudo userdel -r "+login) + line = fh.readline() + + fh.close() diff --git a/sio2/sisr/python/passusr.py b/sio2/sisr/python/passusr.py new file mode 100755 index 0000000..75e3ef1 --- /dev/null +++ b/sio2/sisr/python/passusr.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login + res = os.system ("getent passwd "+login) + if res != 0: + passw = ["pwgen", "4","1"] + #passw = "pwgen 4 1" + os.system (cmd) + #mdp = str(os.system (passw)) + #print (mdp) + mdp = subprocess.run(passw,capture_output=True) + mdp2 = mdp.stdout.decode("utf-8") + mdp3 = mdp2.rstrip() + print (mdp3) + ch3 = "echo "+login+":"+mdp3+"|sudo chpasswd" + print (ch3) + os.system (ch3) + os.system ("sudo echo "+login+":"+mdp3+" >> "+filename+".pwd") + else: + print ("Utilisateur "+login+" déjà éxistant") + os.system ("sudo userdel -r "+login) + line = fh.readline() + + fh.close()