From 6c52462c8cdaf2771c015465e8137e5fa8a68f2f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 21 Oct 2019 17:36:26 +0200 Subject: [PATCH] Modular WebSocket engine, added ssh and telnet to quickshell extension --- pandora_console/extensions/quick_shell.php | 255 +++++++++++++----- .../godmode/setup/setup_general.php | 49 +++- .../include/class/ConsoleSupervisor.php | 54 +++- pandora_console/include/functions_config.php | 8 + .../lib/{WSProxy.php => WSManager.php} | 242 ++++++++++------- pandora_console/include/lib/WSProxyUser.php | 89 ------ .../include/lib/WebSocketServer.php | 91 ++++--- .../include/websocket_registrations.php | 189 +++++++++++++ .../vendor/composer/autoload_classmap.php | 3 +- .../vendor/composer/autoload_static.php | 3 +- pandora_console/ws.php | 68 +++-- 11 files changed, 717 insertions(+), 334 deletions(-) rename pandora_console/include/lib/{WSProxy.php => WSManager.php} (67%) delete mode 100644 pandora_console/include/lib/WSProxyUser.php create mode 100644 pandora_console/include/websocket_registrations.php diff --git a/pandora_console/extensions/quick_shell.php b/pandora_console/extensions/quick_shell.php index 0626497560..a2266fbc01 100644 --- a/pandora_console/extensions/quick_shell.php +++ b/pandora_console/extensions/quick_shell.php @@ -1,65 +1,203 @@ printForm( + [ + 'form' => [ + 'id' => 'pene', + 'action' => '#', + 'class' => 'wizard', + 'method' => 'post', + ], + 'inputs' => [ + [ + 'label' => __('Username'), + 'arguments' => [ + 'type' => 'text', + 'name' => 'username', + ], + ], + [ + 'label' => __('Port'), + 'arguments' => [ + 'type' => 'text', + 'id' => 'port', + 'name' => 'port', + 'value' => 22, + ], + ], + [ + 'label' => __('Method'), + 'arguments' => [ + 'type' => 'select', + 'name' => 'method', + 'fields' => [ + 'ssh' => __('SSH'), + 'telnet' => __('Telnet'), + ], + ], + ], + [ + 'arguments' => [ + 'type' => 'submit', + 'label' => __('Connect'), + 'attributes' => 'class="sub next"', + ], + ], + ], + ], + false, + true + ); + + return; } - if (!isset($config['wetty_port'])) { - config_update_value('wetty_port', '3000'); + // WebSocket host, where to connect. + if (isset($config['ws_host']) === false) { + config_update_value('ws_host', $_SERVER['SERVER_ADDR']); } - $buttons['maps'] = [ - 'active' => false, - 'text' => ''.html_print_image('images/setup.png', true, ['title' => __('Wetty settings')]).'', - ]; + if (isset($config['ws_port']) === false) { + config_update_value('ws_port', 8080); + } - ui_print_page_header(__('Wetty'), 'images/extensions.png', false, '', true, $buttons); + if (isset($config['gotty_host']) === false) { + config_update_value('gotty_host', '127.0.0.1'); + } - $host = '127.0.0.1'; - $port = 8080; + if (isset($config['gotty_telnet_port']) === false) { + config_update_value('gotty_telnet_port', 8082); + } + + if (isset($config['gotty_ssh_port']) === false) { + config_update_value('gotty_ssh_port', 8081); + } + + $host = $config['gotty_host']; + if ($method == 'ssh') { + // SSH. + $port = $config['gotty_ssh_port']; + $command_arguments = "var args = '?arg=".$username.'@'.$address; + $command_arguments .= '&arg=-p '.$method_port."';"; + } else if ($method == 'telnet') { + // Telnet. + $port = $config['gotty_telnet_port']; + $command_arguments = "var args = '?arg=-l ".$username; + $command_arguments .= '&arg= '.$address; + $command_arguments .= '&arg= '.$method_port."';"; + } else { + ui_print_error_message(__('Please use SSH or Telnet.')); + return; + } $r = file_get_contents('http://'.$host.':'.$port.'/js/hterm.js'); - $r .= file_get_contents('http://'.$host.':'.$port.'/auth_token.js'); + + if (empty($r) === true) { + echo 'No hay nadie al volante, peligro constante'; + return; + } + + if (empty($config['gotty_user']) + && empty($config['gotty_pass']) + ) { + $r .= "var gotty_auth_token = '';"; + } else { + $r .= "var gotty_auth_token = '"; + $r .= $config['gotty_user'].':'.$gotty_pass."';"; + } + $gotty = file_get_contents('http://'.$host.':'.$port.'/js/gotty.js'); + // Set websocket target. $url = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';"; - $new = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + ':8081' + window.location.pathname;"; + if (empty($config['ws_proxy_url']) === true) { + $new = "var url = (httpsEnabled ? 'wss://' : 'ws://')"; + $new .= " + window.location.host + ':"; + $new .= $config['ws_port'].'/'.$method."';"; + } else { + $new = "var url = (httpsEnabled ? 'wss://' : 'ws://') + "; + $new .= 'window.location.host + '; + $new .= "'".$config['ws_proxy_url'].'/'.$method."';"; + } + // Update url. $gotty = str_replace($url, $new, $gotty); + // Update websocket arguments. + $args = 'var args = window.location.search;'; + $new = $command_arguments; + + // Update arguments. + $gotty = str_replace($args, $new, $gotty); + ?>