summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-31 20:36:19 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-05-31 20:36:19 +0200
commitdcb1894e0c708df0677187355c6743c08ac44c26 (patch)
tree9edd4c4eccde099a95edc8d7436dce8b92e3aba0
parentShareLinksBiz decrypter (diff)
downloadpyload-dcb1894e0c708df0677187355c6743c08ac44c26.tar.xz
fixed positional captchas + availbillity over thrift
-rw-r--r--module/CaptchaManager.py12
-rw-r--r--module/database/DatabaseBackend.py4
-rw-r--r--module/plugins/crypter/ShareLinksBiz.py5
-rw-r--r--module/plugins/hooks/CaptchaTrader.py3
-rw-r--r--module/plugins/hooks/IRCInterface.py2
-rw-r--r--module/remote/thriftbackend/Handler.py6
-rw-r--r--module/remote/thriftbackend/pyload.thrift5
-rwxr-xr-xmodule/remote/thriftbackend/thriftgen/pyload/Pyload-remote8
-rw-r--r--module/remote/thriftbackend/thriftgen/pyload/Pyload.py52
-rw-r--r--module/remote/thriftbackend/thriftgen/pyload/ttypes.py14
-rw-r--r--module/web/templates/default/captcha.html6
-rw-r--r--pyLoadCli.py2
-rwxr-xr-xpyLoadCore.py1
13 files changed, 94 insertions, 26 deletions
diff --git a/module/CaptchaManager.py b/module/CaptchaManager.py
index 539e80744..02cd10a11 100644
--- a/module/CaptchaManager.py
+++ b/module/CaptchaManager.py
@@ -99,9 +99,9 @@ class CaptchaTask():
return self.captchaImg, self.captchaFormat, self.captchaResultType
def setResult(self, text):
- if self.captchaResultType == 'textual':
+ if self.isTextual():
self.result = text
- if self.captchaResultType == 'positional':
+ if self.isPositional():
try:
parts = text.split(',')
self.result = (int(parts[0]), int(parts[1]))
@@ -130,6 +130,14 @@ class CaptchaTask():
return True
+ def isTextual(self):
+ """ returns if text is written on the captcha """
+ return self.captchaResultType == 'textual'
+
+ def isPositional(self):
+ """ returns if user have to click a specific region on the captcha """
+ return self.captchaResultType == 'positional'
+
def setWatingForUser(self, exclusive):
if exclusive:
self.status = "user"
diff --git a/module/database/DatabaseBackend.py b/module/database/DatabaseBackend.py
index 0ce01cdc5..95bb6a198 100644
--- a/module/database/DatabaseBackend.py
+++ b/module/database/DatabaseBackend.py
@@ -95,12 +95,12 @@ class DatabaseJob():
try:
self.result = self.f(*self.args, **self.kwargs)
except Exception, e:
+ print_exc()
try:
print "Database Error @", self.f.__name__, self.args[1:], self.kwargs, e
except:
pass
-
- print_exc()
+
self.exception = e
finally:
self.done.set()
diff --git a/module/plugins/crypter/ShareLinksBiz.py b/module/plugins/crypter/ShareLinksBiz.py
index 407d2ff56..fef10b7f1 100644
--- a/module/plugins/crypter/ShareLinksBiz.py
+++ b/module/plugins/crypter/ShareLinksBiz.py
@@ -106,10 +106,11 @@ class ShareLinksBiz(Crypter):
# Resolve captcha
href = self._resolveCoords(coords, captchaMap)
- if href == None:
+ if href is None:
self.log.debug("%s: Invalid captcha resolving, retrying" % self.__name__)
self.invalidCaptcha()
- self.wait(5)
+ self.setWait(5, False)
+ self.wait()
self.retry()
url = self.baseUrl + href
self.html = self.load(url)
diff --git a/module/plugins/hooks/CaptchaTrader.py b/module/plugins/hooks/CaptchaTrader.py
index 985288090..88b928a50 100644
--- a/module/plugins/hooks/CaptchaTrader.py
+++ b/module/plugins/hooks/CaptchaTrader.py
@@ -101,6 +101,9 @@ class CaptchaTrader(Hook):
raise CaptchaTraderException(response[1])
def newCaptchaTask(self, task):
+ if not task.isTextual():
+ return False
+
if not self.getConfig("username") or not self.getConfig("passkey"):
return False
diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py
index 0142c3610..6fdb7622f 100644
--- a/module/plugins/hooks/IRCInterface.py
+++ b/module/plugins/hooks/IRCInterface.py
@@ -81,7 +81,7 @@ class IRCInterface(Thread, Hook):
pass
def newCaptchaTask(self, task):
- if self.getConfig("captcha"):
+ if self.getConfig("captcha") and task.isTextual():
task.handler.append(self)
task.setWaiting(60)
diff --git a/module/remote/thriftbackend/Handler.py b/module/remote/thriftbackend/Handler.py
index 9a7c1489e..e45cdfcaa 100644
--- a/module/remote/thriftbackend/Handler.py
+++ b/module/remote/thriftbackend/Handler.py
@@ -445,8 +445,8 @@ class Handler(Iface):
Parameters:
- exclusive
"""
- tid, data, type = self.serverMethods.get_captcha_task(exclusive)
- t = CaptchaTask(int(tid), standard_b64encode(data), type)
+ tid, data, type, result = self.serverMethods.get_captcha_task(exclusive)
+ t = CaptchaTask(int(tid), standard_b64encode(data), type, result)
return t
def getCaptchaTaskStatus(self, tid):
@@ -536,7 +536,7 @@ class Handler(Iface):
"""
return self.backend.checkAuth(username, password, remoteip)
- def getUserData(self):
+ def getUserData(self, username, password):
return self.serverMethods.checkAuth(username, password)
diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift
index c26334051..52fa1f08d 100644
--- a/module/remote/thriftbackend/pyload.thrift
+++ b/module/remote/thriftbackend/pyload.thrift
@@ -118,7 +118,8 @@ struct PackageInfo {
struct CaptchaTask {
1: i16 tid,
2: binary data,
- 3: string type
+ 3: string type,
+ 4: string resultType
}
struct Event {
@@ -250,7 +251,7 @@ service Pyload {
//auth
bool login(1: string username, 2: string password),
- UserData getUserData(),
+ UserData getUserData(1: string username, 2:string password),
//services
map<string, ServiceInfo> getServices(),
diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
index a9311d32b..d87ef6e28 100755
--- a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
+++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote
@@ -77,7 +77,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print ' void updateAccounts(AccountData data)'
print ' void removeAccount(string plugin, string account)'
print ' bool login(string username, string password)'
- print ' UserData getUserData()'
+ print ' UserData getUserData(string username, string password)'
print ' getServices()'
print ' bool hasService(string plugin, string func)'
print ' string call(ServiceCall info)'
@@ -468,10 +468,10 @@ elif cmd == 'login':
pp.pprint(client.login(args[0],args[1],))
elif cmd == 'getUserData':
- if len(args) != 0:
- print 'getUserData requires 0 args'
+ if len(args) != 2:
+ print 'getUserData requires 2 args'
sys.exit(1)
- pp.pprint(client.getUserData())
+ pp.pprint(client.getUserData(args[0],args[1],))
elif cmd == 'getServices':
if len(args) != 0:
diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
index ba9d6a7a2..e4cfba605 100644
--- a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
+++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py
@@ -334,7 +334,12 @@ class Iface:
"""
pass
- def getUserData(self, ):
+ def getUserData(self, username, password):
+ """
+ Parameters:
+ - username
+ - password
+ """
pass
def getServices(self, ):
@@ -1914,13 +1919,20 @@ class Client(Iface):
return result.success
raise TApplicationException(TApplicationException.MISSING_RESULT, "login failed: unknown result");
- def getUserData(self, ):
- self.send_getUserData()
+ def getUserData(self, username, password):
+ """
+ Parameters:
+ - username
+ - password
+ """
+ self.send_getUserData(username, password)
return self.recv_getUserData()
- def send_getUserData(self, ):
+ def send_getUserData(self, username, password):
self._oprot.writeMessageBegin('getUserData', TMessageType.CALL, self._seqid)
args = getUserData_args()
+ args.username = username
+ args.password = password
args.write(self._oprot)
self._oprot.writeMessageEnd()
self._oprot.trans.flush()
@@ -2738,7 +2750,7 @@ class Processor(Iface, TProcessor):
args.read(iprot)
iprot.readMessageEnd()
result = getUserData_result()
- result.success = self._handler.getUserData()
+ result.success = self._handler.getUserData(args.username, args.password)
oprot.writeMessageBegin("getUserData", TMessageType.REPLY, seqid)
result.write(oprot)
oprot.writeMessageEnd()
@@ -8897,10 +8909,22 @@ class login_result:
return not (self == other)
class getUserData_args:
+ """
+ Attributes:
+ - username
+ - password
+ """
thrift_spec = (
+ None, # 0
+ (1, TType.STRING, 'username', None, None, ), # 1
+ (2, TType.STRING, 'password', None, None, ), # 2
)
+ def __init__(self, username=None, password=None,):
+ self.username = username
+ self.password = password
+
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
@@ -8910,6 +8934,16 @@ class getUserData_args:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
+ if fid == 1:
+ if ftype == TType.STRING:
+ self.username = iprot.readString();
+ else:
+ iprot.skip(ftype)
+ elif fid == 2:
+ if ftype == TType.STRING:
+ self.password = iprot.readString();
+ else:
+ iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
@@ -8920,6 +8954,14 @@ class getUserData_args:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
return
oprot.writeStructBegin('getUserData_args')
+ if self.username != None:
+ oprot.writeFieldBegin('username', TType.STRING, 1)
+ oprot.writeString(self.username)
+ oprot.writeFieldEnd()
+ if self.password != None:
+ oprot.writeFieldBegin('password', TType.STRING, 2)
+ oprot.writeString(self.password)
+ oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
diff --git a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
index b3ef98de3..6fec5a405 100644
--- a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
+++ b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py
@@ -1153,6 +1153,7 @@ class CaptchaTask:
- tid
- data
- type
+ - resultType
"""
thrift_spec = (
@@ -1160,12 +1161,14 @@ class CaptchaTask:
(1, TType.I16, 'tid', None, None, ), # 1
(2, TType.STRING, 'data', None, None, ), # 2
(3, TType.STRING, 'type', None, None, ), # 3
+ (4, TType.STRING, 'resultType', None, None, ), # 4
)
- def __init__(self, tid=None, data=None, type=None,):
+ def __init__(self, tid=None, data=None, type=None, resultType=None,):
self.tid = tid
self.data = data
self.type = type
+ self.resultType = resultType
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
@@ -1191,6 +1194,11 @@ class CaptchaTask:
self.type = iprot.readString();
else:
iprot.skip(ftype)
+ elif fid == 4:
+ if ftype == TType.STRING:
+ self.resultType = iprot.readString();
+ else:
+ iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
@@ -1213,6 +1221,10 @@ class CaptchaTask:
oprot.writeFieldBegin('type', TType.STRING, 3)
oprot.writeString(self.type)
oprot.writeFieldEnd()
+ if self.resultType != None:
+ oprot.writeFieldBegin('resultType', TType.STRING, 4)
+ oprot.writeString(self.resultType)
+ oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
def validate(self):
diff --git a/module/web/templates/default/captcha.html b/module/web/templates/default/captcha.html
index 0165fed10..6c0099773 100644
--- a/module/web/templates/default/captcha.html
+++ b/module/web/templates/default/captcha.html
@@ -29,7 +29,7 @@
}
function set_captcha(data) {
- $('cap_id').set('value', data.id);
+ $('cap_id').set('value', data.id);
if (data.result_type == 'textual') {
$('cap_textual_img').set('src', data.src);
$('cap_title').set('text', '{{_("Please read the text on the captcha.")}}');
@@ -61,7 +61,7 @@
}
function on_cap_click(e) {
- var position = event.target.getPosition();
+ var position = e.target.getPosition();
var x = e.page.x - position.x;
var y = e.page.y - position.y;
$('cap_result').value = x + "," + y;
@@ -96,7 +96,7 @@
</div>
<div id="cap_positional" style="text-align: center">
- <img id="cap_positional_img" src="" style="margin: 10px;">
+ <img id="cap_positional_img" src="" style="margin: 10px; cursor:pointer">
</div>
<div id="button_bar" style="text-align: center">
diff --git a/pyLoadCli.py b/pyLoadCli.py
index cc2598600..f73b1fad8 100644
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -421,7 +421,7 @@ def writeConfig(opts):
with open(join(homedir, ".pyloadcli"), "w") as cfgfile:
cfgfile.write("[cli]")
for opt in opts:
- cfgfile.write("%s=%s" % (opt, opts[opt]))
+ cfgfile.write("%s=%s\n" % (opt, opts[opt]))
except:
print _("Couldn't write user config file")
diff --git a/pyLoadCore.py b/pyLoadCore.py
index a4311b75b..e8b024f4c 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -771,6 +771,7 @@ class ServerMethods():
return not task is None
def get_captcha_task(self, exclusive=False):
+ """ returns tid, data, type, resulttype """
self.core.lastClientConnected = time()
task = self.core.captchaManager.getTask()
if task: