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.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by frymaster on Fri 29th Jan 18:33
download | new post

  1. #!/bin/python
  2. import urllib,MySQLdb,re
  3. forumdb = MySQLdb.connect(host="localhost", user="ausername", passwd="apassword",db="adatabase")
  4. cursor = forumdb.cursor()
  5. forumCookie = re.compile(".*nervousenergyforumsv1=(?P<cookie>.*?)($|;)")
  6. forumDetails = re.compile("s:[0-9]+:\"(?P<uid>[0-9]+)\";i:[0-9]+;s:40:\"(?P<hash>[0-9a-f]+)\";")
  7. memberQuery="select id_group,additional_groups from smf_members where id_member=%s and sha1(concat(passwd , password_salt))=%s;"
  8. allowedGroup=(24,)
  9.  
  10. def checkAuth(req):
  11.         cookie = forumCookie.search(req.headers_in["Cookie"])
  12.         if cookie:
  13.                 cookieData = urllib.unquote(cookie.group("cookie"))
  14.                 memberDetails = forumDetails.search(cookieData)
  15.                 if memberDetails:
  16.                         uid = int(memberDetails.group("uid"))
  17.                         hash = memberDetails.group("hash")
  18.                         cursor.execute(memberQuery,(uid,hash))
  19.                         result = cursor.fetchone()
  20.                         if result:
  21.                                 if result[0] in allowedGroup:
  22.                                         return True
  23.                                 else:
  24.                                         if not result[1]=="":
  25.                                                 for group in [int(x) for x in result[1].split(",")]:
  26.                                                         if group in allowedGroup:
  27.                                                                 return True
  28.         return False
  29.  
  30. def index(req):
  31.         if checkAuth(req):
  32.                 return "Allowed"
  33.         return "If your name's not down, you're not getting in"

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.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings