diff options
-rw-r--r-- | module/config/default.conf | 1 | ||||
-rw-r--r-- | module/network/Browser.py | 13 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 2 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 5 | ||||
-rw-r--r-- | module/network/HTTPRequest.py | 11 | ||||
-rw-r--r-- | module/network/RequestFactory.py | 15 | ||||
-rw-r--r-- | module/web/json_app.py | 180 | ||||
-rw-r--r-- | module/web/templates/default/filemanager_ui.js | 9 |
8 files changed, 99 insertions, 137 deletions
diff --git a/module/config/default.conf b/module/config/default.conf index 5c90888e9..bc9bcee3e 100644 --- a/module/config/default.conf +++ b/module/config/default.conf @@ -36,6 +36,7 @@ download - "Download": bool limit_speed : "Limit Download Speed" = False
bool proxy : "Use Proxy" = False
str interface : "Download interface to bind (ip or Name)" = None
+ bool ipv6 : "Allow IPv6" = False
permission - "Permissions":
bool change_user : "Change user of running process" = False
str user : "Username" = user
diff --git a/module/network/Browser.py b/module/network/Browser.py index 9020a6de1..2dc9c3d83 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -8,17 +8,16 @@ from HTTPDownload import HTTPDownload class Browser(object): - def __init__(self, interface=None, bucket=None, proxies={}): + def __init__(self, bucket=None, options={}): self.log = getLogger("log") - self.interface = interface + self.options = options #holds pycurl options self.bucket = bucket - self.proxies = proxies self.cj = None # needs to be setted later self._size = 0 - self.http = HTTPRequest(self.cj, interface, proxies) + self.http = HTTPRequest(self.cj, options) self.dl = None def setLastURL(self, val): @@ -73,12 +72,12 @@ class Browser(object): self._size = self.dl.size self.dl.abort = True - def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None, disposition=False): + def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, + progressNotify=None, disposition=False): """ this can also download ftp """ self._size = 0 self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None, - self.cj if cookies else None, self.bucket, self.interface, - self.proxies, progressNotify, disposition) + self.cj if cookies else None, self.bucket, self.options, progressNotify, disposition) name = self.dl.download(chunks, resume) self._size = self.dl.size diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index a88d94afe..88e6e49c6 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -134,7 +134,7 @@ class HTTPChunk(HTTPRequest): self.fp = None #file handle self.initHandle() - self.setInterface(self.p.interface, self.p.proxies) + self.setInterface(self.p.options["interface"], self.p.options["proxies"], self.p.options["ipv6"]) self.BOMChecked = False # check and remove byte order mark diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 9d0395c6f..56f1cb1e4 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -33,7 +33,7 @@ from module.utils import save_join class HTTPDownload(): """ loads a url http + ftp """ def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None, - interface=None, proxies={}, progressNotify=None, disposition=False): + options={}, progressNotify=None, disposition=False): self.url = url self.filename = filename #complete file destination, not only name self.get = get @@ -41,8 +41,7 @@ class HTTPDownload(): self.referer = referer self.cj = cj #cookiejar if cookies are needed self.bucket = bucket - self.interface = interface - self.proxies = proxies + self.options = options self.disposition = disposition # all arguments diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index f0a80fd93..598be78c7 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -34,7 +34,7 @@ class BadHeader(Exception): class HTTPRequest(): - def __init__(self, cookies=None, interface=None, proxies=None): + def __init__(self, cookies=None, options=None): self.c = pycurl.Curl() self.rep = StringIO() @@ -50,7 +50,7 @@ class HTTPRequest(): self.headers = [] #temporary request header self.initHandle() - self.setInterface(interface, proxies) + self.setInterface(options["interface"], options["proxies"], options["ipv6"]) self.c.setopt(pycurl.WRITEFUNCTION, self.write) self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader) @@ -80,7 +80,7 @@ class HTTPRequest(): "Connection: keep-alive", "Keep-Alive: 300"]) - def setInterface(self, interface, proxy): + def setInterface(self, interface, proxy, ipv6=False): if interface and interface.lower() != "none": self.c.setopt(pycurl.INTERFACE, str(interface)) @@ -98,6 +98,11 @@ class HTTPRequest(): if proxy["username"]: self.c.setopt(pycurl.PROXYUSERPWD, "%s:%s" % (proxy["username"], proxy["password"])) + if ipv6: + self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_WHATEVER) + else: + self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4) + def addCookies(self): """ put cookies from curl handle to cj """ if self.cj: diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py index 27854e95e..9b32ed570 100644 --- a/module/network/RequestFactory.py +++ b/module/network/RequestFactory.py @@ -43,7 +43,7 @@ class RequestFactory(): if type == "XDCC": return XDCCRequest(proxies=self.getProxies()) - req = Browser(self.iface(), self.bucket, self.getProxies()) + req = Browser(self.bucket, self.getOptions()) if account: cj = self.getCookieJar(pluginName, account) @@ -56,10 +56,10 @@ class RequestFactory(): def getHTTPRequest(self): """ returns a http request, dont forget to close it ! """ - return HTTPRequest(CookieJar(None), self.iface(), self.getProxies()) + return HTTPRequest(CookieJar(None), self.getOptions()) def getURL(self, url, get={}, post={}, multipart=False): - h = HTTPRequest(None, self.iface(), self.getProxies()) + h = HTTPRequest(None, self.getOptions()) rep = h.load(url, get, post, multipart=multipart) h.close() return rep @@ -96,7 +96,13 @@ class RequestFactory(): "port": self.core.config["proxy"]["port"], "username": username, "password": pw, - } + } + + def getOptions(self): + """returns options needed for pycurl""" + return {"interface": self.iface(), + "proxies": self.getProxies(), + "ipv6": self.core.config["download"]["ipv6"]} def updateBucket(self): """ set values in the bucket according to settings""" @@ -109,5 +115,6 @@ class RequestFactory(): def getURL(*args, **kwargs): return pyreq.getURL(*args, **kwargs) + def getRequest(*args, **kwargs): return pyreq.getHTTPRequest()
\ No newline at end of file diff --git a/module/web/json_app.py b/module/web/json_app.py index 5b3b9f1fd..9cf1d236d 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -25,6 +25,7 @@ def format_time(seconds): minutes, seconds = divmod(seconds, 60) return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) + def get_sort_key(item): return item["order"] @@ -66,6 +67,7 @@ def links(): except Exception, e: return HTTPError() + @route("/json/queue") @login_required('see_downloads') def queue(): @@ -104,6 +106,7 @@ def cancel(): except: return HTTPError() + @route("/json/packages") @login_required('see_downloads') def packages(): @@ -120,6 +123,7 @@ def packages(): except: return HTTPError() + @route("/json/package/:id") @validate(id=int) @login_required('see_downloads') @@ -151,16 +155,18 @@ def package(id): except: return HTTPError() + @route("/json/package_order/:ids") @login_required('add') def package_order(ids): try: pid, pos = ids.split("|") PYLOAD.order_package(int(pid), int(pos)) - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() + @route("/json/link/:id") @validate(id=int) @login_required('see_downloads') @@ -171,46 +177,51 @@ def link(id): except: return HTTPError() + @route("/json/remove_link/:id") @validate(id=int) @login_required('delete') def remove_link(id): try: PYLOAD.del_links([id]) - return {"response" : "success"} + return {"response": "success"} except Exception, e: return HTTPError() + @route("/json/restart_link/:id") @validate(id=int) @login_required('add') def restart_link(id): try: PYLOAD.restart_file(id) - return {"response" : "success"} + return {"response": "success"} except Exception: return HTTPError() + @route("/json/abort_link/:id") @validate(id=int) @login_required('delete') def abort_link(id): try: PYLOAD.stop_download("link", id) - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() + @route("/json/link_order/:ids") @login_required('add') def link_order(ids): try: pid, pos = ids.split("|") PYLOAD.order_file(int(pid), int(pos)) - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() + @route("/json/add_package") @route("/json/add_package", method="POST") @login_required('add') @@ -253,31 +264,34 @@ def add_package(): def remove_package(id): try: PYLOAD.del_packages([id]) - return {"response" : "success"} + return {"response": "success"} except Exception, e: return HTTPError() + @route("/json/restart_package/:id") @validate(id=int) @login_required('add') def restart_package(id): try: PYLOAD.restart_package(id) - return {"response" : "success"} + return {"response": "success"} except Exception: print_exc() return HTTPError() + @route("/json/move_package/:dest/:id") @validate(dest=int, id=int) @login_required('add') def move_package(dest, id): try: PYLOAD.move_package(dest, id) - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() + @route("/json/edit_package", method="POST") @login_required('add') def edit_package(): @@ -289,11 +303,12 @@ def edit_package(): "password": request.forms.get("pack_pws").decode("utf8", "ignore")} PYLOAD.set_package_data(id, data) - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() + @route("/json/set_captcha") @route("/json/set_captcha", method="POST") @login_required('add') @@ -320,18 +335,19 @@ def set_captcha(): def delete_finished(): return {"del": PYLOAD.delete_finished()} + @route("/json/restart_failed") @login_required('delete') def restart_failed(): restart = PYLOAD.restart_failed() if restart: return restart - return {"response" : "success"} + return {"response": "success"} + @route("/json/load_config/:category/:section") @login_required("settings") def load_config(category, section): - conf = None if category == "general": conf = PYLOAD.get_config() @@ -348,14 +364,14 @@ def load_config(category, section): return render_to_response("settings_item.html", {"skey": section, "section": conf[section]}) + @route("/json/save_config/:category", method="POST") @login_required("settings") def save_config(category): - for key, value in request.POST.iteritems(): try: section, option = key.split("|") - except : + except: continue if category == "general": category = "core" @@ -366,17 +382,16 @@ def save_config(category): @route("/json/add_account", method="POST") @login_required("settings") def add_account(): - login = request.POST["account_login"] password = request.POST["account_password"] type = request.POST["account_type"] PYLOAD.update_account(type, login, password) + @route("/json/update_accounts", method="POST") @login_required("settings") def update_accounts(): - for name, value in request.POST.iteritems(): tmp, user = name.split(";") plugin, action = tmp.split("|") @@ -387,124 +402,65 @@ def update_accounts(): PYLOAD.update_account(plugin, user, options={"time": [value]}) elif action == "delete" and value: PYLOAD.remove_account(plugin, user) - + + @route("/json/filemanager/rename", method="POST") @login_required('filemanager') def rename_dir(): try: - path = request.forms.get("path").decode("utf8", "ignore") - old_name = path + "/" + request.forms.get("old_name").decode("utf8", "ignore") - new_name = path + "/" + request.forms.get("new_name").decode("utf8", "ignore") - + path = decode(request.forms.get("path")) + old_name = path + "/" + decode(request.forms.get("old_name")) + new_name = path + "/" + decode(request.forms.get("new_name")) + try: - #check if file exists - os.rename(old_name, new_name); - except Exception as (errno, strerror): - return { "response": "fail", "error" : strerror + "\n" + old_name + " => " + new_name } - - return {"response" : "success"} + #check if file exists + os.rename(old_name, new_name) + except Exception, e: + return {"response": "fail", "error": str(e) + "\n" + old_name + " => " + new_name} - except: - return HTTPError() - -@route("/json/filemanager/delete", method="POST") -@login_required('filemanager') -def rename_dir(): - try: - - try: - path = request.forms.get("path").decode("utf8", "ignore") - name = request.forms.get("name").decode("utf8", "ignore") - - shutil.rmtree(path + "/" + name) - except Exception as (errno, strerror): - return { "response": "fail", "error": strerror + "\n" + path + "/" + name } - - return {"response" : "success"} + return {"response": "success"} except: return HTTPError() - -@route("/json/filemanager/mkdir", method="POST") -@login_required('filemanager') -def make_dir(): - try: - path = request.forms.get("path").decode("utf8", "ignore") - name = request.forms.get("name").decode("utf8", "ignore") - try: - #i = 1 - #full_name = path + "/" + name - #while os.path.exists(full_name) - # full_name = full_name + i - # i = i + 1 - # - #os.mkdir(full_name) - - os.mkdir(path + "/" + name) - except Exception as (errno, strerror): - return { "response": "fail", "error": strerror + "\nUnable to create directory: " + path + "/" + name } - - return {"response" : "success", "path": path, "name": name} - except: - return HTTPError() -@route("/json/filemanager/rename", method="POST") -@login_required('filemanager') -def rename_dir(): - try: - path = request.forms.get("path").decode("utf8", "ignore") - old_name = path + "/" + request.forms.get("old_name").decode("utf8", "ignore") - new_name = path + "/" + request.forms.get("new_name").decode("utf8", "ignore") - - try: - #check if file exists - os.rename(old_name, new_name); - except Exception as (errno, strerror): - return { "response": "fail", "error" : strerror + "\n" + old_name + " => " + new_name } - - return {"response" : "success"} - except: - return HTTPError() - @route("/json/filemanager/delete", method="POST") @login_required('filemanager') -def rename_dir(): +def delete_dir(): try: - - try: - path = request.forms.get("path").decode("utf8", "ignore") - name = request.forms.get("name").decode("utf8", "ignore") - - shutil.rmtree(path + "/" + name) - except Exception as (errno, strerror): - return { "response": "fail", "error": strerror + "\n" + path + "/" + name } - - return {"response" : "success"} + try: + path = decode(request.forms.get("path")) + name = decode(request.forms.get("name")) + shutil.rmtree(path + "/" + name) + except Exception, e: + return {"response": "fail", "error": str(e) + "\n" + path + "/" + name} + + return {"response": "success"} except: return HTTPError() - + + @route("/json/filemanager/mkdir", method="POST") @login_required('filemanager') def make_dir(): try: - path = request.forms.get("path").decode("utf8", "ignore") - name = request.forms.get("name").decode("utf8", "ignore") - try: - #i = 1 - #full_name = path + "/" + name - #while os.path.exists(full_name) - # full_name = full_name + i - # i = i + 1 - # - #os.mkdir(full_name) - - os.mkdir(path + "/" + name) - except Exception as (errno, strerror): - return { "response": "fail", "error": strerror + "\nUnable to create directory: " + path + "/" + name } - - return {"response" : "success", "path": path, "name": name} + path = decode(request.forms.get("path")) + name = decode(request.forms.get("name")) + try: + #i = 1 + #full_name = path + "/" + name + #while os.path.exists(full_name) + # full_name = full_name + i + # i = i + 1 + # + #os.mkdir(full_name) + + os.mkdir(path + "/" + name) + except Exception, e: + return {"response": "fail", "error": str(e) + "\nUnable to create directory: " + path + "/" + name} + + return {"response": "success", "path": path, "name": name} except: return HTTPError()
\ No newline at end of file diff --git a/module/web/templates/default/filemanager_ui.js b/module/web/templates/default/filemanager_ui.js index 2808317be..0b801316c 100644 --- a/module/web/templates/default/filemanager_ui.js +++ b/module/web/templates/default/filemanager_ui.js @@ -1,13 +1,8 @@ -var load, success, fail, rename_box, confirm_box; +var load, rename_box, confirm_box; document.addEvent("domready", function() { load = new Fx.Tween($("load-indicator"), {link: "cancel"}); - success = new Fx.Tween($("load-success"), {link: "chain"}); - fail = new Fx.Tween($("load-failure"), {link: "chain"}); - - [load,success,fail].each(function(fx) { - fx.set("opacity", 0) - }); + load.set("opacity", 0); rename_box = new Fx.Tween($('rename_box')); confirm_box = new Fx.Tween($('confirm_box')); |