diff options
-rw-r--r-- | module/lib/SecureXMLRPCServer.py (renamed from module/remote/SecureXMLRPCServer.py) | 0 | ||||
-rw-r--r-- | module/remote/RemoteManager.py | 68 | ||||
-rw-r--r-- | module/remote/XMLRPCBackend.py | 41 | ||||
-rwxr-xr-x | pyLoadCore.py | 33 |
4 files changed, 114 insertions, 28 deletions
diff --git a/module/remote/SecureXMLRPCServer.py b/module/lib/SecureXMLRPCServer.py index 48586ee0b..48586ee0b 100644 --- a/module/remote/SecureXMLRPCServer.py +++ b/module/lib/SecureXMLRPCServer.py diff --git a/module/remote/RemoteManager.py b/module/remote/RemoteManager.py new file mode 100644 index 000000000..bc40ea124 --- /dev/null +++ b/module/remote/RemoteManager.py @@ -0,0 +1,68 @@ +# -*- 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 <http://www.gnu.org/licenses/>. + + @author: mkaay +""" + +from threading import Thread +from traceback import print_exc + +class BackendBase(Thread): + def __init__(self, manager): + Thread.__init__(self) + self.manager = manager + self.core = manager.core + + def run(self): + self.core.log.info(_("Starting %s") % self.__class__.__name__) + try: + self.serve() + except: + self.core.log.error(_("%s: Remote backend error") % self.__class__.__name__) + if self.core.debug: + print_exc() + + def setup(self): + pass + + def checkDeps(self): + return True + + def serve(self): + pass + +class RemoteManager(): + available = ("XMLRPCBackend", ) + + def __init__(self, core): + self.core = core + self.backends = [] + + def startBackends(self): + for b in self.available: + klass = getattr(__import__("module.remote.%s" % b, globals(), locals(), [b] , -1), b) + backend = klass(self) + if not backend.checkDeps(): + continue + try: + backend.setup() + except: + self.core.log.error(_("Failed loading backend %s") % b) + if self.core.debug: + print_exc() + else: + backend.start() + self.backends.append(backend) + diff --git a/module/remote/XMLRPCBackend.py b/module/remote/XMLRPCBackend.py new file mode 100644 index 000000000..6a7f9f96e --- /dev/null +++ b/module/remote/XMLRPCBackend.py @@ -0,0 +1,41 @@ +# -*- 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 <http://www.gnu.org/licenses/>. + + @author: mkaay, RaNaN +""" + +import module.lib.SecureXMLRPCServer as Server +from module.remote.RemoteManager import BackendBase + +from traceback import print_exc + +class XMLRPCBackend(BackendBase): + def setup(self): + server_addr = (self.core.config['remote']['listenaddr'], int(self.core.config['remote']['port'])) + usermap = {self.core.config.username: self.core.config.password} + if self.core.config['ssl']['activated']: + if exists(self.core.config['ssl']['cert']) and exists(self.core.config['ssl']['key']): + self.server = Server.SecureXMLRPCServer(server_addr, self.core.config['ssl']['cert'], + self.core.config['ssl']['key'], usermap) + else: + self.core.log.warning(_("SSL Certificates not found, fallback to auth XMLRPC server")) + self.server = Server.AuthXMLRPCServer(server_addr, usermap) + else: + self.server = Server.AuthXMLRPCServer(server_addr, usermap) + + self.server.register_instance(self.core.server_methods) + + def serve(self): + self.server.serve_forever() diff --git a/pyLoadCore.py b/pyLoadCore.py index eb6ffb468..9c2acfd81 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -67,6 +67,7 @@ from module.web.ServerThread import WebServer from module.FileDatabase import PyFile from module.Scheduler import Scheduler from module.JsEngine import JsEngine +from module.remote.RemoteManager import RemoteManager from codecs import getwriter if os.name == "nt": @@ -331,13 +332,14 @@ class Core(object): self.threadManager = ThreadManager(self) self.captchaManager = CaptchaManager(self) self.hookManager = HookManager(self) + self.remoteManager = RemoteManager(self) self.js = JsEngine() self.log.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) - - if xmlrpc: - self.init_server() + + self.remoteManager.startBackends() + if web: self.init_webserver() @@ -387,31 +389,6 @@ class Core(object): self.threadManager.work() self.scheduler.work() - def init_server(self): - try: - server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) - usermap = {self.config.username: self.config.password} - if self.config['ssl']['activated']: - if exists(self.config['ssl']['cert']) and exists(self.config['ssl']['key']): - self.server = Server.SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], - self.config['ssl']['key'], usermap) - self.log.info(_("Secure XMLRPC Server Started")) - else: - self.log.warning(_("SSL Certificates not found, fallback to auth XMLRPC server")) - self.server = Server.AuthXMLRPCServer(server_addr, usermap) - self.log.info(_("Auth XMLRPC Server Started")) - else: - self.server = Server.AuthXMLRPCServer(server_addr, usermap) - self.log.info(_("Auth XMLRPC Server Started")) - - self.server.register_instance(self.server_methods) - - thread.start_new_thread(self.server.serve_forever, ()) - except Exception, e: - self.log.error(_("Failed starting XMLRPC server CLI and GUI will not be available: %s") % str(e)) - if self.debug: - print_exc() - def init_webserver(self): if self.config['webinterface']['activated']: self.webserver = WebServer(self) |