Commit ac7c4d77 authored by Imran Hussain's avatar Imran Hussain
Browse files

Fix bugs so the program actually runs

parent 8b380201
debugmode = 1
debugmode = 0
import os
import pwd
......@@ -11,6 +11,7 @@ import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import ldap
import subprocess
def correctPaidUntilStr():
......@@ -257,29 +258,30 @@ def deleteUser(peopleList):
subprocess.call(['sudo', 'mkdir', "-m", "700", basedir])
for person in peopleList:
# get all their info from the db
cur = DBconn.cursor()
cur.execute("SELECT * from members WHERE username=%(user)s",{"user" : person[0]})
cur.execute("SELECT * from members WHERE username=%(user)s",{"user" : person})
userDBinfo = cur.fetchall()
cur.close()
# fail safe, if the DB username we just got isn't the one we are
# messing with, die
if str(person[0]) != userDBinfo[0][1]:
if str(person) != userDBinfo[0][1]:
print("Something went wrong getting info from DB, quitting! NO CHNAGES MADE")
sys.exit(9)
# get all their info from the ldap
userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person))
# fail safe, if the ldap username we just got isn't the one we
# are messing with, die
if str(person[0]) != userLDAPinfo[0][1]["uid"][0]:
if str(person) != userLDAPinfo[0][1]["uid"][0]:
print("Something went wrong getting info from LDAP, quitting! NO CHNAGES MADE")
sys.exit(9)
# declare some easy to use vars
username = str(person[0])
username = str(person)
persondir = basedir+"/"+username
# make the dir to store their stuff
......@@ -331,17 +333,17 @@ def deleteUser(peopleList):
# /usr/lib/mailman/bin/remove_members users imranh@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', "members", str(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
subprocess.call(['sudo', '/usr/lib/mailman/bin/remove_members', "users", str(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]})
cur.execute("DELETE FROM doorcards WHERE uid=%(uid)s",{"uid" : str(userDBinfo[0][0])})
# delete from members table
cur.execute("DELETE FROM members WHERE username=%(user)s",{"user" : person[0]})
cur.execute("DELETE FROM members WHERE username=%(user)s",{"user" : username})
# 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()
......@@ -353,7 +355,7 @@ def deleteUser(peopleList):
# them
emailDeletedUser(userDBinfo)
# logs@
emailAdminDeleteUser(person[0])
emailAdminDeleteUser(person)
# remove the entry from the list
peopleList.remove(person)
......
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