<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class OIDplusPageAdminNotifications extends OIDplusPagePluginAdmin {
public function init($html=true) {
}
public function gui($id, &$out, &$handled) {
$id = $parts[0];
if ($id == 'oidplus:notifications') {
$handled = true;
$ra_email = isset($parts[1]) ?
$parts[1] : null/*no filter*/;
$out['title'] = _L('Notifications');
$out['icon'] = file_exists(__DIR__
.'/img/main_icon.png') ? OIDplus
::webpath(__DIR__
,OIDplus
::PATH_RELATIVE).'img/main_icon.png' : '';
if ($ra_email == 'admin') {
if (!OIDplus::authUtils()->isAdminLoggedIn()) {
$out['icon'] = 'img/error.png';
$out['text'] = '<p>'._L
('You need to <a %1>log in</a> as administrator.',OIDplus
::gui()->link('oidplus:login$admin')).'</p>';
return;
}
} else if ($ra_email) {
if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) {
$out['icon'] = 'img/error.png';
$out['text'] = '<p>'._L
('You need to <a %1>log in</a> as the requested RA %2.',OIDplus
::gui()->link('oidplus:login$ra$'.$ra_email),'<b>'.htmlentities($ra_email).'</b>').'</p>';
return;
}
} else {
if ((OIDplus::authUtils()->raNumLoggedIn() == 0) && !OIDplus::authUtils()->isAdminLoggedIn()) {
$out['icon'] = 'img/error.png';
$out['text'] = '<p>'._L
('You need to <a %1>log in</a>.',OIDplus
::gui()->link('oidplus:login')).'</p>';
return;
}
}
$notifications_by_sev = array();
foreach (OIDplus::getPagePlugins() as $plugin) {
if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.8')) {
$notifications = $plugin->getNotifications($ra_email);
if ($notifications) {
foreach ($notifications as $notification) {
list($severity, $htmlMessage) = $notification;
// Same severities as the log plugin (also same CSS classes)
if ($severity == 'OK') $severity = 1; // (this makes no sense)
if ($severity == 'INFO') $severity = 2;
if ($severity == 'WARN') $severity = 3;
if ($severity == 'ERR') $severity = 4;
if ($severity == 'CRIT') $severity = 5;
if (!isset($notifications_by_sev[$severity])) $notifications_by_sev[$severity] = array();
$notifications_by_sev[$severity][] = $htmlMessage;
}
}
}
}
if (count($notifications_by_sev) == 0) {
$out['text'] .= '<p><i>'._L('No notifications').'</i></p>';
} else {
krsort($notifications_by_sev);
foreach ($notifications_by_sev as $severity => $htmlMessages) {
if ($severity == 1) $sev_hf = _L('OK');
else if ($severity == 2) $sev_hf = _L('Informational');
else if ($severity == 3) $sev_hf = _L('Warnings');
else if ($severity == 4) $sev_hf = _L('Errors');
else if ($severity == 5) $sev_hf = _L('Critical issues');
else $sev_hf = _L('Severity %1', $severity-1);
$out['text'] .= '<h2><span class="severity_'.$severity.'">'.$sev_hf.'</span></h2>';
foreach ($htmlMessages as $htmlMessage) {
$out['text'] .= '<p><span class="severity_'.$severity.'">'.$htmlMessage.'</span></p>';
}
}
}
}
}
public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
$tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
} else {
$tree_icon = null; // default icon (folder)
}
'id' => 'oidplus:notifications$admin',
'icon' => $tree_icon,
'text' => _L('Notifications')
);
return true;
}
public function tree_search($request) {
return false;
}
}