#!/usr/bin/python # PynBB Version 0.0.1 (Alpha) Python Interface PunBB Forum # Autor: Alberto Isaac Ayala Esquivias (Albertux) # Web: [http://albertux.ayalasoft.com] # FeedBack: # License: GPLv3 [http://www.gnu.org/licenses/gpl-3.0.txt] # BEGIN OF EDITABLE OPTIONS # ################################################################### HOST = "" # PunBB WebSite without http:// and slashes PATH = "" # Example: domain.com/forum PATH ="/forum" USER = "" # Your Username (Important: case sensitive) PASS = "" # Your Password ################################################################### # END OF EDITABLE OPTIONS # # DO NOT EDIT BELOW THIS LINE # ################################################################### FORUM = "/post.php?fid=" TOPIC = "/post.php?tid=" import httplib, urllib, getpass, re, sys params,headers = {},{} # Login function to PunBB Forums def Login(): conn = httplib.HTTPConnection(HOST) params = urllib.urlencode({'form_sent': 1,'req_username': USER, 'req_password': PASS}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn.request("POST",PATH+"/login.php?action=in", params, headers) response = conn.getresponse() cookie = response.getheader('set-cookie') conn.close() return cookie # Write new post (new topic) def PostForum(fid, subject, message): conn = httplib.HTTPConnection(HOST) params = urllib.urlencode({'form_sent': 1,'form_user': USER, 'req_subject': subject, 'req_message': message}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain", "Cookie": cookie} conn.request("POST", PATH+FORUM+str(fid), params, headers) response = conn.getresponse() if response.status == 200: print "\n\n(+) Done.\n" conn.close() # Write new post on Topic def PostTopic(tid, message): conn = httplib.HTTPConnection(HOST) params = urllib.urlencode({'form_sent': 1,'form_user': USER, 'req_message': message}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain", "Cookie":cookie} conn.request("POST", PATH+TOPIC+str(tid), params, headers) response = conn.getresponse() if response.status == 200: print "\n\n(+) Done.\n" conn.close() # Download function def Down(host, path): params,headers = {},{} conn = httplib.HTTPConnection(host) conn.request('GET', PATH+path, params, headers) response = conn.getresponse() page = response.read() conn.close() return page # Display All Main Forums def ShowForums(d): j=0 fids = {} k= d.keys() print "" for i in k: if ((j)%10==0 and j>0): print "" x = raw_input("Press enter to show more forums\nOr write forum number: ") if x != "": return fids[int(x)-1] print "" print str(j+1)+') '+d[i] fids[j]=i j+=1 print "" fid = int(raw_input("Forum: ")) fid = fids[fid-1] return fid # Display SubForums using fid def SubForumsList(fid): i,j=0,0 d = {} page = Down(HOST,'/viewforum.php?id='+str(fid)) lineas = page.split("\n") total = len(lineas) while i < total: index = lineas[i].find('viewtopic.php?id=') if index > -1: fids = lineas[i].split('viewtopic.php?id=') fids = fids[1].split('">') nombres = fids[1].split(" -1: fids = lineas[i].split('viewforum.php?id=') fids = fids[1].split('">') nombres = fids[1].split("") total = len(posts) while i < total: index = posts[i].find("
") if index > -1: p = posts[i].split("
") tags = re.compile('<.*?>',re.S) print tags.sub('',p[0]) i+=1 # Read Forum def ReadForum(): forumlist=ForumList() fid=ShowForums(forumlist) d = SubForumsList(fid) fid =ShowForums(d) ViewForum(fid) x = raw_input("Write on this topic (y/n): ") if x =="y" or x =="Y": print "" message = raw_input("(+) Write your message: ") PostTopic(fid,message) MainMenu() # Write new post def WritePost(): forumlist=ForumList() fid=ShowForums(forumlist) print "" subject = raw_input("(+) Write your subject: ") message = raw_input("(+) Write your message: ") PostForum(fid,subject,message) MainMenu() # About def About(): print """ PyPunBB Version 0.0.1 (Alpha) Python Script Interface PunBB Forum Autor: Alberto Isaac Ayala Esquivias (Albertux) Web: [http://albertux.ayalasoft.com] FeedBack: License: GPLv3 [http://www.gnu.org/licenses/gpl-3.0.txt] """ # MainMenu def MainMenu(): print "PyPunBB v0.0.1 (Alpha) [http://"""+HOST+PATH+"""] Welcome """+USER+""" a) About w) Write Post r) Read Forums e) Exit""" op = raw_input("Option: ") if (op=="w" or op=="W"): WritePost() if (op=="r" or op=="R"): ReadForum() if (op=="a" or op=="A"): About() MainMenu() if (op=="e" or op=="E"): sys.exit() if HOST is "" or PATH is "" or USER is "" or PASS is "": print "To made this script work you need\nEdit this script on EDITABLE OPTIONS" About() sys.exit() else: cookie=Login() if (cookie): MainMenu() else: print "Wrong user or password"