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' => [ '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'), ], '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']; $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; } // If rediretion is enabled, we will try to connect to http:// or https:// endpoint. $test = get_headers($ws_url); 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; } $r = file_get_contents('http://'.$host.':'.$port.'/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($config['gotty_user']) && empty($config['gotty_pass']) ) { $r .= "var gotty_auth_token = '';"; } else { $r .= "var gotty_auth_token = '"; $r .= $config['gotty_user'].':'.$gotty_pass."';"; } // Set websocket target and method. $gotty = file_get_contents('http://'.$host.':'.$port.'/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 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); ?>