mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
WIP: Backup upload
This commit is contained in:
parent
9e54f9517b
commit
d43c51cc66
@ -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
|
||||
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
|
468
pandora_console/godmode/agentes/module_manager_editor_web.php
Normal file
468
pandora_console/godmode/agentes/module_manager_editor_web.php
Normal file
@ -0,0 +1,468 @@
|
||||
<?php
|
||||
/**
|
||||
* Web Module Editor for Module Manager.
|
||||
*
|
||||
* @category Module manager
|
||||
* @package Pandora FMS
|
||||
* @subpackage Module manager
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
enterprise_include_once('include/functions_policies.php');
|
||||
|
||||
$disabledBecauseInPolicy = false;
|
||||
$disabledTextBecauseInPolicy = '';
|
||||
$classdisabledBecauseInPolicy = '';
|
||||
$page = get_parameter('page', '');
|
||||
if (strstr($page, 'policy_modules') === false) {
|
||||
if ($config['enterprise_installed']) {
|
||||
if (policies_is_module_linked($id_agent_module) == 1) {
|
||||
$disabledBecauseInPolicy = 1;
|
||||
} else {
|
||||
$disabledBecauseInPolicy = 0;
|
||||
}
|
||||
} else {
|
||||
$disabledBecauseInPolicy = false;
|
||||
}
|
||||
|
||||
if ($disabledBecauseInPolicy) {
|
||||
$disabledTextBecauseInPolicy = 'disabled = "disabled"';
|
||||
$classdisabledBecauseInPolicy = 'readonly';
|
||||
}
|
||||
}
|
||||
|
||||
global $id_agente;
|
||||
|
||||
$extra_title = __('Web server module');
|
||||
|
||||
// Div for modal.
|
||||
html_print_div(
|
||||
[
|
||||
'id' => '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 = ' <span id="check_conf_suc" class="checks invisible">'.html_print_image('/images/ok.png', true).'</span>';
|
||||
$suc_err_check .= ' <span id="check_conf_err" class="checks invisible">'.html_print_image('/images/error_red.png', true).'</span>';
|
||||
$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] .= '<br><br>'.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] .= '<br><br>'.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 '<span class="invisible" id="'.$code.'">'.$text.'</span>';
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var supported_tokens = [
|
||||
"task_begin",
|
||||
"post",
|
||||
"variable_name",
|
||||
"variable_value",
|
||||
"cookie",
|
||||
"resource",
|
||||
"get",
|
||||
"check_string",
|
||||
"check_not_string",
|
||||
"get_content_advanced",
|
||||
"get_content",
|
||||
"debug",
|
||||
"task_end",
|
||||
"head",
|
||||
"http_auth_user",
|
||||
"http_auth_pass"
|
||||
];
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
var plugin_parameter = $("#textarea_plugin_parameter");
|
||||
var http_auth_user = $('#text-http_user');
|
||||
var http_auth_pass = $('#password-http_pass');
|
||||
|
||||
$(plugin_parameter).keyup(function() {
|
||||
|
||||
// Check and fill textbox.
|
||||
if ($(plugin_parameter).val() == '') {
|
||||
$('#button-btn_loadbasic').removeAttr('disabled');
|
||||
} else {
|
||||
$('#button-btn_loadbasic').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
// Update http_auth_user from conf data
|
||||
var http_auth_user_value = get_module_token_from_config('http_auth_user', plugin_parameter, "\n");
|
||||
if (http_auth_user_value != "") {
|
||||
http_auth_user.val(http_auth_user_value);
|
||||
}
|
||||
|
||||
// Update http_auth_pass from conf data
|
||||
var http_auth_pass_value = get_module_token_from_config('http_auth_pass', plugin_parameter, "\n");
|
||||
if (http_auth_pass_value != "") {
|
||||
http_auth_pass.val(http_auth_pass_value);
|
||||
}
|
||||
});
|
||||
|
||||
$('#button-btn_loadbasic').click(function() {
|
||||
if ($(plugin_parameter).val() != '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$(plugin_parameter).val(
|
||||
'task_begin\ncookie 0\nresource 0\ntask_end');
|
||||
|
||||
$('#button-btn_loadbasic').attr('disabled', 'disabled');
|
||||
|
||||
// Hide success and error indicators
|
||||
$('.checks').hide();
|
||||
});
|
||||
|
||||
$('#button-btn_checkconf').click(function() {
|
||||
var msg_error = '';
|
||||
|
||||
if (plugin_parameter.val() == '') {
|
||||
msg_error = 'missed_begin';
|
||||
} else {
|
||||
var lines = plugin_parameter.val().split("\n");
|
||||
|
||||
var started = false;
|
||||
var ended = false;
|
||||
var lines_after_end = false;
|
||||
var lines_before_begin = false;
|
||||
var token_fail = false;
|
||||
var token_get_post = false;
|
||||
var token_check = true;
|
||||
var str_token_fail = '';
|
||||
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
if (lines[i].match(/^\s*$/)) {
|
||||
// Empty line
|
||||
continue;
|
||||
} else if (!started) {
|
||||
if (lines[i].match(/^task_begin\s*$/)) {
|
||||
started = true;
|
||||
} else {
|
||||
// Found a not empty line before task_begin
|
||||
lines_before_begin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lines[i].match(/^task_end\s*$/)) {
|
||||
ended = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check token is correct
|
||||
if (!lines[i].match(/^([\s])*[#]/)) {
|
||||
|
||||
var token = lines[i].match(/^([^\s]+)\s*/);
|
||||
|
||||
if (typeof(token) == 'object') {
|
||||
token = token[1];
|
||||
|
||||
if ((!token_get_post) && (token == 'get' || token == 'post' || token == 'header')) {
|
||||
token_get_post = true;
|
||||
continue;
|
||||
}
|
||||
if (token == 'check_string') {
|
||||
if (token_get_post) {
|
||||
token_check = true;
|
||||
continue;
|
||||
} else {
|
||||
token_check = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($.inArray(token, supported_tokens) == -1) {
|
||||
token_fail = true;
|
||||
str_token_fail = token;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var msg_error = '';
|
||||
|
||||
if (token_fail) {
|
||||
var temp_msg = $("#unknown_token").html();
|
||||
temp_msg = temp_msg.replace(/['](.*)[']/, "'" + str_token_fail + "'");
|
||||
|
||||
$("#unknown_token").html(temp_msg);
|
||||
|
||||
msg_error = 'unknown_token';
|
||||
} else if (lines_before_begin) {
|
||||
msg_error = 'lines_before_begin';
|
||||
} else if (!started) {
|
||||
msg_error = 'missed_begin';
|
||||
} else if (!ended) {
|
||||
msg_error = 'missed_end';
|
||||
} else if (lines_after_end) {
|
||||
msg_error = 'lines_after_end';
|
||||
} else if (!token_check) {
|
||||
msg_error = 'missed_get_post';
|
||||
} else {
|
||||
msg_error = 'correct';
|
||||
}
|
||||
|
||||
|
||||
if (msg_error == 'correct') {
|
||||
$('#check_conf_suc').find('img').eq(0)
|
||||
.attr('title', $('#' + msg_error).html());
|
||||
|
||||
$('#check_conf_err').hide();
|
||||
$('#check_conf_suc').show();
|
||||
} else {
|
||||
$('#check_conf_err').find('img').eq(0)
|
||||
.attr('title', $('#' + msg_error).html());
|
||||
|
||||
$('#check_conf_suc').hide();
|
||||
$('#check_conf_err').show();
|
||||
}
|
||||
});
|
||||
|
||||
$(plugin_parameter).trigger('keyup');
|
||||
|
||||
http_auth_user.keyup(function() {
|
||||
config = plugin_parameter.val();
|
||||
if (config.search("http_auth_user") == -1) {
|
||||
var http_auth_user_end =
|
||||
"http_auth_user " + this.value + "\n" + "task_end" + "\n";
|
||||
plugin_parameter.val(config.replace(/^task_end.*$/m, http_auth_user_end));
|
||||
} else {
|
||||
plugin_parameter.val(
|
||||
config.replace(/^http_auth_user.*$/m, "http_auth_user " + this.value)
|
||||
);
|
||||
// Hide success and error indicators
|
||||
$(".checks").hide();
|
||||
}
|
||||
});
|
||||
|
||||
http_auth_pass.keyup(function() {
|
||||
config = plugin_parameter.val();
|
||||
if (config.search("http_auth_pass") == -1) {
|
||||
var http_auth_pass_end =
|
||||
"http_auth_pass " + this.value + "\n" + "task_end" + "\n";
|
||||
plugin_parameter.val(config.replace(/^task_end.*$/m, http_auth_pass_end));
|
||||
} else {
|
||||
plugin_parameter.val(
|
||||
config.replace(/^http_auth_pass.*$/m, "http_auth_pass " + this.value)
|
||||
);
|
||||
// Hide success and error indicators
|
||||
$(".checks").hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function get_module_token_from_config(token_name, plugin_parameter, separator) {
|
||||
var return_var = "";
|
||||
if(token_name == null || token_name == '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
data = plugin_parameter.val().split(separator);
|
||||
len = data.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (data[i][0] == "#") continue;
|
||||
tokens = data[i].split(" ");
|
||||
if (tokens.length == 0) continue;
|
||||
token = tokens.shift();
|
||||
if (token == token_name ) return_var = tokens.join(" ");
|
||||
}
|
||||
|
||||
return_var = $.trim(return_var);
|
||||
|
||||
return return_var;
|
||||
}
|
||||
|
||||
</script>
|
74
pandora_console/include/ajax/web_server_module_debug.php
Normal file
74
pandora_console/include/ajax/web_server_module_debug.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Web Server Module Debug ajax controller.
|
||||
*
|
||||
* @category Web Server Module Debug
|
||||
* @package Pandora FMS
|
||||
* @subpackage Module Debug
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
global $id_agent_module;
|
||||
// Module Debug Class.
|
||||
require_once $config['homedir'].'/include/class/WebServerModuleDebug.class.php';
|
||||
|
||||
// This page.
|
||||
$ajaxPage = '/include/ajax/web_server_module_debug';
|
||||
|
||||
// Control call flow for debug window.
|
||||
try {
|
||||
// Return of id of the agent module in AJAX.
|
||||
if (is_ajax()) {
|
||||
$id_agent_module = get_parameter('idAgentModule');
|
||||
}
|
||||
|
||||
// User access and validation is being processed on class constructor.
|
||||
$obj = new WebServerModuleDebug($ajaxPage, $id_agent_module);
|
||||
} catch (Exception $e) {
|
||||
if (is_ajax()) {
|
||||
echo json_encode(['error' => '[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();
|
||||
}
|
407
pandora_console/include/class/WebServerModuleDebug.class.php
Normal file
407
pandora_console/include/class/WebServerModuleDebug.class.php
Normal file
@ -0,0 +1,407 @@
|
||||
<?php
|
||||
/**
|
||||
* WebServer Module debug feature.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Web Server Module
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2020 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/godmode/wizards/Wizard.main.php';
|
||||
|
||||
/**
|
||||
* Class WebServerModuleDebug.
|
||||
*/
|
||||
class WebServerModuleDebug extends Wizard
|
||||
{
|
||||
|
||||
/**
|
||||
* Controller Url.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $ajaxController;
|
||||
|
||||
/**
|
||||
* Timeout for HTTP requests.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $requestTimeout;
|
||||
|
||||
/**
|
||||
* CURL Query.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $query;
|
||||
|
||||
/**
|
||||
* Id of the current module.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $idAgentModule;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $ajaxController Ajax Page Controller.
|
||||
* @param integer $idAgentModule Id of the module.
|
||||
*/
|
||||
public function __construct(string $ajaxController, int $idAgentModule)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// Check access.
|
||||
check_login();
|
||||
|
||||
if (! check_acl($config['id_user'], 0, 'AR')) {
|
||||
db_pandora_audit(
|
||||
'ACL Violation',
|
||||
'Trying to access event viewer'
|
||||
);
|
||||
|
||||
if (is_ajax()) {
|
||||
echo json_encode(['error' => '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),
|
||||
]
|
||||
);
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
// Query section
|
||||
var query = ace.edit("webserverdebug_editor");
|
||||
let queryDefined = "<?php echo $this->defineQuery(); ?>";
|
||||
let queryRegex = /([-]+[a-zA-Z]\s)|(([-]{2})+[a-z]+[-]*[a-z]*)/g;
|
||||
query.setValue(queryDefined.replace(queryRegex, "\n$&"));
|
||||
query.clearSelection();
|
||||
// Result section
|
||||
var results = ace.edit("webserverdebug_view");
|
||||
var text = '';
|
||||
results.setTheme("ace/theme/textmate");
|
||||
results.session.setMode("ace/mode/json");
|
||||
results.renderer.setShowGutter(false);
|
||||
results.setReadOnly(true);
|
||||
results.setShowPrintMargin(false);
|
||||
|
||||
$("#submit-execute_query").click(function() {
|
||||
// Show the spinner.
|
||||
showSpinner(true);
|
||||
// Empty the results container.
|
||||
results.setValue("");
|
||||
// Get the entire text.
|
||||
text = query.getValue();
|
||||
// There are not values in the query section.
|
||||
if (text === null || text === undefined) {
|
||||
results.setValue('<?php echo __('No results'); ?>');
|
||||
results.clearSelection();
|
||||
// Hide spinner.
|
||||
showSpinner(false);
|
||||
return;
|
||||
}
|
||||
// Clean the carriage jumps.
|
||||
text = text.split("\n").join("");
|
||||
// Call to the method for execute the command.
|
||||
$.ajax({
|
||||
method: "post",
|
||||
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||
data: {
|
||||
page: "<?php echo $this->ajaxController; ?>",
|
||||
method: "executeCommand",
|
||||
text: text,
|
||||
idAgentModule: "<?php echo $this->idAgentModule; ?>",
|
||||
},
|
||||
datatype: "json",
|
||||
success: function(result) {
|
||||
results.setValue(result);
|
||||
},
|
||||
error: function(e) {
|
||||
results.setValue('<?php echo __('Error performing execution'); ?>');
|
||||
},
|
||||
complete: function() {
|
||||
results.clearSelection();
|
||||
showSpinner(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Definition of the query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function defineQuery()
|
||||
{
|
||||
// Get the value of the debug_content.
|
||||
$outputDebugQuery = db_get_value_filter(
|
||||
'debug_content',
|
||||
'tagente_modulo',
|
||||
[
|
||||
'id_agente_modulo' => $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();
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#button-btn_debugModule').click(function() {
|
||||
load_modal({
|
||||
target: $("#modal"),
|
||||
form: "add_module_form",
|
||||
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||
ajax_callback: showMsg,
|
||||
modal: {
|
||||
title: "<?php echo __('Debug'); ?>",
|
||||
},
|
||||
extradata: [
|
||||
{
|
||||
name: "idAgentModule",
|
||||
value: "<?php echo $this->idAgentModule; ?>"
|
||||
}],
|
||||
onshow: {
|
||||
page: "<?php echo $this->ajaxController; ?>",
|
||||
width: 800,
|
||||
method: "showWebServerDebug"
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggle the visibility of spinner.
|
||||
*/
|
||||
function showSpinner(setVisibility) {
|
||||
var spinner = $('#WebServerDebugSpinner');
|
||||
if (setVisibility) {
|
||||
spinner.css('visibility', 'visible');
|
||||
} else {
|
||||
spinner.css('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process ajax responses and shows a dialog with results.
|
||||
*/
|
||||
function showMsg(data) {
|
||||
var title = "<?php echo __('Success'); ?>";
|
||||
var text = "";
|
||||
var failed = 0;
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
text = data["result"];
|
||||
} catch (err) {
|
||||
title = "<?php echo __('Failed'); ?>";
|
||||
text = err.message;
|
||||
failed = 1;
|
||||
}
|
||||
if (!failed && data["error"] != undefined) {
|
||||
title = "<?php echo __('Failed'); ?>";
|
||||
text = data["error"];
|
||||
failed = 1;
|
||||
}
|
||||
if (data["report"] != undefined) {
|
||||
data["report"].forEach(function(item) {
|
||||
text += "<br>" + item;
|
||||
});
|
||||
}
|
||||
|
||||
$("#msg").empty();
|
||||
$("#msg").html(text);
|
||||
$("#msg").dialog({
|
||||
width: 450,
|
||||
position: {
|
||||
my: "center",
|
||||
at: "center",
|
||||
of: window,
|
||||
collision: "fit"
|
||||
},
|
||||
title: title
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<?php
|
||||
// Get the JS script.
|
||||
$str = ob_get_clean();
|
||||
// Return the loaded JS.
|
||||
echo $str;
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
}
|
10
pandora_console/include/styles/WebServerModuleDebug.css
Normal file
10
pandora_console/include/styles/WebServerModuleDebug.css
Normal file
@ -0,0 +1,10 @@
|
||||
/* Web Server Module Debug Specific CSS file */
|
||||
.query_result_editor,
|
||||
.query_result_view {
|
||||
min-height: 45em;
|
||||
height: 45em;
|
||||
}
|
||||
|
||||
#query_result_container {
|
||||
margin-top: 30px;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user