sync webui to rev56
This commit is contained in:
parent
b16930ea4c
commit
5d62060bd8
|
@ -1,7 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Dbus Ipc for experimental web interface
|
||||
#
|
||||
# dbus_interface.py
|
||||
#
|
||||
# Copyright (C) Martijn Voncken 2007 <mvoncken@gmail.com>
|
||||
#
|
||||
|
@ -30,7 +28,7 @@
|
|||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
|
||||
plugin_name = "Web User interface"
|
||||
plugin_name = "Web User Interface"
|
||||
plugin_author = "Martijn Voncken"
|
||||
plugin_version = "rev."
|
||||
plugin_description = "A Web based User Interface\n"
|
||||
|
@ -51,6 +49,9 @@ plugin_version += open(os.path.join(os.path.dirname(__file__),'revno')).read()
|
|||
plugin_description += (
|
||||
open(os.path.join(os.path.dirname(__file__),'version')).read())
|
||||
|
||||
#not found a way to stop a dbus manager.
|
||||
#global so it does not get started twice.
|
||||
dbus_manager = None
|
||||
|
||||
def deluge_init(deluge_path):
|
||||
global path
|
||||
|
@ -62,11 +63,14 @@ def enable(core, interface):
|
|||
|
||||
class plugin_WebUi:
|
||||
def __init__(self, path, deluge_core, deluge_interface):
|
||||
global dbus_manager
|
||||
self.path = path
|
||||
self.core = deluge_core
|
||||
self.interface = deluge_interface
|
||||
self.proc = None
|
||||
|
||||
|
||||
|
||||
self.config_file = deluge.common.CONFIG_DIR + "/webui.conf"
|
||||
self.config = deluge.pref.Preferences(self.config_file, False)
|
||||
try:
|
||||
|
@ -91,11 +95,16 @@ class plugin_WebUi:
|
|||
self.config.set("pwd_salt", "invalid")
|
||||
self.config.set("pwd_md5", "invalid")
|
||||
|
||||
if self.config.get("cache_templates") == None:
|
||||
self.config.set("cache_templates", True)
|
||||
|
||||
self.dbusManager = DbusManager(deluge_core, deluge_interface
|
||||
, self.config, self.config_file)
|
||||
|
||||
print dir(self.dbusManager)
|
||||
if not dbus_manager:
|
||||
self.dbusManager = DbusManager(deluge_core, deluge_interface
|
||||
, self.config, self.config_file)
|
||||
|
||||
self.dbus_manager = dbus_manager
|
||||
|
||||
self.start_server()
|
||||
|
||||
def unload(self):
|
||||
|
@ -108,7 +117,7 @@ class plugin_WebUi:
|
|||
|
||||
## This will be only called if your plugin is configurable
|
||||
def configure(self,parent_dialog):
|
||||
d = ConfigDialog(self.config,self)
|
||||
d = ConfigDialog(self.config, self, parent_dialog)
|
||||
if d.run() == gtk.RESPONSE_OK:
|
||||
d.save_config()
|
||||
d.destroy()
|
||||
|
@ -133,8 +142,8 @@ class ConfigDialog(gtk.Dialog):
|
|||
sorry, can't get used to gui builders.
|
||||
from what I read glade is better, but i dont want to invest time in them.
|
||||
"""
|
||||
def __init__(self, config, plugin):
|
||||
gtk.Dialog.__init__(self)
|
||||
def __init__(self, config, plugin, parent):
|
||||
gtk.Dialog.__init__(self ,parent=parent)
|
||||
self.config = config
|
||||
self.plugin = plugin
|
||||
self.vb = gtk.VBox()
|
||||
|
@ -151,6 +160,8 @@ class ConfigDialog(gtk.Dialog):
|
|||
self.template = self.add_widget(_('Template'), gtk.combo_box_new_text())
|
||||
self.button_style = self.add_widget(_('Button Style'),
|
||||
gtk.combo_box_new_text())
|
||||
self.cache_templates = self.add_widget(_('Cache Templates'),
|
||||
gtk.CheckButton())
|
||||
self.download_dir = self.add_widget(_('Download Directory'),
|
||||
gtk.FileChooserButton(_('Download Directory')))
|
||||
self.torrent_dir = self.add_widget(_('Torrent Directory'),
|
||||
|
@ -165,7 +176,7 @@ class ConfigDialog(gtk.Dialog):
|
|||
|
||||
for item in self.templates:
|
||||
self.template.append_text(item)
|
||||
self.button_style
|
||||
|
||||
if not self.config.get("template") in self.templates:
|
||||
self.config.set("template","deluge")
|
||||
|
||||
|
@ -178,6 +189,8 @@ class ConfigDialog(gtk.Dialog):
|
|||
self.template.set_active(
|
||||
self.templates.index(self.config.get("template")))
|
||||
self.button_style.set_active(self.config.get("button_style"))
|
||||
self.cache_templates.set_active(self.config.get("cache_templates"))
|
||||
|
||||
self.torrent_dir.set_filename(self.config.get("torrent_dir"))
|
||||
self.download_dir.set_filename(self.config.get("download_dir"))
|
||||
self.vbox.pack_start(self.vb, True, True, 0)
|
||||
|
@ -213,6 +226,7 @@ class ConfigDialog(gtk.Dialog):
|
|||
self.config.set("port", int(self.port.get_value()))
|
||||
self.config.set("template", self.template.get_active_text())
|
||||
self.config.set("button_style", self.button_style.get_active())
|
||||
self.config.set("cache_templates", self.cache_templates.get_active())
|
||||
self.config.set("torrent_dir", self.torrent_dir.get_filename())
|
||||
self.config.set("download_dir",self.download_dir.get_filename())
|
||||
self.config.save(self.plugin.config_file)
|
||||
|
|
|
@ -32,21 +32,21 @@
|
|||
# statement from all source files in the program, then also delete it here.
|
||||
|
||||
"""
|
||||
Todo's before beta:
|
||||
-alternating rows?
|
||||
-__init__:unload plugin is broken!
|
||||
Todo's before stable:
|
||||
-__init__:kill->restart is not waiting for kill to be finished.
|
||||
-redir is broken.
|
||||
--later/features:---
|
||||
-alternating rows?
|
||||
-set prio
|
||||
-clear finished?
|
||||
-torrent files.
|
||||
"""
|
||||
import webpy022 as web
|
||||
|
||||
from webpy022.webapi import cookies, setcookie
|
||||
from webpy022.http import seeother, url
|
||||
from webpy022.utils import Storage
|
||||
from webpy022 import template
|
||||
from webpy022.net import urlquote
|
||||
from webpy022 import template, changequery as self_url
|
||||
|
||||
import dbus
|
||||
|
||||
|
@ -79,9 +79,12 @@ proxy = bus.get_object("org.deluge_torrent.dbusplugin"
|
|||
|
||||
web.webapi.internalerror = web.debugerror
|
||||
|
||||
render = template.render('templates/%s/' % proxy.get_webui_config('template')
|
||||
,cache=proxy.get_webui_config('cache_templates'))
|
||||
#/init
|
||||
|
||||
#framework:
|
||||
|
||||
SESSIONS = {}
|
||||
|
||||
def do_redirect():
|
||||
|
@ -105,7 +108,7 @@ def deluge_page_noauth(func):
|
|||
web.header("Content-Type", "text/html; charset=utf-8")
|
||||
web.header("Cache-Control", "no-cache, must-revalidate")
|
||||
res = func(self, name)
|
||||
print unicode(res)
|
||||
print res
|
||||
return deco
|
||||
|
||||
def check_session(func):
|
||||
|
@ -114,9 +117,13 @@ def check_session(func):
|
|||
return func if session is valid, else redirect to login page.
|
||||
"""
|
||||
def deco(self, name):
|
||||
vars = web.input(redir_after_login=None)
|
||||
|
||||
ck = cookies()
|
||||
if ck.has_key("session_id") and ck["session_id"] in SESSIONS:
|
||||
return func(self, name) #ok, continue..
|
||||
elif vars.redir_after_login:
|
||||
seeother("/login?redir=" + urlquote(self_url()))
|
||||
else:
|
||||
seeother("/login") #do not continue, and redirect to login page
|
||||
return deco
|
||||
|
@ -129,8 +136,7 @@ def auto_refreshed(func):
|
|||
def deco(self, name):
|
||||
if proxy.get_webui_config('auto_refresh'):
|
||||
web.header("Refresh", "%i ; url=%s" %
|
||||
(proxy.get_webui_config('auto_refresh_secs'),
|
||||
web.changequery()))
|
||||
(proxy.get_webui_config('auto_refresh_secs'),self_url()))
|
||||
return func(self, name)
|
||||
return deco
|
||||
|
||||
|
@ -218,9 +224,6 @@ def template_sort_head(id,name):
|
|||
|
||||
return render.sort_column_head(id, name, order, active_up, active_down)
|
||||
|
||||
|
||||
render = template.render('templates/%s/' % proxy.get_webui_config('template'))
|
||||
|
||||
template.Template.globals.update({
|
||||
'sort_head': template_sort_head,
|
||||
'crop': template_crop,
|
||||
|
@ -228,7 +231,7 @@ template.Template.globals.update({
|
|||
'str': str, #because % in templetor is broken.
|
||||
'sorted': sorted,
|
||||
'get_config': proxy.get_webui_config,
|
||||
'self_url': web.changequery,
|
||||
'self_url': self_url,
|
||||
'fspeed': common.fspeed,
|
||||
'fsize': common.fsize,
|
||||
'render': render, #for easy resuse of templates
|
||||
|
@ -236,7 +239,8 @@ template.Template.globals.update({
|
|||
'rev': ('rev.' +
|
||||
open(os.path.join(os.path.dirname(__file__),'revno')).read()),
|
||||
'version': (
|
||||
open(os.path.join(os.path.dirname(__file__),'version')).read())
|
||||
open(os.path.join(os.path.dirname(__file__),'version')).read()),
|
||||
'get': lambda (var): getattr(web.input(**{var:None}),var) # unreadable :-(
|
||||
})
|
||||
#/template-defs
|
||||
|
||||
|
@ -271,7 +275,7 @@ class login:
|
|||
return render.login(vars.error)
|
||||
|
||||
def POST(self, name):
|
||||
vars = web.input(pwd = None)
|
||||
vars = web.input(pwd = None ,redir = None)
|
||||
|
||||
if proxy.check_pwd(vars.pwd):
|
||||
#start new session
|
||||
|
@ -279,6 +283,8 @@ class login:
|
|||
SESSIONS[session_id] = {"not":"used"}
|
||||
setcookie("session_id", session_id)
|
||||
do_redirect()
|
||||
elif vars.redir:
|
||||
seeother('/login?error=1&redir=' + urlquote(vars.redir))
|
||||
else:
|
||||
seeother('/login?error=1')
|
||||
|
||||
|
@ -334,7 +340,6 @@ class torrent_add:
|
|||
|
||||
@check_session
|
||||
def POST(self, name):
|
||||
|
||||
vars = web.input(url = None, torrent = {})
|
||||
|
||||
if vars.url and vars.torrent.filename:
|
||||
|
@ -354,7 +359,7 @@ class torrent_add:
|
|||
class remote_torrent_add:
|
||||
"""
|
||||
For use in remote scripts etc.
|
||||
POST user and file
|
||||
POST pwd and torrent
|
||||
Example : curl -F torrent=@./test1.torrent -F pwd=deluge http://localhost:8112/remote/torrent/add"
|
||||
"""
|
||||
@remote
|
||||
|
|
|
@ -1 +1 @@
|
|||
48
|
||||
56
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
// ==UserScript==
|
||||
// @name Add Torrents To Deluge
|
||||
// @namespace http://blog.monstuff.com/archives/cat_greasemonkey.html
|
||||
// @description Let's you add torrents to the deluge WebUi
|
||||
// @include http://isohunt.com/torrent_details/*
|
||||
// @include http://thepiratebay.org/details.php?*
|
||||
// @include http://torrentreactor.net/view.php?*
|
||||
// @include http://www.mininova.org/*
|
||||
// @include http://www.torrentspy.com/*
|
||||
// @include http://ts.searching.com/*
|
||||
// @include *
|
||||
// ==/UserScript==
|
||||
|
||||
//http://userscripts.org/scripts/show/12639
|
||||
//This script is based on : "Add Torrents To utorrent" by Julien Couvreur
|
||||
//Thanks Julian!
|
||||
//modified by:
|
||||
//mvoncken
|
||||
//these 2 parameters need to be edited before using the script
|
||||
|
||||
// Server address
|
||||
var host = "localhost";
|
||||
|
||||
// Server port
|
||||
var port = "8112";
|
||||
|
||||
if (host == "") { alert('You need to configure the "Add Torrents To Deluge" user script with your uTorrent WebUI parameters before using it.'); }
|
||||
|
||||
|
||||
|
||||
function scanLinks() {
|
||||
var links = getLinks();
|
||||
|
||||
for (var i=0; i < links.length; i++){
|
||||
var link = links[i];
|
||||
if (match(link.href)) {
|
||||
var uTorrentLink = makeUTorrentLink(link);
|
||||
|
||||
link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function makeUTorrentLink(link) {
|
||||
var uTorrentLink = document.createElement('a');
|
||||
uTorrentLink.setAttribute("href", makeUTorrentUrl(link.href));
|
||||
uTorrentLink.setAttribute("target", "_blank");
|
||||
uTorrentLink.style.paddingLeft = "5px";
|
||||
uTorrentLink.innerHTML = "<img src=\"" + image + "\" style='border: 0px' />";
|
||||
|
||||
return uTorrentLink;
|
||||
}
|
||||
|
||||
function match(url) {
|
||||
|
||||
// isohunt format
|
||||
if (url.match(/http:\/\/.*isohunt\.com\/download\//i)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (url.match(/\.torrent$/)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (url.match(/http:\/\/.*bt-chat\.com\/download\.php/)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TorrentReactor
|
||||
if (url.match(/http:\/\/dl\.torrentreactor\.net\/download.php\?/i)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mininova
|
||||
if (url.match(/http:\/\/www\.mininova\.org\/get\//i)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mininova
|
||||
if (url.match(/http:\/\/www\.mininova\.org\/get\//i)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TorrentSpy
|
||||
if (url.match(/http:\/\/ts\.searching\.com\/download\.asp\?/i)) {
|
||||
return true;
|
||||
}
|
||||
if (url.match(/http:\/\/www\.torrentspy\.com\/download.asp\?/i)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Seedler
|
||||
if (url.match(/http:\/\/.*seedler\.org\/download\.x\?/i)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeUTorrentUrl(url) {
|
||||
var uTorrentUrl = "http://"+host+":"+port+"/torrent/add?redir_after_login=1";
|
||||
return uTorrentUrl + "&url=" + escape(url);
|
||||
}
|
||||
|
||||
function getLinks() {
|
||||
var doc_links = document.links;
|
||||
var links = new Array();
|
||||
for (var i=0; i < doc_links.length; i++){
|
||||
links.push(doc_links[i]);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
var image = "data:image/gif;base64,R0lGODlhEAAQAMZyAB1CdihAYx5CdiBEeCJGeSZJfChKfChLfSpPgTBRgThRdDRUgzRVhDVWhDZWhThYhjtbiD1ciD5diT5eiz9eikBeiUFeiT5fjT1gjkBfjERijkdjiUhljkVnlEdolUxokExqkk5qkU9rklBrklFtk1BullFulk5vmlZymFx3nE97rVZ5pUx8sl54nlt5oVl6pE5/tWJ6nVp9qFqArWOEq1uIuW6EpGCItl2Ku26Gp2KKuGuIrF+MvWaLtl+Nv3KJqG+KrGaOu2aQv2SRwnGOs2uQvGqSwICOpoCQqm6Ww3OVvHKWv3iWuoKWsn+XtnacxXaeynifyXigzICewn2gxnqizoqfunujzpWesX6l0IyivYijw4+jvpOiuoOp0puktY2x2I6y2Y+z2pG02pW43Ze42pa43Z/A4qjG56jH56nI6KzJ6a/M67nR67zW8sLa9cff+M/k+P///////////////////////////////////////////////////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgB/ACwAAAAAEAAQAAAHkIB/goOEhYaCX1iHhkdIXU2LgzFARExbkYInCBcvRVSRHgQNEiYoPUmHGAkjO1FSSilBNYYQFTllY2BeSzJChg4iWmhpZ2JXOjgqhBMFH1xvbmtmWUMwM4QZBws/cXBsZFU+LCuFDwIhVm1qYVA8Nx2FEQQDHDZOU09GNIcWDAAGFEC0cBEpwAYNJUgowMQwEAA7";
|
||||
|
||||
|
||||
scanLinks();
|
|
@ -1,5 +1,6 @@
|
|||
$def with (torrent_list)
|
||||
$:render.header(_('Torrent list'))
|
||||
|
||||
<form action="/torrent/pause" method="POST">
|
||||
<table class="torrent_list" border=1>
|
||||
<tr>
|
||||
|
|
|
@ -5,6 +5,7 @@ $if error > 0:
|
|||
<div class="error">$_("Password is invalid,try again")</div>
|
||||
|
||||
<form method="POST" id="loginform" action='/login'>
|
||||
<input type="hidden" name="redir" value="$get('redir')">
|
||||
<div id="loginpanel">
|
||||
<div class="form_row">
|
||||
<span class="form_label">$_('Password')</span>
|
||||
|
@ -21,4 +22,4 @@ $if error > 0:
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
$:render.footer()
|
||||
$:render.footer()
|
||||
|
|
|
@ -4,7 +4,8 @@ $:render.header(_("Add Torrent"))
|
|||
<div id="torrent_add">
|
||||
<div class="form_row">
|
||||
<span class="form_label">$_('Url')</span>
|
||||
<input type="text" name="url" class="form_input" size=60>
|
||||
<input type="text" name="url" class="form_input" size=60
|
||||
value="$get('url')" >
|
||||
</div>
|
||||
<div class="form_row">
|
||||
<span class="form_label">$_('Upload torrent')</span>
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
48
|
||||
revision-id: mvoncken@gmail.com-20070929213431-0iftu3c3jnmj9lr5
|
||||
date: 2007-09-29 23:34:31 +0200
|
||||
build-date: 2007-09-29 23:34:36 +0200
|
||||
revno: 56
|
||||
branch-nick: WebUi
|
||||
|
|
|
@ -3,8 +3,3 @@ This is not according to HTTP/1.1 Spec
|
|||
But many deluge users will want to route the webui through firewalls/routers or use apache redirects.
|
||||
|
||||
2:Disabled logging in the builtin http-server.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue