diff --git a/deluge/ui/webui/config_forms.py b/deluge/ui/webui/config_forms.py index fa2eeba8a..5a411ed25 100644 --- a/deluge/ui/webui/config_forms.py +++ b/deluge/ui/webui/config_forms.py @@ -36,7 +36,7 @@ from deluge.ui.client import sclient as proxy from deluge.log import LOG as log from render import render -from web import seeother +from utils import seeother import sys import os import utils diff --git a/deluge/ui/webui/deluge_webserver.py b/deluge/ui/webui/deluge_webserver.py index 1138c019f..398cea266 100644 --- a/deluge/ui/webui/deluge_webserver.py +++ b/deluge/ui/webui/deluge_webserver.py @@ -79,11 +79,9 @@ config_forms.register() #/self registering pages. -utils.set_config_defaults() -sclient.set_core_uri(config.get('daemon')) - - -def WsgiApplication(middleware): +def WsgiApplication(middleware = None): + if not middleware: + middleware = [] from web import webpyfunc, wsgifunc from deluge import component @@ -92,17 +90,21 @@ def WsgiApplication(middleware): def WebServer(debug = False): "starts builtin webserver" + + utils.set_config_defaults() + config.set('base','') + config.set('disallow',{}) + utils.apply_config() + import web from lib.gtk_cherrypy_wsgiserver import CherryPyWSGIServer - if debug: middleware = [web.reloader] else: middleware = [] - wsgi_app = WsgiApplication(middleware) server_address=("0.0.0.0", int(config.get('port'))) @@ -116,6 +118,9 @@ def WebServer(debug = False): print "http://%s:%d/" % server_address return server +def mod_wsgi_application(sub_dir, config_dir , template_dir): + pass + def run(debug = False): server = WebServer(debug) try: diff --git a/deluge/ui/webui/lib/static_handler.py b/deluge/ui/webui/lib/static_handler.py index 5d02d0041..9b4a8c3e0 100644 --- a/deluge/ui/webui/lib/static_handler.py +++ b/deluge/ui/webui/lib/static_handler.py @@ -7,7 +7,7 @@ static fileserving for web.py without the need for wsgi wrapper magic. """ import web -from web import seeother, url +from web import url import posixpath import urlparse diff --git a/deluge/ui/webui/page_decorators.py b/deluge/ui/webui/page_decorators.py index 29eb252b9..a200a02aa 100644 --- a/deluge/ui/webui/page_decorators.py +++ b/deluge/ui/webui/page_decorators.py @@ -10,8 +10,9 @@ from deluge.log import LOG as log #/relative from web import cookies, setcookie as w_setcookie -from web import seeother, url -from web import changequery as self_url +from web import url, changequery +from utils import self_url +from render import error_page #deco's: def deluge_page_noauth(func): @@ -28,20 +29,32 @@ def deluge_page_noauth(func): def check_session(func): """ + 1:check session + 2:block urls in config.disallow return func if session is valid, else redirect to login page. mostly used for POST-pages. """ def deco(self, name = None): log.debug('%s.%s(name=%s)' % (self.__class__.__name__, func.__name__, name)) + #check disallow config + current_url = changequery() + for blocked in utils.config["disallow"]: + if current_url.startswith(blocked): + return error_page("Not allowed to : '%s' , Reason: '%s'" % + (blocked , utils.config["disallow"][blocked])) + #/check disallow + + #check session: vars = web.input(redir_after_login = None) ck = cookies() if ck.has_key("session_id") and ck["session_id"] in utils.SESSIONS: return func(self, name) #check_session:ok elif vars.redir_after_login: - seeother(url("/login",redir=self_url())) + utils.seeother(url("/login",redir=self_url())) else: - seeother("/login") #do not continue, and redirect to login page + utils.seeother("/login") #do not continue, and redirect to login page + #/check session deco.__name__ = func.__name__ return deco @@ -56,9 +69,7 @@ def check_connected(func): if connected: return func(self, name) #check_connected:ok else: - seeother("/connect") - - + utils.seeother("/connect") deco.__name__ = func.__name__ return deco @@ -122,3 +133,16 @@ def remote(func): print traceback.format_exc() deco.__name__ = func.__name__ return deco + +""" +obsolete: -> using check-session. +def check_allowed(capability): + def check_allowed_inner(func): + def deco(self, name = None): #check allowed (capablity) + if capability in config.get("disallow"): + return error_page("Not allowed to: '%s' , because:'%s'" + % (capability , config.get("disallow")[capability])) + return func(self, name) + return deco + return check_allowed_inner +""" \ No newline at end of file diff --git a/deluge/ui/webui/pages.py b/deluge/ui/webui/pages.py index 5e088f5c1..cd10eb1d1 100644 --- a/deluge/ui/webui/pages.py +++ b/deluge/ui/webui/pages.py @@ -43,7 +43,7 @@ from deluge.common import get_pixmap from deluge.log import LOG as log import web -from web import seeother, url +from web import url from lib.static_handler import static_handler from operator import attrgetter @@ -74,9 +74,10 @@ class login: start_session() do_redirect() elif vars.redir: - seeother(url('/login', error=1, redir=vars.redir)) + utils.seeother(url('/login', error=1, redir=vars.redir)) else: - seeother('/login?error=1') + utils.seeother('/login?error=1') + route('/login',login) class index: @@ -259,7 +260,7 @@ class logout: @deco.check_session def POST(self, name): end_session() - seeother('/login') + utils.seeother('/login') route('/logout', logout) class connect: @@ -304,7 +305,7 @@ class daemon_control: else: raise Exception('Unknown command:"%s"' % command) - seeother('/connect') + utils.seeother('/connect') def start(self): import time @@ -388,3 +389,13 @@ class pixmaps: web.header("Cache-Control" , "public, must-revalidate, max-age=86400") print content route("/pixmaps/(.*)", pixmaps) + +""" +#debug: +class catch_all: + @deco.deluge_page_noauth + def GET(self, name): + log.debug("xname=" + name) + print "name=" + name +route("(.*)", catch_all) +""" \ No newline at end of file diff --git a/deluge/ui/webui/render.py b/deluge/ui/webui/render.py index 36bc3ee66..733e2cca3 100644 --- a/deluge/ui/webui/render.py +++ b/deluge/ui/webui/render.py @@ -32,9 +32,10 @@ #relative: from webserver_common import REVNO, VERSION from utils import * +import utils #/relative from deluge import common -from web import changequery as self_url, template, Storage +from web import template, Storage import os from deluge.configmanager import ConfigManager @@ -56,14 +57,14 @@ class subclassed_render(object): self.webui_path = os.path.dirname(__file__) #load template-meta-data - cfg_template = config.get('template') - template_path = os.path.join(self.webui_path, 'templates/%s/' % cfg_template) + self.cfg_template = config.get('template') + template_path = os.path.join(self.webui_path, 'templates/%s/' % self.cfg_template) if not os.path.exists(template_path): template_path = os.path.join(self.webui_path, 'templates/deluge/') self.meta = Storage(eval(open(os.path.join(template_path,'meta.cfg')).read())) #load renerders - for template_name in [cfg_template] + list(reversed(self.meta.inherits)): + for template_name in [self.cfg_template] + list(reversed(self.meta.inherits)): self.renderers.append(template.render( os.path.join(self.webui_path, 'templates/%s/' % template_name),cache=False)) @@ -86,8 +87,7 @@ class subclassed_render(object): if hasattr(renderer, attr): self.template_cache[attr] = getattr(renderer, attr) return getattr(renderer, attr) - - raise AttributeError, 'no template named "%s" ' % attr + raise AttributeError, 'no template named "%s" in base path "%s"' % (attr, self.webui_path) def __getitem__(self, item): "for plugins/templates" @@ -102,6 +102,9 @@ class subclassed_render(object): if os.path.isdir(os.path.join(template_path, dirname)) and not dirname.startswith('.')] + @staticmethod + def set_global(key, val): + template.Template.globals[key] = val render = subclassed_render() @@ -186,7 +189,7 @@ template.Template.globals.update({ 'sorted': sorted, 'altrow':altrow, 'get_config': get_config, - 'self_url': self_url, + 'self_url': utils.self_url, 'fspeed': common.fspeed, 'fsize': common.fsize, 'ftime':ftime, @@ -195,10 +198,10 @@ template.Template.globals.update({ 'version': VERSION, 'getcookie':getcookie, 'get': lambda (var): getattr(web.input(**{var:None}), var), # unreadable :-( - 'env':'0.6', + #'env':'0.6', 'forms':web.Storage(), - 'enumerate':enumerate - + 'enumerate':enumerate, + 'base':'' #updated when running within apache. }) #/template-defs diff --git a/deluge/ui/webui/static/deluge.js b/deluge/ui/webui/static/deluge.js index da6be06e1..55ad88cd3 100644 --- a/deluge/ui/webui/static/deluge.js +++ b/deluge/ui/webui/static/deluge.js @@ -7,8 +7,9 @@ so i'd rather start from scratch, Probably broken in an unexpected way , but worksforme. */ state = { - 'row_js_continue':true - ,'selected_rows': new Array() + 'row_js_continue':true, + 'selected_rows': new Array(), + 'base_url':'' }; function $(el_id){ @@ -91,7 +92,7 @@ function open_details(e, id){ function open_inner_details(id){ /*probably broken for IE, use FF!*/ - $('torrent_info').src = '/torrent/info_inner/' + id; + $('torrent_info').src = state.base_url + '/torrent/info_inner/' + id; } function on_click_do_nothing(e, id){ diff --git a/deluge/ui/webui/templates/advanced/header.html b/deluge/ui/webui/templates/advanced/header.html index 0bab1d04b..4533bcbdb 100644 --- a/deluge/ui/webui/templates/advanced/header.html +++ b/deluge/ui/webui/templates/advanced/header.html @@ -2,10 +2,10 @@ $def with (title, active_tab=None)
- | diff --git a/deluge/ui/webui/templates/advanced/torrent_info_inner.html b/deluge/ui/webui/templates/advanced/torrent_info_inner.html index 3054e8508..a9bb622dc 100644 --- a/deluge/ui/webui/templates/advanced/torrent_info_inner.html +++ b/deluge/ui/webui/templates/advanced/torrent_info_inner.html @@ -3,7 +3,7 @@ $def with (torrent, active_tab)- |
-
@@ -25,7 +25,7 @@ $if connected:
$else:
$_("Not Connected to a daemon")
- |