Changelog: https://roxy-wi.org/changelog#7.0.1
pull/366/head
Aidaho 2023-10-22 10:18:39 +03:00
parent bcdd41bcd5
commit 57db17c86b
4 changed files with 32 additions and 26 deletions

View File

@ -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:

View File

@ -222,13 +222,14 @@ def get_lists(server_ip):
return f'{e}'
@bp.route('/list/<server_ip>/<int:list_id>/<list_name>')
def get_list(server_ip, list_id, list_name):
@bp.route('/list/<server_ip>/<int:list_id>/<color>/<list_name>')
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}'

View File

@ -22,7 +22,7 @@
List name: {{list_name}}
</td>
<td>
<button title="Add IP in this list" id="list_add_ip" data-list-id="{{list_id}}" data-list-name="{{list_name}}">Add IP</button>
<button title="Add IP in this list" id="list_add_ip" data-list-id="{{list_id}}" data-list-name="{{color}}/{{list_name}}">Add IP</button>
</td>
</tr>
</table>

View File

@ -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');
}