diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/gui/ConnectionManager.py | 30 | ||||
-rw-r--r-- | module/gui/Overview.py | 2 | ||||
-rw-r--r-- | module/gui/Queue.py | 10 | ||||
-rw-r--r-- | module/gui/connector.py | 40 | ||||
-rw-r--r-- | module/plugins/hooks/Ev0InFetcher.py | 3 | ||||
-rw-r--r-- | module/remote/RemoteManager.py | 2 | ||||
-rw-r--r-- | module/remote/ThriftBackend.py | 6 | ||||
-rw-r--r-- | module/remote/thriftbackend/Handler.py | 7 | ||||
-rw-r--r-- | module/remote/thriftbackend/Processor.py | 4 | ||||
-rw-r--r-- | module/remote/thriftbackend/Socket.py | 2 | ||||
-rw-r--r-- | module/remote/thriftbackend/ThriftClient.py | 4 | ||||
-rw-r--r-- | module/remote/thriftbackend/Transport.py | 15 |
12 files changed, 70 insertions, 55 deletions
diff --git a/module/gui/ConnectionManager.py b/module/gui/ConnectionManager.py index c101a7add..51f39f2be 100644 --- a/module/gui/ConnectionManager.py +++ b/module/gui/ConnectionManager.py @@ -61,7 +61,6 @@ class ConnectionManager(QWidget): form.setAlignment(Qt.AlignRight) checkbox = QCheckBox() - checkbox.setDisabled(True) form.addRow(_("Use internal Core:"), checkbox) boxLayout.addLayout(form) @@ -110,7 +109,7 @@ class ConnectionManager(QWidget): self.connList.setCurrentItem(item) def slotNew(self): - data = {"id":uuid().hex, "type":"remote", "default":False, "name":"", "host":"", "ssl":False, "port":"7227", "user":"admin", "password":""} + data = {"id":uuid().hex, "type":"remote", "default":False, "name":"", "host":"", "port":"7228", "user":"admin", "password":""} self.edit.setData(data) self.edit.show() @@ -173,12 +172,14 @@ class ConnectionManager(QWidget): class EditWindow(QWidget): def __init__(self): QWidget.__init__(self) + + self.setWindowTitle(_("pyLoad ConnectionManager")) + self.setWindowIcon(QIcon(join(pypath, "icons","logo.png"))) grid = QGridLayout() nameLabel = QLabel(_("Name:")) hostLabel = QLabel(_("Host:")) - sslLabel = QLabel(_("SSL:")) localLabel = QLabel(_("Local:")) userLabel = QLabel(_("User:")) pwLabel = QLabel(_("Password:")) @@ -186,7 +187,6 @@ class ConnectionManager(QWidget): name = QLineEdit() host = QLineEdit() - ssl = QCheckBox() local = QCheckBox() user = QLineEdit() password = QLineEdit() @@ -205,20 +205,17 @@ class ConnectionManager(QWidget): grid.addWidget(host, 2, 1) grid.addWidget(portLabel, 3, 0) grid.addWidget(port, 3, 1) - grid.addWidget(sslLabel, 4, 0) - grid.addWidget(ssl, 4, 1) - grid.addWidget(userLabel, 5, 0) - grid.addWidget(user, 5, 1) - grid.addWidget(pwLabel, 6, 0) - grid.addWidget(password, 6, 1) - grid.addWidget(cancel, 7, 0) - grid.addWidget(save, 7, 1) + grid.addWidget(userLabel, 4, 0) + grid.addWidget(user, 4, 1) + grid.addWidget(pwLabel, 5, 0) + grid.addWidget(password, 5, 1) + grid.addWidget(cancel, 6, 0) + grid.addWidget(save, 6, 1) self.setLayout(grid) self.controls = {} self.controls["name"] = name self.controls["host"] = host - self.controls["ssl"] = ssl self.controls["local"] = local self.controls["user"] = user self.controls["password"] = password @@ -245,22 +242,18 @@ class ConnectionManager(QWidget): data["local"] = False self.controls["local"].setChecked(data["local"]) if not data["local"]: - self.controls["ssl"].setChecked(data["ssl"]) self.controls["user"].setText(data["user"]) self.controls["password"].setText(data["password"]) self.controls["port"].setValue(int(data["port"])) self.controls["host"].setText(data["host"]) - self.controls["ssl"].setDisabled(False) self.controls["user"].setDisabled(False) self.controls["password"].setDisabled(False) self.controls["port"].setDisabled(False) self.controls["host"].setDisabled(False) else: - self.controls["ssl"].setChecked(False) self.controls["user"].setText("") self.controls["port"].setValue(1) self.controls["host"].setText("") - self.controls["ssl"].setDisabled(True) self.controls["user"].setDisabled(True) self.controls["password"].setDisabled(True) self.controls["port"].setDisabled(True) @@ -268,13 +261,11 @@ class ConnectionManager(QWidget): def slotLocalChanged(self, val): if val == 2: - self.controls["ssl"].setDisabled(True) self.controls["user"].setDisabled(True) self.controls["password"].setDisabled(True) self.controls["port"].setDisabled(True) self.controls["host"].setDisabled(True) elif val == 0: - self.controls["ssl"].setDisabled(False) self.controls["user"].setDisabled(False) self.controls["password"].setDisabled(False) self.controls["port"].setDisabled(False) @@ -286,7 +277,6 @@ class ConnectionManager(QWidget): d["default"] = self.default d["name"] = self.controls["name"].text() d["local"] = self.controls["local"].isChecked() - d["ssl"] = self.controls["ssl"].isChecked() d["user"] = self.controls["user"].text() d["password"] = self.controls["password"].text() d["host"] = self.controls["host"].text() diff --git a/module/gui/Overview.py b/module/gui/Overview.py index ad63bf9fd..72daf2e46 100644 --- a/module/gui/Overview.py +++ b/module/gui/Overview.py @@ -28,7 +28,7 @@ def formatSpeed(speed): while speed > 1000: speed /= 1024.0 steps += 1 - return "%i %s" % (speed, sizes[steps]) + return "%.2f %s" % (speed, sizes[steps]) class OverviewModel(QAbstractListModel): PackageName = 10 diff --git a/module/gui/Queue.py b/module/gui/Queue.py index 5acbf2eb3..977dd6e9a 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -44,7 +44,7 @@ def formatSpeed(speed): while speed > 1000: speed /= 1024.0 steps += 1 - return "%i %s" % (speed, sizes[steps]) + return "%.2f %s" % (speed, sizes[steps]) class QueueModel(CollectorModel): def __init__(self, view, connector): @@ -95,6 +95,10 @@ class QueueModel(CollectorModel): CollectorModel.removeEvent(self, event) self.updateCount() + def updateEvent(self, event): + CollectorModel.updateEvent(self, event) + self.updateCount() + def updateCount(self): packageCount = len(self._data) fileCount = 0 @@ -308,9 +312,9 @@ class QueueView(CollectorView): self.setColumnWidth(0, 300) self.setColumnWidth(1, 100) - self.setColumnWidth(2, 130) + self.setColumnWidth(2, 140) self.setColumnWidth(3, 50) - self.setColumnWidth(4, 120) + self.setColumnWidth(4, 130) self.setColumnWidth(5, 70) self.setEditTriggers(QAbstractItemView.NoEditTriggers) diff --git a/module/gui/connector.py b/module/gui/connector.py index a9cb0610c..5acfdfc8b 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -26,13 +26,8 @@ from PyQt4.QtGui import * import socket -from module.remote.thriftbackend.thriftgen.pyload import Pyload -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * -from module.remote.thriftbackend.Socket import Socket -from module.remote.thriftbackend.Protocol import Protocol - -from thrift import Thrift -from thrift.transport import TTransport +from module.remote.thriftbackend.ThriftClient import ThriftClient, WrongLogin, NoSSL, NoConnection +from thrift.Thrift import TException class Connector(QObject): def __init__(self): @@ -55,16 +50,17 @@ class Connector(QObject): self.ssl = ssl def connectProxy(self): - transport = Socket(self.host, self.port, self.ssl) - transport = TTransport.TBufferedTransport(transport) - protocol = Protocol(transport) - client = Pyload.Client(protocol) - - transport.open() - - if not client.login(self.user, self.password): + try: + client = ThriftClient(self.host, self.port, self.user, self.password) + except WrongLogin: self.emit(SIGNAL("error_box"), "bad login credentials") return False + except NoSSL: + self.emit(SIGNAL("error_box"), "no ssl support") + return False + except NoConnection: + self.emit(SIGNAL("connectionLost")) + return False self.proxy = DispatchRPC(self.mutex, client) self.connect(self.proxy, SIGNAL("proxy_error"), self._proxyError) @@ -113,15 +109,21 @@ class DispatchRPC(QObject): self.f = f self.mutex = mutex self.dispatcher = dispatcher - self.error = True def __call__(self, *args, **kwargs): + lost = False + error = False try: return self.f(*args, **kwargs) except socket.error: - self.dispatcher.emit(SIGNAL("connectionLost")) + lost = True + except TException: + lost = True except Exception, e: - if self.error: - self.dispatcher.emit(SIGNAL("proxy_error"), self.dispatcher.fname, e) + err = e finally: self.mutex.unlock() + if lost: + self.dispatcher.emit(SIGNAL("connectionLost")) + if error: + self.dispatcher.emit(SIGNAL("proxy_error"), self.dispatcher.fname, error) diff --git a/module/plugins/hooks/Ev0InFetcher.py b/module/plugins/hooks/Ev0InFetcher.py index f3703ea04..f573d28a3 100644 --- a/module/plugins/hooks/Ev0InFetcher.py +++ b/module/plugins/hooks/Ev0InFetcher.py @@ -79,7 +79,8 @@ class Ev0InFetcher(Hook, PluginStorage): self.setStorage("show_%s_lastfound" % show, int(mktime(item.date_parsed))) found = True if not found: - self.core.log.debug("Ev0InFetcher: no new episodes found") + #self.core.log.debug("Ev0InFetcher: no new episodes found") + pass for show, lastfound in self.getStorage().iteritems(): if int(lastfound) > 0 and int(lastfound) + (3600*24*30) < int(time()): diff --git a/module/remote/RemoteManager.py b/module/remote/RemoteManager.py index b66ed75e5..e0e5cdccf 100644 --- a/module/remote/RemoteManager.py +++ b/module/remote/RemoteManager.py @@ -73,4 +73,6 @@ class RemoteManager(): def checkAuth(self, user, password, remoteip=None): if self.core.config["remote"]["nolocalauth"] and remoteip == "127.0.0.1": return True + if self.core.startedInGui and remoteip == "127.0.0.1": + return True return self.core.db.checkAuth(user, password) diff --git a/module/remote/ThriftBackend.py b/module/remote/ThriftBackend.py index ab262cf76..208fb8c72 100644 --- a/module/remote/ThriftBackend.py +++ b/module/remote/ThriftBackend.py @@ -23,8 +23,8 @@ from thriftbackend.Handler import Handler from thriftbackend.Processor import Processor from thriftbackend.Protocol import ProtocolFactory from thriftbackend.Socket import ServerSocket +from thriftbackend.Transport import TransportFactory -from thrift.transport import TTransport from thrift.server import TServer class ThriftBackend(BackendBase): @@ -41,9 +41,9 @@ class ThriftBackend(BackendBase): key = self.core.config['ssl']['key'] cert = self.core.config['ssl']['cert'] - transport = ServerSocket(7228, self.core.config["remote"]["listenaddr"], key, cert) + transport = ServerSocket(int(self.core.config['remote']['port'])+1, self.core.config["remote"]["listenaddr"], key, cert) - tfactory = TTransport.TBufferedTransportFactory() + tfactory = TransportFactory() pfactory = ProtocolFactory() self.server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) 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 |