diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 485425ec62..add3ab4019 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -532,6 +532,54 @@ echo sprintf('
', $menuTypeClass); element.style.display = "none" } + function notifications_clean_all() { + let wrapper_inner = document.getElementById('notification-wrapper-inner'); + while (wrapper_inner.firstChild) { + wrapper_inner.removeChild(wrapper_inner.firstChild); + } + } + + function mark_all_notification_as_read() { + jQuery.post ("ajax.php", + { + "page" : "godmode/setup/setup_notifications", + "mark_all_notification_as_read" : 1 + }, + function (data, status) { + notifications_clean_all(); + location.reload(); + }, + "json" + ) + .fail(function(xhr, textStatus, errorThrown){ + console.error( + "Failed to mark al notification as read. Error: ", + xhr.responseText + ); + }); + } + + function filter_notification() { + let notification_type = ''; + $('.notification-item').hide(); + $(".checkbox_filter_notifications:checkbox:checked").each(function() { + notification_type = $(this).val(); + console.log(notification_type); + $('.notification-item[value='+notification_type+']').show(); + if (notification_type == 'All'){ + $('.notification-item').show(); + } + }); + + if (notification_type == 'All'){ + $('.notification-item').show(); + } + + if (notification_type == ''){ + $('.notification-item').hide(); + } + } + function click_on_notification_toast(event) { var match = /notification-(.*)-id-([0-9]+)/.exec(event.target.id); if (!match) { diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 6aaaabf032..f2289a7cc3 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -187,6 +187,27 @@ if (get_parameter('mark_notification_as_read', 0)) { return; } +if (get_parameter('mark_all_notification_as_read', 0)) { + $unread_messages = db_get_all_rows_sql('SELECT id_mensaje FROM tnotification_user WHERE utimestamp_read is NULL'); + + if ($unread_messages !== false) { + foreach ($unread_messages as $messages) { + messages_process_read($messages['id_mensaje']); + } + + $result = true; + } else { + $result = false; + } + + // If there is new messages, get the info. + echo json_encode( + ['result' => $result] + ); + + return; +} + if (get_parameter('get_notifications_dropdown', 0)) { echo notifications_print_dropdown(); return; diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 2e839958cb..f6d3767708 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -169,6 +169,7 @@ class ConsoleSupervisor * NOTIF.PHP.DISABLE_FUNCTIONS * NOTIF.PHP.CHROMIUM * NOTIF.PHP.VERSION + * NOTIF.PHP.VERSION.SUPPORT */ $this->checkPHPSettings(); @@ -383,6 +384,7 @@ class ConsoleSupervisor * NOTIF.PHP.DISABLE_FUNCTIONS * NOTIF.PHP.CHROMIUM * NOTIF.PHP.VERSION + * NOTIF.PHP.VERSION.SUPPORT */ $this->checkPHPSettings(); @@ -874,6 +876,7 @@ class ConsoleSupervisor case 'NOTIF.PHP.DISABLE_FUNCTIONS': case 'NOTIF.PHP.CHROMIUM': case 'NOTIF.PHP.VERSION': + case 'NOTIF.PHP.VERSION.SUPPORT': case 'NOTIF.HISTORYDB': case 'NOTIF.PANDORADB': case 'NOTIF.PANDORADB.HISTORICAL': @@ -1830,14 +1833,14 @@ class ConsoleSupervisor $url = 'https://www.php.net/supported-versions.php'; $this->notify( [ - 'type' => 'NOTIF.PHP.VERSION', + 'type' => 'NOTIF.PHP.VERSION.SUPPORT', 'title' => __('PHP UPDATE REQUIRED'), 'message' => __('You should update your PHP version because it will be out of official support').'
'.__('Current PHP version: ').PHP_VERSION, 'url' => $url, ] ); } else { - $this->cleanNotifications('NOTIF.PHP.VERSION'); + $this->cleanNotifications('NOTIF.PHP.VERSION.SUPPORT'); } } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 0d74ec9005..ae37cb616a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2904,6 +2904,8 @@ function html_print_anchor( $output .= '>'; + $output .= (isset($options['text']) === true) ? $options['text'] : ''; + $output .= (isset($options['content']) === true) ? io_safe_input_html($options['content']) : ''; $output .= ''; @@ -7118,6 +7120,7 @@ function html_print_menu_button(array $options, bool $return=false) 'class' => ($options['class'] ?? ''), 'style' => ($options['style'] ?? ''), 'onClick' => ($options['onClick'] ?? ''), + 'text' => ($options['text'] ?? ''), 'content' => $content, ], $return diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index e3d16f13e7..60a8e6bce0 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -136,6 +136,7 @@ function notifications_get_subtypes(?string $source=null) 'NOTIF.PHP.DISABLE_FUNCTIONS', 'NOTIF.PHP.CHROMIUM', 'NOTIF.PHP.VERSION', + 'NOTIF.PHP.VERSION.SUPPORT', 'NOTIF.HISTORYDB', 'NOTIF.PANDORADB', 'NOTIF.PANDORADB.HISTORICAL', @@ -1010,6 +1011,106 @@ function notifications_print_user_switch($source, $user, $label) } +/** + * Generates an HTML of notification filter types. + * + * @return string HTML filter notification. + */ +function notification_filter() +{ + $types_list[] = 'All'; + $notification_types = db_get_all_rows_sql('SELECT DISTINCT tm.subtype FROM tmensajes as tm INNER JOIN tnotification_user as tnu ON tm.id_mensaje = tnu.id_mensaje WHERE tnu.utimestamp_read IS NULL'); + if ($notification_types !== false) { + foreach ($notification_types as $notification_type) { + $type = explode('.', $notification_type['subtype'])[1]; + $types_list[] = $type; + } + } + + $types_list = array_unique($types_list); + $notification_filter = "'; + return $notification_filter; +} + + /** * Generates the dropdown notifications menu. * @@ -1022,9 +1123,24 @@ function notifications_print_dropdown() $mess = []; } + $notification_menu = html_print_menu_button( + [ + 'href' => 'javascript:', + 'class' => 'notification_menu_actions', + 'text' => __('Mark all as read'), + 'onClick' => 'mark_all_notification_as_read()', + ], + true + ); + $notification_filter = notification_filter(); + return sprintf( "
+
+ + +
%s
@@ -1034,6 +1150,8 @@ function notifications_print_dropdown() >
", + $notification_filter, + $notification_menu, array_reduce( $mess, function ($carry, $message) { @@ -1093,6 +1211,8 @@ function notifications_print_dropdown_element($message_info) $message_info['subject'] = io_safe_input($img); } + $type = explode('.', $message_info['subtype'])[1]; + if (strlen($body_preview) >= 170) { $body_preview = substr($body_preview, 0, 150); $body_preview .= __('. Read More...'); @@ -1103,6 +1223,7 @@ function notifications_print_dropdown_element($message_info) class='notification-item' onclick='%s' id='notification-item-id-%s' + value='%s' href='%s' target='%s' > @@ -1116,8 +1237,9 @@ function notifications_print_dropdown_element($message_info)

", - $action.';click_on_notification_toast(event)', + $action.'; click_on_notification_toast(event)', $message_info['id_mensaje'], + $type, messages_get_url($message_info['id_mensaje']), $target, html_print_image('images/info.svg', true, ['style' => 'height: 40px;margin-left: -20px;margin-top: -40px;']), diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 007b2f315d..1d50c8ae0f 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -12358,6 +12358,59 @@ tr[id^="network_component-plugin-snmp-fields-dynamicMacroRow-"] input { width: 100% !important; } +.notificaion_menu_container { + display: flex; + padding-top: 10px; + padding-left: 15px; +} +.notification_menu { + width: 100px; +} + +.filter_notification { + width: auto; + min-width: 50px; +} + +#menu-filter_notification * { + list-style: none; +} +#menu-filter_notification li { + line-height: 180%; +} +#menu-filter_notification input[name="filter_menu"] { + position: absolute; + left: -1000em; +} +#menu-filter_notification label[id="filter_menu_label"]:before { + content: "\025b8"; + margin-right: 4px; +} +#menu-filter_notification + input[name="filter_menu"]:checked + ~ label[id="filter_menu_label"]:before { + content: "\025be"; +} +#menu-filter_notification .sublevel-filter_notification { + display: none; +} +#menu-filter_notification input[name="filter_menu"]:checked ~ ul { + display: block; +} + +.item-filter > label { + display: inline-block; + width: auto; + vertical-align: middle; +} + +.item-filter > input[type="checkbox"] { + display: inline-block; + width: 40px; + height: 100%; + vertical-align: middle; +} + /*Horizontal tree*/ .horizontal_tree-icon { diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index d331c7986d..2703f65113 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -2058,6 +2058,8 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist#' ); + $notification->{'subtype'} .= safe_input('NOTIF.DISCOVERYTASK.REVIEW'); + $notification->{'mensaje'} = safe_input( 'Discovery task (host&devices) \''.safe_output($self->{'task_data'}{'name'}) .'\' has been completed. Please review the results.'