From 2bc0f3a90a62c2ca3a4fdcccfa0afa6dd112f231 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 2 Oct 2012 23:50:57 +0900 Subject: [PATCH] Add SSL/TLS encryption --- index.html | 7 +++++++ js/connection.js | 8 +++++--- js/script.js | 7 ++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 2cfc53e..7ef6832 100755 --- a/index.html +++ b/index.html @@ -573,6 +573,13 @@

Enter the port of the server on which the rpc for aria2 is running (default = 6800)

+ + +
+ +

Enable SSL/TLS encryption.

+
+
diff --git a/js/connection.js b/js/connection.js index 0a43c1c..7b1fe0c 100644 --- a/js/connection.js +++ b/js/connection.js @@ -30,8 +30,9 @@ JsonRPC.prototype = { }, invoke: function(opts) { var rpc = this; + var scheme = rpc.serverConf.encryption ? 'https' : 'http'; rpc.ariaRequest( - 'http://' + rpc.serverConf.host + ':' + rpc.serverConf.port + '/jsonrpc', + scheme + '://' + rpc.serverConf.host + ':' + rpc.serverConf.port + '/jsonrpc', opts.multicall, opts.func, opts.params, @@ -44,7 +45,7 @@ JsonRPC.prototype = { return opts.error(); } - var authUrl = 'http://' + + var authUrl = scheme + '://' + rpc.serverConf.user + ":" + rpc.serverConf.pass + "@" + rpc.serverConf.host + ':' + @@ -80,7 +81,8 @@ var SocketRPC = function(conf) { rpc.serverConf = conf; rpc.initialized = false; rpc.handles = []; - rpc.sock = new WebSocket('ws://' + conf.host + ':' + conf.port + '/jsonrpc'); + var scheme = rpc.serverConf.encryption ? 'wss' : 'ws'; + rpc.sock = new WebSocket(scheme + '://' + conf.host + ':' + conf.port + '/jsonrpc'); rpc.sock.onopen = function() { rpc.initialized = true; }; diff --git a/js/script.js b/js/script.js index a6cd53d..4eeedf4 100755 --- a/js/script.js +++ b/js/script.js @@ -24,7 +24,8 @@ var server_conf = { host: 'localhost', port: 6800, user: "", - pass: "" + pass: "", + encryption: false }; var ariaConnection = new AriaConnection(server_conf); @@ -40,6 +41,9 @@ var custom_aria2_connect = function() { clear_dialogs(); $("#input_host").attr("placeholder", server_conf.host); $("#input_port").attr("placeholder", server_conf.port); + if(server_conf.encryption) { + $("#input_encryption").addClass("active"); + } modals.change_conf.modal('show'); }; var update_server_conf = function() { @@ -47,6 +51,7 @@ var update_server_conf = function() { var port = $('#input_port').val().trim(); server_conf.user = $('#input_user').val().trim(); server_conf.pass = $('#input_pass').val().trim(); + server_conf.encryption = $('#input_encryption').hasClass('active'); if(host.length !== 0) { server_conf.host = host; }