summaryrefslogtreecommitdiffstats
path: root/module/web
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-17 16:14:26 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-12-17 16:14:26 +0100
commit511ae48877f8f3fae2a3ba282d979c33f2ea5491 (patch)
tree946b97a81fa6a3efbc181177e805cee922305a47 /module/web
parentLittle Rapidshare Fix (diff)
downloadpyload-511ae48877f8f3fae2a3ba282d979c33f2ea5491.tar.xz
webinterface: config working, downloadable files
Diffstat (limited to 'module/web')
-rw-r--r--module/web/ServerThread.py13
-rw-r--r--module/web/pyload.dbbin39936 -> 39936 bytes
-rw-r--r--module/web/pyload/urls.py2
-rw-r--r--module/web/pyload/views.py67
-rw-r--r--module/web/settings.py11
-rw-r--r--module/web/templates/default/base.html6
-rw-r--r--module/web/templates/default/downloads.html28
-rw-r--r--module/web/templates/default/home.html6
8 files changed, 120 insertions, 13 deletions
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
--- a/module/web/pyload.db
+++ b/module/web/pyload.db
Binary files 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<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