# -*- coding:utf-8 -*-
import sys, httplib, urllib, re, string, hashlib
from PyQt4 import QtCore, QtGui
class MyConnection(httplib.HTTPConnection):
def __init__(self, username, password):
httplib.HTTPConnection.__init__(self, "www.cc98.org")
self.username = username
self.password = password
def setPasswd(self, passwd):
self.passwd = passwd
def setCookie(self, cookie):
self.cookie = cookie
def setUrlAndContent(self, url, content, time, times):
self.url = url.replace("http://www.cc98.org", "")
self.url = url.replace("http://10.10.98.98", "")
self.time = string.atoi(time, 10)
self.content = content
self.times = string.atoi(times, 10)
def setContentform(self, contentform):
self.contentform = contentform
self.Content_Length = contentform.__len__()
def getUsernameAndPassword(self):
return self.username, self.password
def getUsernameAndPasswd(self):
return self.username, self.passwd
def getContentform(self):
return self.contentform, self.Content_Length
def getUrlAndContent(self):
return self.url, self.content, self.time, self.times
def getConnPara(self):
return self.url, self.contentform, self.Content_Length, self.times, self.time, self.cookie
def getCookie(self):
return self.cookie
def setBoardid(self, boardid):
self.boardid = boardid
def getBoardid(self):
return self.boardid
class loginInfo(QtCore.QThread):
def __init__(self, conn, parent):
QtCore.QThread.__init__(self, parent)
self.conn = conn
self.username, self.password = self.conn.getUsernameAndPassword()
def run(self):
mutex2.lock()
self.status = self.getConnection()
mutex2.unlock()
def getConnection(self):
md5passwd = hashlib.md5(self.password).hexdigest()
self.passwd = md5passwd[8:24]
self.conn.setPasswd(self.passwd)
self.conn = httplib.HTTPConnection("www.cc98.org")
self.conn.putrequest("GET", "/index.asp")
self.conn.endheaders()
res = self.conn.getresponse()
res.read()
self.cookie = res.getheader("set-cookie")
sessionlist = re.findall(r"ASPSESSION.*(?=; path=/)", self.cookie)
session = sessionlist[0]
self.cookie = "BoardList=BoardID=Show; " + session
data = urllib.urlencode({"a":"i", "u":self.username, "p":md5passwd, "userhidden":"2"})
Content_Length = data.__len__()
self.conn.putrequest("GET", "/sign.asp")
self.conn.putheader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
self.conn.putheader("Cookie", self.cookie)
self.conn.putheader("Content-Length", str(Content_Length))
self.conn.endheaders()
self.conn.send(data)
res = self.conn.getresponse()
if res.read() != "9898":
return False
userinfo = re.findall(r"aspsky.*?(?=;\s)", res.getheader("set-cookie"))
self.cookie = "BoardList=BoardID=Show; upNum=0; " + session + "; " + userinfo[0]
return True
def getStatus(self):
return self.status
def getCookie(self):
return self.cookie
class ConnectionInfo(QtCore.QThread):
cookie = ""
def __init__(self, conn, parent):
QtCore.QThread.__init__(self, parent)
self.flag = False
self.conn = conn
self.cookie = self.conn.getCookie()
self.username, self.passwd = self.conn.getUsernameAndPasswd()
self.url, self.content, self.time, self.times = self.conn.getUrlAndContent()
self.count = 0;
def run(self):
mutex.lock()
self.status = self.connectUrl()
self.count = self.count + 1
mutex.unlock()
def getStatus(self):
return self.status
def connectUrl(self):
try:
self.conn.putrequest("GET", self.url)
self.conn.putheader("Cookie", self.cookie)
self.conn.endheaders()
res = self.conn.getresponse()
pageMsg = res.read()
if res.status != 200:
return 0
boardid = re.findall("(?<=boardid=)\d+", self.url, re.IGNORECASE)
self.boardid = boardid[0]
temp = re.findall("(?<=<input type=hidden name=\"followup\" value=\")\d+", pageMsg, re.IGNORECASE)
followup = temp[0]
temp = re.findall("(?<=<input type=hidden name=\"RootID\" value=\")\d+", pageMsg, re.IGNORECASE)
RootID = temp[0]
temp = re.findall("(?<=<input type=hidden name=\"star\" value=\")\d+", pageMsg, re.IGNORECASE)
star = temp[0]
temp = re.findall("(?<=<input type=hidden name=\"TotalUseTable\" value=\")bbs\d+", pageMsg, re.IGNORECASE)
TotalUseTable = temp[0]
self.contentform = urllib.urlencode({"followup":followup, "RootID":RootID, "star":star, "TotalUseTable":TotalUseTable, "UserName":self.username, "passwd":self.passwd, "Expression":"face7.gif", "Content":self.content, "Button":"预 览", "signflag":"yes"})
self.conn.setContentform(self.contentform)
self.conn.setBoardid(boardid)
except IndexError:
return 1
return 2
class SendData(QtCore.QThread):
def __init__(self, conn, parent):
QtCore.QThread.__init__(self, parent)
self.mutex = QtCore.QMutex()
self.conn = conn
self.url, self.contentform, self.Content_Length, self.times, self.time, self.cookie = self.conn.getConnPara()
self.flag = True
self.isExit = False
self.boardid = self.conn.getBoardid()
def startSend(self):
self.conn.putrequest("POST", "/SaveReAnnounce.asp?method=fastreply&BoardID=" + str(self.boardid[0]))
self.conn.putheader("Referer", "http://www.cc98.org" + self.url)
self.conn.putheader("Cookie", self.cookie)
self.conn.putheader("Content-Type", "application/x-www-form-urlencoded")
self.conn.putheader("Content-Length", str(self.Content_Length))
self.conn.endheaders()
self.conn.send(self.contentform)
res = self.conn.getresponse()
res.read()
QtCore.QThread.sleep(self.time)
def run(self):
self.mutex.lock()
if self.times != -1:
cnt = 0
while cnt < self.times:
if self.isExit == True:
break
if self.flag == True:
self.emit(QtCore.SIGNAL("restored()"))
self.startSend()
cnt = cnt + 1
self.emit(QtCore.SIGNAL("finishOnce()"))
else:
self.emit(QtCore.SIGNAL("Paused()"))
else:
while True:
if self.isExit == True:
break
if self.flag == True:
self.emit(QtCore.SIGNAL("restored()"))
self.startSend()
self.emit(QtCore.SIGNAL("finishOnce()"))
else:
self.emit(QtCore.SIGNAL("Paused()"))
self.mutex.unlock()
def pause(self):
self.flag = False
def stop(self):
self.isExit = True
def restore(self):
self.flag = True
class MyWindow(QtGui.QMainWindow):
sd = None
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowTitle("CC98灌水机 by flykite")
self.resize(500, 300)
self.widget = QtGui.QWidget()
self.setCentralWidget(self.widget)
self.addMenuBar()
self.doLayout()
self.addStatusBar()
def addMenuBar(self):
helpMenu = self.menuBar().addMenu("帮助(&H)")
aboutAction = QtGui.QAction("关于(&A)", self)
aboutQtAction = QtGui.QAction("关于Qt(&Q)", self)
self.connect(aboutAction, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("about()"))
s