mirror of https://github.com/Aidaho12/haproxy-wi
v7.2.5.0: Add IP address validation and server field check
This commit primarily adds a function that validates IP addresses and a function that checks if a server field is filled in the script.js file. Also, it removes the token from several ajax requests, and improves error handling in server.py. In the users.js file, it updates the server info display functionality.pull/387/head v7.2.6.0
parent
4caa8fdec3
commit
07cdbbfab5
|
@ -131,7 +131,16 @@ def get_system_info(server_ip: str) -> str:
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
os_info = os_info.strip()
|
os_info = os_info.strip()
|
||||||
system_info = json.loads(sys_info_returned)
|
try:
|
||||||
|
system_info = json.loads(sys_info_returned)
|
||||||
|
system_info['id']
|
||||||
|
except Exception:
|
||||||
|
sys_info_returned = json.loads(sys_info_returned)
|
||||||
|
try:
|
||||||
|
sys_info_returned = sys_info_returned[0]
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f'error: Cannot parse output {e}')
|
||||||
|
system_info = sys_info_returned
|
||||||
|
|
||||||
sys_info = {'hostname': system_info['id'], 'family': ''}
|
sys_info = {'hostname': system_info['id'], 'family': ''}
|
||||||
cpu = {'cpu_model': '', 'cpu_core': 0, 'cpu_thread': 0, 'hz': 0}
|
cpu = {'cpu_model': '', 'cpu_core': 0, 'cpu_thread': 0, 'hz': 0}
|
||||||
|
@ -342,7 +351,7 @@ def get_system_info(server_ip: str) -> str:
|
||||||
try:
|
try:
|
||||||
server_sql.insert_system_info(server_id, os_info, sys_info, cpu, ram, network, disks)
|
server_sql.insert_system_info(server_id, os_info, sys_info, cpu, ram, network, disks)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise f'error: Cannot get system info from server: {e}'
|
||||||
|
|
||||||
|
|
||||||
def show_system_info(server_ip: str, server_id: int) -> str:
|
def show_system_info(server_ip: str, server_id: int) -> str:
|
||||||
|
@ -350,7 +359,7 @@ def show_system_info(server_ip: str, server_id: int) -> str:
|
||||||
try:
|
try:
|
||||||
get_system_info(server_ip)
|
get_system_info(server_ip)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f'error: Cannot get system info: {e}'
|
return f'{e}'
|
||||||
try:
|
try:
|
||||||
system_info = server_sql.select_one_system_info(server_id)
|
system_info = server_sql.select_one_system_info(server_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -365,8 +374,10 @@ def update_system_info(server_ip: str, server_id: int) -> str:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
get_system_info(server_ip)
|
get_system_info(server_ip)
|
||||||
|
except Exception as e:
|
||||||
|
return f'{e}'
|
||||||
|
try:
|
||||||
system_info = server_sql.select_one_system_info(server_id)
|
system_info = server_sql.select_one_system_info(server_id)
|
||||||
|
|
||||||
return render_template('ajax/show_system_info.html', system_info=system_info, server_ip=server_ip, server_id=server_id)
|
return render_template('ajax/show_system_info.html', system_info=system_info, server_ip=server_ip, server_id=server_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f'error: Cannot update server info: {e}'
|
return f'error: Cannot update server info: {e}'
|
||||||
|
|
|
@ -1392,9 +1392,8 @@ function updateServerInfo(ip, id) {
|
||||||
if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') {
|
if (data.indexOf('error:') != '-1' || data.indexOf('error_code') != '-1') {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
} else {
|
} else {
|
||||||
$("#server_info-" + id).html(data);
|
$("#server-info").html(data);
|
||||||
$('#server_info-' + id).show();
|
$('#server-info').show();
|
||||||
$('#server_info_link-' + id).attr('title', 'Hide System info');
|
|
||||||
$.getScript(awesome);
|
$.getScript(awesome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,20 @@ function validateEmail(email) {
|
||||||
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
return re.test(email);
|
return re.test(email);
|
||||||
}
|
}
|
||||||
|
function ValidateIPaddress(ipaddress) {
|
||||||
|
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
|
||||||
|
return (true)
|
||||||
|
}
|
||||||
|
return (false)
|
||||||
|
}
|
||||||
|
var select_server = $('#translate').attr('data-select_server');
|
||||||
|
function checkIsServerFiled(select_id, message = select_server) {
|
||||||
|
if ($(select_id).val() == null || $(select_id).val() == '') {
|
||||||
|
toastr.warning(message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
function escapeHtml(unsafe) {
|
function escapeHtml(unsafe) {
|
||||||
return unsafe
|
return unsafe
|
||||||
.replace(/&/g, "&")
|
.replace(/&/g, "&")
|
||||||
|
@ -166,10 +180,6 @@ if(localStorage.getItem('restart')) {
|
||||||
var ip_for_restart = localStorage.getItem('restart');
|
var ip_for_restart = localStorage.getItem('restart');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/service/check-restart/" + ip_for_restart,
|
url: "/app/service/check-restart/" + ip_for_restart,
|
||||||
// data: {
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
// type: "POST",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.indexOf('ok') != '-1') {
|
if (data.indexOf('ok') != '-1') {
|
||||||
var apply_div = $.find("#apply_div");
|
var apply_div = $.find("#apply_div");
|
||||||
|
@ -320,10 +330,6 @@ $( document ).ajaxComplete(function( event, request, settings ) {
|
||||||
function showStats() {
|
function showStats() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/stats/view/" + $("#service").val() + "/" + $("#serv").val(),
|
url: "/app/stats/view/" + $("#service").val() + "/" + $("#serv").val(),
|
||||||
// data: {
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
// type: "POST",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.indexOf('error:') != '-1' && data.indexOf('Internal error:') == '-1') {
|
if (data.indexOf('error:') != '-1' && data.indexOf('Internal error:') == '-1') {
|
||||||
toastr.error(data);
|
toastr.error(data);
|
||||||
|
@ -399,7 +405,6 @@ function showLog() {
|
||||||
hour1: hour1,
|
hour1: hour1,
|
||||||
minute1: minute1,
|
minute1: minute1,
|
||||||
file: file,
|
file: file,
|
||||||
token: $('#token').val()
|
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
|
@ -429,7 +434,6 @@ function showRemoteLogFiles() {
|
||||||
url: "/app/logs/" + service + "/" + serv ,
|
url: "/app/logs/" + service + "/" + serv ,
|
||||||
data: {
|
data: {
|
||||||
serv: $("#serv").val(),
|
serv: $("#serv").val(),
|
||||||
token: $('#token').val()
|
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
|
@ -479,7 +483,6 @@ function showCompare() {
|
||||||
data: {
|
data: {
|
||||||
left: $('#left').val(),
|
left: $('#left').val(),
|
||||||
right: $("#right").val(),
|
right: $("#right").val(),
|
||||||
token: $('#token').val()
|
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
|
@ -681,7 +684,6 @@ function viewLogs() {
|
||||||
minute: minute,
|
minute: minute,
|
||||||
hour1: hour1,
|
hour1: hour1,
|
||||||
minute1: minute1,
|
minute1: minute1,
|
||||||
token: $('#token').val(),
|
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
@ -1334,7 +1336,6 @@ function changeUserPasswordItOwn(d) {
|
||||||
data: {
|
data: {
|
||||||
updatepassowrd: pass,
|
updatepassowrd: pass,
|
||||||
uuid: Cookies.get('uuid'),
|
uuid: Cookies.get('uuid'),
|
||||||
token: $('#token').val()
|
|
||||||
},
|
},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
|
Loading…
Reference in New Issue