diff options
Diffstat (limited to 'module/web')
-rw-r--r-- | module/web/api_app.py | 15 | ||||
-rw-r--r-- | module/web/json_app.py | 13 | ||||
-rw-r--r-- | module/web/pyload_app.py | 16 | ||||
-rw-r--r-- | module/web/utils.py | 1 | ||||
-rw-r--r-- | module/web/webinterface.py | 4 |
5 files changed, 23 insertions, 26 deletions
diff --git a/module/web/api_app.py b/module/web/api_app.py index affcdb39a..6c93266fc 100644 --- a/module/web/api_app.py +++ b/module/web/api_app.py @@ -24,13 +24,17 @@ class TBaseEncoder(json.JSONEncoder): return json.JSONEncoder.default(self, o) +def add_header(r): + r.headers.replace("Content-type", "application/json") + r.headers.append("Cache-Control", "no-cache, must-revalidate") + r.headers.append("Access-Control-Allow-Origin", "*") # allow xhr requests + # accepting positional arguments, as well as kwargs via post and get # only forbidden path symbol are "?", which is used to seperate GET data and # @route("/api/<func><args:re:[^#?]*>") @route("/api/<func><args:re:[^#?]*>", method="POST") def call_api(func, args=""): - response.headers.replace("Content-type", "application/json") - response.headers.append("Cache-Control", "no-cache, must-revalidate") + add_header(response) s = request.environ.get('beaker.session') if 'session' in request.POST: @@ -62,6 +66,7 @@ def callApi(func, *args, **kwargs): print "Invalid API call", func return HTTPError(404, json.dumps("Not Found")) + # TODO: encoding result = getattr(PYLOAD, func)(*[literal_eval(x) for x in args], **dict([(x, literal_eval(y)) for x, y in kwargs.iteritems()])) @@ -74,8 +79,7 @@ def callApi(func, *args, **kwargs): #post -> username, password @route("/api/login", method="POST") def login(): - response.headers.replace("Content-type", "application/json") - response.headers.append("Cache-Control", "no-cache, must-revalidate") + add_header(response) user = request.forms.get("username") password = request.forms.get("password") @@ -97,8 +101,7 @@ def login(): @route("/api/logout") def logout(): - response.headers.replace("Content-type", "application/json") - response.headers.append("Cache-Control", "no-cache, must-revalidate") + add_header(response) s = request.environ.get('beaker.session') s.delete() diff --git a/module/web/json_app.py b/module/web/json_app.py index 5acafe153..fcaa906e1 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -11,16 +11,7 @@ from webinterface import PYLOAD from utils import login_required, render_to_response, toDict -from module.utils import decode, formatSize - - -def format_time(seconds): - seconds = int(seconds) - - hours, seconds = divmod(seconds, 3600) - minutes, seconds = divmod(seconds, 60) - return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) - +from module.utils import decode, format_size def get_sort_key(item): return item["order"] @@ -49,7 +40,7 @@ def links(): ids.append(link['fid']) if link['status'] == 12: - link['info'] = "%s @ %s/s" % (link['format_eta'], formatSize(link['speed'])) + link['info'] = "%s @ %s/s" % (link['format_eta'], format_size(link['speed'])) elif link['status'] == 5: link['percent'] = 0 link['size'] = 0 diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index dcfc3266e..4edc6e0a5 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -25,6 +25,7 @@ import sys from os.path import isdir, isfile, join, abspath from sys import getfilesystemencoding from urllib import unquote +from traceback import print_exc from bottle import route, static_file, request, response, redirect, HTTPError, error @@ -35,8 +36,8 @@ from utils import render_to_response, parse_permissions, parse_userdata, \ from filters import relpath, unquotepath -from module.utils import formatSize -from module.utils.fs import save_join, fs_encode, fs_decode, listdir, free_space +from module.utils import format_size +from module.utils.fs import save_join, fs_encode, fs_decode, listdir # Helper @@ -79,7 +80,7 @@ def error500(error): if error.traceback: print error.traceback - return base(["An Error occured, please enable debug mode to get more details.", error, + return base(["An error occured while processing the request.", error, error.traceback.replace("\n", "<br>") if error.traceback else "No Traceback"]) # render js @@ -151,10 +152,11 @@ def logout(): @login_required("LIST") def home(): try: - res = [toDict(x) for x in PYLOAD.statusDownloads()] + res = [toDict(x) for x in PYLOAD.getProgressInfo()] except: s = request.environ.get('beaker.session') s.delete() + print_exc() return redirect("/login") for link in res: @@ -241,7 +243,7 @@ def get_download(path): @route("/settings") @login_required('SETTINGS') def config(): - conf = PYLOAD.getConfigPointer() + conf = PYLOAD.getConfigRef() conf_menu = [] plugin_menu = [] @@ -509,7 +511,7 @@ def setup(): @login_required("STATUS") @route("/info") def info(): - conf = PYLOAD.getConfigPointer() + conf = PYLOAD.getConfigRef() if hasattr(os, "uname"): extra = os.uname() @@ -521,7 +523,7 @@ def info(): "version": PYLOAD.getServerVersion(), "folder": abspath(PYLOAD_DIR), "config": abspath(""), "download": abspath(conf["general"]["download_folder"]), - "freespace": formatSize(PYLOAD.freeSpace()), + "freespace": format_size(PYLOAD.freeSpace()), "remote": conf["remote"]["port"], "webif": conf["webinterface"]["port"], "language": conf["general"]["language"]} diff --git a/module/web/utils.py b/module/web/utils.py index a89c87558..5cb0cebdd 100644 --- a/module/web/utils.py +++ b/module/web/utils.py @@ -104,6 +104,7 @@ def login_required(perm=None): if s.get("name", None) and s.get("authenticated", False): if perm: perms = parse_permissions(s) + if perm not in perms or not perms[perm]: if request.headers.get('X-Requested-With') == 'XMLHttpRequest': return HTTPError(403, "Forbidden") diff --git a/module/web/webinterface.py b/module/web/webinterface.py index ec8b2e56c..56043063e 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -30,7 +30,7 @@ PYLOAD_DIR = abspath(join(PROJECT_DIR, "..", "..")) sys.path.append(PYLOAD_DIR) from module import InitHomeDir -from module.utils import decode, formatSize +from module.utils import decode, format_size import bottle from bottle import run, app @@ -92,7 +92,7 @@ env.filters["path_make_relative"] = path_make_relative env.filters["path_make_absolute"] = path_make_absolute env.filters["decode"] = decode env.filters["type"] = lambda x: str(type(x)) -env.filters["formatsize"] = formatSize +env.filters["formatsize"] = format_size env.filters["getitem"] = lambda x, y: x.__getitem__(y) if PREFIX: env.filters["url"] = lambda x: x |