From 5abe7f6eb7eb8eeab1849e9da659450bc50b7084 Mon Sep 17 00:00:00 2001 From: zoidberg10 Date: Thu, 4 Oct 2012 21:26:31 +0200 Subject: 9kw.eu captcha service plugin - (see http://9kw.eu/hilfe.html) - closed #691 --- module/plugins/hooks/Captcha9kw.py | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 module/plugins/hooks/Captcha9kw.py (limited to 'module/plugins/hooks/Captcha9kw.py') diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py new file mode 100644 index 000000000..b4d23f6e8 --- /dev/null +++ b/module/plugins/hooks/Captcha9kw.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay, RaNaN, zoidberg +""" +from __future__ import with_statement + +from thread import start_new_thread +from base64 import b64encode +import cStringIO +import pycurl +import time + +from module.network.RequestFactory import getURL, getRequest +from module.network.HTTPRequest import BadHeader + +from module.plugins.Hook import Hook + +class Captcha9kw(Hook): + __name__ = "Captcha9kw" + __version__ = "0.02" + __description__ = """send captchas to 9kw.eu""" + __config__ = [("activated", "bool", "Activated", False), + ("force", "bool", "Force CT even if client is connected", False), + ("passkey", "password", "API key", ""),] + __author_name__ = ("RaNaN") + __author_mail__ = ("RaNaN@pyload.org") + + API_URL = "http://www.9kw.eu/index.cgi" + + def setup(self): + self.info = {} + + def getCredits(self): + response = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "pyload": "1", "action": "usercaptchaguthaben" }) + + if response.isdigit(): + self.logInfo(_("%s credits left") % response) + self.info["credits"] = credits = int(response) + return credits + else: + self.logError(response) + return 0 + + def processCaptcha(self, task): + result = None + + with open(task.captchaFile, 'rb') as f: + data = f.read() + data = b64encode(data) + self.logDebug("%s : %s" % (task.captchaFile, data)) + + response = getURL(self.API_URL, post = { + "apikey": self.getConfig("passkey"), + "pyload": "1", + "base64": "1", + "file-upload-01": data, + "action": "usercaptchaupload" }) + + for i in range(1, 100, 2): + response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1", "action": "usercaptchacorrectdata" }) + + if(response2 != ""): + break; + + time.sleep(1) + + result = response2 + task.data["ticket"] = response + self.logDebug("result %s : %s" % (response, result)) + task.setResult(result) + + def newCaptchaTask(self, task): + if "service" in task.data: #captcha already beeing handled + return False + + if not task.isTextual(): + return False + + if not self.getConfig("passkey"): + return False + + if self.core.isClientConnected() and not self.getConfig("force"): + return False + + if self.getCredits() > 0: + task.handler.append(self) + task.data['service'] = self.__name__ + task.setWaiting(100) + start_new_thread(self.processCaptcha, (task,)) + + else: + self.logInfo(_("Your Captcha 9kw.eu Account has not enough credits")) + + def captchaCorrect(self, task): + if "ticket" in task.data: + + try: + response = getURL(self.API_URL, + post={ "action": "usercaptchacorrectback", + "apikey": self.getConfig("passkey"), + "api_key": self.getConfig("passkey"), + "correct": "1", + "pyload": "1", + "id": task.data["ticket"] } + ) + self.logInfo("Request correct: %s" % response) + + except BadHeader, e: + self.logError("Could not send correct request.", str(e)) + + def captchaInvalid(self, task): + if "ticket" in task.data: + + try: + response = getURL(self.API_URL, + post={ "action": "usercaptchacorrectback", + "apikey": self.getConfig("passkey"), + "api_key": self.getConfig("passkey"), + "correct": "2", + "pyload": "1", + "id": task.data["ticket"] } + ) + self.logInfo("Request refund: %s" % response) + + except BadHeader, e: + self.logError("Could not send refund request.", str(e)) \ No newline at end of file -- cgit v1.2.3 From ad2a4ba837fb450df24094d916deebb10837c9eb Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 2 Mar 2013 16:34:43 +0100 Subject: closed #27 --- module/plugins/hooks/Captcha9kw.py | 61 ++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'module/plugins/hooks/Captcha9kw.py') diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py index b4d23f6e8..dc223ae1e 100644 --- a/module/plugins/hooks/Captcha9kw.py +++ b/module/plugins/hooks/Captcha9kw.py @@ -30,7 +30,7 @@ from module.plugins.Hook import Hook class Captcha9kw(Hook): __name__ = "Captcha9kw" - __version__ = "0.02" + __version__ = "0.03" __description__ = """send captchas to 9kw.eu""" __config__ = [("activated", "bool", "Activated", False), ("force", "bool", "Force CT even if client is connected", False), @@ -43,13 +43,13 @@ class Captcha9kw(Hook): def setup(self): self.info = {} - def getCredits(self): - response = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "pyload": "1", "action": "usercaptchaguthaben" }) - + def getCredits(self): + response = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "pyload": "1", "source": "pyload", "action": "usercaptchaguthaben" }) + if response.isdigit(): self.logInfo(_("%s credits left") % response) self.info["credits"] = credits = int(response) - return credits + return credits else: self.logError(response) return 0 @@ -63,29 +63,33 @@ class Captcha9kw(Hook): self.logDebug("%s : %s" % (task.captchaFile, data)) response = getURL(self.API_URL, post = { - "apikey": self.getConfig("passkey"), - "pyload": "1", - "base64": "1", - "file-upload-01": data, - "action": "usercaptchaupload" }) + "apikey": self.getConfig("passkey"), + "pyload": "1", + "source": "pyload", + "base64": "1", + "file-upload-01": data, + "action": "usercaptchaupload" }) + + if response.isdigit(): + self.logInfo(_("NewCaptchaID from upload: %s : %s" % (response,task.captchaFile))) - for i in range(1, 100, 2): - response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1", "action": "usercaptchacorrectdata" }) + for i in range(1, 200, 2): + response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1","source": "pyload", "action": "usercaptchacorrectdata" }) - if(response2 != ""): - break; + if(response2 != ""): + break; - time.sleep(1) + time.sleep(1) - result = response2 - task.data["ticket"] = response - self.logDebug("result %s : %s" % (response, result)) - task.setResult(result) + result = response2 + task.data["ticket"] = response + self.logInfo("result %s : %s" % (response, result)) + task.setResult(result) + else: + self.logError("Bad upload: %s" % response) + return False def newCaptchaTask(self, task): - if "service" in task.data: #captcha already beeing handled - return False - if not task.isTextual(): return False @@ -97,12 +101,11 @@ class Captcha9kw(Hook): if self.getCredits() > 0: task.handler.append(self) - task.data['service'] = self.__name__ - task.setWaiting(100) + task.setWaiting(220) start_new_thread(self.processCaptcha, (task,)) else: - self.logInfo(_("Your Captcha 9kw.eu Account has not enough credits")) + self.logError(_("Your Captcha 9kw.eu Account has not enough credits")) def captchaCorrect(self, task): if "ticket" in task.data: @@ -114,12 +117,15 @@ class Captcha9kw(Hook): "api_key": self.getConfig("passkey"), "correct": "1", "pyload": "1", + "source": "pyload", "id": task.data["ticket"] } ) self.logInfo("Request correct: %s" % response) except BadHeader, e: self.logError("Could not send correct request.", str(e)) + else: + self.logError("No CaptchaID for correct request (task %s) found." % task) def captchaInvalid(self, task): if "ticket" in task.data: @@ -131,9 +137,12 @@ class Captcha9kw(Hook): "api_key": self.getConfig("passkey"), "correct": "2", "pyload": "1", + "source": "pyload", "id": task.data["ticket"] } ) self.logInfo("Request refund: %s" % response) except BadHeader, e: - self.logError("Could not send refund request.", str(e)) \ No newline at end of file + self.logError("Could not send refund request.", str(e)) + else: + self.logError("No CaptchaID for not correct request (task %s) found." % task) -- cgit v1.2.3 From 803ae199c53aad8b682b2d0a8e46af786589a1b0 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 9 Mar 2013 13:03:08 +0100 Subject: updated 9kw plugin (#27) --- module/plugins/hooks/Captcha9kw.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) mode change 100644 => 100755 module/plugins/hooks/Captcha9kw.py (limited to 'module/plugins/hooks/Captcha9kw.py') diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py old mode 100644 new mode 100755 index dc223ae1e..b34ffeb05 --- a/module/plugins/hooks/Captcha9kw.py +++ b/module/plugins/hooks/Captcha9kw.py @@ -32,8 +32,8 @@ class Captcha9kw(Hook): __name__ = "Captcha9kw" __version__ = "0.03" __description__ = """send captchas to 9kw.eu""" - __config__ = [("activated", "bool", "Activated", False), - ("force", "bool", "Force CT even if client is connected", False), + __config__ = [("activated", "bool", "Activated", True), + ("force", "bool", "Force CT even if client is connected", True), ("passkey", "password", "API key", ""),] __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") @@ -61,12 +61,17 @@ class Captcha9kw(Hook): data = f.read() data = b64encode(data) self.logDebug("%s : %s" % (task.captchaFile, data)) + if task.isPositional(): + mouse = 1 + else: + mouse = 0 response = getURL(self.API_URL, post = { "apikey": self.getConfig("passkey"), "pyload": "1", "source": "pyload", "base64": "1", + "mouse": mouse, "file-upload-01": data, "action": "usercaptchaupload" }) @@ -90,7 +95,7 @@ class Captcha9kw(Hook): return False def newCaptchaTask(self, task): - if not task.isTextual(): + if not task.isTextual() and not task.isPositional(): return False if not self.getConfig("passkey"): @@ -145,4 +150,4 @@ class Captcha9kw(Hook): except BadHeader, e: self.logError("Could not send refund request.", str(e)) else: - self.logError("No CaptchaID for not correct request (task %s) found." % task) + self.logError("No CaptchaID for not correct request (task %s) found." % task) \ No newline at end of file -- cgit v1.2.3 From 8342aad089589479650703de915a356d634b202b Mon Sep 17 00:00:00 2001 From: Stefano Date: Sat, 23 Mar 2013 22:32:28 +0100 Subject: Plugins: fixed inconsistent indentation --- module/plugins/hooks/Captcha9kw.py | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'module/plugins/hooks/Captcha9kw.py') diff --git a/module/plugins/hooks/Captcha9kw.py b/module/plugins/hooks/Captcha9kw.py index b34ffeb05..a01ce9576 100755 --- a/module/plugins/hooks/Captcha9kw.py +++ b/module/plugins/hooks/Captcha9kw.py @@ -62,40 +62,40 @@ class Captcha9kw(Hook): data = b64encode(data) self.logDebug("%s : %s" % (task.captchaFile, data)) if task.isPositional(): - mouse = 1 + mouse = 1 else: - mouse = 0 + mouse = 0 response = getURL(self.API_URL, post = { - "apikey": self.getConfig("passkey"), - "pyload": "1", - "source": "pyload", - "base64": "1", - "mouse": mouse, - "file-upload-01": data, - "action": "usercaptchaupload" }) + "apikey": self.getConfig("passkey"), + "pyload": "1", + "source": "pyload", + "base64": "1", + "mouse": mouse, + "file-upload-01": data, + "action": "usercaptchaupload" }) - if response.isdigit(): - self.logInfo(_("NewCaptchaID from upload: %s : %s" % (response,task.captchaFile))) + if response.isdigit(): + self.logInfo(_("NewCaptchaID from upload: %s : %s" % (response,task.captchaFile))) - for i in range(1, 200, 2): - response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1","source": "pyload", "action": "usercaptchacorrectdata" }) + for i in range(1, 200, 2): + response2 = getURL(self.API_URL, get = { "apikey": self.getConfig("passkey"), "id": response,"pyload": "1","source": "pyload", "action": "usercaptchacorrectdata" }) - if(response2 != ""): - break; + if(response2 != ""): + break; - time.sleep(1) + time.sleep(1) - result = response2 - task.data["ticket"] = response - self.logInfo("result %s : %s" % (response, result)) - task.setResult(result) - else: - self.logError("Bad upload: %s" % response) - return False + result = response2 + task.data["ticket"] = response + self.logInfo("result %s : %s" % (response, result)) + task.setResult(result) + else: + self.logError("Bad upload: %s" % response) + return False def newCaptchaTask(self, task): - if not task.isTextual() and not task.isPositional(): + if not task.isTextual() and not task.isPositional(): return False if not self.getConfig("passkey"): @@ -130,7 +130,7 @@ class Captcha9kw(Hook): except BadHeader, e: self.logError("Could not send correct request.", str(e)) else: - self.logError("No CaptchaID for correct request (task %s) found." % task) + self.logError("No CaptchaID for correct request (task %s) found." % task) def captchaInvalid(self, task): if "ticket" in task.data: @@ -150,4 +150,4 @@ class Captcha9kw(Hook): except BadHeader, e: self.logError("Could not send refund request.", str(e)) else: - self.logError("No CaptchaID for not correct request (task %s) found." % task) \ No newline at end of file + self.logError("No CaptchaID for not correct request (task %s) found." % task) -- cgit v1.2.3