mirror of https://github.com/Aidaho12/haproxy-wi
parent
bcdd41bcd5
commit
57db17c86b
|
@ -317,12 +317,12 @@ def list_of_lists(serv) -> str:
|
||||||
return '------'
|
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')
|
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
|
||||||
cmd = f'echo "show acl #{list_id}"|nc {serv} {haproxy_sock_port}'
|
cmd = f'echo "show acl #{list_id}"|nc {serv} {haproxy_sock_port}'
|
||||||
output, stderr = server_mod.subprocess_execute(cmd)
|
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:
|
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]:
|
if 'is not a valid IPv4 or IPv6 address' not in output[0]:
|
||||||
cmd = f'echo "{ip}" >> {lib_path}/lists/{user_group}/{list_name}'
|
cmd = f'echo "{ip}" >> {lib_path}/lists/{user_group}/{list_name}'
|
||||||
|
print(cmd)
|
||||||
output, stderr = server_mod.subprocess_execute(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')
|
roxywi_common.logging(serv, f'{ip} has been added to list {list_id}', login=1, keep_history=1, service='haproxy')
|
||||||
if output:
|
if output:
|
||||||
return f'error: {output}'
|
return f'error: {output}'
|
||||||
if stderr:
|
if stderr:
|
||||||
return f'error: {stderr}'
|
return f'error: {stderr}'
|
||||||
|
return 'ok'
|
||||||
|
|
||||||
|
|
||||||
def select_session(server_ip: str) -> str:
|
def select_session(server_ip: str) -> str:
|
||||||
|
|
|
@ -222,13 +222,14 @@ def get_lists(server_ip):
|
||||||
return f'{e}'
|
return f'{e}'
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/list/<server_ip>/<int:list_id>/<list_name>')
|
@bp.route('/list/<server_ip>/<int:list_id>/<color>/<list_name>')
|
||||||
def get_list(server_ip, list_id, list_name):
|
def get_list(server_ip, list_id, color, list_name):
|
||||||
server_ip = common.is_ip_or_dns(server_ip)
|
server_ip = common.is_ip_or_dns(server_ip)
|
||||||
list_name = common.checkAjaxInput(list_name)
|
list_name = common.checkAjaxInput(list_name)
|
||||||
|
color = common.checkAjaxInput(color)
|
||||||
|
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
return f'{e}'
|
return f'{e}'
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
List name: {{list_name}}
|
List name: {{list_name}}
|
||||||
</td>
|
</td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -250,45 +250,48 @@ function clearTable(table) {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
function getTable() {
|
function getTable() {
|
||||||
$.ajax( {
|
$.ajax({
|
||||||
url: "/app/runtimeapi/table/" + $('#table_serv_select').val() + "/" + $('#table_select').val(),
|
url: "/app/runtimeapi/table/" + $('#table_serv_select').val() + "/" + $('#table_select').val(),
|
||||||
success: function( data ) {
|
success: function (data) {
|
||||||
if (data.indexOf('error:') != '-1') {
|
if (data.indexOf('error:') != '-1') {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
} else {
|
} else {
|
||||||
$("#ajaxtable").html(data);
|
$("#ajaxtable").html(data);
|
||||||
$( "input[type=submit], button" ).button();
|
$("input[type=submit], button").button();
|
||||||
$.getScript("/inc/script.js");
|
$.getScript("/inc/script.js");
|
||||||
$.getScript("/inc/fontawesome.min.js");
|
$.getScript("/inc/fontawesome.min.js");
|
||||||
FontAwesomeConfig = { searchPseudoElements: true, observeMutations: false };
|
FontAwesomeConfig = {searchPseudoElements: true, observeMutations: false};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
function getList() {
|
function getList() {
|
||||||
$.ajax( {
|
let color = $('#list_select option:selected').text().split('/')[0];
|
||||||
url: "/app/runtimeapi/list/" + $('#list_serv_select').val() + "/" + $('#list_select').val() + "/" + $('#list_select option:selected').text(),
|
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: {
|
// data: {
|
||||||
// token: $('#token').val()
|
// token: $('#token').val()
|
||||||
// },
|
// },
|
||||||
// type: "POST",
|
// type: "POST",
|
||||||
success: function( data ) {
|
success: function (data) {
|
||||||
if (data.indexOf('error: ') != '-1') {
|
if (data.indexOf('error: ') != '-1') {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
} else {
|
} else {
|
||||||
$("#ajaxlist").html(data);
|
$("#ajaxlist").html(data);
|
||||||
$( "input[type=submit], button" ).button();
|
$("input[type=submit], button").button();
|
||||||
$.getScript("/inc/script.js");
|
$.getScript("/inc/script.js");
|
||||||
$.getScript("/inc/fontawesome.min.js");
|
$.getScript("/inc/fontawesome.min.js");
|
||||||
FontAwesomeConfig = { searchPseudoElements: true, observeMutations: false };
|
FontAwesomeConfig = {searchPseudoElements: true, observeMutations: false};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
function deleteListIp(id, list_id, ip_id, ip) {
|
function deleteListIp(id, list_id, ip_id, ip) {
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
$(id).parent().parent().css("background-color", "#f2dede !important");
|
$(id).parent().parent().css("background-color", "#f2dede !important");
|
||||||
$.ajax( {
|
$.ajax({
|
||||||
url: "/app/runtimeapi/list/delete",
|
url: "/app/runtimeapi/list/delete",
|
||||||
data: {
|
data: {
|
||||||
serv: $('#list_serv_select').val(),
|
serv: $('#list_serv_select').val(),
|
||||||
|
@ -299,7 +302,7 @@ function deleteListIp(id, list_id, ip_id, ip) {
|
||||||
token: $('#token').val()
|
token: $('#token').val()
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function (data) {
|
||||||
if (data.indexOf('error: ') != '-1') {
|
if (data.indexOf('error: ') != '-1') {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
} else {
|
} else {
|
||||||
|
@ -308,18 +311,18 @@ function deleteListIp(id, list_id, ip_id, ip) {
|
||||||
getList();
|
getList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
function addNewIp() {
|
function addNewIp() {
|
||||||
toastr.clear();
|
toastr.clear();
|
||||||
var valid = true;
|
var valid = true;
|
||||||
allFields = $( [] ).add( $('#list_add_ip_new_ip') );
|
allFields = $([]).add($('#list_add_ip_new_ip'));
|
||||||
allFields.removeClass( "ui-state-error" );
|
allFields.removeClass("ui-state-error");
|
||||||
valid = valid && checkLength( $('#list_add_ip_new_ip'), "IP", 1 );
|
valid = valid && checkLength($('#list_add_ip_new_ip'), "IP", 1);
|
||||||
var ip = $('#list_add_ip_new_ip').val();
|
var ip = $('#list_add_ip_new_ip').val();
|
||||||
if(valid) {
|
if (valid) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/runtimeapi/list/add/",
|
url: "/app/runtimeapi/list/add",
|
||||||
data: {
|
data: {
|
||||||
serv: $('#list_serv_select').val(),
|
serv: $('#list_serv_select').val(),
|
||||||
list_ip_for_add: ip,
|
list_ip_for_add: ip,
|
||||||
|
@ -333,7 +336,7 @@ function addNewIp() {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
} else {
|
} else {
|
||||||
getList();
|
getList();
|
||||||
$( "#list_add_ip_form" ).dialog("destroy" );
|
$("#list_add_ip_form").dialog("destroy");
|
||||||
toastr.success('IP ' + ip + ' has been added');
|
toastr.success('IP ' + ip + ' has been added');
|
||||||
toastr.info('Do not forget upload updated list to the properly server. Restart does not need');
|
toastr.info('Do not forget upload updated list to the properly server. Restart does not need');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue