2024-06-16 05:02:08 +00:00
|
|
|
let nice_names = {
|
|
|
|
'haproxy': 'HAProxy',
|
|
|
|
'nginx': 'NGINX',
|
|
|
|
'apache': 'Apache',
|
|
|
|
'node': 'Node',
|
|
|
|
'keepalived': 'Keepalived'
|
|
|
|
};
|
2024-03-17 06:38:00 +00:00
|
|
|
$( function() {
|
2024-05-15 12:38:05 +00:00
|
|
|
$('#install').click(function () {
|
|
|
|
installService('haproxy')
|
|
|
|
});
|
|
|
|
$('#nginx_install').click(function () {
|
|
|
|
installService('nginx');
|
|
|
|
});
|
|
|
|
$('#apache_install').click(function () {
|
|
|
|
installService('apache');
|
|
|
|
});
|
|
|
|
$('#grafana_install').click(function () {
|
|
|
|
$("#ajaxmon").html('');
|
|
|
|
$("#ajaxmon").html(wait_mess);
|
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/grafana",
|
2024-05-15 12:38:05 +00:00
|
|
|
success: function (data) {
|
|
|
|
data = data.replace(/\s+/g, ' ');
|
|
|
|
$("#ajaxmon").html('');
|
|
|
|
if (data.indexOf('FAILED') != '-1' || data.indexOf('UNREACHABLE') != '-1' || data.indexOf('ERROR') != '-1') {
|
|
|
|
toastr.clear();
|
2024-06-16 05:02:08 +00:00
|
|
|
let p_err = show_pretty_ansible_error(data);
|
2024-05-15 12:38:05 +00:00
|
|
|
toastr.error(p_err);
|
|
|
|
} else if (data.indexOf('success') != '-1') {
|
|
|
|
toastr.clear();
|
|
|
|
toastr.success(data);
|
|
|
|
} else if (data.indexOf('Info') != '-1') {
|
|
|
|
toastr.clear();
|
|
|
|
toastr.info(data);
|
|
|
|
} else {
|
|
|
|
toastr.clear();
|
|
|
|
toastr.info(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('#haproxy_exp_install').click(function () {
|
|
|
|
installExporter('haproxy');
|
|
|
|
});
|
|
|
|
$('#nginx_exp_install').click(function () {
|
|
|
|
installExporter('nginx');
|
|
|
|
});
|
|
|
|
$('#apache_exp_install').click(function () {
|
|
|
|
installExporter('apache');
|
|
|
|
});
|
|
|
|
$('#keepalived_exp_install').click(function () {
|
|
|
|
installExporter('keepalived');
|
|
|
|
});
|
|
|
|
$('#node_exp_install').click(function () {
|
|
|
|
installExporter('node');
|
|
|
|
});
|
|
|
|
$("#haproxyaddserv").on('selectmenuchange', function () {
|
|
|
|
showServiceVersion('haproxy');
|
|
|
|
});
|
|
|
|
$("#nginxaddserv").on('selectmenuchange', function () {
|
|
|
|
showServiceVersion('nginx');
|
|
|
|
});
|
|
|
|
$("#apacheaddserv").on('selectmenuchange', function () {
|
|
|
|
showServiceVersion('apache');
|
|
|
|
});
|
|
|
|
$("#haproxy_exp_addserv").on('selectmenuchange', function () {
|
|
|
|
showExporterVersion('haproxy');
|
|
|
|
});
|
|
|
|
$("#nginx_exp_addserv").on('selectmenuchange', function () {
|
|
|
|
showExporterVersion('nginx');
|
|
|
|
});
|
|
|
|
$("#apache_exp_addserv").on('selectmenuchange', function () {
|
|
|
|
showExporterVersion('apache');
|
|
|
|
});
|
|
|
|
$("#keepalived_exp_addserv").on('selectmenuchange', function () {
|
|
|
|
showExporterVersion('keepalived');
|
|
|
|
});
|
|
|
|
$("#node_exp_addserv").on('selectmenuchange', function () {
|
|
|
|
showExporterVersion('node');
|
|
|
|
});
|
|
|
|
$("#geoipserv").on('selectmenuchange', function () {
|
|
|
|
if ($('#geoip_service option:selected').val() != '------') {
|
2024-03-17 06:38:00 +00:00
|
|
|
checkGeoipInstallation();
|
|
|
|
}
|
|
|
|
});
|
2024-05-15 12:38:05 +00:00
|
|
|
$("#geoip_service").on('selectmenuchange', function () {
|
|
|
|
if ($('#geoipserv option:selected').val() != '------') {
|
2024-03-17 06:38:00 +00:00
|
|
|
checkGeoipInstallation();
|
|
|
|
}
|
|
|
|
});
|
2024-05-15 12:38:05 +00:00
|
|
|
$("#geoip_install").click(function () {
|
2024-06-16 05:02:08 +00:00
|
|
|
let updating_geoip = 0;
|
2024-03-17 06:38:00 +00:00
|
|
|
if ($('#updating_geoip').is(':checked')) {
|
|
|
|
updating_geoip = '1';
|
|
|
|
}
|
|
|
|
$("#ajax-geoip").html(wait_mess);
|
2024-05-15 12:38:05 +00:00
|
|
|
let service = $('#geoip_service option:selected').val();
|
2024-06-16 05:02:08 +00:00
|
|
|
let jsonData = {
|
|
|
|
"server_ip": $('#geoipserv option:selected').val(),
|
|
|
|
"service": service,
|
|
|
|
"update": updating_geoip
|
|
|
|
}
|
2024-03-17 06:38:00 +00:00
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/geoip",
|
2024-06-16 05:02:08 +00:00
|
|
|
data: JSON.stringify(jsonData),
|
|
|
|
contentType: "application/json; charset=utf-8",
|
2024-03-17 06:38:00 +00:00
|
|
|
type: "POST",
|
|
|
|
success: function (data) {
|
2024-05-15 12:38:05 +00:00
|
|
|
$("#ajax-geoip").html('');
|
2024-06-16 05:02:08 +00:00
|
|
|
if (data.status === 'failed') {
|
|
|
|
toastr.error(data.error);
|
|
|
|
} else {
|
2024-08-04 14:44:11 +00:00
|
|
|
parseAnsibleJsonOutput(data, service + ' GeoIP', '#geoip_service');
|
2024-03-17 06:38:00 +00:00
|
|
|
$("#geoip_service").trigger("selectmenuchange");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
function checkGeoipInstallation() {
|
2024-06-16 05:02:08 +00:00
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/geoip/" + $('#geoip_service option:selected').val() + "/" + $('#geoipserv option:selected').val(),
|
2024-06-16 05:02:08 +00:00
|
|
|
success: function (data) {
|
|
|
|
data = data.replace(/^\s+|\s+$/g, '');
|
|
|
|
if (data.indexOf('No such file or directory') != '-1' || data.indexOf('cannot access') != '-1') {
|
2024-03-17 06:38:00 +00:00
|
|
|
$('#cur_geoip').html('<b style="color: var(--red-color)">GeoIPLite is not installed</b>');
|
|
|
|
$('#geoip_install').show();
|
|
|
|
} else {
|
|
|
|
$('#cur_geoip').html('<b style="color: var(--green-color)">GeoIPLite is installed<b>');
|
|
|
|
$('#geoip_install').hide();
|
|
|
|
}
|
|
|
|
}
|
2024-06-16 05:02:08 +00:00
|
|
|
});
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
|
|
|
function installService(service) {
|
|
|
|
$("#ajax").html('')
|
2024-06-16 05:02:08 +00:00
|
|
|
let syn_flood = 0;
|
|
|
|
let docker = 0;
|
|
|
|
let select_id = '#' + service + 'addserv';
|
2024-03-17 06:38:00 +00:00
|
|
|
if ($('#' + service + '_syn_flood').is(':checked')) {
|
|
|
|
syn_flood = '1';
|
|
|
|
}
|
|
|
|
if ($('#' + service + '_docker').is(':checked')) {
|
|
|
|
docker = '1';
|
|
|
|
}
|
2024-08-02 09:50:02 +00:00
|
|
|
if ($(select_id).val() === '------' || $(select_id).val() === null) {
|
2024-06-16 09:27:47 +00:00
|
|
|
let select_server = translate_div.attr('data-select_server');
|
2024-03-17 06:38:00 +00:00
|
|
|
toastr.warning(select_server);
|
|
|
|
return false
|
|
|
|
}
|
2024-06-16 05:02:08 +00:00
|
|
|
let jsonData = {};
|
2024-08-02 09:50:02 +00:00
|
|
|
let server = {
|
|
|
|
"master": '0',
|
2024-08-28 08:30:05 +00:00
|
|
|
"id": $(select_id + ' option:selected').attr('data-id'),
|
2024-08-02 09:50:02 +00:00
|
|
|
}
|
|
|
|
if (service === 'haproxy') {
|
|
|
|
server['version'] = $('#hapver option:selected').val();
|
|
|
|
}
|
|
|
|
jsonData['servers'] = {}
|
2024-03-17 06:38:00 +00:00
|
|
|
jsonData['services'] = {};
|
|
|
|
jsonData['services'][service] = {};
|
|
|
|
jsonData['syn_flood'] = syn_flood;
|
2024-08-02 09:50:02 +00:00
|
|
|
jsonData['servers'] = [];
|
|
|
|
jsonData['servers'].push(server);
|
2024-03-17 06:38:00 +00:00
|
|
|
jsonData['services'][service]['enabled'] = 1;
|
|
|
|
jsonData['services'][service]['docker'] = docker;
|
|
|
|
$("#ajax").html(wait_mess);
|
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/" + service + "/" + $(select_id).val(),
|
2024-03-17 06:38:00 +00:00
|
|
|
500: function () {
|
|
|
|
showErrorStatus(nice_names[service], $(select_id + ' option:selected').text());
|
|
|
|
},
|
|
|
|
504: function () {
|
|
|
|
showErrorStatus(nice_names[service], $(select_id + ' option:selected').text());
|
|
|
|
},
|
2024-06-16 05:02:08 +00:00
|
|
|
data: JSON.stringify(jsonData),
|
|
|
|
contentType: "application/json; charset=utf-8",
|
2024-03-17 06:38:00 +00:00
|
|
|
type: "POST",
|
|
|
|
success: function (data) {
|
2024-06-16 05:02:08 +00:00
|
|
|
if (data.status === 'failed') {
|
|
|
|
toastr.error(data.error);
|
|
|
|
} else {
|
2024-08-04 14:44:11 +00:00
|
|
|
parseAnsibleJsonOutput(data, nice_names[service], select_id);
|
2024-03-17 06:38:00 +00:00
|
|
|
$(select_id).trigger("selectmenuchange");
|
2024-08-02 09:50:02 +00:00
|
|
|
$("#ajax").empty();
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function installExporter(exporter) {
|
|
|
|
$("#ajaxmon").html('');
|
|
|
|
$("#ajaxmon").html(wait_mess);
|
2024-06-16 05:02:08 +00:00
|
|
|
let exporter_id = '#' + exporter + '_exp_addserv';
|
|
|
|
let ext_prom = 0;
|
|
|
|
let nice_exporter_name = nice_names[exporter] + ' exporter';
|
|
|
|
if ($('#' + exporter + '_ext_prom').is(':checked')) {
|
|
|
|
ext_prom = '1';
|
|
|
|
}
|
|
|
|
let jsonData = {
|
|
|
|
"server_ip": $(exporter_id).val(),
|
|
|
|
"exporter_v": $('#' + exporter + 'expver').val(),
|
|
|
|
"ext_prom": ext_prom,
|
|
|
|
}
|
2024-03-17 06:38:00 +00:00
|
|
|
$("#ajax").html(wait_mess);
|
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/exporter/" + exporter,
|
2024-03-17 06:38:00 +00:00
|
|
|
500: function () {
|
2024-06-16 05:02:08 +00:00
|
|
|
showErrorStatus(nice_exporter_name, $(exporter_id + ' option:selected').text());
|
2024-03-17 06:38:00 +00:00
|
|
|
},
|
|
|
|
504: function () {
|
2024-06-16 05:02:08 +00:00
|
|
|
showErrorStatus(nice_exporter_name, $(exporter_id + ' option:selected').text());
|
2024-03-17 06:38:00 +00:00
|
|
|
},
|
2024-06-16 05:02:08 +00:00
|
|
|
data: JSON.stringify(jsonData),
|
|
|
|
contentType: "application/json; charset=utf-8",
|
2024-03-17 06:38:00 +00:00
|
|
|
type: "POST",
|
|
|
|
success: function (data) {
|
2024-06-16 05:02:08 +00:00
|
|
|
if (data.status === 'failed') {
|
|
|
|
toastr.error(data.error);
|
|
|
|
} else {
|
2024-08-02 18:12:14 +00:00
|
|
|
parseAnsibleJsonOutput(data, nice_names[service], exporter_id);
|
2024-03-17 06:38:00 +00:00
|
|
|
$(exporter_id).trigger("selectmenuchange");
|
2024-08-02 09:50:02 +00:00
|
|
|
$("#ajax").empty();
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function showExporterVersion(exporter) {
|
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/install/exporter/" + exporter + "/version/" + $('#' + exporter + '_exp_addserv option:selected').val(),
|
2024-06-16 05:02:08 +00:00
|
|
|
success: function (data) {
|
|
|
|
data = data.replace(/^\s+|\s+$/g, '');
|
|
|
|
if (data.indexOf('error:') != '-1') {
|
|
|
|
toastr.clear();
|
|
|
|
toastr.error(data);
|
|
|
|
} else if (data == 'no' || data.indexOf('command') != '-1' || data.indexOf('_exporter:') != '-1' || data == '') {
|
|
|
|
$('#cur_' + exporter + '_exp_ver').text(nice_names[exporter] + ' exporter has not been installed');
|
|
|
|
} else {
|
|
|
|
$('#cur_' + exporter + '_exp_ver').text(data);
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
2024-06-16 05:02:08 +00:00
|
|
|
}
|
|
|
|
});
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
|
|
|
function showServiceVersion(service) {
|
2024-08-02 09:50:02 +00:00
|
|
|
let install_div = $('#' + service + '_install');
|
|
|
|
let ver_div = $('#cur_' + service + '_ver');
|
2024-03-17 06:38:00 +00:00
|
|
|
$.ajax({
|
2024-08-02 09:50:02 +00:00
|
|
|
url: "/service/" + service + "/" + $('#' + service + 'addserv option:selected').val() + "/status",
|
|
|
|
statusCode: {
|
|
|
|
404: function (xhr) {
|
|
|
|
ver_div.text(service + ' has not installed');
|
|
|
|
install_div.text('Install');
|
|
|
|
install_div.attr('title', 'Install');
|
|
|
|
}
|
|
|
|
},
|
2024-03-17 06:38:00 +00:00
|
|
|
success: function (data) {
|
2024-09-09 19:02:00 +00:00
|
|
|
if (data.status === 'failed' || !data.Version) {
|
2024-08-02 09:50:02 +00:00
|
|
|
ver_div.text(service + ' has not installed');
|
|
|
|
install_div.text('Install');
|
|
|
|
install_div.attr('title', 'Install');
|
2024-03-17 06:38:00 +00:00
|
|
|
} else {
|
2024-08-02 09:50:02 +00:00
|
|
|
ver_div.text(data.Version);
|
|
|
|
ver_div.css('font-weight', 'bold');
|
|
|
|
install_div.text('Update');
|
|
|
|
install_div.attr('title', 'Update');
|
2024-03-17 06:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function showErrorStatus(service_name, server) {
|
2024-06-16 09:27:47 +00:00
|
|
|
let something_wrong = translate_div.attr('data-something_wrong');
|
2024-03-17 06:38:00 +00:00
|
|
|
toastr.error(something_wrong + ' ' + service_name + ' ' + server);
|
|
|
|
}
|
|
|
|
function parseAnsibleJsonOutput(output, service_name, select_id) {
|
2024-06-16 09:27:47 +00:00
|
|
|
let was_installed = translate_div.attr('data-was_installed');
|
2024-04-04 18:19:32 +00:00
|
|
|
let server_name = '';
|
2024-06-16 05:02:08 +00:00
|
|
|
for (let k in output['ok']) {
|
2024-04-04 18:19:32 +00:00
|
|
|
if (select_id) {
|
|
|
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
|
|
|
}
|
2024-03-17 06:38:00 +00:00
|
|
|
toastr.success(service_name + ' ' + was_installed +' ' + server_name);
|
|
|
|
}
|
2024-06-16 05:02:08 +00:00
|
|
|
for (let k in output['failures']) {
|
2024-04-04 18:19:32 +00:00
|
|
|
if (select_id) {
|
|
|
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
|
|
|
}
|
2024-03-17 06:38:00 +00:00
|
|
|
showErrorStatus(service_name, server_name);
|
|
|
|
}
|
2024-06-16 05:02:08 +00:00
|
|
|
for (let k in output['dark']) {
|
2024-04-04 18:19:32 +00:00
|
|
|
if (select_id) {
|
|
|
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
|
|
|
}
|
2024-03-17 06:38:00 +00:00
|
|
|
showErrorStatus(service_name, server_name);
|
|
|
|
}
|
|
|
|
}
|