diff --git a/pandora_console/extensions/quick_shell.php b/pandora_console/extensions/quick_shell.php
index d07342945a..9aee7610d8 100644
--- a/pandora_console/extensions/quick_shell.php
+++ b/pandora_console/extensions/quick_shell.php
@@ -89,13 +89,10 @@ function quickShell()
true
);
- if ($method === 'ssh' && (bool) $config['gotty_ssh_enabled'] === false) {
- ui_print_error_message(__('Please, enable SSH in %s', $setup_anchor));
- return;
- }
-
- if ($method === 'telnet' && (bool) $config['gotty_telnet_enabled'] === false) {
- ui_print_error_message(__('Please, enable Telnet in %s', $setup_anchor));
+ if ((bool) $config['gotty_ssh_enabled'] === false
+ && (bool) $config['gotty_telnet_enabled'] === false
+ ) {
+ ui_print_warning_message(__('Please, enable GoTTY in %s', $setup_anchor));
return;
}
@@ -112,19 +109,13 @@ function quickShell()
// Build URL args.
if ($method === 'ssh') {
// SSH.
- $args .= '?arg='.$username.'@'.$agent_address;
- //$args = '?arg='.$username.'@172.16.0.1';
- $args .= '&arg=-p%20'.$method_port;
+ $args .= '&arg='.$agent_address.'&arg='.$method_port.'&arg='.$username;
} else if ($method == 'telnet') {
// Telnet.
- $username = preg_replace('/[^a-zA-Z0-9\-\.]/', '', $username);
- $args = '?arg=-l%20'.$username;
- $args .= '&arg='.$agent_address;
- $args .= '&arg='.$method_port.'&arg=-E';
+ $args .= '&arg='.$agent_address.'&arg='.$method_port;
}
$connectionURL = buildConnectionURL($method);
- //$basic_auth_hdr = $config['gotty_ssh_user'].':'.$config['gotty_ssh_pass'].'@';
$gotty_addr = $connectionURL.$args;
// Username. Retrieve from form.
@@ -132,6 +123,18 @@ function quickShell()
// No username provided, ask for it.
$wiz = new Wizard();
+ $method_fields = [];
+
+ if ($config['gotty_telnet_enabled']) {
+ $method_fields['telnet'] = __('Telnet');
+ $port_value = 23;
+ }
+
+ if ($config['gotty_ssh_enabled']) {
+ $method_fields['ssh'] = __('SSH');
+ $port_value = 22;
+ }
+
$wiz->printForm(
[
'form' => [
@@ -154,7 +157,7 @@ function quickShell()
'type' => 'text',
'id' => 'port',
'name' => 'port',
- 'value' => 22,
+ 'value' => $port_value,
],
],
[
@@ -162,10 +165,7 @@ function quickShell()
'arguments' => [
'type' => 'select',
'name' => 'method',
- 'fields' => [
- 'ssh' => __('SSH'),
- 'telnet' => __('Telnet'),
- ],
+ 'fields' => $method_fields,
'script' => "p=22; if(this.value == 'telnet') { p=23; } $('#text-port').val(p);",
],
],
@@ -190,6 +190,24 @@ function quickShell()
return;
}
+ // Check gotty connection before trying to load iframe.
+ $ch = curl_init($gotty_addr);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ 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;
+ }
+
?>
-
';
- echo '';
+ echo '';
- $test_start = ' '.html_print_image('images/spinner.gif', true).'';
- $test_start .= ' ';
+ $general_table = new StdClass();
+ $general_table->data = [];
+ $general_table->width = '100%';
+ $general_table->class = 'filter-table-adv';
+ $general_table->data = [];
+ $general_table->style = [];
+ $general_table->style[0] = 'width: 50%;';
+
+ $general_table->data[0][] = html_print_label_input_block(
+ __('Address'),
+ html_print_input_text(
+ 'gotty_addr',
+ $config['gotty_addr'],
+ '',
+ 30,
+ 100,
+ true
+ )
+ );
+
+ $general_table->data[0][] = html_print_label_input_block(
+ __('Port'),
+ html_print_input_text(
+ 'gotty_port',
+ $config['gotty_port'],
+ '',
+ 30,
+ 100,
+ true
+ )
+ );
+
+ html_print_table($general_table);
+ echo '';
+
+ echo '';
echo '