summaryrefslogtreecommitdiffstats
path: root/module/remote
diff options
context:
space:
mode:
Diffstat (limited to 'module/remote')
-rw-r--r--module/remote/RemoteManager.py2
-rw-r--r--module/remote/ThriftBackend.py6
-rw-r--r--module/remote/thriftbackend/Handler.py7
-rw-r--r--module/remote/thriftbackend/Processor.py4
-rw-r--r--module/remote/thriftbackend/Socket.py2
-rw-r--r--module/remote/thriftbackend/ThriftClient.py4
-rw-r--r--module/remote/thriftbackend/Transport.py15
7 files changed, 29 insertions, 11 deletions
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