Subversion Repositories oidplus

Rev

Rev 1086 | Rev 1131 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1086 Rev 1116
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageAdminNotifications extends OIDplusPagePluginAdmin {
26
class OIDplusPageAdminNotifications extends OIDplusPagePluginAdmin {
27
 
27
 
-
 
28
        /**
-
 
29
         * @param bool $html
-
 
30
         * @return void
-
 
31
         */
28
        public function init($html=true) {
32
        public function init(bool $html=true) {
29
        }
33
        }
30
 
34
 
-
 
35
        /**
-
 
36
         * @param string $id
-
 
37
         * @param array $out
-
 
38
         * @param bool $handled
-
 
39
         * @return void
-
 
40
         * @throws OIDplusException
-
 
41
         */
31
        public function gui($id, &$out, &$handled) {
42
        public function gui(string $id, array &$out, bool &$handled) {
32
                $parts = explode('$',$id);
43
                $parts = explode('$',$id);
33
                $id = $parts[0];
44
                $id = $parts[0];
34
 
45
 
35
                if ($id == 'oidplus:notifications') {
46
                if ($id == 'oidplus:notifications') {
36
                        $handled = true;
47
                        $handled = true;
Line 61... Line 72...
61
 
72
 
62
                        $notifications_by_sev = array();
73
                        $notifications_by_sev = array();
63
 
74
 
64
                        foreach (OIDplus::getAllPlugins() as $plugin) {
75
                        foreach (OIDplus::getAllPlugins() as $plugin) {
65
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.8')) {
76
                                if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.8')) {
66
                                        $notifications = $plugin->getNotifications($ra_email);
77
                                        $notifications = $plugin->getNotifications($ra_email); /** @phpstan-ignore-line */
67
                                        if ($notifications) {
78
                                        if ($notifications) {
68
                                                foreach ($notifications as $notification) {
79
                                                foreach ($notifications as $notification) {
69
                                                        list($severity, $htmlMessage) = $notification;
80
                                                        list($severity, $htmlMessage) = $notification;
70
 
81
 
71
                                                        // Same severities as the log plugin (also same CSS classes)
82
                                                        // Same severities as the log plugin (also same CSS classes)
Line 108... Line 119...
108
                                }
119
                                }
109
                        }
120
                        }
110
                }
121
                }
111
        }
122
        }
112
 
123
 
-
 
124
        /**
-
 
125
         * @param array $json
-
 
126
         * @param string|null $ra_email
-
 
127
         * @param bool $nonjs
-
 
128
         * @param string $req_goto
-
 
129
         * @return bool
-
 
130
         * @throws OIDplusException
-
 
131
         */
113
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
132
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
114
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
133
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
115
 
134
 
116
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
135
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
117
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
136
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
118
                } else {
137
                } else {
Line 126... Line 145...
126
                );
145
                );
127
 
146
 
128
                return true;
147
                return true;
129
        }
148
        }
130
 
149
 
-
 
150
        /**
-
 
151
         * @param string $request
-
 
152
         * @return array|false
-
 
153
         */
131
        public function tree_search($request) {
154
        public function tree_search(string $request) {
132
                return false;
155
                return false;
133
        }
156
        }
134
 
157
 
-
 
158
        /**
-
 
159
         * @param string $id
-
 
160
         * @return bool
-
 
161
         */
135
        public function implementsFeature($id) {
162
        public function implementsFeature(string $id): bool {
136
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
163
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
137
                return false;
164
                return false;
138
        }
165
        }
139
 
166
 
-
 
167
        /**
140
        private function webAccessWorks($dir) {
168
         * Checks if the system can be accessed publicly
141
                // Attention! This check does not work if OIDplus is password protected!
169
         * Attention! This check does not work if OIDplus is password protected (solution would be to check via JavaScript,
142
                //            The only real solution is to check via JavaScript, which is done by setup/
170
         * which is done in setup/), or the URL is in the IntraNet rather than the Internet (only solution would be a
-
 
171
         * remote URL check service)
-
 
172
         * @param string $dir
-
 
173
         * @return false|string
-
 
174
         * @throws OIDplusException
-
 
175
         */
-
 
176
        private function webAccessWorks(string $dir) {
143
                $url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).$dir;
177
                $url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).$dir;
144
                $access_worked = url_get_contents($url) !== false;
178
                $access_worked = url_get_contents($url) !== false;
145
                if ($access_worked) return $url;
179
                if ($access_worked) return $url;
146
 
180
 
147
                if (!$access_worked) {
181
                if (!$access_worked) {
Line 153... Line 187...
153
                }
187
                }
154
 
188
 
155
                return false;
189
                return false;
156
        }
190
        }
157
 
191
 
-
 
192
        /**
-
 
193
         * @param string $dir
-
 
194
         * @return array
-
 
195
         * @throws OIDplusException
-
 
196
         */
158
        private function getNotificationsCheckDirAccess($dir) {
197
        private function getNotificationsCheckDirAccess(string $dir) {
159
                $notifications = array();
198
                $notifications = array();
160
                if (($url = $this->webAccessWorks($dir)) !== false) {
199
                if (($url = $this->webAccessWorks($dir)) !== false) {
161
                        // Re-use message taken from setup/includes/setup_base.js
200
                        // Re-use message taken from setup/includes/setup_base.js
162
                        $msg = _L('Attention: The following directory is world-readable: %1 ! You need to configure your web server to restrict access to this directory! (For Apache see <i>.htaccess</i>, for Microsoft IIS see <i>web.config</i>, for Nginx see <i>nginx.conf</i>).','<a target="_blank" href="'.$url.'">'.$dir.'</a>');
201
                        $msg = _L('Attention: The following directory is world-readable: %1 ! You need to configure your web server to restrict access to this directory! (For Apache see <i>.htaccess</i>, for Microsoft IIS see <i>web.config</i>, for Nginx see <i>nginx.conf</i>).','<a target="_blank" href="'.$url.'">'.$dir.'</a>');
163
                        $notifications[] = array('CRIT', $msg);
202
                        $notifications[] = array('CRIT', $msg);
164
                }
203
                }
165
                return $notifications;
204
                return $notifications;
166
        }
205
        }
167
 
206
 
-
 
207
        /**
-
 
208
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
-
 
209
         * These are some basic "system" checks, no checks from other plugin. So we add them to our plugin instead.
-
 
210
         * @param $user
-
 
211
         * @return array
-
 
212
         * @throws OIDplusException
-
 
213
         */
168
        public function getNotifications($user=null): array {
214
        public function getNotifications($user=null): array {
169
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.8
-
 
170
                // These are some basic "system" checks, no checks from other plugin. So we add them to our plugin instead.
-
 
171
                $notifications = array();
215
                $notifications = array();
172
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
216
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
173
                        // Check if critical directories are world-readable
217
                        // Check if critical directories are world-readable
174
                        if ($this->webAccessWorks('index.php') === false) {
218
                        if ($this->webAccessWorks('index.php') === false) {
175
                                $notifications[] = array('INFO', _L("The system can't check if critical directories (%1) are readable via web-browser. Please verify it manually.", 'userdata, res, dev, includes, setup/includes'));
219
                                $notifications[] = array('INFO', _L("The system can't check if critical directories (%1) are readable via web-browser. Please verify it manually.", 'userdata, res, dev, includes, setup/includes'));