diff options
author | mkaay <mkaay@mkaay.de> | 2010-05-02 00:43:47 +0200 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-05-02 00:43:47 +0200 |
commit | 2f399727c8b3d7515549acf34bddb64f4bc9e4b5 (patch) | |
tree | 5f57de5d4fe9bc666290af72cda4c7529aaa06a8 /module/plugins/hooks | |
parent | removed unnecessary files (diff) | |
download | pyload-2f399727c8b3d7515549acf34bddb64f4bc9e4b5.tar.xz |
fixed cnl
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r-- | module/plugins/hooks/ClickAndLoad.py | 111 |
1 files changed, 36 insertions, 75 deletions
diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py index ab29c8731..32af0b7c6 100644 --- a/module/plugins/hooks/ClickAndLoad.py +++ b/module/plugins/hooks/ClickAndLoad.py @@ -31,86 +31,47 @@ class ClickAndLoad(Hook): props['name'] = "ClickAndLoad" props['version'] = "0.1" props['description'] = """Gives abillity to use jd's click and load. depends on webinterface""" - props['author_name'] = ("RaNaN") - props['author_mail'] = ("RaNaN@pyload.de") + props['author_name'] = ("RaNaN", "mkaay") + props['author_mail'] = ("RaNaN@pyload.de", "mkaay@mkaay.de") self.props = props - - self.port = int(self.core.config['webinterface']['port']) + + def coreReady(self): + self.port = int(self.core.config['webinterface']['port']) if self.core.config['webinterface']['activated']: try: - forwarder('127.0.0.1', 9666, '127.0.0.1', self.port) - thread.start_new_thread(asyncore.loop, ()) + thread.start_new_thread(proxy, ("127.0.0.1", self.port, 9666)) except: self.core.logger.error("ClickAndLoad port already in use.") -class forwarder(asyncore.dispatcher): - def __init__(self, ip, port, remoteip, remoteport, backlog=5): - asyncore.dispatcher.__init__(self) - self.remoteip = remoteip - self.remoteport = remoteport - self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - self.set_reuse_addr() - self.bind((ip, port)) - self.listen(backlog) - - def handle_accept(self): - conn, addr = self.accept() - # print '--- Connect --- ' - sender(receiver(conn), self.remoteip, self.remoteport) - -class receiver(asyncore.dispatcher): - def __init__(self, conn): - asyncore.dispatcher.__init__(self, conn) - self.from_remote_buffer = '' - self.to_remote_buffer = '' - self.sender = None - - def handle_connect(self): - pass - - def handle_read(self): - read = self.recv(4096) - # print '%04i -->'%len(read) - self.from_remote_buffer += read - - def writable(self): - return (len(self.to_remote_buffer) > 0) - - def handle_write(self): - sent = self.send(self.to_remote_buffer) - # print '%04i <--'%sent - self.to_remote_buffer = self.to_remote_buffer[sent:] - - def handle_close(self): - self.close() - if self.sender: - self.sender.close() - -class sender(asyncore.dispatcher): - def __init__(self, receiver, remoteaddr, remoteport): - asyncore.dispatcher.__init__(self) - self.receiver = receiver - receiver.sender = self - self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - self.connect((remoteaddr, remoteport)) - - def handle_connect(self): +def proxy(*settings): + thread.start_new_thread(server, settings) + lock = thread.allocate_lock() + lock.acquire() + lock.acquire() + +def server(*settings): + try: + dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + dock_socket.bind(("127.0.0.1", settings[2])) + dock_socket.listen(5) + while True: + client_socket = dock_socket.accept()[0] + server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_socket.connect((settings[0], settings[1])) + thread.start_new_thread(forward, (client_socket, server_socket)) + thread.start_new_thread(forward, (server_socket, client_socket)) + except: pass - - def handle_read(self): - read = self.recv(4096) - # print '<-- %04i'%len(read) - self.receiver.to_remote_buffer += read - - def writable(self): - return (len(self.receiver.from_remote_buffer) > 0) - - def handle_write(self): - sent = self.send(self.receiver.from_remote_buffer) - # print '--> %04i'%sent - self.receiver.from_remote_buffer = self.receiver.from_remote_buffer[sent:] - - def handle_close(self): - self.close() - self.receiver.close() + finally: + thread.start_new_thread(server, settings) + +def forward(source, destination): + string = ' ' + while string: + string = source.recv(1024) + if string: + destination.sendall(string) + else: + #source.shutdown(socket.SHUT_RD) + destination.shutdown(socket.SHUT_WR) |