Exemplo n.º 1
0
    def sourceToServer(self):
        try:
            # 接收消息头
            socetParser = socetMessageParser()
            hasData = False
            for data in DDDProxySocketMessage.recv(self.localProxy):
                baseServer.log(1, self.threadid, ">>>>>", data, len(data))
                socetParser.putMessage(data)
                if socetParser.messageStatus():
                    self.httpMessage = socetParser.httpMessage()
                    hasData = True
                    break
                self.markActive("recv header")

            if not hasData:
                return False

                # 连接原始服务器
            self.method, path, protocol = self.httpMessage
            if self.method:
                baseServer.log(2, "httpMessage", self.threadid, self.method, path, protocol)
            if self.method == "CONNECT":
                self.httpData = False
                self.openOrignConn("https://" + path)
                baseServer.log(1, self.threadid, "CONNECT ", path)
                DDDProxySocketMessage.send(self.localProxy, "HTTP/1.1 200 OK\r\n\r\n")
            else:
                self.httpData = True
                baseServer.log(1, self.threadid, ">>>>>", "openOrignConn")
                self.openOrignConn(path)
                baseServer.log(1, self.threadid, ">>>>>", socetParser.messageData())
                self.orignConn.send(socetParser.messageData())

            self.lock.put("ok")

            # 转发原始请求到原始服务器
            for data in DDDProxySocketMessage.recv(self.localProxy):
                self.orignConn.send(data)
                self.markActive("localProxy recv")

            self.close()
            return True
        except TypeError:
            pass
        except:
            baseServer.log(3, self.threadid, "sourceToServer error!!!")
        self.lock.put("error")
        self.close()
        return False
Exemplo n.º 2
0
	def serverToSource(self):
		baseServer.log(1, self.threadid, "-<")
		try:
			for data in DDDProxySocketMessage.recv(self.remoteSocket):
				self.source.send(data)
				self.markActive()
				self.domainAnalysisAddData("outgoing", len(data))
		except:
			pass
		baseServer.log(1, self.threadid, "->")
		self.close()
Exemplo n.º 3
0
	def serverToSource(self):
		threading.currentThread().name = "worker%s-%s-recv"%(self.threadid,self.addr)
		baseServer.log(1, self.threadid, "-<")
		try:
			count = 0
			for data in DDDProxySocketMessage.recv(self.remoteSocket):
				self.source.send(data)
				self.markActive()
				length = len(data)
				self.dataCountRecv += length
				count += length
				if self.domainAnalysisAddData("outgoing", count):
					count = 0
		except:
			pass
		threading.currentThread().name = "worker%s-IDLE-recv"%(self.threadid)
		baseServer.log(1, self.threadid, "->")
		self.close()
Exemplo n.º 4
0
	def getInThread(self):
		opt = self.get_argument("opt", default="status")
		if opt:
			opt = opt.encode("utf8")
		
# 		threading.currentThread().name = "statusPage-%s"%(opt)
		if opt == "remoteProxy":
			status = "connected"
			try:
				port = self.get_argument("port", default=0)
				port = port if port else 8083
				test = proxyServerHandler(conn=None, addr=["", ""], threadid=None)
				test.connRemoteProxyServer(host=self.get_argument("host", default=""),
										port=int(port),
										auth=self.get_argument("auth", default=""))
				DDDProxySocketMessage.sendOne(test.remoteSocket, "[%s,%s]" % ("0.0.0.0", "test"))
				DDDProxySocketMessage.sendOne(test.remoteSocket,
															"CONNECT www.google.com:443 HTTP/1.1\r\n\r\n");
				status = "connected,auth no pass"
				for d in  DDDProxySocketMessage.recv(test.remoteSocket):
					if d == "HTTP/1.1 200 OK\r\n\r\n":
						status = "connected"
				test.close()
			except:
				printError()
				status = "can not connect"
			self.write({"status":status})
		elif opt == "pac_setting_test_local":
			self.write({"status":"fail"})
		else:
			working = []
			working.extend(t.name for t in mainThreadPool.working)
			idle = []
			idle.extend(t.name for t in mainThreadPool.waiters)
			
			connectList = {}
			for handler in localProxyServer.theadList:
				try:
					addrList = None
					addr = self.gethostbyaddr(handler.addr)
					if addr in connectList:
						addrList = connectList[addr]
					else:
						connectList[addr] = addrList = []
					addrList.append([handler.httpMessage[1] if (type(handler.httpMessage) == tuple and len(handler.httpMessage) > 2) else handler.httpMessage,
									handler.remoteServer,
									handler.dataCountSend,
									handler.dataCountRecv])
				except:
					printError()
			data = {
				"count":{
						"worker":len(mainThreadPool.working),
						"idle":len(mainThreadPool.waiters)
						},
				"thread":{
# 						"worker":working,
# 						"idle":idle
						"connect":connectList
						}
				}
			self.write(data)
		self.finish()