2018-10-30 23:59:59 +01:00
|
|
|
var action_queue = [];
|
|
|
|
|
2018-08-17 14:10:29 +02:00
|
|
|
$(function() {
|
|
|
|
$('#update-host').on('submit', update_host);
|
|
|
|
$('#verify-dns').on('click', verify_dns);
|
|
|
|
$('#verify-https').on('click', verify_https);
|
|
|
|
$('#verify-http').on('click', verify_http);
|
|
|
|
$('#cert-method').on('change', toggle_cert_method);
|
|
|
|
$('#update-cert').on('submit', update_cert);
|
|
|
|
$('#update-common').on('submit', update_common);
|
2018-10-26 11:15:48 +02:00
|
|
|
$('#app-manager')
|
2018-10-28 18:20:27 +01:00
|
|
|
.on('click', '.app-visible', update_app_visibility)
|
|
|
|
.on('click', '.app-autostart', update_app_autostart)
|
2018-10-26 11:15:48 +02:00
|
|
|
.on('click', '.app-start', start_app)
|
|
|
|
.on('click', '.app-stop', stop_app)
|
2018-10-26 14:12:12 +02:00
|
|
|
.on('click', '.app-install', install_app)
|
2018-10-26 19:08:14 +02:00
|
|
|
.on('click', '.app-uninstall', uninstall_app);
|
2018-08-17 14:10:29 +02:00
|
|
|
$('#update-password').on('submit', update_password);
|
|
|
|
$('#reboot-vm').on('click', reboot_vm);
|
|
|
|
$('#shutdown-vm').on('click', shutdown_vm);
|
2018-10-30 23:59:59 +01:00
|
|
|
window.setInterval(check_progress, 1000);
|
2018-08-17 14:10:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function update_host() {
|
|
|
|
$('#host-submit').hide();
|
|
|
|
$('#host-message').hide();
|
|
|
|
$('#host-wait').show();
|
|
|
|
$.post('/update-host', {'domain': $('#domain').val(), 'port': $('#port').val()}, function(data) {
|
|
|
|
$('#host-wait').hide();
|
|
|
|
if (data.error) {
|
|
|
|
$('#host-message').attr('class','error').html(data.error).show();
|
|
|
|
$('#host-submit').show();
|
|
|
|
} else {
|
|
|
|
$('#host-message').attr('class','info').html(data.ok).show();
|
2018-08-30 18:04:47 +02:00
|
|
|
$('input').prop('disabled', true);
|
|
|
|
$('.setup-box').slice(1).css('opacity', '0.5');
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_dns() {
|
|
|
|
$('#verify-dns').hide();
|
|
|
|
$('#dns-message').hide();
|
|
|
|
$('#dns-wait').show();
|
|
|
|
$.get('/verify-dns', function(data) {
|
|
|
|
$('#dns-wait').hide();
|
|
|
|
if (data.error) {
|
|
|
|
$('#dns-message').attr('class','error').html(data.error).show();
|
|
|
|
$('#verify-dns').show();
|
|
|
|
} else {
|
|
|
|
$('#dns-message').attr('class','info').html(data.ok).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _verify_http(proto) {
|
|
|
|
$('#verify-'+proto).hide();
|
|
|
|
$('#'+proto+'-message').hide();
|
|
|
|
$('#'+proto+'-wait').show();
|
|
|
|
$.get('/verify-' + proto, function(data) {
|
|
|
|
$('#'+proto+'-wait').hide();
|
|
|
|
if (data.error) {
|
|
|
|
$('#'+proto+'-message').attr('class','error').html(data.error).show();
|
|
|
|
$('#verify-'+proto).show();
|
|
|
|
} else {
|
|
|
|
$('#'+proto+'-message').attr('class','info').html(data.ok).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_http() {
|
|
|
|
return _verify_http('http');
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_https() {
|
|
|
|
return _verify_http('https');
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_cert_method() {
|
|
|
|
if ($('#cert-method').val() == 'manual') {
|
|
|
|
$('.cert-upload').show();
|
|
|
|
} else {
|
|
|
|
$('.cert-upload').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_cert() {
|
|
|
|
$('#cert-submit').hide();
|
|
|
|
$('#cert-message').hide();
|
|
|
|
$('#cert-wait').show();
|
|
|
|
$.ajax({url: '/update-cert', type: 'POST', data: new FormData($('#update-cert')[0]), cache: false, contentType: false, processData: false, success: function(data) {
|
|
|
|
$('#cert-wait').hide();
|
|
|
|
if (data.error) {
|
2018-08-30 18:04:47 +02:00
|
|
|
$('#cert-message').attr('class','error').html(data.error).show();
|
2018-08-17 14:10:29 +02:00
|
|
|
$('#cert-submit').show();
|
|
|
|
} else {
|
2018-08-30 18:04:47 +02:00
|
|
|
$('#cert-message').attr('class','info').html(data.ok).show();
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
}});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_common() {
|
|
|
|
$('#common-submit').hide();
|
|
|
|
$('#common-message').hide();
|
|
|
|
$('#common-wait').show();
|
|
|
|
$.post('/update-common', {'email': $('#email').val(), 'gmaps-api-key': $('#gmaps-api-key').val()}, function(data) {
|
|
|
|
$('#common-wait').hide();
|
|
|
|
if (data.error) {
|
|
|
|
$('#common-message').attr('class','error').html(data.error).show();
|
|
|
|
$('#common-submit').show();
|
|
|
|
} else {
|
|
|
|
$('#common-message').attr('class','info').html(data.ok).show();
|
|
|
|
$('#common-submit').show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:12:12 +02:00
|
|
|
function _update_app(item, ev) {
|
2018-08-17 14:10:29 +02:00
|
|
|
var el = $(ev.target);
|
|
|
|
var app = el.closest('tr').data('app');
|
|
|
|
var value = el.is(':checked') ? 'true' : '';
|
2018-10-26 14:12:12 +02:00
|
|
|
$.post('/update-app-'+item, {'app': app, 'value': value}, function(data) {
|
2018-08-17 14:10:29 +02:00
|
|
|
if (data.error) {
|
|
|
|
el.prop('checked', !value);
|
|
|
|
alert(data.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:12:12 +02:00
|
|
|
function update_app_visibility(ev) {
|
|
|
|
return _update_app('visibility', ev);
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:10:29 +02:00
|
|
|
function update_app_autostart(ev) {
|
2018-10-26 14:12:12 +02:00
|
|
|
return _update_app('autostart', ev);
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 14:12:12 +02:00
|
|
|
function _do_app(action, ev) {
|
2018-08-17 14:10:29 +02:00
|
|
|
var el = $(ev.target);
|
2018-10-26 11:15:48 +02:00
|
|
|
var tr = el.closest('tr');
|
2018-08-17 14:10:29 +02:00
|
|
|
var td = el.closest('td');
|
|
|
|
td.html('<div class="loader"></div>');
|
2018-10-26 14:12:12 +02:00
|
|
|
$.post('/'+action+'-app', {'app': tr.data('app')}, function(data) {
|
2018-08-17 14:10:29 +02:00
|
|
|
if (data.error) {
|
|
|
|
td.attr('class','error').html(data.error);
|
2018-10-26 19:08:14 +02:00
|
|
|
} else if (action) {
|
2018-10-30 23:59:59 +01:00
|
|
|
tr.html(data.html);
|
|
|
|
action_queue.push(data.id);
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:12:12 +02:00
|
|
|
function start_app(ev) {
|
|
|
|
return _do_app('start', ev);
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:10:29 +02:00
|
|
|
function stop_app(ev) {
|
2018-10-26 14:12:12 +02:00
|
|
|
return _do_app('stop', ev);
|
2018-10-26 11:15:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_app(ev) {
|
2018-10-26 14:12:12 +02:00
|
|
|
return _do_app('install', ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstall_app(ev) {
|
2018-10-27 12:21:00 +02:00
|
|
|
var app = $(ev.target).closest('tr').children().first().text()
|
2018-10-27 12:49:22 +02:00
|
|
|
if (confirm('Opravdu chcete odinstalovat aplikaci '+app+'?')) {
|
2018-10-26 14:12:12 +02:00
|
|
|
return _do_app('uninstall', ev);
|
|
|
|
}
|
2018-08-17 14:10:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-26 17:31:40 +02:00
|
|
|
function check_progress() {
|
2018-10-30 23:59:59 +01:00
|
|
|
if (action_queue.length) {
|
|
|
|
$.post('/get-progress', {'ids': action_queue}, function(data) {
|
|
|
|
for (id in data) {
|
|
|
|
var app = id.split(':')[0];
|
|
|
|
$('#app-manager tr[data-app="'+app+'"]').html(data[id].html);
|
|
|
|
if (data[id].last) {
|
|
|
|
action_queue = action_queue.filter(function(item) {
|
|
|
|
return item !== id
|
|
|
|
});
|
2018-10-27 12:21:00 +02:00
|
|
|
}
|
2018-10-26 17:31:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:10:29 +02:00
|
|
|
function update_password() {
|
|
|
|
$('#password-submit').hide();
|
|
|
|
$('#password-message').hide();
|
|
|
|
$('#password-wait').show();
|
|
|
|
$.post('/update-password', {'oldpassword': $('#oldpassword').val(), 'newpassword': $('#newpassword').val(), 'newpassword2': $('#newpassword2').val()}, function(data) {
|
|
|
|
$('#password-wait').hide();
|
|
|
|
if (data.error) {
|
|
|
|
$('#password-message').attr('class','error').html(data.error).show();
|
|
|
|
$('#password-submit').show();
|
|
|
|
} else {
|
|
|
|
$('#password-message').attr('class','info').html(data.ok).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:12:12 +02:00
|
|
|
function _do_vm(action) {
|
|
|
|
$.get('/'+action+'-vm', function(data) {
|
|
|
|
$('#vm-message').attr('class','info').html(data.ok).show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:10:29 +02:00
|
|
|
function reboot_vm() {
|
2018-10-27 12:21:00 +02:00
|
|
|
if (confirm('Opravdu chcete restartovat VM?')) {
|
2018-10-26 14:12:12 +02:00
|
|
|
_do_vm('reboot');
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function shutdown_vm() {
|
2018-10-27 12:21:00 +02:00
|
|
|
if (confirm('Opravdu chcete vypnout VM?')) {
|
2018-10-26 14:12:12 +02:00
|
|
|
_do_vm('shutdown');
|
2018-08-17 14:10:29 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|