diff options
-rw-r--r-- | config | 13 | ||||
-rw-r--r-- | module/web/ServerThread.py | 13 | ||||
-rw-r--r-- | module/web/pyload.db | bin | 39936 -> 39936 bytes | |||
-rw-r--r-- | module/web/pyload/urls.py | 2 | ||||
-rw-r--r-- | module/web/pyload/views.py | 67 | ||||
-rw-r--r-- | module/web/settings.py | 11 | ||||
-rw-r--r-- | module/web/templates/default/base.html | 6 | ||||
-rw-r--r-- | module/web/templates/default/downloads.html | 28 | ||||
-rw-r--r-- | module/web/templates/default/home.html | 6 |
9 files changed, 128 insertions, 18 deletions
@@ -10,14 +10,17 @@ cert = ssl.crt key = ssl.key [webinterface] -activated = False -port = 8080 +activated = True +host = 127.0.0.1 +# 0.0.0.0 to make it accessible from everywhere +port = 8000 template = default local = True -ssl = None #ONLY SPECIFY IF PYLOAD NOT RUN ON YOUR LOCALHOST +#ONLY SPECIFY IF PYLOAD NOT RUN ON YOUR LOCALHOST +ssl = None username = None adress = None -port = None +extport = None pw = None [log] @@ -52,4 +55,4 @@ end = 0:00 [proxy] activated = False adress = http://localhost:8080 -protocol = http +protocol = http
\ No newline at end of file diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py index 803dc5dc5..790ac152b 100644 --- a/module/web/ServerThread.py +++ b/module/web/ServerThread.py @@ -2,6 +2,7 @@ import threading import os from os.path import join +import subprocess class WebServer(threading.Thread): def __init__(self, pycore): @@ -10,6 +11,12 @@ class WebServer(threading.Thread): self.setDaemon(True) def run(self): - self.pycore.logger.info("Starting Webserver @ Port 8000") - os.system("python " + join(self.pycore.path,"module","web","manage.py runserver")) - #@TODO: really bad approach, better would be real python code, or subprocess
\ No newline at end of file + host = self.pycore.config['webinterface']['host'] + port = self.pycore.config['webinterface']['port'] + self.pycore.logger.info("Starting Webserver: %s:%s" % (host,port) ) + try: + subprocess.call(['python',join(self.pycore.path,"module","web","manage.py"), "runserver", "%s:%s" % (host,port)], close_fds=True) + except Exception, e: + print e + #os.system("python " + join(self.pycore.path,"module","web","manage.py runserver %s:%s" % (host,port))) + #@TODO: better would be real python code
\ No newline at end of file diff --git a/module/web/pyload.db b/module/web/pyload.db Binary files differindex 5993a9515..bd9c5b257 100644 --- a/module/web/pyload.db +++ b/module/web/pyload.db diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py index 667a4ed3d..63badeb25 100644 --- a/module/web/pyload/urls.py +++ b/module/web/pyload/urls.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from os.path import join @@ -8,6 +9,7 @@ from django.conf.urls.defaults import * urlpatterns = patterns('pyload', (r'^home/$', 'views.home'), (r'^downloads/$', 'views.downloads',{},'downloads'), + (r'^download/(?P<path>[a-zA-z\.0-9\-/_%]+)$', 'views.download',{},'download'), (r'^queue/$', 'views.queue',{}, 'queue'), (r'^logs/$', 'views.logs',{}, 'logs'), (r'^$', 'views.home',{}, 'home'), diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 405bd2753..0cdc87873 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -1,11 +1,17 @@ # Create your views here. +import mimetypes from django.http import HttpResponse from django.http import HttpResponseRedirect +from django.http import HttpResponseNotFound from django.conf import settings from django.shortcuts import render_to_response from django.template import RequestContext from django.contrib.auth.decorators import login_required from os.path import join +from os.path import isdir +from os.path import isfile +from os import listdir +from os import stat def check_server(function): @@ -67,13 +73,64 @@ def queue(request): @permission('pyload.can_download') @check_server def downloads(request): - return render_to_response(join(settings.TEMPLATE,'downloads.html'), RequestContext(request)) - + if not isdir(settings.DL_ROOT): + return base(request, ['Download directory not found.']) + data = { + 'folder': [], + 'files': [] + } + + for item in listdir(settings.DL_ROOT): + if isdir(join(settings.DL_ROOT, item)): + folder = { + 'name' : item, + 'files' : [] + } + for file in listdir(join(settings.DL_ROOT, item)): + if isfile(join(settings.DL_ROOT, item, file)): + folder['files'].append(file) + + data['folder'].append(folder) + elif isfile(join(settings.DL_ROOT, item)): + data['files'].append(item) + + + return render_to_response(join(settings.TEMPLATE,'downloads.html'), {'files': data}, RequestContext(request)) + +@login_required +@permission('pyload.user.can_download') +@check_server +def download(request,path): + path = path.split("/") + + dir = join(settings.DL_ROOT, path[1].replace('..','')) + if isdir(dir) or isfile(dir): + if isdir(dir): filepath = join(dir, path[2]) + elif isfile(dir): filepath = dir + + print filepath + if isfile(filepath): + try: + type, encoding = mimetypes.guess_type(filepath) + if type is None: + type = 'application/octet-stream' + + response = HttpResponse(mimetype=type) + response['Content-Length'] = str(stat(filepath).st_size) + + if encoding is not None: + response['Content-Encoding'] = encoding + + response.write(file(filepath, "rb").read()) + return response + + except Exception, e: + return HttpResponseNotFound("File not Found. %s" % str(e)) + + return HttpResponseNotFound("File not Found.") @login_required @permission('pyload.user.can_see_logs') @check_server def logs(request): - return render_to_response(join(settings.TEMPLATE,'logs.html'), RequestContext(request)) - -
\ No newline at end of file + return render_to_response(join(settings.TEMPLATE,'logs.html'), RequestContext(request))
\ No newline at end of file diff --git a/module/web/settings.py b/module/web/settings.py index 00395b328..2695b0648 100644 --- a/module/web/settings.py +++ b/module/web/settings.py @@ -18,7 +18,10 @@ PROJECT_DIR = os.path.dirname(__file__) #chdir(dirname(abspath(__file__)) + sep) config = ConfigParser.SafeConfigParser() -config.read(os.path.join(PROJECT_DIR,"..","..","config")) + +PYLOAD_DIR = os.path.join(PROJECT_DIR,"..","..") + +config.read(os.path.join(PYLOAD_DIR,"config")) ssl = "" @@ -36,6 +39,8 @@ server_url = "http%s://%s:%s@%s:%s/" % ( PYLOAD = xmlrpclib.ServerProxy(server_url, allow_none=True) TEMPLATE = config.get('webinterface','template') +DL_ROOT = os.path.join(PYLOAD_DIR, config.get('general','download_folder')) + ADMINS = ( # ('Your Name', 'your_email@domain.com'), @@ -44,7 +49,7 @@ ADMINS = ( MANAGERS = ADMINS DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. -DATABASE_NAME = 'pyload.db' # Or path to database file if using sqlite3. +DATABASE_NAME = os.path.join(PROJECT_DIR, 'pyload.db') # Or path to database file if using sqlite3. DATABASE_USER = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. @@ -55,7 +60,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with # although not all choices may be available on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. -TIME_ZONE = 'America/Chicago' +TIME_ZONE = 'Europe' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html index ef2685a83..46e9caa11 100644 --- a/module/web/templates/default/base.html +++ b/module/web/templates/default/base.html @@ -98,23 +98,27 @@ $(document).ready(function(){ <div style="clear:both;"></div>
</div>
+{% if perms.pyload.can_change_status %}
<ul id="page-actions2">
<li id="action_play"><a href="/json/unpause" class="action play" accesskey="o" rel="nofollow">Play</a></li>
<li id="action_stop"><a href="" class="action stop" accesskey="o" rel="nofollow">Stop</a></li>
<li id="action_stop"><a href="/json/pause" class="action stop" accesskey="o" rel="nofollow" name="Stop after ending last one" alt="Stop after ending last one">SAELO</a></li>
</ul>
+{% endif %}
+{% if perms.pyload.can_see_dl %}
<ul id="page-actions">
<li><a href="" class="action backlink" accesskey="o" rel="nofollow">Speed: <b id="speed">0</b> kb/s</a></li>
<li><a href="" class="action cog" accesskey="o" rel="nofollow">Aktiv: <b id="aktiv">0</b> / <b id="aktiv_from">0</b></a></li>
<li><a href="" class="action revisions" accesskey="o" rel="nofollow">Reload page</a></li>
</ul><br />
+{% endif %}
<div id="body-wrapper" class="dokuwiki">
<div id="content" lang="en" dir="ltr">
-<h1>Queue</h1>
+<h1>{% block subtitle %}pyLoad - Webinterface{% endblock %}</h1>
{% block statusbar %}
{% endblock %}
diff --git a/module/web/templates/default/downloads.html b/module/web/templates/default/downloads.html index 202965b3c..3f07bec47 100644 --- a/module/web/templates/default/downloads.html +++ b/module/web/templates/default/downloads.html @@ -13,4 +13,32 @@ <li class="right"> <a href="{% url logs %}" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-index.png" alt="" />Logs</a> </li> +{% endblock %} + +{% block subtitle %} +Downloads +{% endblock %} + +{% block content %} + +It's recommend not to download Files bigger than ~10MB from here. + +<ul> + {% for folder in files.folder %} + <li> + {{ folder.name }} + <ul> + {% for file in folder.files %} + <li><a href='{% url download 'get/' %}{{ folder.name }}/{{ file }}'>{{ file }}</a></li> + {% endfor %} + </ul> + </li> + {% endfor %} + + {% for file in files.files %} + <li> <a href={% url download 'get/' %}{{ file }}>{{ file }}</a></li> + {% endfor %} + +</ul> + {% endblock %}
\ No newline at end of file diff --git a/module/web/templates/default/home.html b/module/web/templates/default/home.html index 40f124712..fac4b6e63 100644 --- a/module/web/templates/default/home.html +++ b/module/web/templates/default/home.html @@ -1,5 +1,9 @@ {% extends 'default/base.html' %} -{% block content %} +{% block subtitle %} +Active Downloads +{% endblock %} + +{% block content %} {% endblock %}
\ No newline at end of file |