'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=quickshell', 'content' => __('GoTTY setup'), ], true ); 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; } $agent_id = get_parameter('id_agente', 0); $username = get_parameter('username', null); $method_port = get_parameter('port', null); // Retrieve main IP Address. $agent_address = agents_get_address($agent_id); ui_require_css_file('wizard'); ui_require_css_file('discovery'); // Build URL args. if ($method === 'ssh') { // SSH. $args .= '&arg='.$agent_address.'&arg='.$method_port.'&arg='.$username; } else if ($method == 'telnet') { // Telnet. $args .= '&arg='.$agent_address.'&arg='.$method_port; } $connectionURL = buildConnectionURL($method); $gotty_addr = $connectionURL.$args; // Username. Retrieve from form. if ($form_sent === false) { // 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; } $method_script = " var wizard = document.querySelector('.wizard'); p=22; wizard.querySelector('ul > li').classList.remove('invisible_important'); wizard.querySelector('ul > li').classList.add('visible'); if(this.value == 'telnet') { p=23; wizard.querySelector('ul > li').classList.remove('visible'); wizard.querySelector('ul > li').classList.add('invisible_important'); $('#text-username').prop('required', false); } else { $('#text-username').prop('required', true); } $('#text-port').val(p);"; $wiz->printForm( [ 'form' => [ 'action' => '#', 'class' => 'wizard', 'method' => 'post', 'id' => 'connect_form', ], 'inputs' => [ [ 'label' => __('Username'), 'arguments' => [ 'type' => 'text', 'name' => 'username', 'required' => true, ], ], [ 'label' => __('Port'), 'arguments' => [ 'type' => 'text', 'id' => 'port', 'name' => 'port', 'value' => $port_value, ], ], [ 'label' => __('Method'), 'arguments' => [ 'type' => 'select', 'name' => 'method', 'fields' => $method_fields, 'script' => $method_script, ], ], [ 'arguments' => [ 'type' => 'hidden', 'name' => 'form-sent', 'value' => true, ], ], ], ], false, true ); html_print_action_buttons( html_print_submit_button( __('Connect'), 'submit', false, [ 'icon' => 'cog', 'form' => 'connect_form', ], true ) ); 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); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $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 ''.__('GoTTY general parameters').''; $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 ''.__('GoTTY SSH connection parameters').''; $ssh_table = new StdClass(); $ssh_table->data = []; $ssh_table->width = '100%'; $ssh_table->class = 'filter-table-adv'; $ssh_table->data = []; $ssh_table->style = []; $ssh_table->style[0] = 'width: 50%;'; $ssh_table->data[0][] = html_print_label_input_block( __('Enable SSH method'), html_print_checkbox_switch( 'gotty_ssh_enabled', 1, $config['gotty_ssh_enabled'], true ) ); $ssh_table->data[1][] = html_print_label_input_block( __('Use SSL'), html_print_checkbox_switch( 'gotty_ssh_use_ssl', 1, $config['gotty_ssh_use_ssl'], true, $disable_agentaccess ) ); // Test. $row = []; $test_start = ''; $test_start .= ' '; $ssh_table->data[3][] = html_print_button( __('Test'), 'test-gotty-ssh', false, 'handleTestSSH()', [ 'icon' => 'cog', 'mode' => 'secondary', 'style' => 'width: 115px;', ], true ).$test_start; html_print_table($ssh_table); echo '
'; echo '
'; echo ''.__('GoTTY telnet connection parameters').''; $telnet_table = new StdClass(); $telnet_table->data = []; $telnet_table->width = '100%'; $telnet_table->class = 'filter-table-adv'; $telnet_table->data = []; $telnet_table->style = []; $telnet_table->style[0] = 'width: 50%;'; $telnet_table->data[0][] = html_print_label_input_block( __('Enable telnet method'), html_print_checkbox_switch( 'gotty_telnet_enabled', 1, $config['gotty_telnet_enabled'], true ) ); $telnet_table->data[1][] = html_print_label_input_block( __('Use SSL'), html_print_checkbox_switch( 'gotty_telnet_use_ssl', 1, $config['gotty_telnet_use_ssl'], true ) ); // Test. $row = []; $test_start = ''; $test_start .= ' '; $telnet_table->data[3][] = html_print_button( __('Test'), 'test-gotty-telnet', false, 'handleTestTelnet()', [ 'icon' => 'cog', 'mode' => 'secondary', 'style' => 'width: 115px;', ], true ).$test_start; html_print_table($telnet_table); html_print_input_hidden('update_config', 1); echo '
'; } if (is_ajax() === true) { $method = (string) get_parameter('method', ''); if (empty($method) === false) { $address = buildConnectionURL($method); $ch = curl_init($address); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Maximum time for the entire request. curl_setopt($ch, CURLOPT_TIMEOUT, 2); // Maximum time to establish a connection. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_exec($ch); $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($response_code === 200) { $result = ['status' => 'success']; } else { $result = ['status' => 'error']; } echo json_encode($result); return; } $result = ['status' => 'error']; return; } // This extension is useful 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/quick-shell@svg.svg', // TabFunction. 'quickShell', // Version. 'N/A', // Acl. 'PM' ); } } echo ''; extensions_add_godmode_function('quickShellSettings');