Merge branch 'nmaier'

This commit is contained in:
hamza zia 2014-05-31 20:43:55 +08:00
commit 3589434d97
6 changed files with 74 additions and 27 deletions

View File

@ -746,11 +746,20 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<label class="control-label">SSL/TLS encryption:</label> <label class="control-label">SSL/TLS encryption:</label>
<div class="controls"> <div class="controls">
<input type="checkbox" <label>
ng-model="connection.conf.encrypt"> <input type="checkbox" ng-model="connection.conf.encrypt"/>
Enable encryption connection to aria2 Enable SSL/TLS encryption.
</input> </label>
<p class="help-block">Enable SSL/TLS encryption.</p> </div>
<label class="control-label">Enter the secret token (optional):</label>
<div class="controls">
<label>
<input type="text" class="input-xlarge" ng-model="connection.conf.auth.token"/>
<p class="help-block">
Enter the aria2 RPC secret token (leave empty if authentication is not enabled)>
</p>
</label>
</div> </div>
<label class="control-label">Enter the username (optional):</label> <label class="control-label">Enter the username (optional):</label>

View File

@ -12,11 +12,20 @@ angular.module('webui.ctrls.alert', [
alerts.addAlerter(function(msg, type) { alerts.addAlerter(function(msg, type) {
type = type || 'warning'; type = type || 'warning';
var obj = { msg: sce.trustAsHtml(msg), type: type }; var obj = { msg: sce.trustAsHtml(msg), type: type };
scope.pendingAlerts = _.filter(scope.pendingAlerts, function(al) {
return !al.expired;
});
scope.pendingAlerts.push(obj); scope.pendingAlerts.push(obj);
setTimeout(function() { setTimeout(function() {
var ind = scope.pendingAlerts.indexOf(obj); 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); }, type == "error" ? 10000 : 3000);
scope.$digest(); scope.$digest();

View File

@ -24,7 +24,7 @@ angular
}, },
success: function(data) { success: function(data) {
conn.avgTimeout = 2000 + 3 * (new Date() - startTime); conn.avgTimeout = 2000 + 3 * (new Date() - startTime);
return success(data) return success(data);
}, },
error: error, error: error,
dataType: 'jsonp', dataType: 'jsonp',
@ -42,7 +42,7 @@ angular
function() { function() {
// check if authentication details are given, if yes then use a hack to support // check if authentication details are given, if yes then use a hack to support
// http authentication otherwise emit error // http authentication otherwise emit error
if (!rpc.serverConf.auth) { if (!rpc.serverConf.auth || !rpc.serverConf.auth.user) {
console.log("jsonrpc disconnect!!!"); console.log("jsonrpc disconnect!!!");
return opts.error(); return opts.error();
} }

View File

@ -11,6 +11,7 @@ function(syscall, time, alerts, utils, rootScope, uri) {
var subscriptions = [] var subscriptions = []
, configurations = [{ host: 'localhost', port: 6800, encrypt: false }] , configurations = [{ host: 'localhost', port: 6800, encrypt: false }]
, currentConf = {} , currentConf = {}
, currentToken
, timeout = null , timeout = null
, forceNextUpdate = false; , forceNextUpdate = false;
@ -27,7 +28,7 @@ function(syscall, time, alerts, utils, rootScope, uri) {
var cookieConf = utils.getCookie('aria2conf'); var cookieConf = utils.getCookie('aria2conf');
// try at the end, so that it is not overwridden in case it doesnt work // 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 // update is implemented such that
// only one syscall at max is ongoing // only one syscall at max is ongoing
@ -48,26 +49,60 @@ function(syscall, time, alerts, utils, rootScope, uri) {
} }
if (configurations.length) { if (configurations.length) {
currentConf = configurations.shift(); currentConf = configurations[0];
if (currentConf && currentConf.auth && currentConf.auth.token) {
currentToken = currentConf.auth.token;
}
else {
currentToken = null;
}
syscall.init(currentConf); syscall.init(currentConf);
} }
var params = _.map(subs, function(s) { var params = _.map(subs, function(s) {
var p = s.params;
if (currentToken) {
p = ["token:" + currentToken].concat(p || []);
}
return { return {
methodName: s.name, methodName: s.name,
params: s.params && s.params.length ? s.params : undefined params: p && p.length ? p : undefined
}; };
}); });
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('<strong>Oh Snap!</strong> 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);
}
};
syscall.invoke({ syscall.invoke({
name: 'system.multicall', name: 'system.multicall',
params: [params], params: [params],
success: function(data) { success: function(data) {
var failed = _.any(data.result, function(d) {
return d.code && d.message === "Unauthorized";
});
if (failed) {
alerts.addAlert('<strong>Oh Snap!</strong> 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) { if (configurations.length) {
// configuration worked, save it in cookie for next time and // configuration worked, save it in cookie for next time and
// delete the pipelined configurations!! // delete the pipelined configurations!!
alerts.log('Success alas! Saving the current configuration…'); alerts.addAlert('Successfully connected to Aria2 through its remote RPC…', 'success');
configurations = []; configurations = [];
} }
@ -104,17 +139,7 @@ function(syscall, time, alerts, utils, rootScope, uri) {
timeout = setTimeout(update, time); timeout = setTimeout(update, time);
} }
}, },
error: function() { error: error
// 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('<strong>Oh Snap!</strong> 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);
}
}
}); });
}; };
@ -126,12 +151,17 @@ function(syscall, time, alerts, utils, rootScope, uri) {
// each one will be tried one after the other till success, // each one will be tried one after the other till success,
// for all options for one conf read rpc/syscall.js // for all options for one conf read rpc/syscall.js
configure: function(conf) { 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) if (conf instanceof Array)
configurations = conf; configurations = conf;
else else
configurations = [conf]; configurations = [conf];
if (timeout) {
clearTimeout(timeout);
timeout = setTimeout(update, 0);
}
}, },
// get current configuration being used // get current configuration being used

View File

@ -28,8 +28,7 @@ function(_, JSON, name, utils, alerts) {
_.each(sockRPC.handles, function(h) { h.error() }); _.each(sockRPC.handles, function(h) { h.error() });
sockRPC.handles = []; sockRPC.handles = [];
sockRPC.initialized = false; 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) { onclose: function(ev) {
if (sockRPC.handles && sockRPC.handles.length) if (sockRPC.handles && sockRPC.handles.length)
@ -39,7 +38,6 @@ function(_, JSON, name, utils, alerts) {
// when connection opens // when connection opens
onopen: function() { onopen: function() {
alerts.addAlert('Successfully connected to aria2 over a WebSocket!', 'success');
sockRPC.initialized = true; sockRPC.initialized = true;
}, },

View File

@ -13,6 +13,7 @@ function(log, jsonRPC, sockRPC, alerts) {
// port (number): port number for the aria2 server // port (number): port number for the aria2 server
// encrypt (boolean, optional): true if encryption is enabled in the aria2 server // encrypt (boolean, optional): true if encryption is enabled in the aria2 server
// auth (optional): { // auth (optional): {
// token (string): secret token for authentication (--rpc-secret)
// user (string): username for http authentication if enabled // user (string): username for http authentication if enabled
// pass (string): password for the http authentication if enabled // pass (string): password for the http authentication if enabled
// } // }