'noaccess']); } include 'general/noaccess.php'; exit; } // Parameter assigments. $this->ajaxController = $ajaxController; $this->query = ''; $this->idAgentModule = $idAgentModule; // Hardcoded request timeout. $this->requestTimeout = 15; return $this; } /** * Run Module Debug window. * * @return void */ public function run() { // Added all necessary basic files for QueryResult. ui_require_css_file('ace'); ui_require_javascript_file('ace', 'include/javascript/ace/'); // Load Javascript. $this->loadJS(); // CSS. ui_require_css_file('wizard'); ui_require_css_file('discovery'); // Specific CSS for this feature. ui_require_css_file('WebServerModuleDebug', '/include/styles/', true); } /** * Show the modal with the QueryResult. * * @return void */ public function showWebServerDebug() { // Show QueryResult editor. ui_query_result_editor('webserverdebug'); // Spinner for wait loads. html_print_div( [ 'id' => 'WebServerDebugSpinner', 'style' => 'visibility: hidden;', 'content' => __('Performing query. Please wait.').' '.html_print_image('images/spinner.gif', true), ] ); ?> $this->idAgentModule, ] ); $this->query = ($outputDebugQuery !== false) ? $outputDebugQuery : __('Please, wait for a first execution of module'); return $this->query; } /** * Perform the cURL execution. * * @return void * @throws Exception $e Error message. */ public function executeCommand() { try { $executionForPerform = io_safe_output(get_parameter('text')); // If the execution comes empty. if (empty($executionForPerform) === true) { throw new Exception('Execution failed'); } // For security reasons, only allow the 'curl' command. $executionForPerform = strstr($executionForPerform, 'curl'); // Avoid pipes or concatenation of commands. $unallowedChars = [ '|', '&', '||', '&&', ';', '\n', ]; $executionForPerform = str_replace( $unallowedChars, ' ', $executionForPerform ); // Set execution timeout. $executionForPerform .= sprintf( $executionForPerform.' -m %d', $this->requestTimeout ); // Perform the execution. system($executionForPerform, $returnCode); // If execution does not got well. if ($returnCode != 0) { switch ($returnCode) { case '2': throw new Exception('Failed to initialize. Review the syntax.'); case '3': throw new Exception('URL malformed. The syntax was not correct.'); case '5': throw new Exception('Couldn\'t resolve proxy. The given proxy host could not be resolved.'); case '6': throw new Exception('Couldn\'t resolve host. The given remote host could not be resolved.'); case '7': throw new Exception('Failed to connect to host.'); default: throw new Exception('Failed getting data.'); } } } catch (Exception $e) { // Show execution error message. echo __($e->getMessage()); } exit; } /** * Loads JS and return code. * * @return string */ public function loadJS() { $str = ''; ob_start(); ?>