Rev 1000 | Rev 1006 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1000 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminNotifications extends OIDplusPagePluginAdmin { |
||
23 | |||
24 | public function init($html=true) { |
||
25 | } |
||
26 | |||
27 | public function gui($id, &$out, &$handled) { |
||
28 | $parts = explode('$',$id); |
||
29 | $id = $parts[0]; |
||
30 | |||
31 | if ($id == 'oidplus:notifications') { |
||
32 | $handled = true; |
||
33 | $ra_email = isset($parts[1]) ? $parts[1] : null/*no filter*/; |
||
34 | |||
35 | $out['title'] = _L('Notifications'); |
||
36 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
||
37 | |||
38 | if ($ra_email == 'admin') { |
||
39 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
40 | $out['icon'] = 'img/error.png'; |
||
41 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
||
42 | return; |
||
43 | } |
||
44 | } else if ($ra_email) { |
||
45 | if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
||
46 | $out['icon'] = 'img/error.png'; |
||
47 | $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>'; |
||
48 | return; |
||
49 | } |
||
50 | } else { |
||
51 | if ((OIDplus::authUtils()->raNumLoggedIn() == 0) && !OIDplus::authUtils()->isAdminLoggedIn()) { |
||
52 | $out['icon'] = 'img/error.png'; |
||
53 | $out['text'] = '<p>'._L('You need to <a %1>log in</a>.',OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
54 | return; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | $notifications_by_sev = array(); |
||
59 | |||
1005 | daniel-mar | 60 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1000 | daniel-mar | 61 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.8')) { |
62 | $notifications = $plugin->getNotifications($ra_email); |
||
63 | if ($notifications) { |
||
64 | foreach ($notifications as $notification) { |
||
65 | list($severity, $htmlMessage) = $notification; |
||
66 | |||
67 | // Same severities as the log plugin (also same CSS classes) |
||
68 | if ($severity == 'OK') $severity = 1; // (this makes no sense) |
||
69 | if ($severity == 'INFO') $severity = 2; |
||
70 | if ($severity == 'WARN') $severity = 3; |
||
71 | if ($severity == 'ERR') $severity = 4; |
||
72 | if ($severity == 'CRIT') $severity = 5; |
||
73 | |||
74 | if (!isset($notifications_by_sev[$severity])) $notifications_by_sev[$severity] = array(); |
||
75 | $notifications_by_sev[$severity][] = $htmlMessage; |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | if (count($notifications_by_sev) == 0) { |
||
82 | |||
83 | $out['text'] .= '<p><i>'._L('No notifications').'</i></p>'; |
||
84 | |||
85 | } else { |
||
86 | krsort($notifications_by_sev); |
||
87 | |||
88 | foreach ($notifications_by_sev as $severity => $htmlMessages) { |
||
89 | |||
90 | if ($severity == 1) $sev_hf = _L('OK'); |
||
91 | else if ($severity == 2) $sev_hf = _L('Informational'); |
||
92 | else if ($severity == 3) $sev_hf = _L('Warnings'); |
||
93 | else if ($severity == 4) $sev_hf = _L('Errors'); |
||
94 | else if ($severity == 5) $sev_hf = _L('Critical issues'); |
||
95 | else $sev_hf = _L('Severity %1', $severity-1); |
||
96 | |||
97 | $out['text'] .= '<h2><span class="severity_'.$severity.'">'.$sev_hf.'</span></h2>'; |
||
98 | foreach ($htmlMessages as $htmlMessage) { |
||
99 | $out['text'] .= '<p><span class="severity_'.$severity.'">'.$htmlMessage.'</span></p>'; |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | |||
106 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
107 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
108 | |||
109 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
||
110 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
||
111 | } else { |
||
112 | $tree_icon = null; // default icon (folder) |
||
113 | } |
||
114 | |||
115 | $json[] = array( |
||
116 | 'id' => 'oidplus:notifications$admin', |
||
117 | 'icon' => $tree_icon, |
||
118 | 'text' => _L('Notifications') |
||
119 | ); |
||
120 | |||
121 | return true; |
||
122 | } |
||
123 | |||
124 | public function tree_search($request) { |
||
125 | return false; |
||
126 | } |
||
127 | } |