Repository navigation
Expand file tree
/
Copy pathClickAndLoad.py
More file actions
108 lines (78 loc) · 3.38 KB
/
Copy pathClickAndLoad.py
File metadata and controls
108 lines (78 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
import socket
import time
try:
import ssl
except ImportError:
pass
from threading import Lock
from module.plugins.internal.Addon import Addon, threaded
def forward(source, destination):
try:
bufsize = 1024
bufdata = source.recv(bufsize)
while bufdata:
destination.sendall(bufdata)
bufdata = source.recv(bufsize)
finally:
destination.shutdown(socket.SHUT_WR)
#: destination.close()
#@TODO: IPv6 support
class ClickAndLoad(Addon):
__name__ = "ClickAndLoad"
__type__ = "hook"
__version__ = "0.45"
__status__ = "testing"
__config__ = [("activated", "bool", "Activated" , True),
("port" , "int" , "Port" , 9666),
("extern" , "bool", "Listen on the public network interface", True)]
__description__ = """Click'n'Load hook plugin"""
__license__ = "GPLv3"
__authors__ = [("RaNaN" , "RaNaN@pyload.de" ),
("Walter Purcaro", "vuolter@gmail.com")]
def activate(self):
if not self.pyload.config.get("webinterface", "activated"):
return
ip = "" if self.get_config('extern') else "127.0.0.1"
webport = self.pyload.config.get("webinterface", "port")
cnlport = self.get_config('port')
self.proxy(ip, webport, cnlport)
@threaded
def proxy(self, ip, webport, cnlport):
time.sleep(10) #@TODO: Remove in 0.4.10 (implement addon delay on startup)
self.log_info(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport))
self._server(ip, webport, cnlport)
lock = Lock()
lock.acquire()
lock.acquire()
@threaded
def _server(self, ip, webport, cnlport):
try:
dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dock_socket.bind((ip, cnlport))
dock_socket.listen(5)
while True:
client_socket, client_addr = dock_socket.accept()
self.log_debug("Connection from %s:%s" % client_addr)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.pyload.config.get("webinterface", "https"):
try:
server_socket = ssl.wrap_socket(server_socket)
except NameError:
self.log_error(_("pyLoad's webinterface is configured to use HTTPS, Please install python's ssl lib or disable HTTPS"))
client_socket.close() #: Reset the connection.
continue
except Exception, e:
self.log_error(_("SSL error: %s") % e.message)
client_socket.close() #: Reset the connection.
continue
server_socket.connect(("127.0.0.1", webport))
self.manager.startThread(forward, client_socket, server_socket)
self.manager.startThread(forward, server_socket, client_socket)
except socket.timeout:
self.log_debug("Connection timed out, retrying...")
return self._server(ip, webport, cnlport)
except socket.error, e:
self.log_error(e)
time.sleep(240)
return self._server(ip, webport, cnlport)