From cea5f8bd12fa19a8d036347791476c3dfcddace4 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Sat, 17 May 2014 17:41:00 +0200 Subject: [PATCH 1/3] Implement --rpc-secret support --- index.html | 10 +++++++++ js/services/rpc/jsoncall.js | 4 ++-- js/services/rpc/rpc.js | 45 +++++++++++++++++++++++++++---------- js/services/rpc/syscall.js | 1 + 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index a3fe5dd..a21019d 100755 --- a/index.html +++ b/index.html @@ -754,6 +754,16 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4

Enable SSL/TLS encryption.

+ +
+ +
+
Oh Snap! Could not connect to the aria2 RPC server. Will retry in ' + time / 1000 + ' secs. You might want to check the connection settings by going to Settings > Connection Settings', 'error'); + timeout = setTimeout(update, time); + } + }; + syscall.invoke({ name: 'system.multicall', params: [params], success: function(data) { + var failed = _.any(data.result, function(d) { + return d.code && d.message === "Unauthorized"; + }); + if (failed) { + error(); + return; + } + if (configurations.length) { // configuration worked, save it in cookie for next time and // delete the pipelined configurations!! @@ -104,17 +135,7 @@ function(syscall, time, alerts, utils, rootScope, uri) { timeout = setTimeout(update, time); } }, - error: function() { - // If some proposed configurations are still in the pipeline then retry - if (configurations.length) { - alerts.log("The last connection attempt was unsuccessful. Trying another configuration"); - timeout = setTimeout(update, 0); - } - else { - alerts.addAlert('Oh Snap! Could not connect to the aria2 RPC server. Will retry in ' + time / 1000 + ' secs. You might want to check the connection settings by going to Settings > Connection Settings', 'error'); - timeout = setTimeout(update, time); - } - } + error: error }); }; diff --git a/js/services/rpc/syscall.js b/js/services/rpc/syscall.js index bbaa3fb..00ea1cb 100644 --- a/js/services/rpc/syscall.js +++ b/js/services/rpc/syscall.js @@ -13,6 +13,7 @@ function(log, jsonRPC, sockRPC, alerts) { // port (number): port number for the aria2 server // encrypt (boolean, optional): true if encryption is enabled in the aria2 server // auth (optional): { + // token (string): secret token for authentication (--rpc-secret) // user (string): username for http authentication if enabled // pass (string): password for the http authentication if enabled // } From b83c4de0ca4f86f10c6cde3134facdd7213cd32d Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Sat, 24 May 2014 17:02:23 +0200 Subject: [PATCH 2/3] Fix "Enable SSL/TLS" display --- index.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index a21019d..5ae375a 100755 --- a/index.html +++ b/index.html @@ -747,11 +747,10 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
- - Enable encryption connection to aria2 - -

Enable SSL/TLS encryption.

+
From 58d9221aa58d2dbf6ef545f2365160a5deeaf96f Mon Sep 17 00:00:00 2001 From: hamza zia Date: Sat, 31 May 2014 20:42:09 +0800 Subject: [PATCH 3/3] made rpc error handling more robust --- js/ctrls/alert.js | 11 ++++++++++- js/services/rpc/rpc.js | 25 +++++++++++++++++-------- js/services/rpc/sockcall.js | 4 +--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/js/ctrls/alert.js b/js/ctrls/alert.js index 331a499..25ae640 100644 --- a/js/ctrls/alert.js +++ b/js/ctrls/alert.js @@ -12,11 +12,20 @@ angular.module('webui.ctrls.alert', [ alerts.addAlerter(function(msg, type) { type = type || 'warning'; var obj = { msg: sce.trustAsHtml(msg), type: type }; + scope.pendingAlerts = _.filter(scope.pendingAlerts, function(al) { + return !al.expired; + }); scope.pendingAlerts.push(obj); setTimeout(function() { var ind = scope.pendingAlerts.indexOf(obj); - if (ind != -1) scope.removeAlert(ind); + if (ind != -1) { + scope.pendingAlerts[ind].expired = true; + + // only remove if more notifications are pending in the pipeline + if (scope.pendingAlerts.length > 1) + scope.removeAlert(ind); + } }, type == "error" ? 10000 : 3000); scope.$digest(); diff --git a/js/services/rpc/rpc.js b/js/services/rpc/rpc.js index fa9adfe..51d478d 100644 --- a/js/services/rpc/rpc.js +++ b/js/services/rpc/rpc.js @@ -28,7 +28,7 @@ function(syscall, time, alerts, utils, rootScope, uri) { var cookieConf = utils.getCookie('aria2conf'); // try at the end, so that it is not overwridden in case it doesnt work - if (cookieConf) configurations.push(cookieConf); + if (cookieConf) configurations.unshift(cookieConf); // update is implemented such that // only one syscall at max is ongoing @@ -49,7 +49,7 @@ function(syscall, time, alerts, utils, rootScope, uri) { } if (configurations.length) { - currentConf = configurations.shift(); + currentConf = configurations[0]; if (currentConf && currentConf.auth && currentConf.auth.token) { currentToken = currentConf.auth.token; } @@ -71,14 +71,17 @@ function(syscall, time, alerts, utils, rootScope, uri) { }); var error = function() { + var ind = configurations.indexOf(currentConf); + if (ind != -1) configurations.splice(ind, 1); + // If some proposed configurations are still in the pipeline then retry if (configurations.length) { alerts.log("The last connection attempt was unsuccessful. Trying another configuration"); timeout = setTimeout(update, 0); } else { - alerts.addAlert('Oh Snap! Could not connect to the aria2 RPC server. Will retry in ' + time / 1000 + ' secs. You might want to check the connection settings by going to Settings > Connection Settings', 'error'); - timeout = setTimeout(update, time); + alerts.addAlert('Oh Snap! Could not connect to the aria2 RPC server. Will retry in 10 secs. You might want to check the connection settings by going to Settings > Connection Settings', 'error'); + timeout = setTimeout(update, 10000); } }; @@ -86,19 +89,20 @@ function(syscall, time, alerts, utils, rootScope, uri) { name: 'system.multicall', params: [params], success: function(data) { - var failed = _.any(data.result, function(d) { return d.code && d.message === "Unauthorized"; }); + if (failed) { - error(); + alerts.addAlert('Oh Snap! Authentication failed while connecting to Aria2 RPC server. Will retry in 10 secs. You might want to confirm your authentication details by going to Settings > Connection Settings', 'error'); + timeout = setTimeout(update, 10000); return; } if (configurations.length) { // configuration worked, save it in cookie for next time and // delete the pipelined configurations!! - alerts.log('Success alas! Saving the current configuration…'); + alerts.addAlert('Successfully connected to Aria2 through its remote RPC…', 'success'); configurations = []; } @@ -147,12 +151,17 @@ function(syscall, time, alerts, utils, rootScope, uri) { // each one will be tried one after the other till success, // for all options for one conf read rpc/syscall.js configure: function(conf) { - alerts.addAlert('Successfully changed aria2 connection configuration', 'success'); + alerts.addAlert('Trying to connect to aria2 using the new connection configuration', 'info'); if (conf instanceof Array) configurations = conf; else configurations = [conf]; + + if (timeout) { + clearTimeout(timeout); + timeout = setTimeout(update, 0); + } }, // get current configuration being used diff --git a/js/services/rpc/sockcall.js b/js/services/rpc/sockcall.js index 007b977..8e7a8e2 100644 --- a/js/services/rpc/sockcall.js +++ b/js/services/rpc/sockcall.js @@ -28,8 +28,7 @@ function(_, JSON, name, utils, alerts) { _.each(sockRPC.handles, function(h) { h.error() }); sockRPC.handles = []; sockRPC.initialized = false; - alerts.log('Cannot talk to aria2 over WebSockets! Switching to regular HTTP requests…'); - + alerts.log('Cannot talk to aria2 over WebSockets. Switching to regular HTTP requests…'); }, onclose: function(ev) { if (sockRPC.handles && sockRPC.handles.length) @@ -39,7 +38,6 @@ function(_, JSON, name, utils, alerts) { // when connection opens onopen: function() { - alerts.addAlert('Successfully connected to aria2 over a WebSocket!', 'success'); sockRPC.initialized = true; },