mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
revert changes
This commit is contained in:
parent
10d94daf30
commit
295654d26b
@ -79,6 +79,8 @@ function quickShell()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$method = get_parameter('method', null);
|
||||||
|
|
||||||
$setup_anchor = html_print_anchor(
|
$setup_anchor = html_print_anchor(
|
||||||
[
|
[
|
||||||
'href' => 'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=quickshell',
|
'href' => 'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=quickshell',
|
||||||
@ -87,15 +89,6 @@ function quickShell()
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$fetch_result = get_parameter('fetch-result', null);
|
|
||||||
|
|
||||||
if (isset($fetch_result) === true && $fetch_result === '0') {
|
|
||||||
ui_print_error_message(__('Connection error. Please check your settings at %s', $setup_anchor));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$method = get_parameter('method', null);
|
|
||||||
|
|
||||||
if ((bool) $config['gotty_ssh_enabled'] === false
|
if ((bool) $config['gotty_ssh_enabled'] === false
|
||||||
&& (bool) $config['gotty_telnet_enabled'] === false
|
&& (bool) $config['gotty_telnet_enabled'] === false
|
||||||
) {
|
) {
|
||||||
@ -125,9 +118,6 @@ function quickShell()
|
|||||||
$connectionURL = buildConnectionURL($method);
|
$connectionURL = buildConnectionURL($method);
|
||||||
$gotty_addr = $connectionURL.$args;
|
$gotty_addr = $connectionURL.$args;
|
||||||
|
|
||||||
$connectionURLSSH = buildConnectionURL('ssh');
|
|
||||||
$connectionURLTelnet = buildConnectionURL('telnet');
|
|
||||||
|
|
||||||
// Username. Retrieve from form.
|
// Username. Retrieve from form.
|
||||||
if (empty($username) === true) {
|
if (empty($username) === true) {
|
||||||
// No username provided, ask for it.
|
// No username provided, ask for it.
|
||||||
@ -170,7 +160,6 @@ function quickShell()
|
|||||||
'label' => __('Username'),
|
'label' => __('Username'),
|
||||||
'arguments' => [
|
'arguments' => [
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'id' => 'username',
|
|
||||||
'name' => 'username',
|
'name' => 'username',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
],
|
],
|
||||||
@ -202,7 +191,7 @@ function quickShell()
|
|||||||
html_print_action_buttons(
|
html_print_action_buttons(
|
||||||
html_print_submit_button(
|
html_print_submit_button(
|
||||||
__('Connect'),
|
__('Connect'),
|
||||||
'submit-btn',
|
'submit',
|
||||||
false,
|
false,
|
||||||
[
|
[
|
||||||
'icon' => 'cog',
|
'icon' => 'cog',
|
||||||
@ -211,57 +200,30 @@ function quickShell()
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
echo "<script>
|
|
||||||
$(document).ready(function() {
|
|
||||||
// Intercept form submission.
|
|
||||||
var connectForm = document.getElementById('connect_form');
|
|
||||||
connectForm.addEventListener('submit', function (event) {
|
|
||||||
var username = $('#text-username').val();
|
|
||||||
var port = $('#text-port').val();
|
|
||||||
var method = $('#method').val();
|
|
||||||
|
|
||||||
var connectionURL = '';
|
|
||||||
if (method == 'ssh') {
|
|
||||||
connectionURL = '".$connectionURLSSH."'+'&arg=".$agent_address."&arg='+port+'&arg='+username;
|
|
||||||
} else if (method == 'telnet') {
|
|
||||||
connectionURL = '&arg=".$agent_address."&arg='+port;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent the default form submission behavior.
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
|
|
||||||
var input = document.createElement('input');
|
|
||||||
input.type = 'hidden';
|
|
||||||
input.name = 'fetch-result';
|
|
||||||
|
|
||||||
// Handle response.
|
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
input.value = (xhr.status === 200) ? 1 : 0;
|
|
||||||
connectForm.appendChild(input);
|
|
||||||
connectForm.submit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Open and send the request.
|
|
||||||
try {
|
|
||||||
xhr.open('GET', connectionURL, true);
|
|
||||||
} catch (error) {
|
|
||||||
input.value = 0;
|
|
||||||
connectForm.appendChild(input);
|
|
||||||
connectForm.submit();
|
|
||||||
}
|
|
||||||
xhr.send();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>";
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check gotty connection before trying to load iframe.
|
||||||
|
$ch = curl_init($gotty_addr);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
// Maximum time for the entire request.
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
||||||
|
// Maximum time to establish a connection.
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||||
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||||
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($responseCode !== 200) {
|
||||||
|
ui_print_error_message(__('Connection error. Please check your settings at %s', $setup_anchor));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<style>#terminal {
|
<style>#terminal {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -318,6 +280,7 @@ 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);
|
||||||
}
|
}
|
||||||
@ -548,151 +511,41 @@ function quickShellSettings()
|
|||||||
html_print_input_hidden('update_config', 1);
|
html_print_input_hidden('update_config', 1);
|
||||||
|
|
||||||
echo '</fieldset>';
|
echo '</fieldset>';
|
||||||
|
}
|
||||||
|
|
||||||
echo '<script>';
|
|
||||||
|
|
||||||
echo 'var server_addr = "'.$_SERVER['SERVER_ADDR'].'";';
|
if (is_ajax() === true) {
|
||||||
echo "
|
$method = (string) get_parameter('method', '');
|
||||||
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]?)$/;
|
|
||||||
|
|
||||||
return ipv4Pattern.test(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkAddressReachability(method, callback) {
|
if (empty($method) === false) {
|
||||||
var connectionURL = (method == 'ssh') ? '".buildConnectionURL('ssh')."' : '".buildConnectionURL('telnet')."';
|
$address = buildConnectionURL($method);
|
||||||
|
|
||||||
if (isValidIP('".$gotty_addr."') === false) {
|
$ch = curl_init($address);
|
||||||
callback(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
// Initialize the request with a 'HEAD' method, which is faster for checking
|
// Maximum time for the entire request.
|
||||||
xhr.open('HEAD', connectionURL, false); // Synchronous request
|
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
||||||
|
|
||||||
try {
|
// Maximum time to establish a connection.
|
||||||
// Send the request
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
|
||||||
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) {
|
curl_exec($ch);
|
||||||
var gotty_addr = $('input#text-gotty_addr').val();
|
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
var gotty_port = $('input#text-gotty_port').val();
|
curl_close($ch);
|
||||||
var gotty_telnet_use_ssl = $('input#checkbox-gotty_telnet_use_ssl').is(':checked');
|
|
||||||
|
if ($response_code === 200) {
|
||||||
if (gotty_addr === '') {
|
$result = ['status' => 'success'];
|
||||||
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_port;
|
|
||||||
} else {
|
} else {
|
||||||
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + gotty_addr + ':' + gotty_port;
|
$result = ['status' => 'error'];
|
||||||
}
|
}
|
||||||
|
|
||||||
var showLoadingImage = function () {
|
|
||||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var showSuccessImage = function () {
|
|
||||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon tick secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var showFailureImage = function () {
|
|
||||||
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon fail secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var hideMessage = function () {
|
|
||||||
$('span#test-gotty-message-telnet').hide();
|
|
||||||
}
|
|
||||||
var showMessage = function () {
|
|
||||||
$('span#test-gotty-message-telnet').show();
|
|
||||||
}
|
|
||||||
var changeTestMessage = function (message) {
|
|
||||||
$('span#test-gotty-message-telnet').text(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMessage = '".__('Unable to connect.')."';
|
|
||||||
|
|
||||||
hideMessage();
|
|
||||||
showLoadingImage();
|
|
||||||
|
|
||||||
checkAddressReachability('telnet', function(isReachable) {
|
|
||||||
if (isReachable) {
|
|
||||||
showSuccessImage();
|
|
||||||
hideMessage();
|
|
||||||
} else {
|
|
||||||
showFailureImage();
|
|
||||||
changeTestMessage(errorMessage);
|
|
||||||
showMessage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
};";
|
|
||||||
|
|
||||||
$handle_test_ssh = "var handleTestSSH = function (event) {
|
echo json_encode($result);
|
||||||
var gotty_addr = $('input#text-gotty_addr').val();
|
return;
|
||||||
var gotty_port = $('input#text-gotty_port').val();
|
}
|
||||||
var gotty_ssh_use_ssl = $('input#checkbox-gotty_ssh_use_ssl').is(':checked');
|
|
||||||
|
|
||||||
if (gotty_addr === '') {
|
|
||||||
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_port;
|
|
||||||
} else {
|
|
||||||
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + gotty_addr + ':' + gotty_port;
|
|
||||||
}
|
|
||||||
|
|
||||||
var showLoadingImage = function () {
|
|
||||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var showSuccessImage = function () {
|
|
||||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon tick secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var showFailureImage = function () {
|
|
||||||
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon fail secondary mini');
|
|
||||||
}
|
|
||||||
|
|
||||||
var hideMessage = function () {
|
|
||||||
$('span#test-gotty-message-ssh').hide();
|
|
||||||
}
|
|
||||||
var showMessage = function () {
|
|
||||||
$('span#test-gotty-message-ssh').show();
|
|
||||||
}
|
|
||||||
var changeTestMessage = function (message) {
|
|
||||||
$('span#test-gotty-message-ssh').text(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
var errorMessage = '".__('Unable to connect.')."';
|
|
||||||
|
|
||||||
|
|
||||||
hideMessage();
|
|
||||||
showLoadingImage();
|
|
||||||
|
|
||||||
checkAddressReachability('ssh', function(isReachable) {
|
|
||||||
if (isReachable) {
|
|
||||||
showSuccessImage();
|
|
||||||
hideMessage();
|
|
||||||
} else {
|
|
||||||
showFailureImage();
|
|
||||||
changeTestMessage(errorMessage);
|
|
||||||
showMessage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};";
|
|
||||||
|
|
||||||
echo $handle_test_ssh;
|
$result = ['status' => 'error'];
|
||||||
echo $handle_test_telnet;
|
return;
|
||||||
echo '</script>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This extension is useful only if the agent has associated IP.
|
// This extension is useful only if the agent has associated IP.
|
||||||
@ -720,4 +573,136 @@ if (empty($agent_id) === false
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo '<script>';
|
||||||
|
|
||||||
|
echo 'var server_addr = "'.$_SERVER['SERVER_ADDR'].'";';
|
||||||
|
echo "function checkAddressReachability(method, callback) {
|
||||||
|
$.ajax({
|
||||||
|
url: 'ajax.php',
|
||||||
|
data: {
|
||||||
|
page: 'extensions/quick_shell',
|
||||||
|
method
|
||||||
|
},
|
||||||
|
type: 'GET',
|
||||||
|
async: false,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (data) {
|
||||||
|
if (data.status === 'success') {
|
||||||
|
callback(true);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}";
|
||||||
|
|
||||||
|
$handle_test_telnet = "var handleTestTelnet = function (event) {
|
||||||
|
var gotty_addr = $('input#text-gotty_addr').val();
|
||||||
|
var gotty_port = $('input#text-gotty_port').val();
|
||||||
|
var gotty_telnet_use_ssl = $('input#checkbox-gotty_telnet_use_ssl').is(':checked');
|
||||||
|
|
||||||
|
if (gotty_addr === '') {
|
||||||
|
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_port;
|
||||||
|
} else {
|
||||||
|
url = (gotty_telnet_use_ssl ? 'https://' : 'http://') + gotty_addr + ':' + gotty_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
var showLoadingImage = function () {
|
||||||
|
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var showSuccessImage = function () {
|
||||||
|
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon tick secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var showFailureImage = function () {
|
||||||
|
$('#button-test-gotty-telnet').children('div').attr('class', 'subIcon fail secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var hideMessage = function () {
|
||||||
|
$('span#test-gotty-message-telnet').hide();
|
||||||
|
}
|
||||||
|
var showMessage = function () {
|
||||||
|
$('span#test-gotty-message-telnet').show();
|
||||||
|
}
|
||||||
|
var changeTestMessage = function (message) {
|
||||||
|
$('span#test-gotty-message-telnet').text(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var errorMessage = '".__('Unable to connect.')."';
|
||||||
|
|
||||||
|
hideMessage();
|
||||||
|
showLoadingImage();
|
||||||
|
|
||||||
|
checkAddressReachability('telnet', function(isReachable) {
|
||||||
|
if (isReachable) {
|
||||||
|
showSuccessImage();
|
||||||
|
hideMessage();
|
||||||
|
} else {
|
||||||
|
showFailureImage();
|
||||||
|
changeTestMessage(errorMessage);
|
||||||
|
showMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};";
|
||||||
|
|
||||||
|
$handle_test_ssh = "var handleTestSSH = function (event) {
|
||||||
|
var gotty_addr = $('input#text-gotty_addr').val();
|
||||||
|
var gotty_port = $('input#text-gotty_port').val();
|
||||||
|
var gotty_ssh_use_ssl = $('input#checkbox-gotty_ssh_use_ssl').is(':checked');
|
||||||
|
|
||||||
|
if (gotty_addr === '') {
|
||||||
|
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + server_addr + ':' + gotty_port;
|
||||||
|
} else {
|
||||||
|
url = (gotty_ssh_use_ssl ? 'https://' : 'http://') + gotty_addr + ':' + gotty_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
var showLoadingImage = function () {
|
||||||
|
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon cog rotation secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var showSuccessImage = function () {
|
||||||
|
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon tick secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var showFailureImage = function () {
|
||||||
|
$('#button-test-gotty-ssh').children('div').attr('class', 'subIcon fail secondary mini');
|
||||||
|
}
|
||||||
|
|
||||||
|
var hideMessage = function () {
|
||||||
|
$('span#test-gotty-message-ssh').hide();
|
||||||
|
}
|
||||||
|
var showMessage = function () {
|
||||||
|
$('span#test-gotty-message-ssh').show();
|
||||||
|
}
|
||||||
|
var changeTestMessage = function (message) {
|
||||||
|
$('span#test-gotty-message-ssh').text(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var errorMessage = '".__('Unable to connect.')."';
|
||||||
|
|
||||||
|
|
||||||
|
hideMessage();
|
||||||
|
showLoadingImage();
|
||||||
|
|
||||||
|
checkAddressReachability('ssh', function(isReachable) {
|
||||||
|
if (isReachable) {
|
||||||
|
showSuccessImage();
|
||||||
|
hideMessage();
|
||||||
|
} else {
|
||||||
|
showFailureImage();
|
||||||
|
changeTestMessage(errorMessage);
|
||||||
|
showMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};";
|
||||||
|
|
||||||
|
echo $handle_test_ssh;
|
||||||
|
echo $handle_test_telnet;
|
||||||
|
echo '</script>';
|
||||||
|
|
||||||
extensions_add_godmode_function('quickShellSettings');
|
extensions_add_godmode_function('quickShellSettings');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user