summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-05-02 00:43:47 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-05-02 00:43:47 +0200
commit2f399727c8b3d7515549acf34bddb64f4bc9e4b5 (patch)
tree5f57de5d4fe9bc666290af72cda4c7529aaa06a8 /module
parentremoved unnecessary files (diff)
downloadpyload-2f399727c8b3d7515549acf34bddb64f4bc9e4b5.tar.xz
fixed cnl
Diffstat (limited to 'module')
-rw-r--r--module/HookManager.py7
-rw-r--r--module/plugins/Hook.py3
-rw-r--r--module/plugins/hooks/ClickAndLoad.py111
-rw-r--r--module/web/cnl/views.py28
4 files changed, 68 insertions, 81 deletions
diff --git a/module/HookManager.py b/module/HookManager.py
index 279fdbaa7..fa6df3323 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -64,6 +64,13 @@ class HookManager():
self.plugins = plugins
self.lock.release()
+ def coreReady(self):
+ self.lock.acquire()
+
+ for plugin in self.plugins:
+ plugin.coreReady()
+ self.lock.release()
+
def downloadStarts(self, pyfile):
self.lock.acquire()
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index 541d0c2e9..404a132b9 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -50,6 +50,9 @@ class Hook():
def isActivated(self):
return self.config["activated"]
+ def coreReady(self):
+ pass
+
def downloadStarts(self, pyfile):
pass
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)
diff --git a/module/web/cnl/views.py b/module/web/cnl/views.py
index 69a2ce4e8..d42a0e60b 100644
--- a/module/web/cnl/views.py
+++ b/module/web/cnl/views.py
@@ -11,6 +11,9 @@ from django.conf import settings
from django.http import HttpResponse
from django.http import HttpResponseServerError
+from django.core.serializers import json
+from django.utils import simplejson
+
try:
from Crypto.Cipher import AES
except:
@@ -35,9 +38,22 @@ def local_check(function):
else:
return _dec(function)
+class JsonResponse(HttpResponse):
+ def __init__(self, obj, request):
+ cb = request.GET.get("callback")
+ if cb:
+ obj = {"content": obj}
+ content = simplejson.dumps(obj, indent=2, cls=json.DjangoJSONEncoder, ensure_ascii=False)
+ content = "%s(%s)\r\n" % (cb, content)
+ HttpResponse.__init__(self, content, content_type="application/json")
+ else:
+ content = "%s\r\n" % obj
+ HttpResponse.__init__(self, content, content_type="text/html")
+ self["Cache-Control"] = "no-cache, must-revalidate"
+
@local_check
def flash(request):
- return HttpResponse("JDownloader")
+ return HttpResponse("JDownloader\r\n")
@local_check
def add(request):
@@ -62,9 +78,9 @@ def addcrypted(request):
try:
settings.PYLOAD.add_package(package, [dlc_path], False)
except:
- return HttpResponse("")
+ return JsonResponse("", request)
else:
- return HttpResponse("success")
+ return JsonResponse("success", request)
@local_check
def addcrypted2(request):
@@ -105,9 +121,9 @@ def addcrypted2(request):
try:
settings.PYLOAD.add_package(package, result, False)
except:
- return HttpResponse("failed can't add")
+ return JsonResponse("failed can't add", request)
else:
- return HttpResponse("success")
+ return JsonResponse("success", request)
@local_check
def flashgot(request):
@@ -121,7 +137,7 @@ def flashgot(request):
settings.PYLOAD.add_package(package, urls, autostart)
- return HttpResponse("")
+ return HttpResponse("\r\n")
@local_check
def crossdomain(request):