diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-19 21:58:08 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-02-19 21:58:08 +0100 |
commit | 63f8af1fc3049527a4a4b53a1bbfde90cb4b2eb3 (patch) | |
tree | 8227674ebd87c28df53bad55de401a9264a283b4 /module/web | |
parent | fixed cli unicode error (diff) | |
download | pyload-63f8af1fc3049527a4a4b53a1bbfde90cb4b2eb3.tar.xz |
encoding fixes
Diffstat (limited to 'module/web')
-rw-r--r-- | module/web/json_app.py | 13 | ||||
-rw-r--r-- | module/web/pyload_app.py | 14 | ||||
-rw-r--r-- | module/web/templates/jinja/default/base.html | 8 | ||||
-rw-r--r-- | module/web/utils.py | 23 | ||||
-rw-r--r-- | module/web/webinterface.py | 5 |
5 files changed, 39 insertions, 24 deletions
diff --git a/module/web/json_app.py b/module/web/json_app.py index f10c09498..8eb2dbbfe 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -210,7 +210,7 @@ def link_order(ids): @route("/json/add_package", method="POST") @login_required('can_add') def add_package(): - name = request.forms['add_name'] + name = request.forms.get("add_name", "New Package") queue = int(request.forms['add_dest']) links = request.forms['add_links'].decode("utf8", "ignore") links = links.split("\n") @@ -219,7 +219,7 @@ def add_package(): try: f = request.files['add_file'] - if name is None or name == "": + if name == "New Package": name = f.name fpath = join(PYLOAD.get_conf_val("general", "download_folder"), "tmp_" + f.filename) @@ -230,9 +230,6 @@ def add_package(): except: pass - if name is None or name == "": - return HTTPError() - name = name.decode("utf8", "ignore") links = map(lambda x: x.strip(), links) @@ -283,10 +280,10 @@ def move_package(dest, id): def edit_package(): try: id = int(request.forms.get("pack_id")) - data = {"name": request.forms.get("pack_name"), - "folder": request.forms.get("pack_folder"), + data = {"name": request.forms.get("pack_name").decode("utf8", "ignore"), + "folder": request.forms.get("pack_folder").decode("utf8", "ignore"), "priority": request.forms.get("pack_prio"), - "password": request.forms.get("pack_pws")} + "password": request.forms.get("pack_pws").decode("utf8", "ignore")} PYLOAD.set_package_data(id, data) return "success" diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index 82701e755..643e1e75c 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -38,7 +38,7 @@ from webinterface import PYLOAD, PROJECT_DIR, SETUP from utils import render_to_response, parse_permissions, parse_userdata, login_required from filters import relpath, unquotepath -from module.utils import formatSize +from module.utils import formatSize, decode # Helper @@ -69,6 +69,9 @@ def base(messages): ## Views @error(500) def error500(error): + if request.header.get('X-Requested-With') == 'XMLHttpRequest': + return HTTPError(500, error.traceback) + return base(["An Error occured, please enable debug mode to get more details.", error, error.traceback.replace("\n", "<br>") if error.traceback else "No Traceback"]) @@ -103,6 +106,7 @@ def login_post(): s = request.environ.get('beaker.session') s["authenticated"] = True + s["id"] = info["id"] s["name"] = info["name"] s["role"] = info["role"] s["perms"] = info["permission"] @@ -171,14 +175,14 @@ def downloads(): for item in sorted(listdir(root)): if isdir(join(root, item)): folder = { - 'name': item, - 'path': item, + 'name': decode(item), + 'path': decode(item), 'files': [] } for file in sorted(listdir(join(root, item))): try: if isfile(join(root, item, file)): - folder['files'].append(file) + folder['files'].append(decode(file)) except: pass @@ -466,7 +470,7 @@ def logs(item=-1): if counter >= item: try: - date, time, level, message = l.split(" ", 3) + date, time, level, message = l.decode("utf8", "ignore").split(" ", 3) dtime = datetime.strptime(date + ' ' + time, '%d.%m.%Y %H:%M:%S') except: dtime = None diff --git a/module/web/templates/jinja/default/base.html b/module/web/templates/jinja/default/base.html index f5e2b9634..0931291b7 100644 --- a/module/web/templates/jinja/default/base.html +++ b/module/web/templates/jinja/default/base.html @@ -30,9 +30,9 @@ document.addEvent("domready", function(){ $('add_form').onsubmit=function() {
$('add_form').target = 'upload_target';
- if ($('add_name').value == "" && $('add_file').value != " "){
+ if ($('add_name').value == "" && $('add_file').value == ""){
alert("{{_("Please Enter a packagename.")}}");
- return false
+ return false;
}else{
out();
}
@@ -259,7 +259,7 @@ function AddBox() <div style="clear:both;"></div>
</div>
-{% if perms.can_change_status %}
+{% if perms.status %}
<ul id="page-actions2">
<li id="action_play"><a href="#" class="action play" accesskey="o" rel="nofollow">{{_("Start")}}</a></li>
<li id="action_stop"><a href="#" class="action stop" accesskey="o" rel="nofollow">{{_("Stop")}}</a></li>
@@ -268,7 +268,7 @@ function AddBox() </ul>
{% endif %}
-{% if perms.can_see_dl %}
+{% if perms.see_downloads %}
<ul id="page-actions">
<li><span class="time">{{_("Download:")}}</span><a id="time" style=" background-color: {% if status.download %}#8ffc25{% else %} #fc6e26{% endif %}; padding-left: 0cm; padding-right: 0.1cm; "> {% if status.download %}{{_("on")}}{% else %}{{_("off")}}{% endif %}</a></li>
<li><span class="reconnect">{{_("Reconnect:")}}</span><a id="reconnect" style=" background-color: {% if status.reconnect %}#8ffc25{% else %} #fc6e26{% endif %}; padding-left: 0cm; padding-right: 0.1cm; "> {% if status.reconnect %}{{_("on")}}{% else %}{{_("off")}}{% endif %}</a></li>
diff --git a/module/web/utils.py b/module/web/utils.py index f738560f7..8674fea1c 100644 --- a/module/web/utils.py +++ b/module/web/utils.py @@ -20,6 +20,8 @@ from bottle import request, HTTPError, redirect, ServerAdapter from webinterface import env, TEMPLATE +from module.database.UserDatabase import has_permission, PERMS, ROLE + def render_to_response(name, args={}, proc=[]): for p in proc: args.update(p()) @@ -28,14 +30,27 @@ def render_to_response(name, args={}, proc=[]): return t.render(**args) def parse_permissions(session): - perms = {"can_change_status": False, - "can_see_dl": False} + perms = {"add": False, + "delete": False, + "status": False, + "see_downloads": False, + "download" : False, + "settings": False} if not session.get("authenticated", False): return perms - perms["can_change_status"] = True - perms["can_see_dl"] = True + if session.get("role") == ROLE.ADMIN: + for k in perms.iterkeys(): + perms[k] = True + else: + p = session.get("permission") + perms["add"] = has_permission(p, PERMS.ADD) + perms["delete"] = has_permission(p, PERMS.DELETE) + perms["status"] = has_permission(p, PERMS.STATUS) + perms["see_downloads"] = has_permission(p, PERMS.SEE_DOWNLOADS) + perms["download"] = has_permission(p, PERMS.DOWNLOAD) + perms["settings"] = has_permission(p, PERMS.SETTINGS) return perms diff --git a/module/web/webinterface.py b/module/web/webinterface.py index 0d94fb4dc..54468d936 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -90,14 +90,14 @@ JS = JsEngine() TEMPLATE = config.get('webinterface', 'template') DL_ROOT = config.get('general', 'download_folder') LOG_ROOT = config.get('log', 'log_folder') -DEBUG = config.get("general","debug_mode") +DEBUG = config.get("general","debug_mode") or "-d" in sys.argv or "--debug" in sys.argv bottle.debug(DEBUG) cache = join("tmp", "jinja_cache") if not exists(cache): makedirs(cache) -bcc = FileSystemBytecodeCache(cache) +bcc = FileSystemBytecodeCache(cache, '%s.cache') loader = PrefixLoader({ "default": FileSystemLoader(join(PROJECT_DIR, "templates", "jinja", "default")) }) @@ -133,7 +133,6 @@ import pyload_app import json_app import cnl_app - def run_simple(host="0.0.0.0", port="8000"): run(app=web, host=host, port=port, quiet=True) |