[SUCS Devel] [Git][sucs/accountmanager][master] 3 commits: Fix some bugs by getting rid of some of the magic numbers

Imran Hussain imranh at sucs.org
Sun Mar 10 11:20:35 GMT 2019


Imran Hussain pushed to branch master at sucs / accountmanager


Commits:
2aa492c8 by Imran Hussain at 2019-03-10T10:46:05Z
Fix some bugs by getting rid of some of the magic numbers

- - - - -
bdcdca45 by Imran Hussain at 2019-03-10T10:58:17Z
Delete func now removes people from the mailing lists

- - - - -
08b447be by Imran Hussain at 2019-03-10T11:19:36Z
Delete function now complete! (feature parity of php scripts)

- - - - -


1 changed file:

- sucsam.py


Changes:

=====================================
sucsam.py
=====================================
@@ -171,7 +171,8 @@ def listUsers():
 def deleteUser(peopleList):
 
 	#get fs ready
-	directory = "/home/deleted"
+	basedir = "/home/deleted"
+	mboxdir = "/var/mail/"
 	subprocess.call(['sudo', 'mkdir', "-m", "700", directory])
 
 	for person in peopleList:
@@ -184,18 +185,22 @@ def deleteUser(peopleList):
 		#get all their info from the ldap
 		userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
 
+		#declare some easy to use vars
+		username = str(person[0])
+		persondir = basedir+"/"+username
+
 		#make the dir to store their stuff
-		subprocess.call(["sudo", "mkdir", directory+"/"+str(person[0])])
+		subprocess.call(["sudo", "mkdir", persondir])
 
 		#kill all their procs
-		subprocess.call(["sudo", "pkill", "-u", str(person[0])])
+		subprocess.call(["sudo", "pkill", "-u", username])
 
 		#backup their ldap entry
 		#sudo ldapsearch -x -D "cn=Manager,dc=sucs,dc=org" -y /etc/ldap.secret  "(uid=imranh)"
 		ldapbackupfile = open("./ldap-ldif", "w")
-		subprocess.call(["sudo", "ldapsearch", "-x", "-D", ldap_manager, "-y", ldap_manager_pass, "-L", "(uid="+str(person[0])+")"], stdout=ldapbackupfile)
+		subprocess.call(["sudo", "ldapsearch", "-x", "-D", ldap_manager, "-y", ldap_manager_pass, "-L", "(uid="+username+")"], stdout=ldapbackupfile)
 		ldapbackupfile.close()
-		subprocess.call(['sudo', 'mv', "-f", "./ldap-ldif", directory+"/"+str(person[0])+"ldap-ldif"])
+		subprocess.call(['sudo', 'mv', "-f", "./ldap-ldif", persondir+"/ldap-ldif"])
 
 		#delete them from ldap
 		#ldapconn.delete_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
@@ -203,20 +208,36 @@ def deleteUser(peopleList):
 		subprocess.call(["sudo", "ldapdelete", "-D", ldap_manager, "-y", ldap_manager_pass, userLDAPinfo[0][0]])
 
 		#move their homedir to the deleted folder
-		subprocess.call(['sudo', 'mv', "-f", userLDAPinfo[0][1]["homeDirectory"][0], directory+"/"+str(person[0])+"/homedir"])
+		subprocess.call(['sudo', 'mv', "-f", userLDAPinfo[0][1]["homeDirectory"][0], persondir+"/homedir"])
 
 		#move their mail to the deleted folder
-		subprocess.call(['sudo', 'mv', "-f", "/var/mail"+"/"+str(person[0]), directory+"/"+str(person[0])+"/mbox"])
+		subprocess.call(['sudo', 'mv', "-f", mboxdir+username, persondir+"/mbox"])
 
 		#remove them from the printer
 		#pkusers --delete imranh		
-		subprocess.call(['sudo', 'pkusers', "--delete", str(person[0])])
+		subprocess.call(['sudo', 'pkusers', "--delete", username])
 
 		#remove from mailing lists
-		#/usr/lib/mailman/bin/remove_members imranh at sucs.org members
-		#/usr/lib/mailman/bin/remove_members imranh at sucs.org users
-		        
-
+		#/usr/lib/mailman/bin/remove_members members imranh at sucs.org
+		#/usr/lib/mailman/bin/remove_members users imranh at sucs.org
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userLDAPinfo[0][1]["mail"][0]]) #sucs email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userDBinfo[0][3]]) #main email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "members", userDBinfo[0][6]+"@swan.ac.uk"]) # iss email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userLDAPinfo[0][1]["mail"][0]]) #sucs email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userDBinfo[0][3]]) #main email
+		subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", userDBinfo[0][6]+"@swan.ac.uk"]) # iss email
+
+		#time to delete them from the db :(
+		cur = DBconn.cursor()
+		#delete from doorcards first
+		cur.execute("DELETE FROM doorcards WHERE uid=%(uid)s",{"uid" : userDBinfo[0][0]})
+		#delete from members table
+		cur.execute("DELETE FROM members WHERE username=%(user)s",{"user" : person[0]})
+		#add their some details to the oldmembers table
+		cur.execute("INSERT into oldmembers (username,realname) VALUES (%(user)s,%(realname)s)",{"user" : username,"realname" : userDBinfo[0][2]})
+		DBconn.commit()
+		cur.close()
+		
 
 def reminderMenu():
 	print("")



View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/c36f5647b62fc0962911ddce2f59122237079e05...08b447bed0ebdcc69883ec83223fba2abf6b0d85

-- 
View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/c36f5647b62fc0962911ddce2f59122237079e05...08b447bed0ebdcc69883ec83223fba2abf6b0d85
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20190310/477b8a09/attachment-0001.html>


More information about the Devel mailing list