diff --git a/deluge/ui/webui/webui_plugin/deluge_webserver.py b/deluge/ui/webui/webui_plugin/deluge_webserver.py index 2f9d31c2a..c3aeed0d7 100644 --- a/deluge/ui/webui/webui_plugin/deluge_webserver.py +++ b/deluge/ui/webui/webui_plugin/deluge_webserver.py @@ -35,10 +35,11 @@ from webserver_common import ws from lib.webpy022.request import webpyfunc from lib.webpy022 import webapi from lib.gtk_cherrypy_wsgiserver import CherryPyWSGIServer +import lib.webpy022 as web import os -def create_webserver(urls, methods): - func = webapi.wsgifunc(webpyfunc(urls, methods, False)) +def create_webserver(urls, methods, middleware): + func = webapi.wsgifunc(webpyfunc(urls, methods, False), *middleware) server_address=("0.0.0.0", int(ws.config.get('port'))) server = CherryPyWSGIServer(server_address, func, server_name="localhost") @@ -49,14 +50,18 @@ def create_webserver(urls, methods): print "http://%s:%d/" % server_address return server -def WebServer(): - import pages - return create_webserver(pages.urls, pages) +def WebServer(debug = False): + if debug: + middleware = [web.reloader] + else: + middleware = [] -def run(): - server = WebServer() + import pages + return create_webserver(pages.urls, pages, middleware) + +def run(debug = False): + server = WebServer(debug) try: server.start() except KeyboardInterrupt: server.stop() - diff --git a/deluge/ui/webui/webui_plugin/pages.py b/deluge/ui/webui/webui_plugin/pages.py index 926fdefee..26511e632 100644 --- a/deluge/ui/webui/webui_plugin/pages.py +++ b/deluge/ui/webui/webui_plugin/pages.py @@ -33,6 +33,7 @@ # from webserver_common import ws, proxy, log from utils import * +import utils #todo remove the line above. from render import render, error_page import page_decorators as deco import config_tabs_webui #auto registers @@ -40,6 +41,7 @@ import config_tabs_deluge #auto registers from config import config_page from torrent_options import torrent_options from torrent_move import torrent_move + #import forms # from debugerror import deluge_debugerror @@ -54,7 +56,7 @@ from lib.static_handler import static_handler from operator import attrgetter import os -from json_api import json_api +#from json_api import json_api #secuity leak, todo:fix #special/complex pages: from torrent_add import torrent_add @@ -85,9 +87,10 @@ urls = ( "/about", "about", "/logout", "logout", "/connect","connect", + "/daemon/control/(.*)","daemon_control", #remote-api: "/remote/torrent/add(.*)", "remote_torrent_add", - "/json/(.*)","json_api", + #"/json/(.*)","json_api", #static: "/static/(.*)", "static", "/template/static/(.*)", "template_static", @@ -328,12 +331,14 @@ class connect: @deco.check_session @deco.deluge_page_noauth def GET(self, name): - if proxy.connected(): - error = _("Not Connected to a daemon") - else: - error = None + try: + proxy.ping() + connected = proxy.get_core_uri() + except: + connected = None + connect_list = ["http://localhost:58846"] - return render.connect(connect_list, error) + return render.connect(connect_list, connected) def POST(self): vars = web.input(uri = None, other_uri = None) @@ -348,6 +353,34 @@ class connect: proxy.set_core_uri(uri) do_redirect() +class daemon_control: + @deco.check_session + def POST(self, command): + if command == 'stop': + proxy.shutdown() + elif command == 'start': + self.start() + elif command == 'restart': + proxy.shutdown() + self.start() + else: + raise Exception('Unknown command:"%s"' % command) + + seeother('/connect') + + def start(self): + import time + uri = web.input(uri = None).uri + if not uri: + uri = 'http://localhost:58846' + + port = int(uri.split(':')[2]) + utils.daemon_start_localhost(port) + + time.sleep(1) #pause a while to let it start? + proxy.set_core_uri( uri ) + + #other stuff: class remote_torrent_add: diff --git a/deluge/ui/webui/webui_plugin/run_webserver06 b/deluge/ui/webui/webui_plugin/run_webserver06 index 9c59c3749..5780cbf1f 100755 --- a/deluge/ui/webui/webui_plugin/run_webserver06 +++ b/deluge/ui/webui/webui_plugin/run_webserver06 @@ -1,5 +1,6 @@ #!/usr/bin/env python +#only for development/debugging. import deluge_webserver deluge_webserver.ws.init_06(uri = 'http://localhost:58846') -deluge_webserver.run() +deluge_webserver.run(debug = True) \ No newline at end of file diff --git a/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html b/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html index ff729ce19..fca2e0bad 100644 --- a/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html +++ b/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html @@ -13,8 +13,8 @@ $else: $_('Enable') ] -$_('Logout') -$_('Settings') + +$_('Admin') diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/about.html b/deluge/ui/webui/webui_plugin/templates/deluge/about.html index b34b7877a..f0d1c2b1e 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/about.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/about.html @@ -1,4 +1,5 @@ $:render.header(_('About')) +$:render.admin_toolbar('about')
$version@@ -20,20 +21,12 @@ $:render.header(_('About'))
+ $_('Connected to') + $connected + | + + | + + |