def sendMessage(userDict, inputList): import datetime if len(inputList) < 2: print "Not enough input for this function!" return username = inputList[0] message = inputList[1] status = userDict.get("status", "guest") if meetsReqs(status, "member") >= 0: users = accountUtilities.masterDict("userInfo.txt") userID = -1 for i in users.keys(): if users[i].get("uname", "") == username: userID = users[i].get("id", -1) if userID < -1: print "The user could not be found." return today = datetime.datetime.today() amOrpm = "AM" if (today.hour) / 12 > 0: amOrpm = "PM" today = "<i>%02d/%d/%04d %d:%02d %s</i> " % (today.month, today.day, today.year, today.hour % 12, today.minute, amOrpm) if accountUtilities.addToUserInfo( "\nPM", "<b>%s</b> (%s): " % (userDict.get('uname', ''), today) + message, userID): print "PM sent!" else: print "PM could not be sent." else: print "Sorry, this action can only be performed by Members+."
def main(): print "Content-type: text/html\n" print "<html><head><link rel = http://marge.stuy.edu/~ricky.chen/foxy.css></head>\n<body>" form = cgi.FieldStorage() allFuncts = { "addCategory": addCategory, "promoteUser": promoteUser, "viewMessages": viewMessages, "sendMessage": sendMessage, "demoteUser": demoteUser, "seeReports": seeReports, "closeThread": closeThread, "seeUserPosts": seeUserPosts, "makeReportThread": makeReportThread } if "runFunction" in form: functionToRun = form.getvalue("runFunction") if "inputs" in form: #NOTE THAT WE EXPECT A STRING OR A LIST HERE inputs = form.getvalue("inputs") userID = -1 if "userID" in form: userID = form.getvalue("userID") if type(userID) == type("") and userID.isdigit(): userID = int(userID) else: userID = -1 users = accountUtilities.masterDict("userInfo.txt") #print str(users) + "<br>" proceed = True userDict = {} if userID in users: userDict = users[userID] else: print "Your account isn't recognized by the control panel. Make sure you're signed in." proceed = False if proceed: if type(inputs) != type([]) and type(inputs) != type((2, 3)): inputs = [inputs] elif type(inputs) == type((2, 3)): inputs = list(inputs) else: for i in range(len(inputs)): inputs[i] = str(inputs[i]) if functionToRun in allFuncts: #print "Function is being called!" allFuncts[functionToRun](userDict, inputs) else: print "The function called is not valid." else: print "Not enough information sent for the function to be performed. Make sure all forms are filled in." else: print "No request sent!" print '''<form method = get action = openSite.py> <input type = hidden name = toSite value = forumHome.html> <input type = submit value = "Forum Home"> </form>''' print "</body></html>"
def main2(form): print "Content-type:text/html\n" print "<html>\n<body>" #form = cgi.FieldStorage() allFuncts = { "addCategory": addCategory, "promoteUser": promoteUser, "makeReportThread": makeReportThread, "demoteUser": demoteUser, "seeReports": seeReports, "closeThread": closeThread, "seeUserPosts": seeUserPosts } if "runFunction" in form: functionToRun = form.get("runFunction", "") if "inputs" in form: #NOTE THAT WE EXPECT A STRING OR A LIST HERE inputs = form.get("inputs", "") userID = -1 if "userID" in form: userID = form.get("userID", "") #print userID if type(userID) == type("") and userID.isdigit(): userID = int(userID) else: userID = -1 users = accountUtilities.masterDict("userInfo.txt") proceed = True userDict = {} if userID in users: userDict = users[userID] else: print "Your account isn't recognized by the control panel. Make sure you're signed in." proceed = False if proceed: if type(inputs) != type([]) and type(inputs) != type((2, 3)): inputs = [inputs] elif type(inputs) == type((2, 3)): inputs = list(inputs) else: for i in range(len(inputs)): inputs[i] = str(inputs[i]) if functionToRun in allFuncts: allFuncts[functionToRun](userDict, inputs) else: print functionToRun print "not recognized" print "</body></html>"
def demoteUser(userDict, inputList): if len(inputList) < 1: print "Not enough input for this function!" return username = inputList[0] status = userDict.get("status", "guest") statuses = ["guest", "member", "moderator", "admin", "owner"] diff = meetsReqs(status, "admin") if diff >= 0: users = accountUtilities.masterDict("userInfo.txt") for i in users.keys(): if users[i].get("uname", "member") == username: if meetsReqs(status, users[i].get("status", "member")) > 0: if status in statuses and users[i].get( "status", "member") in statuses: if statuses.index(users[i].get("status", "member")) > 0: users[i]["status"] = statuses[statuses.index( users[i].get("status", "member")) - 1] #print users[i]["status"] #print users if accountUtilities.writeDict( users, "userInfo.txt"): print "Successfully demoted user." if "id" in userDict: accountUtilities.addToUserInfo( "ACTIVITY", "%s: %s has promoted %s to %s." % (makeTimeStamp(), userDict.get("uname", ""), users[i].get("uname", ""), users[i].get("status", "")), userDict["id"]) else: print "Unable to demote user because the file is inaccessible.<br>" else: print "The user's rank was the lowest possible.<br>" else: print "The site couldn't recognize a status given.<br>" else: print "Sorry, that user doesn't have a lower rank than you, so you can't demote them.<br>" break else: print "User " + username + " could not be found." else: print "Sorry, this action can only be performed by Admins+."
def firstLine(userID, threadName, category): import datetime, accountUtilities threadName = "_".join(threadName.split(" ")) category = "_".join(category.split(" ")) today = datetime.date.today() months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] timeInfo = "%s %d, %d" % (months[today.month - 1], today.day, today.year) users = accountUtilities.masterDict("userInfo.txt") if userID in users: timeInfo = "<i>Created by %s on %s</i><br>" % (users[userID].get( "uname", "Guest"), timeInfo) else: timeInfo = "<i>Created by Guest on %s</i><br>" % (timeInfo) #print timeInfo return forumUtilities.addToThread(threadName, category, timeInfo)
def seeUserPosts(userDict, inputList): if len(inputList) < 1: print "Not enough input for this function!" return username = inputList[0] status = userDict.get("status", "guest") if meetsReqs(status, "member") >= 0: users = accountUtilities.masterDict("userInfo.txt") userID = -1 for i in users.keys(): if users[i].get("uname", "") == username: userID = users[i].get("id", -1) if userID < -1: print "The user could not be found." return if meetsReqs(status, users[i].get("status", "guest")) < 0: print "Sorry, you can only see posts by people of the same or lower rank." return allUserPosts = accountUtilities.parseUserInfo(userID) for k in allUserPosts.get("POST", []): print k + "<br>" else: print "Sorry, this action can only be performed by Members+."
def main(): try: print HTML_HEADER form = cgi.FieldStorage() toSite = "" userID = "" if "userID" in form: userID = form.getvalue("userID") if type(userID) == type("") and userID.isdigit(): userID = int(userID) else: userID = -1 else: userID = -1 if "isForum" in form and "category" in form: forumName = form.getvalue( "isForum") #the txt version of it WITH NO FILE EXTENSION users = accountUtilities.masterDict("userInfo.txt") category = form.getvalue("category") if "userPost" in form and userID in users: try: forumContents = form.getvalue("userPost") postBool = True postVal = accountUtilities.parseUserInfo(userID).get( "POST", ["1"])[-1] morePost = "" errormessage = "" #print "THIS IS POST VAL: " + postVal if type(postVal) == type( "" ) and "</font>" in postVal and "in FORUM: " in postVal: try: morePost = postVal[postVal.rfind(" in FORUM: ") + 11:postVal. rfind(" in CATEGORY: ")] postVal = postVal[postVal.find("</font>") + 9:postVal.rfind(" in FORUM: ")] except: postVal = "" #print "THIS IS POST VAL:" + postVal + "." #print "THIS IS FORUMCONTENTS:" + forumContents + "." if postVal == forumContents and morePost == forumName: postBool = False #print postBool if postBool and "".join(forumContents.split()) != "": forumContents = forumUtilities.makePost( users[userID].get("uname", "unknown user"), users[userID].get("status", "guest"), forumContents) #print "HERE ARE THE FORUM CONTENTS " + forumContents #print userID #print accountUtilities.addToUserInfo("\nPOST", " in FORUM: %s in CATEGORY: %s", userID) forumContents = "<br>".join(forumContents.split("\n")) accountUtilities.addToUserInfo( "\nPOST", forumContents + " in FORUM: %s in CATEGORY: %s" % (forumName, category), userID) forumUtilities.post(forumContents, forumName, category) #print forumUtilities.threadHTML(forumName, category,userID) #print forumUtilities.threadHTML(forumName, category,userID) + "OK THATS IT<br><br><br>" except: print "Post could not be made due to an error while testing if it had already been posted. " toSite += forumUtilities.threadHTML(forumName, category, userID) else: if "toSite" in form: toSite = extractHTML(PATH + form.getvalue("toSite"), userID) if "fromSite" in form: back = form.getvalue("fromSite") if "fromCategory" in form: back = "<input type = hidden name = isForum value = %s>\n<input type = hidden name = category value =%s>" % ( back, form.getvalue("fromCategory")) else: back = "<input type=hidden name=toSite value=%s>" % (back) toSite += ''' <form method = get action = openSite.py> %s <input type = submit value = Back> </form>''' % (back) if not ("toSite" in form and form.getvalue("toSite") == "forumHome.html"): toSite += ''' <form method = get action = openSite.py> <input type = hidden name = toSite value = forumHome.html> <input type = submit value = "Forum Home"> </form>''' if toSite == "": showError() else: if "<input type = hidden name = userID" not in toSite: toAdd = ''' <input type = hidden name = userID value = %d> ''' % (userID) #YOU CAN ADD TO TOADD IF YOU WANT TO CREATE MORE BACK BUTTONS toSite = toSite.replace("</form>", "%s\n</form>" % (toAdd)) """if "<input type = hidden name = userID" not in toSite: toSite = toSite.replace("</form>", "<input type = hidden name = userID value = %d>\n</form>"%(userID))""" print toSite except: print HTML_HEADER print HTML_HEADER2 print "An unknown error occured!" print "</body></html>"