mirror of https://github.com/Aidaho12/haproxy-wi
v7.2.5.0: Add exception handling and remove commented code
This commit applies exception handling for the network operations methods and removes unused/commented-out code. The added exception handling checks for incorrect input to nettools methods and raises explicit exceptions with descriptive messages. This dramatically simplifies the debugging process, providing better visibility into runtime errors.pull/384/head
parent
27494d631a
commit
e5106db5ba
|
@ -136,8 +136,7 @@ def return_nice_path(return_path: str, is_service=1) -> str:
|
||||||
Formats the given return path to make it a nice path.
|
Formats the given return path to make it a nice path.
|
||||||
|
|
||||||
:param return_path: The return path that needs to be formatted.
|
:param return_path: The return path that needs to be formatted.
|
||||||
:param is_service: A flag indicating whether the return path must contain the name of the service.
|
:param is_service: A flag indicating whether the return path must contain the name of the service. Defaults to 1.
|
||||||
Defaults to 1.
|
|
||||||
:return: The formatted nice path.
|
:return: The formatted nice path.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -9,6 +9,8 @@ import app.modules.server.server as server_mod
|
||||||
|
|
||||||
def ping_from_server(server_from: str, server_to: str, action: str) -> Response:
|
def ping_from_server(server_from: str, server_to: str, action: str) -> Response:
|
||||||
action_for_sending = ''
|
action_for_sending = ''
|
||||||
|
if server_to == '':
|
||||||
|
raise Exception('warning: Wrong IP address or name')
|
||||||
|
|
||||||
def paint_output(generated):
|
def paint_output(generated):
|
||||||
yield '<div class="ping_pre">'
|
yield '<div class="ping_pre">'
|
||||||
|
@ -112,6 +114,8 @@ def nslookup_from_server(server_from: str, dns_name: str, record_type: str) -> s
|
||||||
|
|
||||||
|
|
||||||
def whois_check(domain_name: str) -> str:
|
def whois_check(domain_name: str) -> str:
|
||||||
|
if domain_name == '':
|
||||||
|
raise Exception('warning: Wrong DNS name')
|
||||||
try:
|
try:
|
||||||
whois_data = json.loads(str(whois.whois(domain_name)))
|
whois_data = json.loads(str(whois.whois(domain_name)))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -124,13 +124,25 @@ def nettools_check(check):
|
||||||
domain_name = common.is_ip_or_dns(request.form.get('nettools_whois_name'))
|
domain_name = common.is_ip_or_dns(request.form.get('nettools_whois_name'))
|
||||||
|
|
||||||
if check == 'icmp':
|
if check == 'icmp':
|
||||||
return nettools_mod.ping_from_server(server_from, server_to, action)
|
try:
|
||||||
|
return nettools_mod.ping_from_server(server_from, server_to, action)
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
elif check == 'tcp':
|
elif check == 'tcp':
|
||||||
return nettools_mod.telnet_from_server(server_from, server_to, port_to)
|
try:
|
||||||
|
return nettools_mod.telnet_from_server(server_from, server_to, port_to)
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
elif check == 'dns':
|
elif check == 'dns':
|
||||||
return nettools_mod.nslookup_from_server(server_from, dns_name, record_type)
|
try:
|
||||||
|
return nettools_mod.nslookup_from_server(server_from, dns_name, record_type)
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
elif check == 'whois':
|
elif check == 'whois':
|
||||||
return jsonify(nettools_mod.whois_check(domain_name))
|
try:
|
||||||
|
return jsonify(nettools_mod.whois_check(domain_name))
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
else:
|
else:
|
||||||
return 'error: Wrong check'
|
return 'error: Wrong check'
|
||||||
|
|
||||||
|
|
|
@ -265,10 +265,6 @@ $( function() {
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/add/show/ip/" + $("#serv").val(),
|
url: "/app/add/show/ip/" + $("#serv").val(),
|
||||||
// data: {
|
|
||||||
// show_ip: request.term,
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
data = data.replace(/\s+/g, ' ');
|
||||||
response(data.split(" "));
|
response(data.split(" "));
|
||||||
|
@ -289,10 +285,6 @@ $( function() {
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/add/show/ip/" + $("#serv2").val(),
|
url: "/app/add/show/ip/" + $("#serv2").val(),
|
||||||
// data: {
|
|
||||||
// show_ip: request.term,
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
data = data.replace(/\s+/g, ' ');
|
||||||
response(data.split(" "));
|
response(data.split(" "));
|
||||||
|
@ -313,9 +305,6 @@ $( function() {
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/runtimeapi/backends/" + $("#serv2").val(),
|
url: "/app/runtimeapi/backends/" + $("#serv2").val(),
|
||||||
// data: {
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
response(data.split('<br>'));
|
response(data.split('<br>'));
|
||||||
}
|
}
|
||||||
|
@ -1519,10 +1508,6 @@ function deleteSsl(id) {
|
||||||
function change_select_acceleration(id) {
|
function change_select_acceleration(id) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
|
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
|
||||||
// data: {
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
// type: "POST",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
data = data.replace(/\s+/g, ' ');
|
||||||
if (parseFloat(data) < parseFloat('1.8') || data == ' ') {
|
if (parseFloat(data) < parseFloat('1.8') || data == ' ') {
|
||||||
|
@ -1536,10 +1521,6 @@ function change_select_acceleration(id) {
|
||||||
function change_select_waf(id) {
|
function change_select_waf(id) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
|
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
|
||||||
// data: {
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
// type: "POST",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (parseFloat(data) < parseFloat('1.8')) {
|
if (parseFloat(data) < parseFloat('1.8')) {
|
||||||
$("#waf" + id).checkboxradio("disable");
|
$("#waf" + id).checkboxradio("disable");
|
||||||
|
@ -2104,10 +2085,6 @@ function make_actions_for_adding_bind(section_id) {
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/app/add/show/ip/" + $("#" + serv).val(),
|
url: "/app/add/show/ip/" + $("#" + serv).val(),
|
||||||
// data: {
|
|
||||||
// show_ip: request.term,
|
|
||||||
// token: $('#token').val()
|
|
||||||
// },
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data = data.replace(/\s+/g, ' ');
|
data = data.replace(/\s+/g, ' ');
|
||||||
response(data.split(" "));
|
response(data.split(" "));
|
||||||
|
@ -2159,11 +2136,3 @@ function changePortCheckFromServerPort() {
|
||||||
$($(this)).next().val(iNum);
|
$($(this)).next().val(iNum);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue