hack for http authentication for all browsers added over JSONP!!

This commit is contained in:
Hamza Zia 2012-06-06 15:06:05 +08:00
parent b1f297aa7b
commit 433663a584
2 changed files with 50 additions and 21 deletions

View File

@ -117,6 +117,7 @@
<ul class="nav">
<li class="active"><a href="#">Active Downloads</a></li>
<!-- <li><a href="#watiting_downloads">Passive Downloads</a></li> -->
<li><a href="#">Aria2 connection configuration</a></li>
<li><a id="newDownload" href="#">Add Download</a></li>
</ul>
</div><!--/.nav-collapse -->
@ -142,7 +143,7 @@
<!--{{{ Hidden dialogs and out of screen HTML elements -->
<!--{{{ error connection template -->
<div class="modal fade" id="error_connect">
<div class="modal hide" id="error_connect">
<div class="modal-header">
<button class="close" data-dismiss="modal">x</button>
<h3>Connection to Aria failed :( </h3>
@ -162,7 +163,7 @@
<!--{{{ change aria2 rpc host and port template -->
<div class="modal fade" id="change_conf">
<div class="modal hide" id="change_conf">
<div class="modal-header">
<button class="close" data-dismiss="modal">x</button>
<h3>Please enter the aria2 RPC port and host</h3>
@ -205,7 +206,7 @@
<!--{{{ add new Download template -->
<div class="modal fade" id="newDownload_modal">
<div class="modal hide" id="newDownload_modal">
<div class="modal-header">
<button class="close" data-dismiss="modal">x</button>
<h3>Add a new Download</h3>
@ -230,7 +231,7 @@
<button id="addNewDownload" class="btn">Add Download</button>
</div>
</div>
<!--{{{ add new Download template -->
<!-- add new Download template end }}}-->
<!-- }}} hidden modals end -->

View File

@ -5,9 +5,9 @@ var modals = {
};
var clear_dialogs = function() {
modals.err_connect = $('#error_connect').modal('hide');
modals.change_conf = $('#change_conf').modal('hide');
modals.newDownload_modal = $('#newDownload_modal').modal('hide');
modals.err_connect.modal('hide');
modals.change_conf.modal('hide');
modals.newDownload_modal.modal('hide');
};
var server_conf = {
host: 'localhost',
@ -42,19 +42,8 @@ function param_encode(param) {
return param;
}
var aria_syscall = function(conf, multicall) {
var url = "";
if(server_conf.user.length) {
url = 'http://' +
server_conf.user + ":" +
server_conf.pass + "@" +
server_conf.host + ':' +
server_conf.port + '/jsonrpc';
}
else {
url = 'http://' + server_conf.host + ':' + server_conf.port + '/jsonrpc';
}
$.ajax({
url: url,
url: 'http://' + server_conf.host + ':' + server_conf.port + '/jsonrpc',
timeout: 1000,
data: {
jsonrpc: 2.0,
@ -63,7 +52,40 @@ var aria_syscall = function(conf, multicall) {
params: param_encode(conf.params)
},
success: conf.sucess,
error: conf.error,
error: function() {
if(server_conf.user.length) {
var url = 'http://' +
server_conf.user + ":" +
server_conf.pass + "@" +
server_conf.host + ':' +
server_conf.port + '/jsonrpc';
/* hack for http authentication */
var img = $('<img/>').attr("src", url);
$('body').append(img);
img.remove();
setTimeout(function() {
$.ajax({
url: url,
timeout: 1000,
data: {
jsonrpc: 2.0,
id: 'webui',
method: multicall? conf.func:'aria2.' + conf.func,
params: param_encode(conf.params)
},
success: conf.sucess,
error: conf.error,
dataType: 'jsonp',
jsonp: 'jsoncallback'
});
}, 1000);
}
else if(conf.error) {
conf.error();
}
},
dataType: 'jsonp',
jsonp: 'jsoncallback'
});
@ -74,7 +96,13 @@ var update_ui = function() {
};
$(function() {
clear_dialogs();
var modal_conf = {
show: false
};
modals.err_connect = $('#error_connect').modal(modal_conf);
modals.change_conf = $('#change_conf').modal(modal_conf);
modals.newDownload_modal = $('#newDownload_modal').modal(modal_conf);
update_ui();
$('#newDownload').click(function() {
$('#newDownload_url').val("");