Loading sucsam.py +93 −88 Original line number Diff line number Diff line Loading @@ -12,13 +12,14 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import ldap def correctPaidUntilStr(): # same logic as suapi stuff # if it's greater than Sept then year+1 # if it's less than Spet then year if (month >= 9): if month >= 9: paidyear = year + 1 elif (month < 8): elif month < 8: paidyear = year else: print("Something went really wrong") Loading @@ -35,9 +36,9 @@ def stripFuturePeople(listofpeeps): badpeeps.append(person) else: paidyeararray = person[1].split(' ') if (month >= 9): if month >= 9: paidyear = year + 1 elif (month < 8): elif month < 8: paidyear = year else: print("Something went really wrong") Loading @@ -46,6 +47,7 @@ def stripFuturePeople(listofpeeps): badpeeps.append(person) return badpeeps # ok this needs explaning # in comes a list [('user1', 'Sept. 2015'), ('user2', 'Sept. 2014')] # we need to work out what account type it is, Loading @@ -62,12 +64,11 @@ def sendReminderEmail(listofpeeps): username = DBdata[0][1] realname = DBdata[0][2] email = DBdata[0][3] type = DBdata[0][7] acctype = DBdata[0][7] adminname = pwd.getpwuid(os.geteuid())[0] if os.path.isfile(str(type)+"-email"): #file = open(str(type)+"-email","r") file = codecs.open(str(type)+"-email", encoding='utf-8') if os.path.isfile(str(acctype) + "-email"): file = codecs.open(str(acctype) + "-email", encoding='utf-8') data = file.read() file.close() data = data.replace("{$realname}",realname) Loading @@ -94,6 +95,7 @@ def sendReminderEmail(listofpeeps): print("Renewal email template not found!") sys.exit(4) def mainMenu(): print("\nPlease choose an option") print("[h] Diplay some help") Loading @@ -106,22 +108,22 @@ def mainMenu(): option = input("Option: ") print("\n") if (option == "h"): if option == "h": print("help text comming soon") mainMenu() elif (option == "q"): elif option == "q": DBconn.close() sys.exit(0) elif (option == "qs"): elif option == "qs": quickStats() mainMenu() elif (option == "la"): elif option == "la": listUsers() mainMenu() elif (option == "r"): elif option == "r": reminderMenu() mainMenu() elif (option == "d"): elif option == "d": deleteAccounts() mainMenu() else: Loading Loading @@ -170,9 +172,9 @@ def listUsers(): def emailDeletedUser(userDBinfo): username = userDBdata[0][1] realname = userDBdata[0][2] email = userDBdata[0][3] username = userDBinfo[0][1] realname = userDBinfo[0][2] email = userDBinfo[0][3] adminname = pwd.getpwuid(os.geteuid())[0] file = codecs.open("deleted-email", encoding='utf-8') Loading Loading @@ -204,10 +206,10 @@ def emailAdminDeleteUser(username): data = data.replace("{$username}",username) data = data.replace("{$adminname}",adminname) sender = 'staff@sucs.org' receiver = email receiver = "logs@sucs.org" message = MIMEMultipart() message['From'] = sender message['To'] = "logs@sucs.org" message['To'] = receiver message['Subject'] = username + '\'s SUCS account has been deleted' messageBody = MIMEText(data, 'plain', "UTF-8") message.attach(messageBody) Loading @@ -222,7 +224,7 @@ def deleteUser(peopleList): # get fs ready basedir = "/home/deleted" mboxdir = "/var/mail/" subprocess.call(['sudo', 'mkdir', "-m", "700", directory]) subprocess.call(['sudo', 'mkdir', "-m", "700", basedir]) for person in peopleList: # get all their info from the db Loading Loading @@ -294,10 +296,10 @@ def deleteUser(peopleList): emailAdminDeleteUser(person[0]) # remove the entry from the list peoplelist.remove(person) peopleList.remove(person) # return to the deletemenu with an empty list as we've just deleted everyone deleteMenu(peoplelist) deleteMenu(peopleList) def reminderMenu(): Loading @@ -311,7 +313,7 @@ def reminderMenu(): option = input("Option: ") if (option == "1"): if option == "1": for student in studentsBad: print(str(student[0]) + " because the DB says: " + str(student[1])) for soc in societiesBad: Loading @@ -319,17 +321,18 @@ def reminderMenu(): for ass in associatesBad: print(str(ass[0]) + " because the DB says: " + str(ass[1])) reminderMenu() if (option == "2"): if option == "2": sendReminderEmail(studentsBad) sendReminderEmail(societiesBad) sendReminderEmail(associatesBad) if (option == "2.1"): if option == "2.1": sendReminderEmail(studentsBad) if (option == "0"): if option == "0": mainMenu() else: reminderMenu() def deleteMenu(deleteArray): print("") print("1. View list of accounts to be deleted") Loading @@ -341,15 +344,15 @@ def deleteMenu(deleteArray): option = input("Option: ") if (option == "1"): if option == "1": print("\nThe following users will be deleted: ") for user in deleteArray: print(user) deleteMenu(deleteArray) elif (option == "2"): elif option == "2": print("Enter a username to add or remoeve it from the list.") user = input("Username: ") if (user in deleteArray): if user in deleteArray: deleteArray.remove(user) print(str(user) + " won't be deleted.") else: Loading @@ -360,7 +363,7 @@ def deleteMenu(deleteArray): except KeyError: print("\x1b[1;31mInvalid user.\x1b[0m") deleteMenu(deleteArray) elif (option == "3"): elif option == "3": for student in studentsBad: print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1])) deleteArray.append(student[0]) Loading @@ -371,18 +374,19 @@ def deleteMenu(deleteArray): print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1])) deleteArray.append(ass[0]) deleteMenu(deleteArray) elif (option == "3.1"): elif option == "3.1": for student in studentsBad: print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1])) deleteArray.append(student[0]) elif (option == "9"): elif option == "9": print("Nope not yet") deleteMenu(deleteArray) elif (option == "0"): elif option == "0": mainMenu() else: deleteMenu(deleteArray) def deleteAccounts(): # list that store usernames to be deleted # gets reset everytime you go into this bit on purpose Loading @@ -392,7 +396,8 @@ def deleteAccounts(): ### MAIN ### if (os.geteuid() == 0): if os.geteuid() == 0: print("\x1b[1;31mDon't run this as root!\x1b[0m") sys.exit(1) Loading Loading
sucsam.py +93 −88 Original line number Diff line number Diff line Loading @@ -12,13 +12,14 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import ldap def correctPaidUntilStr(): # same logic as suapi stuff # if it's greater than Sept then year+1 # if it's less than Spet then year if (month >= 9): if month >= 9: paidyear = year + 1 elif (month < 8): elif month < 8: paidyear = year else: print("Something went really wrong") Loading @@ -35,9 +36,9 @@ def stripFuturePeople(listofpeeps): badpeeps.append(person) else: paidyeararray = person[1].split(' ') if (month >= 9): if month >= 9: paidyear = year + 1 elif (month < 8): elif month < 8: paidyear = year else: print("Something went really wrong") Loading @@ -46,6 +47,7 @@ def stripFuturePeople(listofpeeps): badpeeps.append(person) return badpeeps # ok this needs explaning # in comes a list [('user1', 'Sept. 2015'), ('user2', 'Sept. 2014')] # we need to work out what account type it is, Loading @@ -62,12 +64,11 @@ def sendReminderEmail(listofpeeps): username = DBdata[0][1] realname = DBdata[0][2] email = DBdata[0][3] type = DBdata[0][7] acctype = DBdata[0][7] adminname = pwd.getpwuid(os.geteuid())[0] if os.path.isfile(str(type)+"-email"): #file = open(str(type)+"-email","r") file = codecs.open(str(type)+"-email", encoding='utf-8') if os.path.isfile(str(acctype) + "-email"): file = codecs.open(str(acctype) + "-email", encoding='utf-8') data = file.read() file.close() data = data.replace("{$realname}",realname) Loading @@ -94,6 +95,7 @@ def sendReminderEmail(listofpeeps): print("Renewal email template not found!") sys.exit(4) def mainMenu(): print("\nPlease choose an option") print("[h] Diplay some help") Loading @@ -106,22 +108,22 @@ def mainMenu(): option = input("Option: ") print("\n") if (option == "h"): if option == "h": print("help text comming soon") mainMenu() elif (option == "q"): elif option == "q": DBconn.close() sys.exit(0) elif (option == "qs"): elif option == "qs": quickStats() mainMenu() elif (option == "la"): elif option == "la": listUsers() mainMenu() elif (option == "r"): elif option == "r": reminderMenu() mainMenu() elif (option == "d"): elif option == "d": deleteAccounts() mainMenu() else: Loading Loading @@ -170,9 +172,9 @@ def listUsers(): def emailDeletedUser(userDBinfo): username = userDBdata[0][1] realname = userDBdata[0][2] email = userDBdata[0][3] username = userDBinfo[0][1] realname = userDBinfo[0][2] email = userDBinfo[0][3] adminname = pwd.getpwuid(os.geteuid())[0] file = codecs.open("deleted-email", encoding='utf-8') Loading Loading @@ -204,10 +206,10 @@ def emailAdminDeleteUser(username): data = data.replace("{$username}",username) data = data.replace("{$adminname}",adminname) sender = 'staff@sucs.org' receiver = email receiver = "logs@sucs.org" message = MIMEMultipart() message['From'] = sender message['To'] = "logs@sucs.org" message['To'] = receiver message['Subject'] = username + '\'s SUCS account has been deleted' messageBody = MIMEText(data, 'plain', "UTF-8") message.attach(messageBody) Loading @@ -222,7 +224,7 @@ def deleteUser(peopleList): # get fs ready basedir = "/home/deleted" mboxdir = "/var/mail/" subprocess.call(['sudo', 'mkdir', "-m", "700", directory]) subprocess.call(['sudo', 'mkdir', "-m", "700", basedir]) for person in peopleList: # get all their info from the db Loading Loading @@ -294,10 +296,10 @@ def deleteUser(peopleList): emailAdminDeleteUser(person[0]) # remove the entry from the list peoplelist.remove(person) peopleList.remove(person) # return to the deletemenu with an empty list as we've just deleted everyone deleteMenu(peoplelist) deleteMenu(peopleList) def reminderMenu(): Loading @@ -311,7 +313,7 @@ def reminderMenu(): option = input("Option: ") if (option == "1"): if option == "1": for student in studentsBad: print(str(student[0]) + " because the DB says: " + str(student[1])) for soc in societiesBad: Loading @@ -319,17 +321,18 @@ def reminderMenu(): for ass in associatesBad: print(str(ass[0]) + " because the DB says: " + str(ass[1])) reminderMenu() if (option == "2"): if option == "2": sendReminderEmail(studentsBad) sendReminderEmail(societiesBad) sendReminderEmail(associatesBad) if (option == "2.1"): if option == "2.1": sendReminderEmail(studentsBad) if (option == "0"): if option == "0": mainMenu() else: reminderMenu() def deleteMenu(deleteArray): print("") print("1. View list of accounts to be deleted") Loading @@ -341,15 +344,15 @@ def deleteMenu(deleteArray): option = input("Option: ") if (option == "1"): if option == "1": print("\nThe following users will be deleted: ") for user in deleteArray: print(user) deleteMenu(deleteArray) elif (option == "2"): elif option == "2": print("Enter a username to add or remoeve it from the list.") user = input("Username: ") if (user in deleteArray): if user in deleteArray: deleteArray.remove(user) print(str(user) + " won't be deleted.") else: Loading @@ -360,7 +363,7 @@ def deleteMenu(deleteArray): except KeyError: print("\x1b[1;31mInvalid user.\x1b[0m") deleteMenu(deleteArray) elif (option == "3"): elif option == "3": for student in studentsBad: print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1])) deleteArray.append(student[0]) Loading @@ -371,18 +374,19 @@ def deleteMenu(deleteArray): print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1])) deleteArray.append(ass[0]) deleteMenu(deleteArray) elif (option == "3.1"): elif option == "3.1": for student in studentsBad: print("Adding " + str(student[0]) + " to the list because the DB says: " + str(student[1])) deleteArray.append(student[0]) elif (option == "9"): elif option == "9": print("Nope not yet") deleteMenu(deleteArray) elif (option == "0"): elif option == "0": mainMenu() else: deleteMenu(deleteArray) def deleteAccounts(): # list that store usernames to be deleted # gets reset everytime you go into this bit on purpose Loading @@ -392,7 +396,8 @@ def deleteAccounts(): ### MAIN ### if (os.geteuid() == 0): if os.geteuid() == 0: print("\x1b[1;31mDon't run this as root!\x1b[0m") sys.exit(1) Loading