This commit is contained in:
alejandro.campos@artica.es 2023-10-10 09:10:42 +02:00
parent c059f83420
commit 6a58a2e86f

View File

@ -318,7 +318,6 @@ function quickShellSettings()
ui_require_css_file('discovery'); ui_require_css_file('discovery');
// Gotty settings. Internal communication (WS). // Gotty settings. Internal communication (WS).
if (isset($config['gotty_ssh_enabled']) === false) { if (isset($config['gotty_ssh_enabled']) === false) {
config_update_value('gotty_ssh_enabled', 1); config_update_value('gotty_ssh_enabled', 1);
} }
@ -553,31 +552,41 @@ function quickShellSettings()
echo '<script>'; echo '<script>';
echo 'var server_addr = "'.$_SERVER['SERVER_ADDR'].'";'; echo 'var server_addr = "'.$_SERVER['SERVER_ADDR'].'";';
echo "function checkAddressReachability(method, callback) { echo "
var connectionURL = (method == 'ssh') ? '".buildConnectionURL('ssh')."' : '".buildConnectionURL('telnet')."'; function isValidIP(ip) {
// Regular expression for IPv4 address pattern
const ipv4Pattern = /^(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]?)$/;
var xhr = new XMLHttpRequest(); return ipv4Pattern.test(ip);
console.log(connectionURL); }
function checkAddressReachability(method, callback) {
var connectionURL = (method == 'ssh') ? '".buildConnectionURL('ssh')."' : '".buildConnectionURL('telnet')."';
// Initialize the request with a 'HEAD' method, which is faster for checking if (isValidIP('".$gotty_addr."') === false) {
xhr.open('HEAD', connectionURL, false); // Synchronous request
try {
// Send the request
xhr.send();
// Check if the request was successful (status code 200)
if (xhr.status === 200) {
callback(true);
} else {
callback(false); callback(false);
} }
} catch (error) {
// An error occurred. var xhr = new XMLHttpRequest();
callback(false);
} // Initialize the request with a 'HEAD' method, which is faster for checking
}"; xhr.open('HEAD', connectionURL, false); // Synchronous request
try {
// Send the request
xhr.send();
// Check if the request was successful (status code 200)
if (xhr.status === 200) {
callback(true);
} else {
callback(false);
}
} catch (error) {
// An error occurred.
callback(false);
}
}";
$handle_test_telnet = "var handleTestTelnet = function (event) { $handle_test_telnet = "var handleTestTelnet = function (event) {
var gotty_addr = $('input#text-gotty_addr').val(); var gotty_addr = $('input#text-gotty_addr').val();