ws gotty credentials and ws gotty proxy redirection

This commit is contained in:
fbsanchez 2019-10-24 10:59:08 +02:00
parent d34aa0917b
commit df576a3b86
2 changed files with 79 additions and 23 deletions
pandora_console

@ -230,7 +230,7 @@ function quickShell()
$r .= "var gotty_auth_token = '';";
} else {
$r .= "var gotty_auth_token = '";
$r .= $config['gotty_user'].':'.$gotty_pass."';";
$r .= $config['gotty_user'].':'.$config['gotty_pass']."';";
}
// Set websocket target and method.
@ -309,10 +309,22 @@ function quickShellSettings()
$config['gotty_telnet_port']
);
$gotty_user = get_parameter(
'gotty_user',
$config['gotty_user']
);
$gotty_pass = get_parameter(
'gotty_pass',
$config['gotty_pass']
);
$changes = 0;
$critical = 0;
if ($config['gotty'] != $gotty) {
config_update_value('gotty', $gotty);
$changes++;
$critical++;
}
if ($config['gotty_host'] != $gotty_host) {
@ -330,13 +342,31 @@ function quickShellSettings()
$changes++;
}
if ($config['gotty_user'] != $gotty_user) {
config_update_value('gotty_user', $gotty_user);
$changes++;
$critical++;
}
if ($config['gotty_pass'] != $gotty_pass) {
config_update_value('gotty_pass', $gotty_pass);
$changes++;
$critical++;
}
// Interface.
ui_print_page_header(__('QuickShell settings'));
if ($changes > 0) {
ui_print_success_message(
__('%d Updated, please restart WebSocket engine service', $changes)
$msg = __(
'%d Updated, please restart WebSocket engine service',
$changes
);
if ($critical > 0) {
$msg = __('%d Updated', $changes);
}
ui_print_success_message($msg);
}
// Form.
@ -382,6 +412,22 @@ function quickShellSettings()
'value' => $config['gotty_telnet_port'],
],
],
[
'label' => __('Gotty user'),
'arguments' => [
'type' => 'text',
'name' => 'gotty_user',
'value' => $config['gotty_user'],
],
],
[
'label' => __('Gotty password'),
'arguments' => [
'type' => 'text',
'name' => 'gotty_pass',
'value' => $config['gotty_pass'],
],
],
[
'arguments' => [
'type' => 'submit',

@ -97,27 +97,37 @@ error_reporting(E_ALL);
$os = strtolower(PHP_OS);
if (substr($os, 0, 3) !== 'win') {
if (is_executable($config['gotty']) === false) {
echo 'Failed to execute gotty ['.$config['gotty']."]\n";
exit(1);
if (empty($config['gotty']) === false) {
// Allow start without gotty binary. External service.
if (is_executable($config['gotty']) === false) {
echo 'Failed to execute gotty ['.$config['gotty']."]\n";
exit(1);
}
$gotty_creds = '';
if (empty($config['gotty_user']) === false
&& empty($config['gotty_pass']) === false
) {
$gotty_creds = " -c '".$gotty_user.':'.$gotty_pass."'";
}
// Kill previous gotty running.
shell_exec('killall "'.$config['gotty'].'" >/dev/null 2>&1');
// Common.
$base_cmd = 'nohup "'.$config['gotty'].'" '.$gotty_creds;
$base_cmd .= ' --permit-arguments -a 127.0.0.1 -w ';
// Launch gotty - SSH.
$cmd = $base_cmd.' --port '.$config['gotty_ssh_port'];
$cmd .= ' ssh >> '.__DIR__.'/pandora_console.log 2>&1 &';
shell_exec($cmd);
// Launch gotty - telnet.
$cmd = $base_cmd.' --port '.$config['gotty_telnet_port'];
$cmd .= ' telnet >> '.__DIR__.'/pandora_console.log 2>&1 &';
shell_exec($cmd);
}
// Kill previous gotty running.
shell_exec('killall "'.$config['gotty'].'" >/dev/null 2>&1');
// Common.
$base_cmd = 'nohup "'.$config['gotty'].'"';
$base_cmd .= ' --permit-arguments -a 127.0.0.1 -w ';
// Launch gotty - SSH.
$cmd = $base_cmd.' --port '.$config['gotty_ssh_port'];
$cmd .= ' ssh >> '.__DIR__.'/pandora_console.log 2>&1 &';
shell_exec($cmd);
// Launch gotty - telnet.
$cmd = $base_cmd.' --port '.$config['gotty_telnet_port'];
$cmd .= ' telnet >> '.__DIR__.'/pandora_console.log 2>&1 &';
shell_exec($cmd);
}
// Start Web SocketProxy.