diff --git a/plugins/WebUi/__init__.py b/plugins/WebUi/__init__.py
index 2d6f3ad4a..85f372757 100644
--- a/plugins/WebUi/__init__.py
+++ b/plugins/WebUi/__init__.py
@@ -260,11 +260,14 @@ class ConfigDialog(gtk.Dialog):
show_popup_warning(self,_("Confirmed Password <> New Password\n"
+ "Password was not changed"))
else:
- salt = str(random.getrandbits(500))
+ sm = md5()
+ sm.update(random.getrandbits(5000))
+ salt = sm.digest()
+ self.config.set("pwd_salt", salt)
+ #
m = md5()
m.update(salt)
m.update(unicode(self.pwd1.get_text()))
- self.config.set("pwd_salt", salt)
self.config.set("pwd_md5", m.digest())
self.config.set("port", int(self.port.get_value()))
diff --git a/plugins/WebUi/deluge_webserver.py b/plugins/WebUi/deluge_webserver.py
index 5b48359e1..6f70f02db 100644
--- a/plugins/WebUi/deluge_webserver.py
+++ b/plugins/WebUi/deluge_webserver.py
@@ -58,7 +58,7 @@ urls = (
"/resume_all", "resume_all",
"/refresh/set", "refresh_set",
"/refresh/(.*)", "refresh",
- "/config", "config",
+ "/config", "config_",
"/home", "home",
"/about", "about",
"/logout", "logout",
@@ -99,7 +99,6 @@ class index:
@auto_refreshed
def GET(self, name):
vars = web.input(sort=None, order=None ,filter=None , category=None)
-
torrent_list = [get_torrent_status(torrent_id)
for torrent_id in ws.proxy.get_session_state()]
all_torrents = torrent_list[:]
@@ -162,8 +161,6 @@ class torrent_stop:
ws.proxy.pause_torrent(torrent_ids)
do_redirect()
-
-
class torrent_reannounce:
@check_session
def POST(self, torrent_id):
@@ -184,11 +181,10 @@ class torrent_add:
*posting of data as string(for greasemonkey-private)
"""
- vars = web.input(url = None, torrent = {},
- torrent_name=None, torrent_data = None)
+ vars = web.input(url = None, torrent = {})
- torrent_name = vars.torrent_name
- torrent_data = vars.torrent_data
+ torrent_name = None
+ torrent_data = None
if vars.torrent.filename:
torrent_name = vars.torrent.filename
torrent_data = vars.torrent.file.read()
@@ -209,17 +205,25 @@ class torrent_add:
class remote_torrent_add:
"""
For use in remote scripts etc.
- POST pwd and torrent
+ curl ->POST pwd and torrent as file
+ greasemonkey: POST pwd torrent_name and data_b64
"""
@remote
def POST(self, name):
- vars = web.input(pwd = None, torrent = {})
+ vars = web.input(pwd = None, torrent = {},
+ data_b64 = None , torrent_name= None)
if not check_pwd(vars.pwd):
return 'error:wrong password'
- data_b64 = base64.b64encode(vars.torrent.file.read())
- ws.proxy.add_torrent_filecontent(vars.torrent.filename, data_b64)
+ if vars.data_b64: #b64 post (greasemonkey)
+ data_b64 = unicode(vars.data_b64)
+ torrent_name = vars.torrent_name
+ else: #file-post (curl)
+ data_b64 = base64.b64encode(vars.torrent.file.read())
+ torrent_name = vars.torrent.filename
+
+ ws.proxy.add_torrent_filecontent(torrent_name, data_b64)
return 'ok'
class torrent_delete:
@@ -299,10 +303,12 @@ class refresh_set:
else:
error_page(_('refresh must be > 0'))
-class config:
+class config_: #namespace clash?
"""core config
TODO:good validation.
"""
+ """
+ SOMEHOW ONLY BREAKS 0.6 ??
cfg_form = web.form.Form(
web.form.Dropdown('max_download', ws.SPEED_VALUES,
description=_('Download Speed Limit'),
@@ -323,6 +329,7 @@ class config:
#self.config.set("max_download_speed", float(str_bwdown))
raise NotImplementedError('todo')
+ """
class home:
@check_session
@@ -356,9 +363,11 @@ class downloads(static_handler):
return static_handler.GET(self, name)
#/pages
+
def WebServer():
return create_webserver(urls, globals())
+
def run():
server = WebServer()
try:
diff --git a/plugins/WebUi/revno b/plugins/WebUi/revno
index a76256037..9e42f3ef0 100644
--- a/plugins/WebUi/revno
+++ b/plugins/WebUi/revno
@@ -1 +1 @@
-160
+165
diff --git a/plugins/WebUi/scripts/add_torrents_to_deluge.user.js b/plugins/WebUi/scripts/add_torrents_to_deluge.user.js
index 187c1799e..ca6c59efc 100644
--- a/plugins/WebUi/scripts/add_torrents_to_deluge.user.js
+++ b/plugins/WebUi/scripts/add_torrents_to_deluge.user.js
@@ -11,20 +11,27 @@
// @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
+//url-based submit and parsing based on : "Add Torrents To utorrent" by Julien Couvreur
+//binary magic,contains from http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
+
+//these parameters need to be edited before using the script
// Server address
var host = "localhost";
-
// Server port
var port = "8112";
+//open_page: "_blank" for a new window or "deluge_webui" for window re-use
+//(not for private=1)
+var open_page = "_blank"
+//Private-trackers 0/1
+//different behavior, gets torrent-data from (private) site and pops up a message.
+var private_submit = 1;
+//deluge_password, only needed if private_submit = 1.
+var deluge_password = 'deluge';
+//========================
-if (host == "") { alert('You need to configure the "Add Torrents To Deluge" user script with your uTorrent WebUI parameters before using it.'); }
+
+if (host == "") { alert('You need to configure the "Add Torrents To Deluge" user script with your WebUI parameters before using it.'); }
@@ -34,9 +41,12 @@ function scanLinks() {
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);
+ if (private_submit) {
+ makeUTorrentLink_private(link,i);
+ }
+ else {
+ makeUTorrentLink(link);
+ }
}
}
}
@@ -44,13 +54,85 @@ function scanLinks() {
function makeUTorrentLink(link) {
var uTorrentLink = document.createElement('a');
uTorrentLink.setAttribute("href", makeUTorrentUrl(link.href));
- uTorrentLink.setAttribute("target", "_blank");
+ uTorrentLink.setAttribute("target", open_page);
uTorrentLink.style.paddingLeft = "5px";
uTorrentLink.innerHTML = "
";
-
- return uTorrentLink;
+ link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
+ return uTorrentLink
}
+function makeUTorrentUrl(url) {
+ var uTorrentUrl = "http://"+host+":"+port+"/torrent/add?redir_after_login=1";
+ return uTorrentUrl + "&url=" + escape(url);
+}
+
+function makeUTorrentLink_private(link,i) {
+ var id = 'deluge_link' + i;
+ var uTorrentLink = document.createElement('a');
+ uTorrentLink.setAttribute("href", '#');
+ uTorrentLink.setAttribute("id", id);
+ uTorrentLink.style.paddingLeft = "5px";
+ uTorrentLink.innerHTML = "
";
+ link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
+
+ ulink = document.getElementById(id)
+ ulink.addEventListener("click", evt_private_submit_factory(link.href),false);
+
+ return uTorrentLink
+}
+
+function evt_private_submit_factory(url) {
+ //can this be done without magic?
+ function evt_private_submit(evt) {
+ GM_xmlhttpRequest({ method: 'GET', url: url,
+ overrideMimeType: 'text/plain; charset=x-user-defined',
+ onload: function(xhr) {
+ var stream = translateToBinaryString(xhr.responseText);
+ var data_b64 = window.btoa(stream);
+ post_to_webui(url, data_b64);
+ },
+ onerror:function(xhr) {
+ alert('error fetching torrent file');
+ }
+ });
+ return false;
+ }
+ return evt_private_submit;
+}
+
+
+function post_to_webui(url,data_b64){
+ //alert('here1');
+ //data contains the content of the .torrent-file.
+ var POST_data = ('pwd=' + encodeURIComponent(deluge_password) +
+ '&torrent_name=' + encodeURIComponent(url) + '.torrent' + //+.torrent is a clutch!
+ '&data_b64=' + encodeURIComponent(data_b64) );
+ //alert(POST_data);
+
+ GM_xmlhttpRequest({ method: 'POST',
+ url: "http://"+host+":"+port+"/remote/torrent/add",
+ headers:{'Content-type':'application/x-www-form-urlencoded'},
+ data: POST_data,
+ onload: function(xhr) {
+ if (xhr.responseText == 'ok\n') {
+ alert('Added torrent to webui : \n' + url);
+ }
+ else {
+ alert('Error adding torrent to webui:\n"' + xhr.responseText + '"');
+ }
+
+ },
+ onerror:function(xhr) {
+ alert('error submitting torrent file');
+ }
+
+ });
+}
+
+
+
+
+
function match(url) {
// isohunt format
@@ -96,10 +178,6 @@ function match(url) {
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;
@@ -112,5 +190,18 @@ function getLinks() {
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();
+
+/*
+binary magic,contains code taken from
+http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
+*/
+function translateToBinaryString(text){
+ var out;
+ out='';
+ for(i=0;i
-
-
-
-
-