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
Aidaho 2024-05-19 20:14:09 +03:00
parent 27494d631a
commit e5106db5ba
4 changed files with 21 additions and 37 deletions

View File

@ -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.
: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.
Defaults to 1.
:param is_service: A flag indicating whether the return path must contain the name of the service. Defaults to 1.
:return: The formatted nice path.
"""

View File

@ -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:
action_for_sending = ''
if server_to == '':
raise Exception('warning: Wrong IP address or name')
def paint_output(generated):
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:
if domain_name == '':
raise Exception('warning: Wrong DNS name')
try:
whois_data = json.loads(str(whois.whois(domain_name)))
except Exception as e:

View File

@ -124,13 +124,25 @@ def nettools_check(check):
domain_name = common.is_ip_or_dns(request.form.get('nettools_whois_name'))
if check == 'icmp':
try:
return nettools_mod.ping_from_server(server_from, server_to, action)
except Exception as e:
return str(e)
elif check == 'tcp':
try:
return nettools_mod.telnet_from_server(server_from, server_to, port_to)
except Exception as e:
return str(e)
elif check == 'dns':
try:
return nettools_mod.nslookup_from_server(server_from, dns_name, record_type)
except Exception as e:
return str(e)
elif check == 'whois':
try:
return jsonify(nettools_mod.whois_check(domain_name))
except Exception as e:
return str(e)
else:
return 'error: Wrong check'

View File

@ -265,10 +265,6 @@ $( function() {
}
$.ajax({
url: "/app/add/show/ip/" + $("#serv").val(),
// data: {
// show_ip: request.term,
// token: $('#token').val()
// },
success: function (data) {
data = data.replace(/\s+/g, ' ');
response(data.split(" "));
@ -289,10 +285,6 @@ $( function() {
}
$.ajax({
url: "/app/add/show/ip/" + $("#serv2").val(),
// data: {
// show_ip: request.term,
// token: $('#token').val()
// },
success: function (data) {
data = data.replace(/\s+/g, ' ');
response(data.split(" "));
@ -313,9 +305,6 @@ $( function() {
}
$.ajax({
url: "/app/runtimeapi/backends/" + $("#serv2").val(),
// data: {
// token: $('#token').val()
// },
success: function (data) {
response(data.split('<br>'));
}
@ -1519,10 +1508,6 @@ function deleteSsl(id) {
function change_select_acceleration(id) {
$.ajax({
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
// data: {
// token: $('#token').val()
// },
// type: "POST",
success: function (data) {
data = data.replace(/\s+/g, ' ');
if (parseFloat(data) < parseFloat('1.8') || data == ' ') {
@ -1536,10 +1521,6 @@ function change_select_acceleration(id) {
function change_select_waf(id) {
$.ajax({
url: "/app/service/haproxy/version/" + $('#serv' + id + ' option:selected').val(),
// data: {
// token: $('#token').val()
// },
// type: "POST",
success: function (data) {
if (parseFloat(data) < parseFloat('1.8')) {
$("#waf" + id).checkboxradio("disable");
@ -2104,10 +2085,6 @@ function make_actions_for_adding_bind(section_id) {
}
$.ajax({
url: "/app/add/show/ip/" + $("#" + serv).val(),
// data: {
// show_ip: request.term,
// token: $('#token').val()
// },
success: function (data) {
data = data.replace(/\s+/g, ' ');
response(data.split(" "));
@ -2159,11 +2136,3 @@ function changePortCheckFromServerPort() {
$($(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;
}