mirror of https://github.com/Aidaho12/haproxy-wi
v7.2.2.0: Refactor JavaScript code and adjust paths
This commit updates variable declarations from 'var' to 'let' in 'install.js' for better scope control. It additionally includes error-handling for undefined 'select_id' in 'parseAnsibleJsonOutput' function. The 'waf.js' file is moved to the 'app/static/js' directory and paths are updated accordingly in both 'waf.js' and 'waf.html'. The success handler in 'waf.js' is also updated to use 'parseAnsibleJsonOutput'.pull/377/head
parent
093b1b890e
commit
fd0f0f194b
|
@ -293,18 +293,24 @@ function showErrorStatus(service_name, server) {
|
||||||
}
|
}
|
||||||
function parseAnsibleJsonOutput(output, service_name, select_id) {
|
function parseAnsibleJsonOutput(output, service_name, select_id) {
|
||||||
output = JSON.parse(JSON.stringify(output));
|
output = JSON.parse(JSON.stringify(output));
|
||||||
var check_apache_log = $('#translate').attr('data-check_apache_log');
|
let was_installed = $('#translate').attr('data-was_installed');
|
||||||
var was_installed = $('#translate').attr('data-was_installed');
|
let server_name = '';
|
||||||
for (var k in output['ok']) {
|
for (var k in output['ok']) {
|
||||||
var server_name = $(select_id + ' option[value="'+k+'"]').text();
|
if (select_id) {
|
||||||
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
||||||
|
}
|
||||||
toastr.success(service_name + ' ' + was_installed +' ' + server_name);
|
toastr.success(service_name + ' ' + was_installed +' ' + server_name);
|
||||||
}
|
}
|
||||||
for (var k in output['failures']) {
|
for (var k in output['failures']) {
|
||||||
var server_name = $(select_id + ' option[value="'+k+'"]').text();
|
if (select_id) {
|
||||||
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
||||||
|
}
|
||||||
showErrorStatus(service_name, server_name);
|
showErrorStatus(service_name, server_name);
|
||||||
}
|
}
|
||||||
for (var k in output['dark']) {
|
for (var k in output['dark']) {
|
||||||
var server_name = $(select_id + ' option[value="'+k+'"]').text();
|
if (select_id) {
|
||||||
|
server_name = $(select_id + ' option[value="'+k+'"]').text();
|
||||||
|
}
|
||||||
showErrorStatus(service_name, server_name);
|
showErrorStatus(service_name, server_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var awesome = "/inc/fontawesome.min.js"
|
var awesome = "/inc/fontawesome.min.js"
|
||||||
var waf = "/inc/waf.js"
|
var waf = "/static/js/waf.js"
|
||||||
var overview = "/inc/overview.js"
|
var overview = "/inc/overview.js"
|
||||||
function showOverviewWaf(serv, hostnamea) {
|
function showOverviewWaf(serv, hostnamea) {
|
||||||
var service = cur_url[1];
|
var service = cur_url[1];
|
||||||
|
@ -23,7 +23,7 @@ function showOverviewWafCallBack(serv, hostnamea) {
|
||||||
// },
|
// },
|
||||||
// type: "POST",
|
// type: "POST",
|
||||||
beforeSend: function () {
|
beforeSend: function () {
|
||||||
$("#" + hostnamea).html('<img class="loading_small" src="/app/static/images/loading.gif" />');
|
$("#" + hostnamea).html('<img class="loading_small" src="/static/images/loading.gif" />');
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
$("#" + hostnamea).empty();
|
$("#" + hostnamea).empty();
|
||||||
|
@ -72,9 +72,9 @@ function installWaf(ip1) {
|
||||||
} else if (data.indexOf('Info') != '-1') {
|
} else if (data.indexOf('Info') != '-1') {
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
toastr.info(data);
|
toastr.info(data);
|
||||||
} else if (data.indexOf('success') != '-1') {
|
} else {
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
toastr.success('WAF service has been installed');
|
parseAnsibleJsonOutput(data, `${service} WAF`, false);
|
||||||
showOverviewWaf(ip, hostnamea);
|
showOverviewWaf(ip, hostnamea);
|
||||||
$("#ajax").html('');
|
$("#ajax").html('');
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
{% block title %}{{title}}{% endblock %}
|
{% block title %}{{title}}{% endblock %}
|
||||||
{% block h2 %}{{title}}{% endblock %}
|
{% block h2 %}{{title}}{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<script src="/inc/waf.js"></script>
|
<script src="/app/static/js/waf.js"></script>
|
||||||
{% if manage_rules == '1' %}
|
{% if manage_rules == '1' %}
|
||||||
{% from 'include/input_macros.html' import input, checkbox %}
|
{% from 'include/input_macros.html' import input, checkbox %}
|
||||||
<table class="overview" id="waf_rules">
|
<table class="overview" id="waf_rules">
|
||||||
|
|
Loading…
Reference in New Issue