Merge branch 'develop' of brutus.artica.lan:artica/pandorafms into develop

Former-commit-id: 1addcf3afd8ef2b4376f7b888ea10e1e5735deb7
This commit is contained in:
manuel 2019-05-14 11:46:39 +02:00
commit 421e6b559d
7 changed files with 113 additions and 45 deletions

View File

@ -1,5 +1,6 @@
START TRANSACTION;
START TRANSACTION;
ALTER TABLE `talert_commands` ADD COLUMN `fields_hidden` text;
ALTER TABLE `talert_templates` MODIFY COLUMN `type` ENUM('regex','max_min','max','min','equal','not_equal','warning','critical','onchange','unknown','always','not_normal');

View File

@ -1197,6 +1197,7 @@ ALTER TABLE talert_actions ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT "
UPDATE `talert_commands` SET `fields_descriptions` = '[\"Integria IMS API path\",\"Integria IMS API pass\",\"Integria IMS user\",\"Integria IMS user pass\",\"Ticket title\",\"Ticket group ID\",\"Ticket priority\",\"Email copy\",\"Ticket owner\",\"Ticket description\"]', `fields_values` = '[\"\",\"\",\"\",\"\",\"\",\"\",\"10,Maintenance;0,Informative;1,Low;2,Medium;3,Serious;4,Very Serious\",\"\",\"\",\"\"]' WHERE `id` = 11 AND `name` = 'Integria IMS Ticket';
UPDATE `talert_commands` SET `description` = 'This alert send an email using internal Pandora FMS Server SMTP capabilities (defined in each server, using:
_field1_ as destination email address, and
_field2_ as subject for message. 
_field3_ as text of message. 
_field4_ as content type (text/plain or html/text).', `fields_descriptions` = '[\"Destination address\",\"Subject\",\"Text\",\"Content Type\",\"\",\"\",\"\",\"\",\"\",\"\"]', `fields_values` = '[\"\",\"\",\"_html_editor_\",\"_content_type_\",\"\",\"\",\"\",\"\",\"\",\"\"]' WHERE id=1;
ALTER TABLE `talert_commands` ADD COLUMN `id_group` mediumint(8) unsigned NULL default 0;
ALTER TABLE `talert_commands` ADD COLUMN `fields_hidden` text;
UPDATE `talert_actions` SET `field4` = 'text/html', `field4_recovery` = 'text/html' WHERE id = 1;

View File

@ -11,7 +11,7 @@
// 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.
// Load global vars
// Load global vars.
global $config;
require_once $config['homedir'].'/include/functions_alerts.php';
@ -46,7 +46,7 @@ if (is_ajax()) {
$id = (int) get_parameter('id', 0);
$get_recovery_fields = (int) get_parameter('get_recovery_fields', 1);
// If command ID is not provided, check for action id
// If command ID is not provided, check for action id.
if ($id == 0) {
$id_action = (int) get_parameter('id_action');
$id = alerts_get_alert_action_alert_command_id($id_action);
@ -59,10 +59,12 @@ if (is_ajax()) {
$command['description'] = io_safe_input(str_replace("\r\n", '<br>', io_safe_output($command['description'])));
}
// Descriptions are stored in json
// Descriptions are stored in json.
$fields_descriptions = empty($command['fields_descriptions']) ? '' : json_decode(io_safe_output($command['fields_descriptions']), true);
// Fields values are stored in json
// Fields values are stored in json.
$fields_values = empty($command['fields_values']) ? '' : io_safe_output(json_decode($command['fields_values'], true));
// Fields hidden conditions are stored in json.
$fields_hidden_checked = empty($command['fields_hidden']) ? '' : io_safe_output(json_decode($command['fields_hidden'], true));
$fields_rows = [];
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
@ -72,18 +74,20 @@ if (is_ajax()) {
$field_description = $fields_descriptions[($i - 1)];
$field_value = $fields_values[($i - 1)];
$field_hidden = $fields_hidden_checked[($i - 1)];
if (!empty($field_description)) {
// If the value is 5, this because severity in snmp alerts is not permit to show
// If the value is 5, this because severity in snmp alerts is not permit to show.
if (($i > 5) && ($command['id'] == 3)) {
$fdesc = $field_description.' <br><span style="font-size:xx-small; font-weight:normal;">'.sprintf(__('Field %s'), ($i - 1)).'</span>';
} else {
$fdesc = $field_description.' <br><span style="font-size:xx-small; font-weight:normal;">'.sprintf(__('Field %s'), $i).'</span>';
}
// If the field is the number one, print the help message
// If the field is the number one, print the help message.
if ($i == 1) {
// If our context is snmpconsole, show snmp_alert helps
// If our context is snmpconsole, show snmp_alert helps.
if ((isset($_SERVER['HTTP_REFERER'])) && ( preg_match('/snmp_alert/', $_SERVER['HTTP_REFERER']) > 0 )) {
$fdesc .= ui_print_help_icon('snmp_alert_field1', true);
} else {
@ -91,7 +95,7 @@ if (is_ajax()) {
}
}
} else {
// If the macro hasn't description and doesnt appear in command, set with empty description to dont show it
// If the macro hasn't description and doesnt appear in command, set with empty description to dont show it.
if (($i > 5) && ($command['id'] == 3)) {
if (substr_count($command['command'], '_field'.($i - 1).'_') > 0) {
$fdesc = sprintf(__('Field %s'), ($i - 1));
@ -107,9 +111,11 @@ if (is_ajax()) {
}
}
$style = ((int) $field_hidden === 1) ? '-webkit-text-security: disc;' : '';
if (!empty($field_value)) {
$field_value = io_safe_output($field_value);
// HTML type
// HTML type.
if (preg_match('/^_html_editor_$/i', $field_value)) {
$editor_type_chkbx = '<div style="padding: 4px 0px;"><b><small>';
$editor_type_chkbx .= __('Basic').ui_print_help_tip(__('For sending emails, text must be HTML format, if you want to use plain text, type it between the following labels: <pre></pre>'), true);
@ -148,7 +154,7 @@ if (is_ajax()) {
$editor_type_chkbx .= html_print_radio_button_extended('field'.$i.'_recovery_value', 'text/html', '', 'text/html', false, '', '', true);
$editor_type_chkbx .= '</small></b></div>';
$rfield = $editor_type_chkbx;
// Select type
// Select type.
} else {
$fields_value_select = [];
$fv = explode(';', $field_value);
@ -200,7 +206,7 @@ if (is_ajax()) {
1,
1,
$fv[0],
'style="min-height:40px" class="fields"',
'style="min-height:40px; '.$style.'" class="fields"',
true
);
$rfield = html_print_textarea(
@ -208,7 +214,7 @@ if (is_ajax()) {
1,
1,
$fv[0],
'style="min-height:40px" class="fields_recovery"',
'style="min-height:40px; '.$style.'" class="fields_recovery',
true
);
}
@ -219,7 +225,7 @@ if (is_ajax()) {
1,
1,
'',
'style="min-height:40px" class="fields"',
'style="min-height:40px; '.$style.'" class="fields"',
true
);
$rfield = html_print_textarea(
@ -227,13 +233,13 @@ if (is_ajax()) {
1,
1,
'',
'style="min-height:40px" class="fields_recovery"',
'style="min-height:40px; '.$style.'" class="fields_recovery"',
true
);
}
// The empty descriptions will be ignored
// The empty descriptions will be ignored.
if ($fdesc == '') {
$fields_rows[$i] = '';
} else {
@ -248,7 +254,7 @@ if (is_ajax()) {
}
}
// If command is PandoraFMS event, field 5 must be empty because "severity" must be set by the alert
// If command is PandoraFMS event, field 5 must be empty because "severity" must be set by the alert.
if ($command['id'] == 3) {
$fields_rows[5] = '';
}
@ -268,7 +274,7 @@ if ($update_command) {
return;
}
// Header
// Header.
if (defined('METACONSOLE')) {
alerts_meta_print_header();
} else {
@ -283,16 +289,19 @@ if ($create_command) {
$fields_descriptions = [];
$fields_values = [];
$fields_hidden = [];
$info_fields = '';
$values = [];
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
$fields_descriptions[] = (string) get_parameter('field'.$i.'_description');
$fields_values[] = (string) get_parameter('field'.$i.'_values');
$fields_hidden[] = get_parameter('field'.$i.'_hide');
$info_fields .= ' Field'.$i.': '.$fields_values[($i - 1)];
}
$values['fields_values'] = io_json_mb_encode($fields_values);
$values['fields_descriptions'] = io_json_mb_encode($fields_descriptions);
$values['fields_hidden'] = io_json_mb_encode($fields_hidden);
$values['description'] = $description;
$values['id_group'] = $id_group;
@ -316,7 +325,7 @@ if ($create_command) {
db_pandora_audit('Command management', 'Fail try to create alert command', false, false);
}
// Show errors
// Show errors.
if (!isset($messageAction)) {
$messageAction = __('Could not be created');
}
@ -340,7 +349,7 @@ if ($create_command) {
if ($delete_command) {
$id = (int) get_parameter('id');
// Internal commands cannot be deleted
// Internal commands cannot be deleted.
if (alerts_get_alert_command_internal($id)) {
db_pandora_audit(
'ACL Violation',
@ -368,17 +377,17 @@ if ($delete_command) {
if ($copy_command) {
$id = (int) get_parameter('id');
// Get the info from the source command
// Get the info from the source command.
$command_to_copy = db_get_row('talert_commands', 'id', $id);
if ($command_to_copy === false) {
ui_print_error_message(__("Command with id $id does not found."));
} else {
// Prepare to insert the copy with same values
// Prepare to insert the copy with same values.
unset($command_to_copy['id']);
$command_to_copy['name'] .= __(' (copy)');
$result = db_process_sql_insert('talert_commands', $command_to_copy);
// Print the result
// Print the result.
ui_print_result_message(
$result,
__('Successfully copied'),

View File

@ -11,7 +11,7 @@
// 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.
// Load global vars
// Load global vars.
global $config;
require_once $config['homedir'].'/include/functions_alerts.php';
@ -35,7 +35,7 @@ $id = (int) get_parameter('id');
$pure = get_parameter('pure', 0);
$alert = [];
// Header
// Header.
if (defined('METACONSOLE')) {
alerts_meta_print_header();
} else {
@ -65,16 +65,19 @@ if ($update_command) {
$fields_descriptions = [];
$fields_values = [];
$fields_hidden = [];
$info_fields = '';
$values = [];
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
$fields_descriptions[] = (string) get_parameter('field'.$i.'_description');
$fields_values[] = (string) get_parameter('field'.$i.'_values');
$fields_hidden[] = get_parameter('field'.$i.'_hide');
$info_fields .= ' Field'.$i.': '.$fields_values[($i - 1)];
}
$values['fields_values'] = io_json_mb_encode($fields_values);
$values['fields_descriptions'] = io_json_mb_encode($fields_descriptions);
$values['fields_hidden'] = io_json_mb_encode($fields_hidden);
$values['name'] = $name;
$values['command'] = $command;
@ -129,6 +132,7 @@ if ($id) {
$id_group = $alert['id_group'];
$fields_descriptions = $alert['fields_descriptions'];
$fields_values = $alert['fields_values'];
$fields_hidden = $alert['fields_hidden'];
}
if (!empty($fields_descriptions)) {
@ -139,6 +143,10 @@ if (!empty($fields_values)) {
$fields_values = json_decode($fields_values, true);
}
if (!empty($fields_hidden)) {
$fields_hidden = json_decode($fields_hidden, true);
}
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
@ -153,6 +161,7 @@ $table->style = [];
if (!defined('METACONSOLE')) {
$table->style[0] = 'font-weight: bold';
$table->style[2] = 'font-weight: bold';
$table->style[4] = 'font-weight: bold';
}
$table->size = [];
@ -190,7 +199,7 @@ $table->data['description'][1] = html_print_textarea('description', 10, 30, $des
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
$table->data['field'.$i][0] = sprintf(__('Field %s description'), $i);
// Only show help on first row
// Only show help on first row.
if ($i == 1) {
$table->data['field'.$i][0] .= ui_print_help_icon('alert_fields_description', true);
}
@ -201,11 +210,11 @@ for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
$field_description = '';
}
$table->data['field'.$i][1] = html_print_input_text('field'.$i.'_description', $field_description, '', 35, 255, true);
$table->data['field'.$i][1] = html_print_input_text('field'.$i.'_description', $field_description, '', 30, 255, true);
$table->data['field'.$i][2] = sprintf(__('Field %s values'), $i);
// Only show help on first row
// Only show help on first row.
if ($i == 1) {
$table->data['field'.$i][2] .= ui_print_help_icon('alert_fields_values', true);
}
@ -216,7 +225,17 @@ for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
$field_values = '';
}
$table->data['field'.$i][3] = html_print_input_text('field'.$i.'_values', $field_values, '', 65, 255, true);
if (!empty($fields_hidden)) {
$selected = (bool) $fields_hidden[($i - 1)];
} else {
$selected = false;
}
$table->data['field'.$i][3] = html_print_input_text('field'.$i.'_values', $field_values, '', 55, 255, true, false, false, '', 'field_value');
$table->data['field'.$i][4] = __('Hide');
$table->data['field'.$i][5] = html_print_checkbox_extended('field'.$i.'_hide', 1, $selected, false, 'cursor: \'pointer\'', 'class="hide_inputs"', true);
}
echo '<form method="post" action="index.php?sec=galertas&sec2=godmode/alerts/alert_commands&pure='.$pure.'">';
@ -236,3 +255,27 @@ echo '</div>';
echo '</form>';
enterprise_hook('close_meta_frame');
?>
<script type="text/javascript">
$(document).ready (function () {
$(".hide_inputs").each(function(index) {
var $input_in_row = $(this).closest('tr').find('.field_value');
if($(this).is(':checked')) {
$input_in_row.prop('style', '-webkit-text-security: disc;');
} else {
$input_in_row.prop('style', '');
}
});
$(".hide_inputs").click(function() {
var $input_in_row = $(this).closest('tr').find('.field_value');
if($(this).is(':checked')) {
$input_in_row.prop('style', '-webkit-text-security: disc;');
} else {
$input_in_row.prop('style', '');
}
});
});
</script>

View File

@ -1762,16 +1762,22 @@ function array_key_to_offset($array, $key)
/**
* Make a snmpwalk and return it.
*
* @param string $ip_target The target address.
* @param string $snmp_version Version of the snmp: 1,2,2c or 3.
* @param string $snmp_community.
* @param string $snmp3_auth_user.
* @param string $snmp3_security_level.
* @param string $snmp3_auth_method.
* @param string $snmp3_auth_pass.
* @param string $snmp3_privacy_method.
* @param string $snmp3_privacy_pass.
* @param integer $quick_print 0 for all details, 1 for only value.
* @param string $ip_target The target address.
* @param string $snmp_version Version of the snmp: 1,2,2c or 3.
* @param string $snmp_community Snmp_community.
* @param string $snmp3_auth_user Snmp3_auth_user.
* @param string $snmp3_security_level Snmp3_security_level.
* @param string $snmp3_auth_method Snmp3_auth_method.
* @param string $snmp3_auth_pass Snmp3_auth_pass.
* @param string $snmp3_privacy_method Snmp3_privacy_method.
* @param string $snmp3_privacy_pass Snmp3_privacy_pass.
* @param integer $quick_print To get all details 0, 1: only value.
* @param string $base_oid Base_oid.
* @param string $snmp_port Snmp_port.
* @param integer $server_to_exec Server_to_exec.
* @param string $extra_arguments Extra_arguments.
* @param string $format Format to apply, for instance, to
* retrieve hex-dumps: --hexOutputLength.
*
* @return array SNMP result.
*/
@ -1789,7 +1795,8 @@ function get_snmpwalk(
$base_oid='',
$snmp_port='',
$server_to_exec=0,
$extra_arguments=''
$extra_arguments='',
$format='-Oa'
) {
global $config;
@ -1840,15 +1847,15 @@ function get_snmpwalk(
case '3':
switch ($snmp3_security_level) {
case 'authNoPriv':
$command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
$command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
break;
case 'noAuthNoPriv':
$command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
$command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
break;
default:
$command_str = $snmpwalk_bin.' -m ALL -Oa '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
$command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
break;
}
break;
@ -1857,7 +1864,7 @@ function get_snmpwalk(
case '2c':
case '1':
default:
$command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' -Oa -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
$command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
break;
}

View File

@ -19,8 +19,14 @@ function parse_alert_command(command, classs) {
var regex = new RegExp(field, "gi");
command = command.replace(regex, $(this).val());
if ($(this).css("-webkit-text-security") == "disc") {
var hidden_character = "*";
var hidden_string = hidden_character.repeat($(this).val().length);
command = command.replace(regex, hidden_string);
} else {
command = command.replace(regex, $(this).val());
}
nfield++;
});

View File

@ -378,6 +378,7 @@ CREATE TABLE IF NOT EXISTS `talert_commands` (
`internal` tinyint(1) default 0,
`fields_descriptions` TEXT,
`fields_values` TEXT,
`fields_hidden` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;