Commit 2aa492c8 authored by Imran Hussain's avatar Imran Hussain
Browse files

Fix some bugs by getting rid of some of the magic numbers

parent c36f5647
......@@ -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,14 +208,14 @@ 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@sucs.org members
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment