From 44941dd9b11d9140589f7b1eacb9baf2a82d4c8b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 3 Apr 2010 11:06:18 +0200 Subject: webif settings page --- module/config/core_default.xml | 6 -- module/web/ServerThread.py | 4 + module/web/cnl/views.py | 2 +- module/web/pyload/views.py | 38 ++++++++- module/web/settings.py | 20 +++-- module/web/templates/default/settings.html | 133 ++++++----------------------- 6 files changed, 82 insertions(+), 121 deletions(-) (limited to 'module') diff --git a/module/config/core_default.xml b/module/config/core_default.xml index d1c059060..ab247be08 100644 --- a/module/config/core_default.xml +++ b/module/config/core_default.xml @@ -18,12 +18,6 @@ 0.0.0.0 8001 - True - False - None - None - None - None True diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py index aa1f67244..c4efc61dc 100644 --- a/module/web/ServerThread.py +++ b/module/web/ServerThread.py @@ -10,10 +10,14 @@ from cStringIO import StringIO import threading import sys +core = None + class WebServer(threading.Thread): def __init__(self, pycore): + global core threading.Thread.__init__(self) self.pycore = pycore + core = pycore self.running = True self.server = pycore.config['webinterface']['server'] self.https = pycore.config['webinterface']['https'] diff --git a/module/web/cnl/views.py b/module/web/cnl/views.py index aeb6174a7..69a2ce4e8 100644 --- a/module/web/cnl/views.py +++ b/module/web/cnl/views.py @@ -19,7 +19,7 @@ except: def local_check(function): def _dec(view_func): def _view(request, * args, ** kwargs): - if request.META['REMOTE_ADDR'] == '127.0.0.1' or request.META['REMOTE_ADDR'] == 'localhost': + if request.META.get('REMOTE_ADDR', "0") in ('127.0.0.1','localhost') or request.META.get('HTTP_HOST','0') == '127.0.0.1:9666': return view_func(request, * args, ** kwargs) else: return HttpResponseServerError() diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 6dbbd22c6..db04f8c67 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -170,5 +170,41 @@ def collector(request): @check_server def config(request): conf = settings.PYLOAD.get_config_data() + + if request.META.get('REQUEST_METHOD', "GET") == "POST": + + errors = [] + + for key, value in request.POST.iteritems(): + if not "|" in key: continue + skey, okey = key.split("|")[:] + if conf.has_key(skey): + if conf[skey]['options'].has_key(okey): + try: + if str(conf[skey]['options'][okey]['value']) != value: + settings.PYLOAD.set_conf_val(skey, okey, value) + except: + errors.append("%s | %s" % (skey, okey)) + else: + continue + else: + continue + + messages = [] + + if errors: + messages.append(_("Error occured when setting the following options:")) + messages.append("") + messages += errors + else: + messages.append(_("All options set correctly.")) + + return render_to_response(join(settings.TEMPLATE, 'settings.html'), RequestContext(request, {'conf': {}, 'errors': messages}, [status_proc])) + + + for section in conf.iterkeys(): + for option in conf[section]['options'].iterkeys(): + if conf[section]['options'][option]['input']: + conf[section]['options'][option]['input'] = conf[section]['options'][option]['input'].split(";") - return render_to_response(join(settings.TEMPLATE, 'settings.html'), RequestContext(request, {'conf': conf}, [status_proc])) + return render_to_response(join(settings.TEMPLATE, 'settings.html'), RequestContext(request, {'conf': conf, 'messages': []}, [status_proc])) diff --git a/module/web/settings.py b/module/web/settings.py index bbea1690b..3ab5ff20e 100644 --- a/module/web/settings.py +++ b/module/web/settings.py @@ -6,7 +6,6 @@ TEMPLATE_DEBUG = DEBUG import os.path import sys -import xmlrpclib SERVER_VERSION = "0.3.2" @@ -22,13 +21,19 @@ config = XMLConfigParser(os.path.join(PYLOAD_DIR,"module","config","core.xml")) #DEBUG = config.get("general","debug") +try: + import module.web.ServerThread + if not module.web.ServerThread.core: + raise Exception + PYLOAD = module.web.ServerThread.core.server_methods +except: + import xmlrpclib + ssl = "" -ssl = "" + if config.get("ssl", "activated"): + ssl = "s" -if config.get("ssl", "activated"): - ssl = "s" - -server_url = "http%s://%s:%s@%s:%s/" % ( + server_url = "http%s://%s:%s@%s:%s/" % ( ssl, config.get("remote", "username"), config.get("remote", "password"), @@ -36,7 +41,8 @@ server_url = "http%s://%s:%s@%s:%s/" % ( config.get("remote", "port") ) -PYLOAD = xmlrpclib.ServerProxy(server_url, allow_none=True) + PYLOAD = xmlrpclib.ServerProxy(server_url, allow_none=True) + TEMPLATE = config.get('webinterface','template') DL_ROOT = os.path.join(PYLOAD_DIR, config.get('general','download_folder')) diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index d3d906c47..4d2d2a591 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -27,126 +27,47 @@ {% block content %} -{{ conf }} +{% for message in errors %} +{{message}}
+{% endfor %} +
-

Coming Soon.

- - - - {% for key, section in conf.items %} + {% for skey, section in conf.items %}
{{section.name}} - {% for key, option in section.options.items %} + {% for okey, option in section.options.items %} -
{% endfor %} - -
- - Name - - - - -
-
-
- - - Address - - - - - - -
-
-
- - Payment details - -
- - - Credit card - - - - - - -
-
- - - - -
- -
+ {% if conf %} + +
+ {% endif %}
-- cgit v1.2.3