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

$version 
@@ -20,20 +21,12 @@ $:render.header(_('About'))
  • Martijn Voncken
  • -

    Template

    - -

    Deluge

    @@ -41,9 +34,7 @@ $:render.header(_('About')) - - -*and all other authors/helpers/contributors I forgot to mention.
    +*and all other authors/helpers/contributors I forgot to mention $:render.footer() diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/admin_toolbar.html b/deluge/ui/webui/webui_plugin/templates/deluge/admin_toolbar.html index cec7fb69a..7b047cf11 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/admin_toolbar.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/admin_toolbar.html @@ -4,5 +4,7 @@ $def with (active_tab) Connect + About + Logout diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/connect.html b/deluge/ui/webui/webui_plugin/templates/deluge/connect.html index 9c29a19a0..9ae35785e 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/connect.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/connect.html @@ -1,12 +1,34 @@ -$def with (connect_list, error) +$def with (connect_list, connected) $:render.header(_("Connect to Daemon")) $:render.admin_toolbar('connect')
    -$if error: -
    $error
    +$if connected: + +
    + $_('Connected to') + $connected + +
    + +
    +
    +
    + +
    +
    +$else: +
    $_("Not Connected to a daemon") +
    +
    + + +
    $for i, uri in enumerate(connect_list): diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/login.html b/deluge/ui/webui/webui_plugin/templates/deluge/login.html index 0436e9076..3aecccfd1 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/login.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/login.html @@ -16,9 +16,6 @@ $if error > 0:
    - -
    - $_('About') diff --git a/deluge/ui/webui/webui_plugin/utils.py b/deluge/ui/webui/webui_plugin/utils.py index 5ccb9d841..005346494 100644 --- a/deluge/ui/webui/webui_plugin/utils.py +++ b/deluge/ui/webui/webui_plugin/utils.py @@ -308,6 +308,30 @@ def get_newforms_data(form_class): #/utils +#generic/ non-webui utils todo: move to trunk/core. +def daemon_test_online_status(uri): + """Tests the status of URI.. Returns True or False depending on status. + """ + online = True + host = None + try: + host = xmlrpclib.ServerProxy(uri) + host.ping() + except socket.error: + online = False + + del host + self.online_status[uri] = online + return online + +def daemon_start_localhost(port): + """Starts a localhost daemon""" + port = str(port) + log.info("Starting localhost:%s daemon..", port) + # Spawn a local daemon + os.popen("deluged -p %s" % port) + +#exceptions: class WebUiError(Exception): """the message of these exceptions will be rendered in render.error(e.message) in debugerror.py"""