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
Aidaho 2024-04-04 21:19:32 +03:00
parent 093b1b890e
commit fd0f0f194b
3 changed files with 16 additions and 10 deletions

View File

@ -293,18 +293,24 @@ function showErrorStatus(service_name, server) {
}
function parseAnsibleJsonOutput(output, service_name, select_id) {
output = JSON.parse(JSON.stringify(output));
var check_apache_log = $('#translate').attr('data-check_apache_log');
var was_installed = $('#translate').attr('data-was_installed');
let was_installed = $('#translate').attr('data-was_installed');
let server_name = '';
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);
}
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);
}
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);
}
}

View File

@ -1,5 +1,5 @@
var awesome = "/inc/fontawesome.min.js"
var waf = "/inc/waf.js"
var waf = "/static/js/waf.js"
var overview = "/inc/overview.js"
function showOverviewWaf(serv, hostnamea) {
var service = cur_url[1];
@ -23,7 +23,7 @@ function showOverviewWafCallBack(serv, hostnamea) {
// },
// type: "POST",
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) {
$("#" + hostnamea).empty();
@ -72,9 +72,9 @@ function installWaf(ip1) {
} else if (data.indexOf('Info') != '-1') {
toastr.clear();
toastr.info(data);
} else if (data.indexOf('success') != '-1') {
} else {
toastr.clear();
toastr.success('WAF service has been installed');
parseAnsibleJsonOutput(data, `${service} WAF`, false);
showOverviewWaf(ip, hostnamea);
$("#ajax").html('');
}

View File

@ -2,7 +2,7 @@
{% block title %}{{title}}{% endblock %}
{% block h2 %}{{title}}{% endblock %}
{% block content %}
<script src="/inc/waf.js"></script>
<script src="/app/static/js/waf.js"></script>
{% if manage_rules == '1' %}
{% from 'include/input_macros.html' import input, checkbox %}
<table class="overview" id="waf_rules">