diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-22 23:14:43 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-22 23:14:43 +0100 |
commit | 6d1fa0e753073a00d9075227a6474f855157fc5d (patch) | |
tree | 17d56ea921443174393954d237e7563779f0f3e7 | |
parent | filesonic info prefetching + premium fix (diff) | |
download | pyload-6d1fa0e753073a00d9075227a6474f855157fc5d.tar.xz |
captcha input via IRC, XMPP
-rw-r--r-- | module/CaptchaManager.py | 6 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 2 | ||||
-rw-r--r-- | module/plugins/hooks/IRCInterface.py | 51 | ||||
-rw-r--r-- | module/plugins/hooks/XMPPInterface.py | 7 | ||||
-rwxr-xr-x | pyLoadCore.py | 4 |
5 files changed, 52 insertions, 18 deletions
diff --git a/module/CaptchaManager.py b/module/CaptchaManager.py index 8296fb9c6..4ebfee30d 100644 --- a/module/CaptchaManager.py +++ b/module/CaptchaManager.py @@ -49,7 +49,7 @@ class CaptchaManager(): self.lock.release() return None - def getTaskFromID(self, tid): + def getTaskByID(self, tid): self.lock.acquire() for task in self.tasks: if task.id == tid: @@ -62,7 +62,6 @@ class CaptchaManager(): cli = self.core.isClientConnected() if cli: #client connected -> should solve the captcha - self.tasks.append(task) task.setWaiting(50) #wait 50 sec for response for plugin in self.core.hookManager.activePlugins(): @@ -73,6 +72,7 @@ class CaptchaManager(): print_exc() if task.handler or cli: #the captcha was handled + self.tasks.append(task) return True task.error = _("No Client connected for captcha decrypting") @@ -113,7 +113,7 @@ class CaptchaTask(): def setWaiting(self, sec): """ let the captcha wait secs for the solution """ - self.waitUntil = time() + sec + self.waitUntil = max(time() + sec, self.waitUntil) self.status = "waiting" def isWaiting(self): diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 6182b0f7f..6c8c47fb7 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -234,7 +234,7 @@ class Plugin(object): content = self.load(url, get=get, post=post, cookies=cookies) - id = ("%.2f" % time())[-6:] + id = ("%.2f" % time())[-6:].replace(".","") temp = open(join("tmp","tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)), "wb") temp.write(content) diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py index 22863916b..31d693018 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRCInterface.py @@ -21,13 +21,16 @@ from select import select import socket -import sys from threading import Thread import time from time import sleep from traceback import print_exc +import re from module.plugins.Hook import Hook +from module.network.RequestFactory import getURL + +from pycurl import FORM_FILE class IRCInterface(Thread, Hook): __name__ = "IRCInterface" @@ -41,7 +44,8 @@ class IRCInterface(Thread, Hook): ("nick", "str", "Nickname the Client will take", "pyLoad-IRC"), ("owner", "str", "Nickname the Client will accept commands from", "Enter your nick here!"), ("info_file", "bool", "Inform about every file finished", "False"), - ("info_pack", "bool", "Inform about every package finished", "True")] + ("info_pack", "bool", "Inform about every package finished", "True"), + ("captcha", "bool", "Send captcha requests", "True")] __author_name__ = ("Jeix") __author_mail__ = ("Jeix@hasnomail.com") @@ -75,7 +79,18 @@ class IRCInterface(Thread, Hook): self.response(_("Download finished: %(name)s @ %(plugin)s ") % { "name" : pyfile.name, "plugin": pyfile.pluginname} ) except: pass - + + def newCaptchaTask(self, task): + if self.getConfig("captcha"): + task.handler.append(self) + task.setWaiting(60) + + page = getURL("http://www.freeimagehosting.net/upload.php", post={"attached" : (FORM_FILE, task.captchaFile)}, multipart=True) + + url = re.search(r"\[url=http://www.freeimagehosting.net/\]\[img\]([^\[]+)\[/img\]\[/url\]", page).group(1) + self.response(_("New Captcha Request: %s") % url) + self.response(_("Answer with 'c %s text on the captcha'") % task.id) + def run(self): # connect to IRC etc. self.sock = socket.socket() @@ -162,12 +177,15 @@ class IRCInterface(Thread, Hook): trigger = "pass" args = None - - temp = msg["text"].split() - trigger = temp[0] - if len(temp) > 1: - args = temp[1:] - + + try: + temp = msg["text"].split() + trigger = temp[0] + if len(temp) > 1: + args = temp[1:] + except: + pass + handler = getattr(self, "event_%s" % trigger, self.event_pass) try: res = handler(args) @@ -360,7 +378,7 @@ class IRCInterface(Thread, Hook): def event_pull(self, args): if not args: - return ["ERROR: Pull package from queue like this: pull <package id>"] + return ["ERROR: Pull package from queue like this: pull <package id>."] id = int(args[0]) if not self.sm.get_package_data(id): @@ -369,6 +387,19 @@ class IRCInterface(Thread, Hook): self.sm.pull_out_package(id) return ["INFO: Pulled package #%d from queue to collector." % id] + def event_c(self, args): + """ captcha answer """ + if not args: + return ["ERROR: Captcha ID missing."] + + task = self.core.captchaManager.getTaskByID(args[0]) + if not task: + return ["ERROR: Captcha Task with ID %s does not exists." % args[0]] + + task.setResult(" ".join(args[1:])) + return ["INFO: Result %s saved." % " ".join(args[1:])] + + def event_help(self, args): lines = [] lines.append("The following commands are available:") diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py index a05d956d5..dc6928127 100644 --- a/module/plugins/hooks/XMPPInterface.py +++ b/module/plugins/hooks/XMPPInterface.py @@ -34,7 +34,8 @@ class XMPPInterface(IRCInterface, JabberClient): ("pw", "str", "Password", ""), ("owners", "str", "List of JIDs accepting commands from", "me@icq-gateway.org;some@msn-gateway.org"), ("info_file", "bool", "Inform about every file finished", "False"), - ("info_pack", "bool", "Inform about every package finished", "True")] + ("info_pack", "bool", "Inform about every package finished", "True"), + ("captcha", "bool", "Send captcha requests", "True")] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") @@ -172,7 +173,9 @@ class XMPPInterface(IRCInterface, JabberClient): else: return True - + + def response(self, msg, origin=""): + return self.announce(msg) def announce(self, message): """ send message to all owners""" diff --git a/pyLoadCore.py b/pyLoadCore.py index d045581b5..6df4816db 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -764,13 +764,13 @@ class ServerMethods(): def get_task_status(self, tid): self.core.lastClientConnected = time() - t = self.core.captchaManager.getTaskFromID(tid) + t = self.core.captchaManager.getTaskByID(tid) if t: return t.getStatus() def set_captcha_result(self, tid, result): self.core.lastClientConnected = time() - task = self.core.captchaManager.getTaskFromID(tid) + task = self.core.captchaManager.getTaskByID(tid) if task: task.setResult(result) self.core.captchaManager.removeTask(task) |