From 025abbed9313b257c1d37aba0f722a870988e56a Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 9 Oct 2023 14:17:16 +0200 Subject: [PATCH] add timeout --- pandora_console/extensions/quick_shell.php | 57 ++++++++-------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/pandora_console/extensions/quick_shell.php b/pandora_console/extensions/quick_shell.php index 0396b06323..b50a7ec828 100644 --- a/pandora_console/extensions/quick_shell.php +++ b/pandora_console/extensions/quick_shell.php @@ -135,6 +135,18 @@ function quickShell() $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-port').val(p);"; + $wiz->printForm( [ 'form' => [ @@ -147,8 +159,9 @@ function quickShell() [ 'label' => __('Username'), 'arguments' => [ - 'type' => 'text', - 'name' => 'username', + 'type' => 'text', + 'name' => 'username', + 'required' => true, ], ], [ @@ -166,7 +179,7 @@ function quickShell() 'type' => 'select', 'name' => 'method', 'fields' => $method_fields, - 'script' => "p=22; if(this.value == 'telnet') { p=23; } $('#text-port').val(p);", + 'script' => $method_script, ], ], ], @@ -193,7 +206,10 @@ function quickShell() // 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); @@ -226,40 +242,7 @@ function quickShell()
- - - // Capture error sent from iframe. - window.addEventListener("message", function(event) { - var received_data = event.data; - if (received_data.error_code) { - // Send error code to the server. - var new_url = window.location.href + "?error_code=" + received_data.error_code; - window.location.href = new_url; - } - }); - - var iframe = document.getElementById('gotty-iframe'); - console.log(iframe ); - - iframe.addEventListener("error", function (event) { - console.log("erorrrrrrr"); - // If an error occurs while loading the iframe content. - if (event.target.contentWindow) { - var status = event.target.contentWindow.document; - if (status && status.location) { - var status_code = status.location.href.match(/(\d{3})\.html/)[1]; - if (status_code >= "400" && status_code < "600") { - // Post the error data to the parent window. - window.parent.postMessage(status_code, window.location.origin); - } - } - } - }); - */ - ?>