diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-08-18 15:51:03 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-08-18 15:51:03 +0200 |
commit | e7605940aee5cde5bc8a55ae403834525601fa2f (patch) | |
tree | fb3fcef37aa79f9f9f4ff63ff94c0d46fabf56b5 | |
parent | Added Depositfiles.com Download Plugin (diff) | |
download | pyload-e7605940aee5cde5bc8a55ae403834525601fa2f.tar.xz |
new webinterface functions
-rw-r--r-- | module/web/WebServer.py | 140 | ||||
-rw-r--r-- | module/web/static/default.css | 8 | ||||
-rw-r--r-- | module/web/static/default/home.js | 95 | ||||
-rw-r--r-- | module/web/static/default/progress-bar-back.gif | bin | 0 -> 10819 bytes | |||
-rw-r--r-- | module/web/static/default/progress-bar.gif | bin | 0 -> 10819 bytes | |||
-rw-r--r-- | module/web/static/mootools-1.2.3.1-more.js | 76 | ||||
-rw-r--r-- | module/web/templates/default.tpl | 42 | ||||
-rw-r--r-- | module/web/templates/footer.tpl | 4 | ||||
-rwxr-xr-x | pyLoadCore.py | 21 |
9 files changed, 361 insertions, 25 deletions
diff --git a/module/web/WebServer.py b/module/web/WebServer.py index cd5c57a70..189a38704 100644 --- a/module/web/WebServer.py +++ b/module/web/WebServer.py @@ -18,16 +18,15 @@ # ### +import random import threading +import time import bottle -import time from bottle import abort -from bottle import db -from bottle import debug +from bottle import redirect from bottle import request from bottle import response -from bottle import redirect from bottle import route from bottle import run from bottle import send_file @@ -39,18 +38,122 @@ core = None PATH = "./module/web/" TIME = time.strftime("%a, %d %b %Y 00:00:00 +0000", time.localtime()) #set time to current day +USERS = {} -@route('/', method= 'POST') -def home(): +@route('/login', method='POST') +def do_login(): #print request.GET - print request.POST - return template('default', page='home', links=core.get_downloads()) -@route('/') + username = core.config['webinterface']['username'] + pw = core.config['webinterface']['password'] + + if request.POST['u'] == username and request.POST['p'] == pw: + + id = int(random.getrandbits(16)) + ua = request.HEADER("HTTP_USER_AGENT") + ip = request.HEADER("REMOTE_ADDR") + + auth = {} + + auth['ua'] = ua + auth['ip'] = ip + auth['user'] = username + + USERS[id] = auth + + response.COOKIES['user'] = username + response.COOKIES['id'] = id + + return template('default', page='home', links=core.get_downloads(), user=username) + else: + return template('default', page='login') + +@route('/login') def login(): + + if check_auth(request): + redirect("/") + return template('default', page='login') +@route('/logout') +def logout(): + try: + del USERS[int(request.COOKIES.get('id'))] + except: + pass + + redirect("/login") + +@route('/') +def home(): + + if not check_auth(request): + redirect("/login") + + username = request.COOKIES.get('user') + + return template('default', page='home', links=core.get_downloads(), user=username) + +@route('/queue') +def queue(): + + if not check_auth(request): + redirect("/login") + + username = request.COOKIES.get('user') + + return template('default', page='queue', links=core.get_downloads(), user=username) + +@route('/downloads') +def downloads(): + + if not check_auth(request): + redirect("/login") + + username = request.COOKIES.get('user') + + return template('default', page='downloads', links=core.get_downloads(), user=username) + + +@route('/logs') +def logs(): + + if not check_auth(request): + redirect("/login") + + username = request.COOKIES.get('user') + + return template('default', page='logs', links=core.get_downloads(), user=username) + +@route('/json/links') +def get_links(): + response.header['Cache-Control'] = 'no-cache, must-revalidate' + response.content_type = 'application/json' + + if not check_auth(request): + abort(404, "No Access") + + json = '{ "downloads": [' + + downloads = core.get_downloads() + + + + for dl in downloads: + json += '{' + json += '"id": "%s", "name": "%s", "speed": "%s", "eta": "%s", "kbleft": "%s", "size": "%s", "percent": "%s", "wait": "%s", "status": "%s"'\ + % (dl['id'], dl['name'], dl['speed'], core.format_time(dl['eta']), dl['kbleft'], dl['size'], dl['percent'], str(core.format_time(dl['wait_until'] - time.time())), dl['status']) + + json += "}," + + if json.endswith(","): json = json[:-1] + + json += "] }" + + return json + @route('/favicon.ico') def favicon(): redirect('/static/favicon.ico') @@ -71,6 +174,23 @@ def static_file(filename): response.header['Last-Modified'] = TIME send_file(filename, root=(PATH + 'static/')) + +def check_auth(req): + + try: + user = req.COOKIES.get('user') + id = int(req.COOKIES.get('id')) + ua = req.HEADER("HTTP_USER_AGENT") + ip = req.HEADER("REMOTE_ADDR") + + if USERS[id]['user'] == user and USERS[id]['ua'] == ua and USERS[id]['ip'] == ip: + return True + except: + return False + + return False + + class WebServer(threading.Thread): def __init__(self, pycore): threading.Thread.__init__(self) @@ -86,6 +206,8 @@ class WebServer(threading.Thread): else: bottle.debug(False) + TIME = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime()) + bottle.TEMPLATE_PATH.append('./module/web/templates/%s.tpl') def run(self): diff --git a/module/web/static/default.css b/module/web/static/default.css index 2a09c541b..06b7a116c 100644 --- a/module/web/static/default.css +++ b/module/web/static/default.css @@ -175,4 +175,10 @@ ul#page-actions a:hover,ul#page-actions a:focus,ul#user-actions a:hover,ul#user- a.admin{background:transparent url(/static/default/user-actions-admin.png) 0px 1px no-repeat;}a.profile{background:transparent url(/static/default/user-actions-profile.png) 0px 1px no-repeat;}a.create,a.edit{background:transparent url(/static/default/page-tools-edit.png) 0px 1px no-repeat;}a.source,a.show{background:transparent url(/static/default/page-tools-source.png) 0px 1px no-repeat;}a.revisions{background:transparent url(/static/default/page-tools-revisions.png) 0px 1px no-repeat;}a.subscribe,a.unsubscribe{background:transparent url(/static/default/page-tools-subscribe.png) 0px 1px no-repeat;}a.backlink{background:transparent url(/static/default/page-tools-backlinks.png) 0px 1px no-repeat;}#head-panel{background:#525252 url(/static/default/head_bg1.png) bottom left repeat-x;}#head-panel h1{display:none;margin:0;text-decoration:none;padding-top:0.8em;padding-left:3.3em;font-size:2.6em;color:#eeeeec;}#head-panel #head-logo{float:left;margin:5px 0 -15px 5px;padding:0;overflow:visible;}#head-menu{background:transparent url(/static/default/tabs-border-bottom.png) 0 100% repeat-x;width:100%;float:left;margin:0;padding:0;padding-top:0.8em;} #head-menu ul{list-style:none;margin:0 1em 0 2em;}#head-menu ul li{float:left;margin:0;margin-left:0.3em;font-size:14px;margin-bottom:4px;}#head-menu ul li.selected,#head-menu ul li:hover{margin-bottom:0px;}#head-menu ul li a img{height:22px;width:22px;vertical-align:middle;}#head-menu ul li a,#head-menu ul li a:link{float:left;text-decoration:none;color:#555;background:#eaeaea url(/static/default/tab-background.png) 0 100% repeat-x;padding:3px 7px 3px 7px;border:2px solid #ccc;border-bottom:0px solid transparent;padding-bottom:3px;-moz-border-radius:5px;}#head-menu ul li a:hover,#head-menu ul li a:focus{color:#111;padding-bottom:7px;border-bottom:0px none transparent;outline:none;-moz-border-radius-bottomright:0px;-moz-border-radius-bottomleft:0px;}#head-menu ul li a:focus{margin-bottom:-4px;}#head-menu ul li.selected a{color:#3566A5;background:#fff;padding-bottom:7px;border-bottom:0px none transparent;-moz-border-radius-bottomright:0px;-moz-border-radius-bottomleft:0px;}#head-menu ul li.selected a:hover,#head-menu ul li.selected a:focus{color:#111;}div#head-search-and-login{float:right;margin:0 1em 0 0;background-color:#222;padding:4px;color:white;-moz-border-radius-bottomright:6px;-moz-border-radius-bottomleft:6px;}div#head-search-and-login form{display:inline;padding:0 3px;}div#head-search-and-login form input{border:2px solid #888;background:#eee;font-size:14px;padding:2px;-moz-border-radius:3px;}div#head-search-and-login form input:focus{background:#fff;}#head-search{font-size:14px;}#head-username,#head-password{width:80px;font-size:14px;}#pageinfo{clear:both;color:#888;padding:0.6em 0;margin:0;}#foot{font-style:normal;color:#888;text-align:center;}#foot a{color:#aaf;}#foot img{vertical-align:middle;}ul.toc{padding:0;padding-left:20px;margin-left:0;margin-right:10px;list-style:none;}ul.toc li{list-style:circle;}ul.toc li a{text-decoration:none;color:black;}ul.toc li a:hover{text-decoration:underline;}div.toc{border:1px dotted #888;background:#f0f0f0;margin:1em 0 1em 1em;float:right;font-size:95%;}div.toc .tocheader{font-weight:bold;margin:0.5em 1em;}div.toc ol{margin:1em 0.5em 1em 1em;padding:0;}div.toc ol li{margin:0;padding:0;margin-left:1em;}div.toc ol ol{margin:0.5em 0.5em 0.5em 1em;padding:0;}div.recentchanges table{clear:both;}div#editor-help{font-size:90%;border:1px dotted #888;padding:0ex 1ex 1ex 1ex;background:#f7f6f2;}div#preview{margin-top:1em;}label.block{display:block;text-align:right;font-weight:bold;}label.simple{display:block;text-align:left;font-weight:normal;}label.block input.edit{width:50%;}fieldset{width:300px;text-align:center;padding:0.5em;margin:auto;}div.editor{margin:0 0 0 0;}table{margin:0.5em 0;border-collapse:collapse;}td{padding:0.25em;border:1pt solid #ADB9CC;}td p{margin:0;padding:0;}.u{text-decoration:underline;}.footnotes ul{padding:0 2em;margin:0 0 1em;}.footnotes li{list-style:none;}.recentchanges p{margin:0.25em;}.recentchanges td{vertical-align:top;border:none;border-bottom:1pt solid #F0ECE6;background:#F7F6F2;}.rcdaybreak td{background:#729fcf;border:none;}.rcdaybreak td a{font-size:0.88em;}.rcicon1,.rcicon2{text-align:center;}.rcpagelink{width:33%;}.rctime{font-size:0.88em;white-space:nowrap;}.rceditor{white-space:nowrap;font-size:0.88em;}.rccomment{width:66%;color:gray;font-size:0.88em;}.rcrss{float:right;}.recentchanges[dir="rtl"] .rcrss{float:left;}.userpref table,.userpref td{border:none;}div.codearea{margin:0.5em 0;padding:0;border:1pt solid #AEBDCC;background-color:#F3F5F7;color:black;}div.codearea pre{margin:0;padding:10pt;border:none;}a.codenumbers{margin:0 10pt;font-size:0.85em;color:gray;}div.codearea pre span.LineNumber{color:gray;}div.codearea pre span.ID{color:#000;}div.codearea pre span.Operator{color:#0000c0;}div.codearea pre span.Char{color:#004080;}div.codearea pre span.Comment{color:#008000;}div.codearea pre span.Number{color:#0080c0;}div.codearea pre span.String{color:#004080;}div.codearea pre span.SPChar{color:#0000c0;}div.codearea pre span.ResWord{color:#a00000;}div.codearea pre span.ConsWord{color:#008080;font-weight:bold;}div.codearea pre span.Error{color:#ff8080;border:solid 1.5pt #f00;}div.codearea pre span.ResWord2{color:#0080ff;font-weight:bold;}div.codearea pre span.Special{color:#00f;}div.codearea pre span.Preprc{color:#803999;}#message{clear:both;padding:5px 10px;background-color:#eee;border-bottom:2px solid #ccc;}#message p{margin:5px 0;padding:0;font-weight:bold;}#message div.buttons{font-weight:normal;}.diff{width:99%;}.diff-title{background-color:#C0C0C0;}.searchresult dd span{font-weight:bold;}.diff{width:100%;border:none;}.diff-blockheader{font-weight:bold;background:#e5e5e5;font-size:1.2em;border-top:2px solid #444;padding:5px;}.diff th{font-size:120%;width:50%;font-weight:normal;text-align:left;padding-bottom:3px;}.diff td{font-family:monospace;font-size:100%;border:none;}.diff-addedline{background-color:#dfd;}.diff-deletedline{background-color:#ffb;}.diff-context{color:#888;}.diff-addedline{background-color:#E0FFE0;vertical-align:sub;}.diff-deletedline{background-color:#FFFFE0;background-color:#f4cece;vertical-align:sub;} .diff-addedline strong{background-color:#80FF80;background-color:#8ae234;} -.diff-deletedline strong{background-color:#FFFF80;background-color:#ef2929;background-color:#d78383;}
\ No newline at end of file +.diff-deletedline strong{background-color:#FFFF80;background-color:#ef2929;background-color:#d78383;} + + + +.box{ background:url(/static/default/progress-bar-back.gif) right center no-repeat; width:200px; height:20px; float:left; } +.perc{ background:url(/static/default/progress-bar.gif) right center no-repeat; height:20px; } +.boxtext{ font-family:tahoma, arial, sans-serif; font-size:11px; color:#000; float:left; padding:3px 0 0 10px; }
\ No newline at end of file diff --git a/module/web/static/default/home.js b/module/web/static/default/home.js new file mode 100644 index 000000000..cfb6e3ed8 --- /dev/null +++ b/module/web/static/default/home.js @@ -0,0 +1,95 @@ +var dwProgressBar = new Class({ + + //implements + Implements: [Options], + + //options + options: { + container: $$('body')[0], + boxID:'', + percentageID:'', + displayID:'', + startPercentage: 0, + displayText: false, + speed:10 + }, + + //initialization + initialize: function(options) { + //set options + this.setOptions(options); + //create elements + this.createElements(); + }, + + //creates the box and percentage elements + createElements: function() { + var box = new Element('div', { id:this.options.boxID + this.options.id, 'class' : this.options.boxID}); + var perc = new Element('div', { id:this.options.percentageID + this.options.id, 'style':'width:0px;', 'class' : this.options.percentageID }); + perc.inject(box); + box.inject(this.options.container); + if(this.options.displayText) { + var text = new Element('div', { id:this.options.displayID + this.options.id, 'class' : this.options.displayID }); + text.inject(this.options.container); + } + this.set(this.options.startPercentage); + }, + + //calculates width in pixels from percentage + calculate: function(percentage) { + return (document.id(this.options.boxID+ this.options.id).getStyle('width').replace('px','') * (percentage / 100)).toInt(); + }, + + //animates the change in percentage + animate: function(to) { + document.id(this.options.percentageID+ this.options.id).set('morph', { duration: this.options.speed, link:'cancel' }).morph({width:this.calculate(to.toInt())}); + if(this.options.displayText) { + document.id(this.options.displayID+ this.options.id).set('text', to.toInt() + '%'); + } + }, + + //sets the percentage from its current state to desired percentage + set: function(to) { + this.animate(to); + } + +}); + + +req = new Request.JSON({ + onSuccess: renderTable, + method: 'get', + url: '/json/links', + initialDelay: 0, + delay: 1000, + limit: 20000 +}); + + +function renderTable(data){ + +data.downloads.forEach() + +} + +window.addEvent('domready', function(){ + +//create the progress bar for example 1 +pb = new dwProgressBar({ + container: $$('.level1 p')[0], + startPercentage: 25, + speed: 1000, + id: 1, + boxID: 'box', + percentageID: 'perc', + displayText: true, + displayID: 'boxtext' +}); + +req.startTimer(); + + + }); + + + diff --git a/module/web/static/default/progress-bar-back.gif b/module/web/static/default/progress-bar-back.gif Binary files differnew file mode 100644 index 000000000..0c8f68211 --- /dev/null +++ b/module/web/static/default/progress-bar-back.gif diff --git a/module/web/static/default/progress-bar.gif b/module/web/static/default/progress-bar.gif Binary files differnew file mode 100644 index 000000000..746f77175 --- /dev/null +++ b/module/web/static/default/progress-bar.gif diff --git a/module/web/static/mootools-1.2.3.1-more.js b/module/web/static/mootools-1.2.3.1-more.js new file mode 100644 index 000000000..f3e4b4121 --- /dev/null +++ b/module/web/static/mootools-1.2.3.1-more.js @@ -0,0 +1,76 @@ +//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License. + +MooTools.More={version:"1.2.3.1"};Class.refactor=function(b,a){$each(a,function(e,d){var c=b.prototype[d];if(c&&(c=c._origin)&&typeof e=="function"){b.implement(d,function(){var f=this.previous; +this.previous=c;var g=e.apply(this,arguments);this.previous=f;return g;});}else{b.implement(d,e);}});return b;};Element.implement({measure:function(e){var g=function(h){return !!(!h||h.offsetHeight||h.offsetWidth); +};if(g(this)){return e.apply(this);}var d=this.getParent(),b=[],f=[];while(!g(d)&&d!=document.body){b.push(d.expose());d=d.getParent();}var c=this.expose(); +var a=e.apply(this);c();b.each(function(h){h();});return a;},expose:function(){if(this.getStyle("display")!="none"){return $empty;}var a=this.style.cssText; +this.setStyles({display:"block",position:"absolute",visibility:"hidden"});return function(){this.style.cssText=a;}.bind(this);},getDimensions:function(a){a=$merge({computeSize:false},a); +var d={};var c=function(f,e){return(e.computeSize)?f.getComputedSize(e):f.getSize();};if(this.getStyle("display")=="none"){d=this.measure(function(){return c(this,a); +});}else{try{d=c(this,a);}catch(b){}}return $chk(d.x)?$extend(d,{width:d.x,height:d.y}):$extend(d,{x:d.width,y:d.height});},getComputedSize:function(a){a=$merge({styles:["padding","border"],plains:{height:["top","bottom"],width:["left","right"]},mode:"both"},a); +var c={width:0,height:0};switch(a.mode){case"vertical":delete c.width;delete a.plains.width;break;case"horizontal":delete c.height;delete a.plains.height; +break;}var b=[];$each(a.plains,function(g,f){g.each(function(h){a.styles.each(function(i){b.push((i=="border")?i+"-"+h+"-width":i+"-"+h);});});});var e={}; +b.each(function(f){e[f]=this.getComputedStyle(f);},this);var d=[];$each(a.plains,function(g,f){var h=f.capitalize();c["total"+h]=0;c["computed"+h]=0;g.each(function(i){c["computed"+i.capitalize()]=0; +b.each(function(k,j){if(k.test(i)){e[k]=e[k].toInt()||0;c["total"+h]=c["total"+h]+e[k];c["computed"+i.capitalize()]=c["computed"+i.capitalize()]+e[k];}if(k.test(i)&&f!=k&&(k.test("border")||k.test("padding"))&&!d.contains(k)){d.push(k); +c["computed"+h]=c["computed"+h]-e[k];}});});});["Width","Height"].each(function(g){var f=g.toLowerCase();if(!$chk(c[f])){return;}c[f]=c[f]+this["offset"+g]+c["computed"+g]; +c["total"+g]=c[f]+c["total"+g];delete c["computed"+g];},this);return $extend(e,c);}});Element.implement({isDisplayed:function(){return this.getStyle("display")!="none"; +},toggle:function(){return this[this.isDisplayed()?"hide":"show"]();},hide:function(){var b;try{if("none"!=this.getStyle("display")){b=this.getStyle("display"); +}}catch(a){}return this.store("originalDisplay",b||"block").setStyle("display","none");},show:function(a){return this.setStyle("display",a||this.retrieve("originalDisplay")||"block"); +},swapClass:function(a,b){return this.removeClass(a).addClass(b);}});Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(b,a){this.elements=this.subject=$$(b); +this.parent(a);},compute:function(g,h,j){var c={};for(var d in g){var a=g[d],e=h[d],f=c[d]={};for(var b in a){f[b]=this.parent(a[b],e[b],j);}}return c; +},set:function(b){for(var c in b){var a=b[c];for(var d in a){this.render(this.elements[c],d,a[d],this.options.unit);}}return this;},start:function(c){if(!this.check(c)){return this; +}var h={},j={};for(var d in c){var f=c[d],a=h[d]={},g=j[d]={};for(var b in f){var e=this.prepare(this.elements[d],b,f[b]);a[b]=e.from;g[b]=e.to;}}return this.parent(h,j); +}});Fx.Reveal=new Class({Extends:Fx.Morph,options:{styles:["padding","border","margin"],transitionOpacity:!Browser.Engine.trident4,mode:"vertical",display:"block",hideInputs:Browser.Engine.trident?"select, input, textarea, object, embed":false},dissolve:function(){try{if(!this.hiding&&!this.showing){if(this.element.getStyle("display")!="none"){this.hiding=true; +this.showing=false;this.hidden=true;var d=this.element.getComputedSize({styles:this.options.styles,mode:this.options.mode});var g=(this.element.style.height===""||this.element.style.height=="auto"); +this.element.setStyle("display","block");if(this.options.transitionOpacity){d.opacity=1;}var b={};$each(d,function(h,e){b[e]=[h,0];},this);var f=this.element.getStyle("overflow"); +this.element.setStyle("overflow","hidden");var a=this.options.hideInputs?this.element.getElements(this.options.hideInputs):null;this.$chain.unshift(function(){if(this.hidden){this.hiding=false; +$each(d,function(h,e){d[e]=h;},this);this.element.setStyles($merge({display:"none",overflow:f},d));if(g){if(["vertical","both"].contains(this.options.mode)){this.element.style.height=""; +}if(["width","both"].contains(this.options.mode)){this.element.style.width="";}}if(a){a.setStyle("visibility","visible");}}this.fireEvent("hide",this.element); +this.callChain();}.bind(this));if(a){a.setStyle("visibility","hidden");}this.start(b);}else{this.callChain.delay(10,this);this.fireEvent("complete",this.element); +this.fireEvent("hide",this.element);}}else{if(this.options.link=="chain"){this.chain(this.dissolve.bind(this));}else{if(this.options.link=="cancel"&&!this.hiding){this.cancel(); +this.dissolve();}}}}catch(c){this.hiding=false;this.element.setStyle("display","none");this.callChain.delay(10,this);this.fireEvent("complete",this.element); +this.fireEvent("hide",this.element);}return this;},reveal:function(){try{if(!this.showing&&!this.hiding){if(this.element.getStyle("display")=="none"||this.element.getStyle("visiblity")=="hidden"||this.element.getStyle("opacity")==0){this.showing=true; +this.hiding=false;this.hidden=false;var g,d;this.element.measure(function(){g=(this.element.style.height===""||this.element.style.height=="auto");d=this.element.getComputedSize({styles:this.options.styles,mode:this.options.mode}); +}.bind(this));$each(d,function(h,e){d[e]=h;});if($chk(this.options.heightOverride)){d.height=this.options.heightOverride.toInt();}if($chk(this.options.widthOverride)){d.width=this.options.widthOverride.toInt(); +}if(this.options.transitionOpacity){this.element.setStyle("opacity",0);d.opacity=1;}var b={height:0,display:this.options.display};$each(d,function(h,e){b[e]=0; +});var f=this.element.getStyle("overflow");this.element.setStyles($merge(b,{overflow:"hidden"}));var a=this.options.hideInputs?this.element.getElements(this.options.hideInputs):null; +if(a){a.setStyle("visibility","hidden");}this.start(d);this.$chain.unshift(function(){this.element.setStyle("overflow",f);if(!this.options.heightOverride&&g){if(["vertical","both"].contains(this.options.mode)){this.element.style.height=""; +}if(["width","both"].contains(this.options.mode)){this.element.style.width="";}}if(!this.hidden){this.showing=false;}if(a){a.setStyle("visibility","visible"); +}this.callChain();this.fireEvent("show",this.element);}.bind(this));}else{this.callChain();this.fireEvent("complete",this.element);this.fireEvent("show",this.element); +}}else{if(this.options.link=="chain"){this.chain(this.reveal.bind(this));}else{if(this.options.link=="cancel"&&!this.showing){this.cancel();this.reveal(); +}}}}catch(c){this.element.setStyles({display:this.options.display,visiblity:"visible",opacity:1});this.showing=false;this.callChain.delay(10,this);this.fireEvent("complete",this.element); +this.fireEvent("show",this.element);}return this;},toggle:function(){if(this.element.getStyle("display")=="none"||this.element.getStyle("visiblity")=="hidden"||this.element.getStyle("opacity")==0){this.reveal(); +}else{this.dissolve();}return this;}});Element.Properties.reveal={set:function(a){var b=this.retrieve("reveal");if(b){b.cancel();}return this.eliminate("reveal").store("reveal:options",$extend({link:"cancel"},a)); +},get:function(a){if(a||!this.retrieve("reveal")){if(a||!this.retrieve("reveal:options")){this.set("reveal",a);}this.store("reveal",new Fx.Reveal(this,this.retrieve("reveal:options"))); +}return this.retrieve("reveal");}};Element.Properties.dissolve=Element.Properties.reveal;Element.implement({reveal:function(a){this.get("reveal",a).reveal(); +return this;},dissolve:function(a){this.get("reveal",a).dissolve();return this;},nix:function(){var a=Array.link(arguments,{destroy:Boolean.type,options:Object.type}); +this.get("reveal",a.options).dissolve().chain(function(){this[a.destroy?"destroy":"dispose"]();}.bind(this));return this;},wink:function(){var b=Array.link(arguments,{duration:Number.type,options:Object.type}); +var a=this.get("reveal",b.options);a.reveal().chain(function(){(function(){a.dissolve();}).delay(b.duration||2000);});}});Fx.Slide=new Class({Extends:Fx,options:{mode:"vertical"},initialize:function(b,a){this.addEvent("complete",function(){this.open=(this.wrapper["offset"+this.layout.capitalize()]!=0); +if(this.open&&Browser.Engine.webkit419){this.element.dispose().inject(this.wrapper);}},true);this.element=this.subject=document.id(b);this.parent(a);var c=this.element.retrieve("wrapper"); +this.wrapper=c||new Element("div",{styles:$extend(this.element.getStyles("margin","position"),{overflow:"hidden"})}).wraps(this.element);this.element.store("wrapper",this.wrapper).setStyle("margin",0); +this.now=[];this.open=true;},vertical:function(){this.margin="margin-top";this.layout="height";this.offset=this.element.offsetHeight;},horizontal:function(){this.margin="margin-left"; +this.layout="width";this.offset=this.element.offsetWidth;},set:function(a){this.element.setStyle(this.margin,a[0]);this.wrapper.setStyle(this.layout,a[1]); +return this;},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(b,e){if(!this.check(b,e)){return this; +}this[e||this.options.mode]();var d=this.element.getStyle(this.margin).toInt();var c=this.wrapper.getStyle(this.layout).toInt();var a=[[d,c],[0,this.offset]]; +var g=[[d,c],[-this.offset,0]];var f;switch(b){case"in":f=a;break;case"out":f=g;break;case"toggle":f=(c==0)?a:g;}return this.parent(f[0],f[1]);},slideIn:function(a){return this.start("in",a); +},slideOut:function(a){return this.start("out",a);},hide:function(a){this[a||this.options.mode]();this.open=false;return this.set([-this.offset,0]);},show:function(a){this[a||this.options.mode](); +this.open=true;return this.set([0,this.offset]);},toggle:function(a){return this.start("toggle",a);}});Element.Properties.slide={set:function(b){var a=this.retrieve("slide"); +if(a){a.cancel();}return this.eliminate("slide").store("slide:options",$extend({link:"cancel"},b));},get:function(a){if(a||!this.retrieve("slide")){if(a||!this.retrieve("slide:options")){this.set("slide",a); +}this.store("slide",new Fx.Slide(this,this.retrieve("slide:options")));}return this.retrieve("slide");}};Element.implement({slide:function(d,e){d=d||"toggle"; +var b=this.get("slide"),a;switch(d){case"hide":b.hide(e);break;case"show":b.show(e);break;case"toggle":var c=this.retrieve("slide:flag",b.open);b[c?"slideOut":"slideIn"](e); +this.store("slide:flag",!c);a=true;break;default:b.start(d,e);}if(!a){this.eliminate("slide:flag");}return this;}});Fx.Sort=new Class({Extends:Fx.Elements,options:{mode:"vertical"},initialize:function(b,a){this.parent(b,a); +this.elements.each(function(c){if(c.getStyle("position")=="static"){c.setStyle("position","relative");}});this.setDefaultOrder();},setDefaultOrder:function(){this.currentOrder=this.elements.map(function(b,a){return a; +});},sort:function(e){if($type(e)!="array"){return false;}var i=0;var a=0;var h={};var d=this.options.mode=="vertical";var f=this.elements.map(function(m,j){var l=m.getComputedSize({styles:["border","padding","margin"]}); +var n;if(d){n={top:i,margin:l["margin-top"],height:l.totalHeight};i+=n.height-l["margin-top"];}else{n={left:a,margin:l["margin-left"],width:l.totalWidth}; +a+=n.width;}var k=d?"top":"left";h[j]={};var o=m.getStyle(k).toInt();h[j][k]=o||0;return n;},this);this.set(h);e=e.map(function(j){return j.toInt();}); +if(e.length!=this.elements.length){this.currentOrder.each(function(j){if(!e.contains(j)){e.push(j);}});if(e.length>this.elements.length){e.splice(this.elements.length-1,e.length-this.elements.length); +}}i=0;a=0;var b=0;var c={};e.each(function(l,j){var k={};if(d){k.top=i-f[l].top-b;i+=f[l].height;}else{k.left=a-f[l].left;a+=f[l].width;}b=b+f[l].margin; +c[l]=k;},this);var g={};$A(e).sort().each(function(j){g[j]=c[j];});this.start(g);this.currentOrder=e;return this;},rearrangeDOM:function(a){a=a||this.currentOrder; +var b=this.elements[0].getParent();var c=[];this.elements.setStyle("opacity",0);a.each(function(d){c.push(this.elements[d].inject(b).setStyles({top:0,left:0})); +},this);this.elements.setStyle("opacity",1);this.elements=$$(c);this.setDefaultOrder();return this;},getDefaultOrder:function(){return this.elements.map(function(b,a){return a; +});},forward:function(){return this.sort(this.getDefaultOrder());},backward:function(){return this.sort(this.getDefaultOrder().reverse());},reverse:function(){return this.sort(this.currentOrder.reverse()); +},sortByElements:function(a){return this.sort(a.map(function(b){return this.elements.indexOf(b);},this));},swap:function(c,b){if($type(c)=="element"){c=this.elements.indexOf(c); +}if($type(b)=="element"){b=this.elements.indexOf(b);}var a=$A(this.currentOrder);a[this.currentOrder.indexOf(c)]=b;a[this.currentOrder.indexOf(b)]=c;this.sort(a); +}});Request.implement({options:{initialDelay:5000,delay:5000,limit:60000},startTimer:function(b){var a=(function(){if(!this.running){this.send({data:b}); +}});this.timer=a.delay(this.options.initialDelay,this);this.lastDelay=this.options.initialDelay;this.completeCheck=function(c){$clear(this.timer);if(c){this.lastDelay=this.options.delay; +}else{this.lastDelay=(this.lastDelay+this.options.delay).min(this.options.limit);}this.timer=a.delay(this.lastDelay,this);};this.addEvent("complete",this.completeCheck); +return this;},stopTimer:function(){$clear(this.timer);this.removeEvent("complete",this.completeCheck);return this;}});
\ No newline at end of file diff --git a/module/web/templates/default.tpl b/module/web/templates/default.tpl index 70671028e..0940dc046 100644 --- a/module/web/templates/default.tpl +++ b/module/web/templates/default.tpl @@ -1,29 +1,52 @@ %header = 'pyLoad Webinterface' -%include header title=header, use_js=['mootools-1.2.3-core.js'], use_css= ['default.css'] +%js = ['mootools-1.2.3-core.js','mootools-1.2.3.1-more.js'] -<a class="anchor" name="dokuwiki__top" id="dokuwiki__top"></a> +%if page== "home": js.append('default/home.js') +%end -<div id="head-panel"> +%include header title=header, use_js=js, use_css= ['default.css'] - <div id="head-search-and-login"> +<a class="anchor" name="top" id="top"></a> +<div id="head-panel"> - <img src="static/default/head-login.png" alt="User:" style="vertical-align:middle; margin:2px" /><span style="padding-right: 2px;">User</span> + <div id="head-search-and-login"> +%if page != "login": + <img src="static/default/head-login.png" alt="User:" style="vertical-align:middle; margin:2px" /><span style="padding-right: 2px;">{{user}}</span> <ul id="user-actions"> - <li><a href="/start?do=logout&sectok=ff40bdf226c283991652e062d187c43a" class="action logout" rel="nofollow">Logout</a></li> + <li><a href="/logout" class="action logout" rel="nofollow">Logout</a></li> <li></li> <li></li> </ul> +%else: + <span style="padding-right: 2px;">Please Login!</span> + +%end </div> <a href="/"><img id="head-logo" src="/static/default/pyload-logo-edited3.5-new-font-small.png" alt="pyLoad" /></a> <div id="head-menu"> <ul> - <li class=" selected"><a href="/" title=""><img src="static/default/head-menu-home.png" alt="" /> Home</a></li><li class=""><a href="/news" title=""><img src="static/default/head-menu-news.png" alt="" /> News</a></li><li class=""><a href="/wiki" title=""><img src="static/default/head-menu-wiki.png" alt="" /> Wiki</a></li><li class=""><a href="/download" title=""><img src="static/default/head-menu-download.png" alt="" /> Download</a></li><li class=""><a href="/development" title=""><img src="static/default/head-menu-development.png" alt="" /> Development</a></li><li class="right"><a href="/start?do=index" class="action index" accesskey="x" rel="nofollow"><img src="static/default/head-menu-index.png" alt="" />Logs</a></li> </ul> + <li class=" + %if page == "home" or page == "login": + selected + %endif + "><a href="/" title=""><img src="static/default/head-menu-home.png" alt="" /> Home</a></li> + <li class=" + %if page == "queue": + selected + %endif + "><a href="/queue" title=""><img src="static/default/head-menu-download.png" alt="" /> Queue</a></li> + <li class=" + %if page == "downloads": + selected + %endif + "><a href="/downloads" title=""><img src="static/default/head-menu-development.png" alt="" /> Downloads</a></li> + <li class="right"><a href="/logs" class="action index" accesskey="x" rel="nofollow"><img src="static/default/head-menu-index.png" alt="" />Logs</a></li> </ul> </div> <div style="clear:both;"></div> @@ -50,7 +73,6 @@ <input type="hidden" name="do" value="login" /><fieldset ><legend>Login</legend> <label class="block" for="focus__this"><span>Username</span> <input type="text" id="focus__this" name="u" class="edit" /></label><br /> <label class="block"><span>Password</span> <input type="password" name="p" class="edit" /></label><br /> -<label class="simple" for="remember__me"><input type="checkbox" id="remember__me" name="r" value="1" /> <span>Remember me</span></label> <input type="submit" value="Login" class="button" /> </fieldset> </div></form> @@ -73,7 +95,7 @@ <div id="foot">© 2008-2009 the pyLoad Team - <a href="#dokuwiki__top" class="action top" accesskey="x"><span>Back to top</span></a><br /> + <a href="#top" class="action top" accesskey="x"><span>Back to top</span></a><br /> <!--<div class="breadcrumbs"></div>--> @@ -81,4 +103,4 @@ </div> -%include footer
\ No newline at end of file +%include footer use_js=[]
\ No newline at end of file diff --git a/module/web/templates/footer.tpl b/module/web/templates/footer.tpl index 308b1d01b..a59b414bf 100644 --- a/module/web/templates/footer.tpl +++ b/module/web/templates/footer.tpl @@ -1,2 +1,6 @@ +%for item in use_js: +<script type="text/javascript" src="static/{{item}}"></script> +%end + </body> </html> diff --git a/pyLoadCore.py b/pyLoadCore.py index 14293cc9a..ff8641d39 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -260,12 +260,23 @@ class Core(object): return status def init_server(self): - self.server = ServerThread(self) - self.server.start() - + + try: + self.server = ServerThread(self) + self.server.start() + except: + self.logger.error("failed starting socket server, CLi and Gui will not be available") + def init_webserver(self): - self.webserver = WebServer(self) - self.webserver.start() + + if not self.config['webinterface']['activated']: + return False + + try: + self.webserver = WebServer(self) + self.webserver.start() + except: + self.looger.error("failed starting webserver, no webinterface available") def kill(self): self.do_kill = True |