diff --git a/index.html b/index.html
index 3ab0c75..d50eb23 100755
--- a/index.html
+++ b/index.html
@@ -753,11 +753,20 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
+
+
+
diff --git a/js/services/rpc/jsoncall.js b/js/services/rpc/jsoncall.js
index bb31ef5..c78c8bd 100644
--- a/js/services/rpc/jsoncall.js
+++ b/js/services/rpc/jsoncall.js
@@ -24,7 +24,7 @@ angular
},
success: function(data) {
conn.avgTimeout = 2000 + 3 * (new Date() - startTime);
- return success(data)
+ return success(data);
},
error: error,
dataType: 'jsonp',
@@ -42,7 +42,7 @@ angular
function() {
// check if authentication details are given, if yes then use a hack to support
// http authentication otherwise emit error
- if (!rpc.serverConf.auth) {
+ if (!rpc.serverConf.auth || !rpc.serverConf.auth.user) {
console.log("jsonrpc disconnect!!!");
return opts.error();
}
diff --git a/js/services/rpc/rpc.js b/js/services/rpc/rpc.js
index c0d2277..fa9adfe 100644
--- a/js/services/rpc/rpc.js
+++ b/js/services/rpc/rpc.js
@@ -11,6 +11,7 @@ function(syscall, time, alerts, utils, rootScope, uri) {
var subscriptions = []
, configurations = [{ host: 'localhost', port: 6800, encrypt: false }]
, currentConf = {}
+ , currentToken
, timeout = null
, forceNextUpdate = false;
@@ -49,21 +50,51 @@ function(syscall, time, alerts, utils, rootScope, uri) {
if (configurations.length) {
currentConf = configurations.shift();
+ if (currentConf && currentConf.auth && currentConf.auth.token) {
+ currentToken = currentConf.auth.token;
+ }
+ else {
+ currentToken = null;
+ }
syscall.init(currentConf);
}
var params = _.map(subs, function(s) {
+ var p = s.params;
+ if (currentToken) {
+ p = ["token:" + currentToken].concat(p || []);
+ }
return {
methodName: s.name,
- params: s.params && s.params.length ? s.params : undefined
+ params: p && p.length ? p : undefined
};
});
+ var 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);
+ }
+ };
+
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
// }