pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python PasteBin - Home - Help - Archive

Posted by snitzlocation on March Fri 16th 10:46 PM - Never Expires
download | new post

  1. #!/usr/bin/env python
  2. # snitzloc.py
  3. # Original script by Family_Guy (lhschris@gmail.com)
  4. # Script modified by Jorge Pena/Blank Denim (jorgepblank@gmail.com)
  5. # New Features:
  6. # -Authentication of user login details
  7. # -Command line execution with parameters
  8. # -Usable with any snitz forum (Unless it's somehow patched)
  9. import httplib, urllib, urllib2, cookielib, webbrowser, time, os, sys
  10. print "Snitz Location Changer by Jorge Pena"
  11. print "Base Code by Family Guy"
  12. def InstallOpener():
  13.         new_jar = cookielib.LWPCookieJar()
  14.         opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(new_jar))
  15.         urllib2.install_opener(opener)
  16.         print "* Opener Installed"
  17. def CreateCookie(username, password, site):
  18.         request = urllib2.Request(site + "/pop_profile.asp?mode=Edit", None)
  19.         grab = urllib2.urlopen(request)
  20.         grab.close()
  21.         data = urllib.urlencode({"Name": username, "Password" : password})
  22.         request = urllib2.Request(site + "/pop_profile.asp?mode=goEdit", data)
  23.         print "* Cookie Created"
  24.         return request
  25. def Authenticate(request):
  26.         grab = urllib2.urlopen(request)
  27.         html = grab.read()
  28.         grab.close()
  29.         page = open("page.html", "w+")
  30.         page.write(html)
  31.         page.close()
  32.         # Check if authentication worked
  33.         checkpage = open("page.html", "r")
  34.         checklines = checkpage.readlines()
  35.         if "Invalid" in checklines[97]:
  36.                 print "Invalid Username or Password, aborting..."
  37.                 print "Removing \"page.html\"..."
  38.                 checkpage.close()
  39.                 os.remove("page.html")
  40.                 print "Exiting..."
  41.                 sys.exit()
  42.         else:
  43.                 print "* Authenticated"
  44. def EditProfile():
  45.         page_two = open("page.html", "r")
  46.         lines = page_two.readlines()
  47.         page_two.close() #close the page
  48.         os.remove("page.html") #remove the page
  49.         new_add = '                                <option selected value="%s">%s</option>' % (new_location, new_location)
  50.         lines[201] = new_add
  51.         lines[97] = '   <p align="center"><form action="' + site + '/pop_profile.asp?mode=EditIt" method="Post" id="Form1" name="Form1">'
  52.         num = 0
  53.         print "* Profile edited"
  54.         return lines
  55. def SaveProfile(lines):
  56.         num = 0
  57.         test_file = open("profile.html", "w")
  58.         line_c = len(lines)
  59.         while num <line_c:
  60.                 test_file.write(lines[num])
  61.                 num+=1
  62.         test_file.close()
  63.         print "* Buffer saved"
  64. if __name__ == "__main__":
  65.         if len(sys.argv)> 1:
  66.                 if sys.argv[1] == "--help" or sys.argv[1] == "-h":
  67.                         print "USAGE: snitzloc.py [URL] [USER] [PASS] [LOC]"
  68.                         print " [URL]  - The URL to the forum without a trailing backslash. For example http://www.jinx.com/forum"
  69.                         print " [USER] - Your UserName in the forum."
  70.                         print " [PASS] - Your PassWord in the forum."
  71.                         print " [LOC]  - Your desired location."
  72.                         sys.exit()
  73.                 site = sys.argv[1]
  74.                 username = sys.argv[2]
  75.                 password = sys.argv[3]
  76.                 new_location = sys.argv[4]
  77.         else:
  78.                 site = raw_input( "Path to Forum (Ex. http://www.jinx.com/forum): ")
  79.                 username = raw_input("Username: ")
  80.                 password = raw_input("Password: ")
  81.                 new_location = raw_input("Desired location: ")
  82.         InstallOpener()
  83.         Authenticate(CreateCookie(username, password, site))
  84.         SaveProfile(EditProfile())
  85.         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.
Syntax Highlighting:
To highlight particular lines, prefix each line with @@
Pressing TAB inserts 3 spaces