diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-31 21:06:18 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-31 21:06:18 +0200 |
commit | 3755da2af7e3f79171d505dd81e0c0b63b4adb9f (patch) | |
tree | b2267b76fe897c3c27ce6ed2a019de08c1394647 | |
parent | xupi.in works again (diff) | |
download | pyload-3755da2af7e3f79171d505dd81e0c0b63b4adb9f.tar.xz |
gui socket finally works
-rw-r--r-- | module/remote/ClientHandler.py | 7 | ||||
-rw-r--r-- | module/remote/ClientSocket.py | 36 | ||||
-rw-r--r-- | module/remote/SocketServer.py | 3 | ||||
-rwxr-xr-x | pyMainGui.py | 28 | ||||
-rw-r--r-- | sockettest.py | 18 |
5 files changed, 49 insertions, 43 deletions
diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py index 0037a874e..6f60d5176 100644 --- a/module/remote/ClientHandler.py +++ b/module/remote/ClientHandler.py @@ -12,11 +12,12 @@ from Crypto.Cipher import Blowfish from RequestHandler import RequestHandler class ClientHandler(RequestHandler): - def __init__(self, client): + def __init__(self, client, pw): self.client = client - key = hashlib.sha256("pwhere") + key = hashlib.sha256(pw) self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB) def proceed(self, data): obj = self.decrypt(data) - return self.encrypt(obj)
\ No newline at end of file + #evaluate object + return self.encrypt(obj) diff --git a/module/remote/ClientSocket.py b/module/remote/ClientSocket.py index 30eaf20e0..9c52681c7 100644 --- a/module/remote/ClientSocket.py +++ b/module/remote/ClientSocket.py @@ -8,31 +8,41 @@ socket for connecting to the core's server """ import asynchat import socket +import asyncore +import threading +import time from ClientHandler import ClientHandler +class SocketThread(threading.Thread): + def __init__(self, adress, port, pw, client): + threading.Thread.__init__(self) + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((adress, port)) + self.socket = ClientSocket(sock, pw, client) + self.start() + def run(self): + asyncore.loop() + print "loop closed" + + class ClientSocket(asynchat.async_chat): - def __init__(self, client): - asynchat.async_chat.__init__(self) - self.client = client + def __init__(self, sock, pw, client): + asynchat.async_chat.__init__(self, conn=sock) self.data = "" - self.handler = ClientHandler(None) + self.handler = ClientHandler(client, pw) self.set_terminator("\n") - self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - - def handle_connect(self): - print "connected" + #self.create_socket(socket.AF_INET, socket.SOCK_STREAM) def handle_close(self): print "Disconnected from", self.getpeername() self.close() def collect_incoming_data(self, data): - print "data arrived" self.data += data def found_terminator(self): - obj = self.handler.proceed(data) - self.push(obj) - print "pushed" - data = "" + obj = self.handler.proceed(self.data) + #self.push(obj+"\n") + print "data arrived" + self.data = "" diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py index 817e956aa..e1b41dd1d 100644 --- a/module/remote/SocketServer.py +++ b/module/remote/SocketServer.py @@ -35,6 +35,7 @@ class MainServerSocket(asyncore.dispatcher): def handle_accept(self): newSocket, address = self.accept() print "Connected from", address + print newSocket SecondaryServerSocket(newSocket, self.pycore) def handle_close(self): print "going to close" @@ -54,7 +55,7 @@ class SecondaryServerSocket(asynchat.async_chat): def found_terminator(self): rep = self.handler.proceed(self.data) self.sendall(rep+"\n") - print "push" + print "data arrived" self.data = "" #having fun with the data def handle_close(self): diff --git a/pyMainGui.py b/pyMainGui.py index 2a51fedd5..83dcad885 100755 --- a/pyMainGui.py +++ b/pyMainGui.py @@ -24,11 +24,7 @@ from os.path import dirname import wx import wx.lib.sized_controls as sized_control -from module.remote.ClientSocket import ClientSocket -from Core import Core -#from module.Py_Load_File import PyLoadFile -from module.remote.SocketServer import ServerThread -#from module.thread_list import Thread_List +from module.remote.ClientSocket import SocketThread class _Download_Dialog(sized_control.SizedDialog): def __init__(self, parent, id): @@ -74,17 +70,10 @@ class Pyload_Main_Gui(wx.Frame): wx.Frame.__init__(self, parent, id, title, size=(910, 500)) app_path = dirname(abspath(__file__)) + sep - # Core - testLoader = Core() - if testLoader.config['remote_activated']: - print _("Server Mode") - server = ServerThread(testLoader) - server.start() - # socket - self.socket = ClientSocket(self) - self.socket.connect(('localhost', 7272)) - self.socket.sendall("nonsense\n") + # socket + self.thread = SocketThread("localhost", 7272, "pwhere", self) + self.thread.socket.push("nonsense\n\n") # Menubar menubar = wx.MenuBar() @@ -125,8 +114,7 @@ class Pyload_Main_Gui(wx.Frame): adddownload = _Download_Dialog(None, -1) result = adddownload.ShowModal() adddownload.Destroy() - -if __name__ == "__main__": - app = wx.App() - Pyload_Main_Gui(None,-1) - app.MainLoop() + +app = wx.App() +Pyload_Main_Gui(None,-1) +app.MainLoop() diff --git a/sockettest.py b/sockettest.py index eab6608c2..5cfebe581 100644 --- a/sockettest.py +++ b/sockettest.py @@ -10,11 +10,12 @@ import base64 import hashlib import random import string +import time import cPickle from Crypto.Cipher import Blowfish from module.remote.RequestObject import RequestObject -from module.remote.ClientSocket import ClientSocket +from module.remote.ClientSocket import SocketThread class Handler: def __init__(self): @@ -59,15 +60,20 @@ import socket handler = Handler() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', 7272)) +th = SocketThread(sock) +#th.socket.connect(('localhost', 7272)) print "Connected to server" obj = RequestObject() obj.command = "exec" obj.function = "get_downloads" -sock.sendall(handler.encrypt(obj) + "\n") +data = handler.encrypt(obj) +print "going to push", data +th.socket.push(data + "\n") +#response = sock.recv(8192) -response = sock.recv(8192) - -print "Received:", handler.decrypt(response).response -sock.close() +#print "Received:", handler.decrypt(response).response +#sock.close() +while True: + sleep(10000) |