Posted by snitzlocation on March Fri 16th 10:46 PM - Never Expires
download | new post
- #!/usr/bin/env python
- # snitzloc.py
- # Original script by Family_Guy (lhschris@gmail.com)
- # Script modified by Jorge Pena/Blank Denim (jorgepblank@gmail.com)
- # New Features:
- # -Authentication of user login details
- # -Command line execution with parameters
- # -Usable with any snitz forum (Unless it's somehow patched)
- import httplib, urllib, urllib2, cookielib, webbrowser, time, os, sys
- print "Snitz Location Changer by Jorge Pena"
- print "Base Code by Family Guy"
- def InstallOpener():
- new_jar = cookielib.LWPCookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(new_jar))
- urllib2.install_opener(opener)
- print "* Opener Installed"
- def CreateCookie(username, password, site):
- request = urllib2.Request(site + "/pop_profile.asp?mode=Edit", None)
- grab = urllib2.urlopen(request)
- grab.close()
- data = urllib.urlencode({"Name": username, "Password" : password})
- request = urllib2.Request(site + "/pop_profile.asp?mode=goEdit", data)
- print "* Cookie Created"
- return request
- def Authenticate(request):
- grab = urllib2.urlopen(request)
- html = grab.read()
- grab.close()
- page = open("page.html", "w+")
- page.write(html)
- page.close()
- # Check if authentication worked
- checkpage = open("page.html", "r")
- checklines = checkpage.readlines()
- if "Invalid" in checklines[97]:
- print "Invalid Username or Password, aborting..."
- print "Removing \"page.html\"..."
- checkpage.close()
- os.remove("page.html")
- print "Exiting..."
- sys.exit()
- else:
- print "* Authenticated"
- def EditProfile():
- page_two = open("page.html", "r")
- lines = page_two.readlines()
- page_two.close() #close the page
- os.remove("page.html") #remove the page
- new_add = ' <option selected value="%s">%s</option>' % (new_location, new_location)
- lines[201] = new_add
- lines[97] = ' <p align="center"><form action="' + site + '/pop_profile.asp?mode=EditIt" method="Post" id="Form1" name="Form1">'
- num = 0
- print "* Profile edited"
- return lines
- def SaveProfile(lines):
- num = 0
- test_file = open("profile.html", "w")
- line_c = len(lines)
- while num <line_c:
- test_file.write(lines[num])
- num+=1
- test_file.close()
- print "* Buffer saved"
- if __name__ == "__main__":
- if len(sys.argv)> 1:
- if sys.argv[1] == "--help" or sys.argv[1] == "-h":
- print "USAGE: snitzloc.py [URL] [USER] [PASS] [LOC]"
- print " [URL] - The URL to the forum without a trailing backslash. For example http://www.jinx.com/forum"
- print " [USER] - Your UserName in the forum."
- print " [PASS] - Your PassWord in the forum."
- print " [LOC] - Your desired location."
- sys.exit()
- site = sys.argv[1]
- username = sys.argv[2]
- password = sys.argv[3]
- new_location = sys.argv[4]
- else:
- site = raw_input( "Path to Forum (Ex. http://www.jinx.com/forum): ")
- username = raw_input("Username: ")
- password = raw_input("Password: ")
- new_location = raw_input("Desired location: ")
- InstallOpener()
- Authenticate(CreateCookie(username, password, site))
- SaveProfile(EditProfile())
- print "[NOTE] Open up \"profile.html\" and click \"submit\" to finish."
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.