diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index 7832042fda..7c4d3b401b 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -78,4 +78,8 @@ pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/Goliat/GoliatCURL.pm pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/Goliat/GoliatConfig.pm pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/Goliat/GoliatLWP.pm pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/Goliat/GoliatTools.pm -pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/PandoraFMS/WebServer.pm \ No newline at end of file +pandora_enterprise/pandora_server/PandoraFMS-Enterprise/lib/PandoraFMS/WebServer.pm +pandora_console/enterprise/godmode/agentes/module_manager_editor_web.php +pandora_console/enterprise/include/ajax/web_server_module_debug.php +pandora_console/enterprise/include/class/WebServerModuleDebug.class.php +pandora_console/enterprise/include/styles/WebServerModuleDebug.css \ No newline at end of file diff --git a/pandora_console/godmode/agentes/module_manager_editor_web.php b/pandora_console/godmode/agentes/module_manager_editor_web.php new file mode 100644 index 0000000000..a15da07caa --- /dev/null +++ b/pandora_console/godmode/agentes/module_manager_editor_web.php @@ -0,0 +1,468 @@ + 'modal', + 'style' => 'display: none;', + ] +); + +require_once $config['homedir'].'/include/ajax/web_server_module_debug.php'; + +define('ID_NETWORK_COMPONENT_TYPE', 7); + +if (!$tcp_port && !$id_agent_module) { + $tcp_port = 80; +} + +// plugin_server is the browser id +if ($plugin_user == '' && !$id_agent_module) { + $plugin_user = get_product_name().' / Webcheck'; +} + +// plugin_server is the referer +if ($plugin_pass == '' && !$id_agent_module) { + $plugin_pass = 1; +} + +if (empty($update_module_id)) { + // Function in module_manager_editor_common.php + add_component_selection(ID_NETWORK_COMPONENT_TYPE); +} else { + // TODO: Print network component if available +} + +$data = []; +$data[0] = __('Web checks'); + +$adopt = false; +if (isset($id_agent_module)) { + $adopt = policies_is_module_adopt($id_agent_module); +} + +$id_policy_module = (int) get_parameter('id_policy_module', ''); +if ($id_policy_module) { + $module = policies_get_module($id_policy_module); + $plugin_parameter = $module['plugin_parameter']; +} + +if (!$adopt) { + $data[1] = html_print_textarea( + 'plugin_parameter', + 15, + 65, + $plugin_parameter, + $disabledTextBecauseInPolicy, + true + ); +} else { + $data[1] = html_print_textarea( + 'plugin_parameter', + 15, + 65, + $plugin_parameter, + false, + true + ); +} + +$table_simple->colspan['web_checks'][1] = 2; + +// Disable debug button if module has not started. +if ($id_agent_module > 0 + && db_get_value_filter( + 'debug_content', + 'tagente_modulo', + ['id_agente_modulo' => $id_agent_module] + ) !== null +) { + $disableDebug = false; + $hintDebug = __('Debug remotely this module'); +} else { + $disableDebug = true; + $hintDebug = __('Debug this module once it has been initialized'); +} + +$suc_err_check = ' '; +$suc_err_check .= ' '; +$data[2] = html_print_button( + __('Load basic'), + 'btn_loadbasic', + false, + '', + 'class="sub config"', + true +).ui_print_help_tip(__('Load a basic structure on Web Checks'), true); +$data[2] .= '

'.html_print_button( + __('Check'), + 'btn_checkconf', + false, + '', + 'class="sub upd"', + true +).ui_print_help_tip(__('Check the correct structure of the WebCheck'), true).$suc_err_check; +$data[2] .= '

'.html_print_button( + __('Debug'), + 'btn_debugModule', + $disableDebug, + '', + 'class="sub config" onClick="loadDebugWindow()"', + true +).ui_print_help_tip($hintDebug, true); + + +push_table_simple($data, 'web_checks'); + +$http_checks_type = [ + 0 => 'Anyauth', + 1 => 'NTLM', + 2 => 'DIGEST', + 3 => 'BASIC', +]; + +$data = []; +$data[0] = __('Check type'); +$data[1] = html_print_select($http_checks_type, 'tcp_port', $tcp_port, false, '', '', true, false, false); + +push_table_advanced($data, 'web_0'); + +$data = []; +$data[0] = __('Requests'); +$data[1] = html_print_input_text('plugin_pass', $plugin_pass, '', 10, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +$data[2] = ''; +$data[3] = __('Agent browser id'); +$data[4] = html_print_input_text('plugin_user', $plugin_user, '', 30, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +push_table_advanced($data, 'web_1'); + +$data = []; +$data[0] = __('HTTP auth (login)'); +$data[1] = html_print_input_text('http_user', $plugin_parameter_http_user, '', 10, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +$data[2] = ''; +$data[3] = __('HTTP auth (password)'); +$data[4] = html_print_input_password('http_pass', $plugin_parameter_http_pass, '', 30, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +push_table_advanced($data, 'web_2'); + +$data = []; + +$data[0] = __('Proxy URL'); +$data[1] = html_print_input_text('snmp_oid', $snmp_oid, '', 30, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +$data[2] = $data[3] = $data[4] = ''; +push_table_advanced($data, 'web_3'); + +$data = []; + +$data[0] = __('Proxy auth (login)'); +$data[1] = html_print_input_text('tcp_send', $tcp_send, '', 30, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +$data[2] = ''; +$data[3] = __('Proxy auth (pass)'); +$data[4] = html_print_input_password('tcp_rcv', $tcp_rcv, '', 30, 0, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +push_table_advanced($data, 'web_4'); + +$data = []; + +$data[0] = __('Proxy auth (server)'); +$data[1] = html_print_input_text('ip_target', $ip_target, '', 30, 100, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +$data[2] = ''; +$data[3] = __('Proxy auth (realm)'); +$data[4] = html_print_input_text('snmp_community', $snmp_community, '', 30, 100, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +push_table_advanced($data, 'web_5'); + +// Add some strings to be used from javascript +$texts = [ + 'lines_before_begin' => __('First line must be "task_begin"'), + 'missed_begin' => __('Webchecks configuration is empty'), + 'missed_end' => __('Last line must be "task_end"'), + 'lines_after_end' => __('Last line must be "task_end"'), + 'unknown_token' => __("There is a line with a unknown token 'token_fail'."), + 'missed_get_post' => __("There isn't get or post"), + 'correct' => __('Web checks are built correctly'), +]; + +foreach ($texts as $code => $text) { + echo ''; +} +?> + \ No newline at end of file diff --git a/pandora_console/include/ajax/web_server_module_debug.php b/pandora_console/include/ajax/web_server_module_debug.php new file mode 100644 index 0000000000..d243257cbd --- /dev/null +++ b/pandora_console/include/ajax/web_server_module_debug.php @@ -0,0 +1,74 @@ + '[WebServerModuleDebug]'.$e->getMessage() ]); + exit; + } else { + echo '[WebServerModuleDebug]'.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if (is_ajax()) { + $method = get_parameter('method'); + + if (method_exists($obj, $method) === true) { + $obj->{$method}(); + } else { + $obj->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $obj->run(); +} diff --git a/pandora_console/include/class/WebServerModuleDebug.class.php b/pandora_console/include/class/WebServerModuleDebug.class.php new file mode 100644 index 0000000000..e0e6f23c84 --- /dev/null +++ b/pandora_console/include/class/WebServerModuleDebug.class.php @@ -0,0 +1,407 @@ + '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(); + ?> + + + +