From 511ae48877f8f3fae2a3ba282d979c33f2ea5491 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 17 Dec 2009 16:14:26 +0100 Subject: webinterface: config working, downloadable files --- module/web/ServerThread.py | 13 ++++-- module/web/pyload.db | Bin 39936 -> 39936 bytes module/web/pyload/urls.py | 2 + module/web/pyload/views.py | 67 +++++++++++++++++++++++++--- module/web/settings.py | 11 +++-- module/web/templates/default/base.html | 6 ++- module/web/templates/default/downloads.html | 28 ++++++++++++ module/web/templates/default/home.html | 6 ++- 8 files changed, 120 insertions(+), 13 deletions(-) (limited to 'module') 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 index 5993a9515..bd9c5b257 100644 Binary files a/module/web/pyload.db and b/module/web/pyload.db differ 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[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(){
+{% if perms.pyload.can_change_status %} +{% endif %} +{% if perms.pyload.can_see_dl %}
+{% endif %}
-

Queue

+

{% block subtitle %}pyLoad - Webinterface{% endblock %}

{% 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 @@
  • Logs
  • +{% endblock %} + +{% block subtitle %} +Downloads +{% endblock %} + +{% block content %} + +It's recommend not to download Files bigger than ~10MB from here. + +
      + {% for folder in files.folder %} +
    • + {{ folder.name }} +
        + {% for file in folder.files %} +
      • {{ file }}
      • + {% endfor %} +
      +
    • + {% endfor %} + + {% for file in files.files %} +
    • {{ file }}
    • + {% endfor %} + +
    + {% 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 -- cgit v1.2.3