|
@ -1,6 +1,8 @@ |
|
|
var websock; |
|
|
var websock; |
|
|
var password = false; |
|
|
var password = false; |
|
|
var maxNetworks; |
|
|
var maxNetworks; |
|
|
|
|
|
var host; |
|
|
|
|
|
var port; |
|
|
|
|
|
|
|
|
// http://www.the-art-of-web.com/javascript/validate-password/
|
|
|
// http://www.the-art-of-web.com/javascript/validate-password/
|
|
|
function checkPassword(str) { |
|
|
function checkPassword(str) { |
|
@ -71,6 +73,44 @@ function doToggle(element, value) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function backupSettings() { |
|
|
|
|
|
document.getElementById('downloader').src = 'http://' + host + ':' + port + '/config'; |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onFileUpload(event) { |
|
|
|
|
|
|
|
|
|
|
|
var inputFiles = this.files; |
|
|
|
|
|
if (inputFiles == undefined || inputFiles.length == 0) return false; |
|
|
|
|
|
var inputFile = inputFiles[0]; |
|
|
|
|
|
|
|
|
|
|
|
var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?"); |
|
|
|
|
|
if (response == false) return false; |
|
|
|
|
|
|
|
|
|
|
|
var reader = new FileReader(); |
|
|
|
|
|
reader.onload = function(e) { |
|
|
|
|
|
var data = getJson(e.target.result); |
|
|
|
|
|
if (data) { |
|
|
|
|
|
websock.send(JSON.stringify({'action': 'restore', 'data': data})); |
|
|
|
|
|
} else { |
|
|
|
|
|
alert("The file is not a configuration backup or is corrupted"); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
reader.readAsText(inputFile); |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function restoreSettings() { |
|
|
|
|
|
if (typeof window.FileReader !== 'function') { |
|
|
|
|
|
alert("The file API isn't supported on this browser yet."); |
|
|
|
|
|
} else { |
|
|
|
|
|
$("#uploader").click(); |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function randomString(length, chars) { |
|
|
function randomString(length, chars) { |
|
|
var mask = ''; |
|
|
var mask = ''; |
|
|
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz'; |
|
|
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz'; |
|
@ -357,13 +397,17 @@ function getJson(str) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function connect(host, port) { |
|
|
|
|
|
if (typeof host === 'undefined') { |
|
|
|
|
|
host = window.location.hostname; |
|
|
|
|
|
|
|
|
function connect(h, p) { |
|
|
|
|
|
|
|
|
|
|
|
if (typeof h === 'undefined') { |
|
|
|
|
|
h = window.location.hostname; |
|
|
} |
|
|
} |
|
|
if (typeof port === 'undefined') { |
|
|
|
|
|
port = location.port; |
|
|
|
|
|
|
|
|
if (typeof p === 'undefined') { |
|
|
|
|
|
p = location.port; |
|
|
} |
|
|
} |
|
|
|
|
|
host = h; |
|
|
|
|
|
port = p; |
|
|
|
|
|
|
|
|
if (websock) websock.close(); |
|
|
if (websock) websock.close(); |
|
|
websock = new WebSocket('ws://' + host + ':' + port + '/ws'); |
|
|
websock = new WebSocket('ws://' + host + ':' + port + '/ws'); |
|
|
websock.onopen = function(evt) { |
|
|
websock.onopen = function(evt) { |
|
@ -388,6 +432,9 @@ function init() { |
|
|
$(".button-update-password").on('click', doUpdatePassword); |
|
|
$(".button-update-password").on('click', doUpdatePassword); |
|
|
$(".button-reset").on('click', doReset); |
|
|
$(".button-reset").on('click', doReset); |
|
|
$(".button-reconnect").on('click', doReconnect); |
|
|
$(".button-reconnect").on('click', doReconnect); |
|
|
|
|
|
$(".button-settings-backup").on('click', backupSettings); |
|
|
|
|
|
$(".button-settings-restore").on('click', restoreSettings); |
|
|
|
|
|
$('#uploader').on('change', onFileUpload); |
|
|
$(".button-apikey").on('click', doGenerateAPIKey); |
|
|
$(".button-apikey").on('click', doGenerateAPIKey); |
|
|
$(".pure-menu-link").on('click', showPanel); |
|
|
$(".pure-menu-link").on('click', showPanel); |
|
|
$(".button-add-network").on('click', function() { |
|
|
$(".button-add-network").on('click', function() { |
|
|