From 57db17c86b487c693c39e4bc68a6e2d960b57d9f Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sun, 22 Oct 2023 10:18:39 +0300 Subject: [PATCH] v7.0.1.0 Changelog: https://roxy-wi.org/changelog#7.0.1 --- app/modules/config/runtime.py | 6 +++-- app/routes/runtime/routes.py | 7 +++--- app/templates/ajax/list.html | 2 +- inc/runtimeapi.js | 43 +++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/modules/config/runtime.py b/app/modules/config/runtime.py index fa87b564..259883b3 100644 --- a/app/modules/config/runtime.py +++ b/app/modules/config/runtime.py @@ -317,12 +317,12 @@ def list_of_lists(serv) -> str: return '------' -def show_lists(serv, list_id, list_name) -> None: +def show_lists(serv, list_id, color, list_name) -> None: haproxy_sock_port = sql.get_setting('haproxy_sock_port') cmd = f'echo "show acl #{list_id}"|nc {serv} {haproxy_sock_port}' output, stderr = server_mod.subprocess_execute(cmd) - return render_template('ajax/list.html', list=output, list_id=list_id, list_name=list_name) + return render_template('ajax/list.html', list=output, list_id=list_id, color=color, list_name=list_name) def delete_ip_from_list(serv, ip_id, ip, list_id, list_name) -> str: @@ -377,12 +377,14 @@ def add_ip_to_list(serv, ip, list_id, list_name) -> str: if 'is not a valid IPv4 or IPv6 address' not in output[0]: cmd = f'echo "{ip}" >> {lib_path}/lists/{user_group}/{list_name}' + print(cmd) output, stderr = server_mod.subprocess_execute(cmd) roxywi_common.logging(serv, f'{ip} has been added to list {list_id}', login=1, keep_history=1, service='haproxy') if output: return f'error: {output}' if stderr: return f'error: {stderr}' + return 'ok' def select_session(server_ip: str) -> str: diff --git a/app/routes/runtime/routes.py b/app/routes/runtime/routes.py index 44cd0001..a6886571 100644 --- a/app/routes/runtime/routes.py +++ b/app/routes/runtime/routes.py @@ -222,13 +222,14 @@ def get_lists(server_ip): return f'{e}' -@bp.route('/list///') -def get_list(server_ip, list_id, list_name): +@bp.route('/list////') +def get_list(server_ip, list_id, color, list_name): server_ip = common.is_ip_or_dns(server_ip) list_name = common.checkAjaxInput(list_name) + color = common.checkAjaxInput(color) try: - return runtime.show_lists(server_ip, list_id, list_name) + return runtime.show_lists(server_ip, list_id, color, list_name) except Exception as e: return f'{e}' diff --git a/app/templates/ajax/list.html b/app/templates/ajax/list.html index c787dd24..33577b27 100644 --- a/app/templates/ajax/list.html +++ b/app/templates/ajax/list.html @@ -22,7 +22,7 @@ List name: {{list_name}} - + diff --git a/inc/runtimeapi.js b/inc/runtimeapi.js index 402fd75a..5441fff8 100644 --- a/inc/runtimeapi.js +++ b/inc/runtimeapi.js @@ -250,45 +250,48 @@ function clearTable(table) { } ); } function getTable() { - $.ajax( { + $.ajax({ url: "/app/runtimeapi/table/" + $('#table_serv_select').val() + "/" + $('#table_select').val(), - success: function( data ) { + success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { $("#ajaxtable").html(data); - $( "input[type=submit], button" ).button(); + $("input[type=submit], button").button(); $.getScript("/inc/script.js"); $.getScript("/inc/fontawesome.min.js"); - FontAwesomeConfig = { searchPseudoElements: true, observeMutations: false }; + FontAwesomeConfig = {searchPseudoElements: true, observeMutations: false}; } } - } ); + }); } function getList() { - $.ajax( { - url: "/app/runtimeapi/list/" + $('#list_serv_select').val() + "/" + $('#list_select').val() + "/" + $('#list_select option:selected').text(), + let color = $('#list_select option:selected').text().split('/')[0]; + let list_name = $('#list_select option:selected').text().split('/')[1]; + console.log(list_name) + $.ajax({ + url: "/app/runtimeapi/list/" + $('#list_serv_select').val() + "/" + $('#list_select').val() + "/" + color + "/" + list_name, // data: { // token: $('#token').val() // }, // type: "POST", - success: function( data ) { + success: function (data) { if (data.indexOf('error: ') != '-1') { toastr.error(data); } else { $("#ajaxlist").html(data); - $( "input[type=submit], button" ).button(); + $("input[type=submit], button").button(); $.getScript("/inc/script.js"); $.getScript("/inc/fontawesome.min.js"); - FontAwesomeConfig = { searchPseudoElements: true, observeMutations: false }; + FontAwesomeConfig = {searchPseudoElements: true, observeMutations: false}; } } - } ); + }); } function deleteListIp(id, list_id, ip_id, ip) { toastr.clear(); $(id).parent().parent().css("background-color", "#f2dede !important"); - $.ajax( { + $.ajax({ url: "/app/runtimeapi/list/delete", data: { serv: $('#list_serv_select').val(), @@ -299,7 +302,7 @@ function deleteListIp(id, list_id, ip_id, ip) { token: $('#token').val() }, type: "POST", - success: function( data ) { + success: function (data) { if (data.indexOf('error: ') != '-1') { toastr.error(data); } else { @@ -308,18 +311,18 @@ function deleteListIp(id, list_id, ip_id, ip) { getList(); } } - } ); + }); } function addNewIp() { toastr.clear(); var valid = true; - allFields = $( [] ).add( $('#list_add_ip_new_ip') ); - allFields.removeClass( "ui-state-error" ); - valid = valid && checkLength( $('#list_add_ip_new_ip'), "IP", 1 ); + allFields = $([]).add($('#list_add_ip_new_ip')); + allFields.removeClass("ui-state-error"); + valid = valid && checkLength($('#list_add_ip_new_ip'), "IP", 1); var ip = $('#list_add_ip_new_ip').val(); - if(valid) { + if (valid) { $.ajax({ - url: "/app/runtimeapi/list/add/", + url: "/app/runtimeapi/list/add", data: { serv: $('#list_serv_select').val(), list_ip_for_add: ip, @@ -333,7 +336,7 @@ function addNewIp() { toastr.error(data); } else { getList(); - $( "#list_add_ip_form" ).dialog("destroy" ); + $("#list_add_ip_form").dialog("destroy"); toastr.success('IP ' + ip + ' has been added'); toastr.info('Do not forget upload updated list to the properly server. Restart does not need'); }