#!/usr/bin/env python # Offender List Manager import os import re import sys import time import fcntl import string import getpass import smtplib # ---------------------------------------------------------------------------- # CONFIG: List of offender files to search # First entry is the one to update with new entries offFiles = [ "/public/groups/helpdesk/data/offences.txt" ] # CONFIG: Where can I find student numbers studNumFile = "/public/groups/helpdesk/data/student-list" # CONFIG: Offences, descriptions, whether the offence warrants instant # suspension offence = [ [ "Unplugging equipment", """ Interfering with equipment (i.e. unplugging terminals to power your laptop) deprives other users of those resources, particularly when you forget to plug them back in when you're finished. Spare power sockets are available in the Games lab, the Caf and the library. """, 1 ], [ "Leaving terminal logged in and unattended", """ Leaving your account logged in and unattended allows others to gain inappropriate access to the contents of your account by using the computer while you are not there. During this time it is possible for a malicious user to adjust permissions on your files or change your passwords, both of which compromise the security of your data. """, 1 ], [ "Changing proxies to use webmail", """ Changing the proxies to access Hotmail or any other non-RMIT web-based email service is categorised as an abuse of resources. Such web-based email services make up a large portion of RMITCS's internet service costs. Student EMS is RMIT's official student email service. """, 1 ], [ "Using instant messaging application", """ Using chat clients including, but not restricted to ICQ, Trillian, AIM or any other instant messaging clones is categorised as an abuse of resources. """, 1 ], [ "Printing non-CS material", """ The Computer Science printers are for printing only Computer Science course-related materials. There are printing facilities in the library and other departments for printing non-Computer Science work. """, 0 ], [ "Abuse of printer resources", """ Printing large amounts of material from Computer Science printers. This act is grossly unfair considering that other students also need to use the resources. It also is a waste of Computer Science resources, considering that the department has to pay for unnessary print jobs. """, 0 ], # This offence is more aimed at bundoora students as some think that # since there is no printing accounts they can print whatever they want # A warning for a first offence then suspend after that [ "Changing system settings", """ The alteration of system settings, such as installation of hardware or software without permission from the TSG is forbidden in the Computer Science department. """, 1 ], [ "Terminal/workstation locking", """ Terminal locking is categorised as an abuse of resources. This act is grossly unfair considering that other students also need the resources. """, 0 ], [ "Eating/drinking in lab", """ Eating or drinking in the Computer Science laboratories is forbidden. Food and drink can cause damage to the equipment, and can also leave the environment unpleasant for students using it after you. """, 0 ], [ "Account sharing", """ For security reasons, account sharing is prohibited at RMIT. """, 1 ], [ "Downloading offensive materials", """ Downloading or viewing of offensive materials at uni is considered a waste of resources, as well as being insulting to students around you. """, 1 ], [ "Downloading MP3s or other non-course related material", """ Downloading MP3s or other non-course related materials is categorised as an abuse of resources. """, 1 ], [ "Playing games in Computer Science lab", """ Playing games is categorised as an abuse of resources. This act is grossly unfair considering that other students also need to use the resources. """, 1 ], [ "Failure to return loaned equipment on time", """ The equipment you have borrowed from the Helpdesk is for all students to use. By not returning the equipment on time, you may have greatly inconvenienced another student. Please ensure that this equipment is returned on time in the future. """, 1 ], [ "After hours access violation", """ You were found to be in an after hours access area without a valid access card. """, 0 ], [ "Training new staff", """ This is just a message for training new staff. They know nothing. """, 0 ], [ "Other", """Replace this """,0 ] ] # CONFIG: Format of the email sent to student, helpdesk and TSG student_email = [ [ "$SN$ <$SN$@student.rmit.edu.au>", "$USER$ <$USER$@yallara.cs.rmit.edu.au>" ], """To: $USER$ From: CS Duty Programmers Subject: $SUB$ Dear CS accountholder, You are receiving this email because you have violated an element of the RMITCS Acceptable Use Policy (AUP). OFFENCE: $OFF$ DETAILS: $PRI$ CONSEQUENCE: $SEC$ -- Regards, CS Duty Programmers """ ] warn_email = ''' This is a warning only. Access to your CS accounts has not been modified, however further breaches may result in suspension or termination of your CS account privileges. You are strongly encouraged to review the AUP, available online: http://www.cs.rmit.edu.au/rules/acceptable-use.shtml ''' sus_email = ''' Access to your CS accounts will be suspended. What you must do to restore your access depends on the nature of your breach. If this suspension is due to leaving your terminal unattended and you have not committed this offence previously, simply visit the Duty Programmers' desk with photo ID to reset your Yallara, Numbat and Blowfly passwords. In all other cases you will need to mail suspended@cs.rmit.edu.au and arrange a consultation with a TSG staff member. ''' helpdesk_email = [ [ "CS Duty Programmer ", "$TSG$" ], """X-Sender: $HD$@cs.rmit.edu.au From: CS Duty Programmers To: CS Duty Programmers Subject: OFFENDER: - $USER$ - $OFF$ $REQUEST$ $REQUEST$ $USER$ - $OFF$ $COMM$ (Past Offences) $PREV$ -- Thanks! $DP$ """ ] # CONFIG: the number of emails to send emails = [ student_email, helpdesk_email ] # ---------------------------------------------------------------------------- # main code if __name__ == '__main__': PRI = "" SEC = "" SUB = "" PREV = "" what_done = "" action = "" send2tsg = "no" instagib = 0 #-------------------------------------------------------------------------- username = "" if len(sys.argv) == 2: # name of user from command line username = sys.argv[1] else: # get name of user username = raw_input("Username of offender: ") if len(username) == 0: print "Cancelled" sys.exit(1) # toAddy = [ "%s <%s@yallara.cs.rmit.edu.au>" % (username, username) ] # hdAddy = [ "CS Helpdesk " ] # print user's student number student_number = "" file = open(studNumFile, "r") # run through the list and print all this user's naughtiness for line in file.readlines(): line = string.split(line, ":") if line[0] == username: student_number = line[1] break elif line[1] == username: # user put student number on command line student_number = line[1] username = line[0] elif username == line[1][0:-1]: student_number = line[1] username = line[0] file.close() # remove the last letter if it exists if len(student_number) > 0: if student_number[-1] in string.ascii_letters: student_number = student_number[0:-1] # Fix for single subject students student_number = student_number.lstrip('Ss') print "Username: ", username if len(student_number) > 0: print "Student number: ", student_number else: print "No student number found! Press Ctrl-C if they should have one!" print # Look thru each of the offender files for filename in offFiles: file = open(filename, "r") # run through the list and print all this user's naughtiness regex = re.compile("^"+username+"\s") for line in file.readlines(): if regex.search(line): # We don't need to see the username on each line line = re.sub('^%s\s+' % username, '', line) print line, PREV = PREV + line file.close() #---------------------------------------------------------------------- # Prompt for latest offence print cnt = 1 for o in range(len(offence)): print "%s)\t%s" % (cnt, offence[o][0]) cnt = cnt + 1 print sel = "" while 1: try: sel = raw_input("Please enter the number of the offence: ") if len (sel) == 0: 1/0 sel = int(sel)-1 except: print "\nCancelled" sys.exit(1) if (sel <= len(offence)-1) & (sel >= 0): break if (sel != len(offence)-1): what_done = offence[sel][0] PRI = offence[sel][1] instagib = offence[sel][2] else: what_done = raw_input("One-liner (seen by student) ") PRI = raw_input("Please elaborate (seen by student) ") instagib = 0 if instagib == 0: # prompt for warn or suspend print "1)\tWarn\n2)\tSuspend\n" sel = "" while 1: try: sel = raw_input("Please enter your action: ") if len (sel) == 0: 1/0 sel = int(sel)-1 except: print "\nCancelled" sys.exit(1) if (sel >= 0 ) & (sel <2): if sel == 1: action = "suspend" else: action = "warn" break else: # instagib - impressive! print "instagib offence - suspending\n" action = "suspend" # new! if action is suspend, do you want to send to tsg if action == "suspend": SEC = sus_email sel = "" while 1: try: sel = raw_input("Should I send an email to TSG [Y/n] ") if len (sel) == 0: 1/0 except: send2tsg = "yes" break if (sel[0] == 'Y') | (sel[0] == 'y'): send2tsg = "yes" break elif (sel[0] == 'N') | (sel[0] == 'n'): send2tsg = "no" break else: print "Fool, type yes or no!" else: SEC = warn_email # new! any extra comments for newOffendersfile & helpdesk/tsg email print "Please mention websites they visited, instant messenger app, etc..." extra_com = raw_input("Any extra comments (not seen by student): ") #---------------------------------------------------------------------- # Grab the Date Of Offence DOO = time.strftime("%Y-%m-%d", time.localtime(time.time())); # Grab the helpdesk user name dp_user = getpass.getuser() if action == "suspend": act = 'S' else: act = 'W' if extra_com != "": com = " [%s]" % extra_com else: com = "" # Lock the file and write the data try: # open the file file = open(offFiles[0], "a+") off_str = '%-8s %-10s %1s %-8s %s%s\n' % (username, DOO, act, dp_user, what_done, com) file.write(off_str) file.close() except: print "Someone else is using the system - please try again shortly" file.close() sys.exit(1) # wreitten the data to the file # now send emails to relevant people fromAddy = "CS Duty Programmer " server = smtplib.SMTP('yallara.cs.rmit.edu.au') # server.set_debuglevel(1) for e in emails: toAddy = [] addy = e[0] # who to send email to email = e[1] # the email to send them # modify the send to string for item in addy: item = re.sub("\$USER\$", username, item) item = re.sub("\$SN\$", "s%s" % student_number, item) if send2tsg == "yes": item = re.sub("\$TSG\$", "TSG ", item) else: item = re.sub("\$TSG\$", "", item) toAddy.append(item) # Some slot-in text has superfluous leading/trailing newlines due # to the way this text is defined above. PRI = re.sub('^\n', '', PRI) PRI = re.sub('\n$', '', PRI) SEC = re.sub('^\n', '', SEC) SEC = re.sub('\n$', '', SEC) # modify the email to have correct content email = re.sub("\$USER\$", username, email) email = re.sub("\$HD\$", dp_user, email) email = re.sub("\$PRI\$", PRI, email) email = re.sub("\$SEC\$", SEC, email) email = re.sub("\$OFF\$", what_done, email) email = re.sub("\$COMM\$", extra_com, email) email = re.sub("\$DATE\$", DOO, email) email = re.sub("\$DP\$", dp_user, email) email = re.sub("\$SN\$", "s%s" % student_number, email) email = re.sub("\$ACT\$", action, email) email = re.sub("\$PREV\$", PREV, email) email = re.sub('\n{3,}', '\n\n', email) if action == "warn": email = re.sub("\$SUB\$", "Account warning (%s)" % (what_done), email) email = re.sub("\$REQUEST\$", "WARNING ONLY", email) else: email = re.sub("\$SUB\$", "Account suspension (%s)" % (what_done), email) email = re.sub("\$REQUEST\$", "Please suspend", email) # print toAddy # print email # print "\n\n" # send the email server.sendmail(fromAddy, toAddy, email) server.quit() print "You just off'd %s for %s" % (username, what_done) sys.exit(0)