From 908c28bab89525250172a4013667319942846065 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 13 Feb 2011 15:06:03 +0100 Subject: fixes + improvements --- module/remote/thriftbackend/Handler.py | 7 ++++--- module/remote/thriftbackend/Processor.py | 4 ++-- module/remote/thriftbackend/Socket.py | 2 +- module/remote/thriftbackend/ThriftClient.py | 4 ++-- module/remote/thriftbackend/Transport.py | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 module/remote/thriftbackend/Transport.py (limited to 'module/remote/thriftbackend') diff --git a/module/remote/thriftbackend/Handler.py b/module/remote/thriftbackend/Handler.py index 6eb2a8bc6..6e1377938 100644 --- a/module/remote/thriftbackend/Handler.py +++ b/module/remote/thriftbackend/Handler.py @@ -4,6 +4,7 @@ from thriftgen.pyload.ttypes import * from thriftgen.pyload.Pyload import Iface from module.PyFile import PyFile +from module.utils import freeSpace class Handler(Iface): def __init__(self, backend): @@ -90,7 +91,7 @@ class Handler(Iface): return serverStatus def freeSpace(self): - return self.core.freeSpace() #bytes + return freeSpace(self.core.config["general"]["download_folder"]) def getServerVersion(self): return self.serverMethods.get_server_version() @@ -479,13 +480,13 @@ class Handler(Iface): self.serverMethods.remove_account(plugin, account) #auth - def login(self, username, password): + def login(self, username, password, remoteip=None): """ Parameters: - username - password """ - return True if self.serverMethods.checkAuth(username, password) else False + return self.backend.checkAuth(username, password, remoteip) def getUserData(self): return self.serverMethods.checkAuth(username, password) diff --git a/module/remote/thriftbackend/Processor.py b/module/remote/thriftbackend/Processor.py index 53c6e404d..8aea42960 100644 --- a/module/remote/thriftbackend/Processor.py +++ b/module/remote/thriftbackend/Processor.py @@ -32,7 +32,7 @@ class Processor(Pyload.Processor): args.read(iprot) iprot.readMessageEnd() result = Pyload.login_result() - self.authenticated[trans] = self._handler.login(args.username, args.password) + self.authenticated[trans] = self._handler.login(args.username, args.password, trans.remoteaddr[0]) result.success = self.authenticated[trans] oprot.writeMessageBegin("login", Pyload.TMessageType.REPLY, seqid) result.write(oprot) @@ -40,4 +40,4 @@ class Processor(Pyload.Processor): oprot.trans.flush() else: self._processMap[name](self, seqid, iprot, oprot) - return True \ No newline at end of file + return True diff --git a/module/remote/thriftbackend/Socket.py b/module/remote/thriftbackend/Socket.py index d8d3d8db4..33daab4c0 100644 --- a/module/remote/thriftbackend/Socket.py +++ b/module/remote/thriftbackend/Socket.py @@ -103,4 +103,4 @@ class ServerSocket(TServerSocket, Socket): client, addr = self.handle.accept() result = Socket() result.setHandle(client) - return result \ No newline at end of file + return result diff --git a/module/remote/thriftbackend/ThriftClient.py b/module/remote/thriftbackend/ThriftClient.py index 9fcabc4e7..67474b2bb 100644 --- a/module/remote/thriftbackend/ThriftClient.py +++ b/module/remote/thriftbackend/ThriftClient.py @@ -52,7 +52,7 @@ class ThriftClient: correct = self.client.login(user, password) finally: self.socket.setTimeout(None) - + if not correct: self.transport.close() raise WrongLogin @@ -80,4 +80,4 @@ if __name__ == "__main__": for p in q: data = client.getPackageData(p.pid) print data - print "Package Name: ", data.name \ No newline at end of file + print "Package Name: ", data.name diff --git a/module/remote/thriftbackend/Transport.py b/module/remote/thriftbackend/Transport.py new file mode 100644 index 000000000..50638f461 --- /dev/null +++ b/module/remote/thriftbackend/Transport.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from thrift.transport.TTransport import TBufferedTransport + +class Transport(TBufferedTransport): + DEFAULT_BUFFER = 4096 + + def __init__(self, trans, rbuf_size = DEFAULT_BUFFER): + TBufferedTransport.__init__(self, trans, rbuf_size) + self.remoteaddr = trans.handle.getpeername() + +class TransportFactory: + def getTransport(self, trans): + buffered = Transport(trans) + return buffered -- cgit v1.2.3