[ 'method' => 'GET'], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, ], ] ); // Username. Retrieve from form. if (empty($username) === true) { // No username provided, ask for it. $wiz = new Wizard(); $test = file_get_contents($ws_url, false, $context); if ($test === false) { ui_print_error_message(__('WebService engine has not been started, please check documentation.')); $wiz->printForm( [ 'form' => [ 'method' => 'POST', 'action' => '#', ], 'inputs' => [ [ 'class' => 'w100p', 'arguments' => [ 'name' => 'submit', 'label' => __('Retry'), 'type' => 'submit', 'attributes' => 'class="sub next"', 'return' => true, ], ], ], ] ); return; } $wiz->printForm( [ 'form' => [ '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'), ], 'script' => "p=22; if(this.value == 'telnet') { p=23; } $('#text-port').val(p);", ], ], [ 'arguments' => [ 'type' => 'submit', 'label' => __('Connect'), 'attributes' => 'class="sub next"', ], ], ], ], false, true ); return; } // Initialize Gotty Client. $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']; $username = preg_replace('/[^a-zA-Z0-9\-\.]/', '', $username); $command_arguments = "var args = '?arg=-l ".$username; $command_arguments .= '&arg='.$address; $command_arguments .= '&arg='.$method_port."&arg=-E';"; } else { ui_print_error_message(__('Please use SSH or Telnet.')); return; } // If rediretion is enabled, we will try to connect using // http:// or https:// endpoint. $test = get_headers($ws_url, null, $context); if ($test === false) { if (empty($wiz) === true) { $wiz = new Wizard(); } ui_print_error_message(__('WebService engine has not been started, please check documentation.')); echo $wiz->printGoBackButton('#'); return; } // Check credentials. $auth_str = ''; $gotty_url = $host.':'.$port; if (empty($config['gotty_user']) === false && empty($config['gotty_pass']) === false ) { $auth_str = io_safe_output($config['gotty_user']); $auth_str .= ':'.io_output_password($config['gotty_pass']); $gotty_url = $auth_str.'@'.$host.':'.$port; } $r = file_get_contents('http://'.$gotty_url.'/js/hterm.js'); if (empty($r) === true) { if (empty($wiz) === true) { $wiz = new Wizard(); } ui_print_error_message(__('WebService engine is not working properly, please check documentation.')); echo $wiz->printGoBackButton('#'); return; } // Override gotty client settings. if (empty($auth_str) === true) { $r .= "var gotty_auth_token = '';"; } else { $r .= "var gotty_auth_token = '"; $r .= $auth_str."';"; } // Set websocket target and method. $gotty = file_get_contents('http://'.$gotty_url.'/js/gotty.js'); $url = "var url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';"; 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 = '"; $new .= $config['ws_proxy_url'].'/'.$method."';"; } // Update firefox issue. $original = ' this.iframe_.src = \'#\';'; $trick = 'this.iframe_.src = \'javascript:\';'; $r = str_replace($original, $trick, $r); // 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); ?>
0) { $msg = __('%d Updated', $changes); if ($critical > 0) { $msg = __( '%d Updated, please restart WebSocket engine service', $changes ); } ui_print_success_message($msg); } // Form. Using old style. echo '
'; echo ''.__('Quickshell').''; $t = new StdClass(); $t->data = []; $t->width = '100%'; $t->class = 'databox filters'; $t->data = []; $t->style = []; $t->style[0] = 'font-weight: bold; width: 40%;'; $t->data[0][0] = __('Gotty path'); $t->data[0][1] = html_print_input_text( 'gotty', $config['gotty'], '', 30, 100, true ); $t->data[1][0] = __('Gotty host'); $t->data[1][1] = html_print_input_text( 'gotty_host', $config['gotty_host'], '', 30, 100, true ); $t->data[2][0] = __('Gotty ssh port'); $t->data[2][1] = html_print_input_text( 'gotty_ssh_port', $config['gotty_ssh_port'], '', 30, 100, true ); $t->data[3][0] = __('Gotty telnet port'); $t->data[3][1] = html_print_input_text( 'gotty_telnet_port', $config['gotty_telnet_port'], '', 30, 100, true ); $hidden = new StdClass(); $hidden->data = []; $hidden->width = '100%'; $hidden->class = 'databox filters'; $hidden->data = []; $hidden->style[0] = 'font-weight: bold;width: 40%;'; $hidden->data[0][0] = __('Gotty user'); $hidden->data[0][1] = html_print_input_text( 'gotty_user', $config['gotty_user'], '', 30, 100, true ); $hidden->data[1][0] = __('Gotty password'); $hidden->data[1][1] = html_print_input_password( 'gotty_pass', io_output_password($config['gotty_pass']), '', 30, 100, true ); $hidden->data[1][1] .= ui_print_reveal_password('gotty_pass', true); html_print_table($t); ui_print_toggle( [ 'content' => html_print_table($hidden, true), 'name' => __('Advanced options'), 'clean' => false, 'main_class' => 'no-border-imp', 'container_class' => 'no-border-imp', ] ); echo '
'; } // This extension is usefull only if the agent has associated IP. $agent_id = get_parameter('id_agente'); if (empty($agent_id) === false && get_parameter('sec2', '') == 'operation/agentes/ver_agente' ) { $address = agents_get_address($agent_id); if (empty($address) === false) { // Extension registration. extensions_add_opemode_tab_agent( // TabId. 'quick_shell', // TabName. __('QuickShell'), // TabIcon. 'images/ehorus/terminal.png', // TabFunction. 'quickShell', // Version. 'N/A', // Acl. 'PM' ); } } extensions_add_godmode_function('quickShellSettings');