diff options
-rw-r--r-- | module/config/default.conf | 2 | ||||
-rw-r--r-- | module/setup.py | 17 | ||||
-rw-r--r-- | module/web/ServerThread.py | 22 | ||||
-rw-r--r-- | module/web/middlewares.py | 6 | ||||
-rw-r--r-- | module/web/utils.py | 4 | ||||
-rw-r--r-- | module/web/webinterface.py | 4 |
6 files changed, 46 insertions, 9 deletions
diff --git a/module/config/default.conf b/module/config/default.conf index 630fcb9ba..b3cc54640 100644 --- a/module/config/default.conf +++ b/module/config/default.conf @@ -11,7 +11,7 @@ ssl - "SSL": file key : "SSL Key" = ssl.key
webinterface - "Webinterface":
bool activated : "Activated" = True
- builtin;threaded;fastcgi server : "Server" = builtin
+ builtin;threaded;fastcgi;lightweight server : "Server" = builtin
bool https : "Use HTTPS" = False
ip host : "IP" = 0.0.0.0
int port : "Port" = 8001
diff --git a/module/setup.py b/module/setup.py index 3a15a8609..367fc7c52 100644 --- a/module/setup.py +++ b/module/setup.py @@ -18,7 +18,6 @@ """ from getpass import getpass import gettext -from hashlib import sha1 import os from os import makedirs from os.path import abspath @@ -304,10 +303,20 @@ class Setup(): self.config["webinterface"]["host"] = self.ask(_("Address"), "0.0.0.0") self.config["webinterface"]["port"] = self.ask(_("Port"), "8000") print "" - print _("In some rare cases the builtin server is not working, if you notice problems with the webinterface") - print _("change the builtin server to the threaded one here.") + print _("pyLoad offers several server backends, now following a short explanation.") + print "builtin:", _("Default server, best choice if you dont know which one to choose.") + print "threaded:", _("This server offers SSL and is a good alternative to builtin.") + print "fastcgi:", _("Can be used by apache, lighttpd, requires you to configure them, which is not too easy job.") + print "lightweight:", _("Very fast alternative written in C, requires libev and linux knowlegde.") + print "\t", _("Get it from here: https://github.com/jonashaag/bjoern, compile it") + print "\t", _("and copy bjoern.so to module/lib") - self.config["webinterface"]["server"] = self.ask(_("Server"), "builtin", ["builtin", "threaded"]) + print + print _("Attention: In some rare cases the builtin server is not working, if you notice problems with the webinterface") + print _("come back here and change the builtin server to the threaded one here.") + + + self.config["webinterface"]["server"] = self.ask(_("Server"), "builtin", ["builtin", "threaded", "fastcgi", "lightweight"]) def conf_ssl(self): print "" diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py index b343b6526..d4992572d 100644 --- a/module/web/ServerThread.py +++ b/module/web/ServerThread.py @@ -47,18 +47,30 @@ class WebServer(threading.Thread): log.warning(_("Can't use %(server)s, python-flup is not installed!") % { "server": self.server}) self.server = "builtin" + elif self.server == "lightweight": + try: + import bjoern + except Exception, e: + log.error(_("Error importing lightweight server: %s") % e) + log.warning(_("You need to download and compile bjoern, https://github.com/jonashaag/bjoern")) + log.warning(_("Copy the boern.so to module/lib folder or use setup.py install")) + log.warning(_("Of course you need to be familiar with linux and know how to compile software")) + log.warning(_("in order to do this, but its worth the effort.")) + self.server = "builtin" if self.server == "fastcgi": self.start_fcgi() elif self.server == "threaded": self.start_threaded() + elif self.server == "lightweight": + self.start_lightweight() else: self.start_builtin() def start_builtin(self): if self.https: - log.warning(_("The simple builtin server offers no SSL, please consider using threaded instead")) + log.warning(_("This server offers no SSL, please consider using threaded instead")) self.core.log.info(_("Starting builtin webserver: %(host)s:%(port)d") % {"host": self.host, "port": self.port}) webinterface.run_simple(host=self.host, port=self.port) @@ -78,5 +90,13 @@ class WebServer(threading.Thread): self.core.log.info(_("Starting fastcgi server: %(host)s:%(port)d") % {"host": self.host, "port": self.port}) webinterface.run_fcgi(host=self.host, port=self.port) + + def start_lightweight(self): + if self.https: + log.warning(_("This server offers no SSL, please consider using threaded instead")) + + self.core.log.info(_("Starting lightweight webserver (bjoern): %(host)s:%(port)d") % {"host": self.host, "port": self.port}) + webinterface.run_lightweight(host=self.host, port=self.port) + def quit(self): self.running = False diff --git a/module/web/middlewares.py b/module/web/middlewares.py index b71138e69..a4b962988 100644 --- a/module/web/middlewares.py +++ b/module/web/middlewares.py @@ -123,7 +123,11 @@ class GzipResponse(object): output.close() finally: if hasattr(app_iter, 'close'): - app_iter.close() + try: + app_iter.close() + except : + pass + content_length = self.buffer.tell() update_header(self.headers, "Content-Length" , str(content_length)) self.start_response(self.status, self.headers)
\ No newline at end of file diff --git a/module/web/utils.py b/module/web/utils.py index fccfb78d6..81baa4fd2 100644 --- a/module/web/utils.py +++ b/module/web/utils.py @@ -93,14 +93,14 @@ def login_required(perm=None): if perm: perms = parse_permissions(s) if not perms.has_key(perm) or not perms[perm]: - if request.header.get('X-Requested-With') == 'XMLHttpRequest': + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': return HTTPError(403, "Forbidden") else: return redirect("/nopermission") return func(*args, **kwargs) else: - if request.header.get('X-Requested-With') == 'XMLHttpRequest': + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': return HTTPError(403, "Forbidden") else: return redirect("/login") diff --git a/module/web/webinterface.py b/module/web/webinterface.py index 387a2cbbf..17be5c3b3 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -98,6 +98,7 @@ session_opts = { web = StripPathMiddleware(SessionMiddleware(app(), session_opts)) web = GZipMiddleWare(web) +#install(otfcompress) import pyload_app import json_app @@ -106,6 +107,9 @@ import cnl_app def run_simple(host="0.0.0.0", port="8000"): run(app=web, host=host, port=port, quiet=True) +def run_lightweight(host="0.0.0.0", port="8000"): + run(app=web, host=host, port=port, quiet=True, server="bjoern") + def run_threaded(host="0.0.0.0", port="8000", theads=3, cert="", key=""): from wsgiserver import CherryPyWSGIServer if cert and key: |