From 5b3dfcbf742162b02714355202ad3b318bddae3d Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 3 May 2019 13:46:52 +0200 Subject: [PATCH 1/3] add feature to enable obfuscation on command fields when creating or updating commands Former-commit-id: ac5a1fb86e7e690bccc9c4f672678781acd1414d --- pandora_console/extras/mr/28.sql | 5 ++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 1 + .../godmode/alerts/alert_commands.php | 17 +++++-- .../alerts/configure_alert_command.php | 47 ++++++++++++++++++- .../include/javascript/pandora_alerts.js | 8 +++- pandora_console/pandoradb.sql | 1 + 6 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 pandora_console/extras/mr/28.sql diff --git a/pandora_console/extras/mr/28.sql b/pandora_console/extras/mr/28.sql new file mode 100644 index 0000000000..8b87a52375 --- /dev/null +++ b/pandora_console/extras/mr/28.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `talert_commands` ADD COLUMN `fields_hidden` text; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 4cdb88ac30..c8324692e6 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -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; diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index e8378d1fc0..25eca072fe 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -63,6 +63,8 @@ if (is_ajax()) { $fields_descriptions = empty($command['fields_descriptions']) ? '' : json_decode(io_safe_output($command['fields_descriptions']), true); // 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,6 +74,8 @@ 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 @@ -107,6 +111,8 @@ 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 @@ -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,7 +233,7 @@ if (is_ajax()) { 1, 1, '', - 'style="min-height:40px" class="fields_recovery"', + 'style="min-height:40px; '.$style.'" class="fields_recovery"', true ); } @@ -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; diff --git a/pandora_console/godmode/alerts/configure_alert_command.php b/pandora_console/godmode/alerts/configure_alert_command.php index 7482c21f63..5e07d1dc56 100644 --- a/pandora_console/godmode/alerts/configure_alert_command.php +++ b/pandora_console/godmode/alerts/configure_alert_command.php @@ -64,16 +64,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; @@ -117,6 +120,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)) { @@ -127,6 +131,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'; @@ -141,6 +149,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 = []; @@ -189,7 +198,7 @@ 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); @@ -204,7 +213,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 '
'; @@ -224,3 +243,27 @@ echo ''; echo '
'; enterprise_hook('close_meta_frame'); +?> + + diff --git a/pandora_console/include/javascript/pandora_alerts.js b/pandora_console/include/javascript/pandora_alerts.js index 41f8d20ad8..1c72d13cf3 100644 --- a/pandora_console/include/javascript/pandora_alerts.js +++ b/pandora_console/include/javascript/pandora_alerts.js @@ -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++; }); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b0aaa7ff2d..97db7b4098 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -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; From 7d8f9f7798d1591e1a26756db68a1f5c8274c435 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 3 May 2019 13:54:39 +0200 Subject: [PATCH 2/3] fix lint errors Former-commit-id: fc0a4502e571495b5ac17174a594aa767e882b21 --- .../godmode/alerts/alert_commands.php | 38 +++++++++---------- .../alerts/configure_alert_command.php | 8 ++-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 25eca072fe..2f8fb2dc04 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -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,11 +59,11 @@ if (is_ajax()) { $command['description'] = io_safe_input(str_replace("\r\n", '
', 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 conditions are stored in json. $fields_hidden_checked = empty($command['fields_hidden']) ? '' : io_safe_output(json_decode($command['fields_hidden'], true)); $fields_rows = []; @@ -78,16 +78,16 @@ if (is_ajax()) { 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.'
'.sprintf(__('Field %s'), ($i - 1)).''; } else { $fdesc = $field_description.'
'.sprintf(__('Field %s'), $i).''; } - // 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 { @@ -95,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)); @@ -115,7 +115,7 @@ if (is_ajax()) { 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 = '
'; $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:
'), true);
@@ -154,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 .= '
'; $rfield = $editor_type_chkbx; - // Select type + // Select type. } else { $fields_value_select = []; $fv = explode(';', $field_value); @@ -239,7 +239,7 @@ if (is_ajax()) { } - // The empty descriptions will be ignored + // The empty descriptions will be ignored. if ($fdesc == '') { $fields_rows[$i] = ''; } else { @@ -254,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] = ''; } @@ -274,7 +274,7 @@ if ($update_command) { return; } -// Header +// Header. if (defined('METACONSOLE')) { alerts_meta_print_header(); } else { @@ -325,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'); } @@ -349,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', @@ -377,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'), diff --git a/pandora_console/godmode/alerts/configure_alert_command.php b/pandora_console/godmode/alerts/configure_alert_command.php index 5e07d1dc56..a64b45c7ba 100644 --- a/pandora_console/godmode/alerts/configure_alert_command.php +++ b/pandora_console/godmode/alerts/configure_alert_command.php @@ -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'; @@ -34,7 +34,7 @@ $update_command = (bool) get_parameter('update_command'); $id = (int) get_parameter('id'); $pure = get_parameter('pure', 0); -// Header +// Header. if (defined('METACONSOLE')) { alerts_meta_print_header(); } else { @@ -187,7 +187,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); } @@ -202,7 +202,7 @@ for ($i = 1; $i <= $config['max_macro_fields']; $i++) { $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); } From 9bc5a2d346a2528ffb9738dd4da7f32c857b9810 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 8 May 2019 14:17:40 +0200 Subject: [PATCH 3/3] IPAM vlan wizard ExtremeXOS --- pandora_console/include/functions.php | 37 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 0b9f71221b..a366abe7a6 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -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; }