Subversion Repositories oidplus

Rev

Rev 1336 | Rev 1398 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
635 daniel-mar 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
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
635 daniel-mar 21
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPageAdminSysteminfo extends OIDplusPagePluginAdmin {
27
 
1116 daniel-mar 28
        /**
29
         * @param string $actionID
30
         * @param array $params
31
         * @return array
32
         * @throws OIDplusException
33
         */
34
        public function action(string $actionID, array $params): array {
35
                return parent::action($actionID, $params);
635 daniel-mar 36
        }
37
 
1116 daniel-mar 38
        /**
39
         * @param bool $html
40
         * @return void
41
         */
42
        public function init(bool $html=true) {
635 daniel-mar 43
        }
44
 
1116 daniel-mar 45
        /**
46
         * @return array|mixed|string|string[]
47
         */
795 daniel-mar 48
        private function getLoadedInis() {
49
                $s_inis = '';
50
 
51
                $inis = array();
52
                $main_ini = php_ini_loaded_file();
53
                if ($main_ini !== false) $s_inis = '<b>'.htmlentities($main_ini).'</b>';
54
 
55
                $more_ini = php_ini_scanned_files();
56
                if ($more_ini !== false) {
57
                        $inis = explode(',', $more_ini);
58
                        foreach ($inis as $ini) {
59
                                $s_inis .= '<br>'.htmlentities($ini);
60
                        }
61
                }
62
 
63
                if ($s_inis == '') $s_inis = _L('n/a');
64
 
65
                return $s_inis;
66
        }
67
 
1116 daniel-mar 68
        /**
69
         * @param string $id
70
         * @param array $out
71
         * @param bool $handled
72
         * @return void
73
         * @throws OIDplusConfigInitializationException
74
         * @throws OIDplusException
75
         */
76
        public function gui(string $id, array &$out, bool &$handled) {
799 daniel-mar 77
                if ($id === 'oidplus:phpinfo') {
635 daniel-mar 78
                        $handled = true;
795 daniel-mar 79
                        $out['title'] = _L('PHP information');
801 daniel-mar 80
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon.png';
795 daniel-mar 81
 
82
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
1266 daniel-mar 83
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
795 daniel-mar 84
                        }
85
 
86
                        $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:systeminfo').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to the system information page').'</a></p>';
87
 
88
                        ob_start();
89
                        $res = phpinfo();
90
                        $cont = ob_get_contents();
91
                        ob_end_clean();
92
 
93
                        if (!$res) {
94
                                $out['text'] .= '<p><font color="red">'._L('phpinfo() could not be called').'</font></p>';
95
                        } else {
796 daniel-mar 96
                                // phpinfo() sets "img {float: right; border: 0;}". We don't want that.
97
                                $cont = str_replace('img {', 'img.phpinfo {', $cont);
98
                                $cont = str_replace('<img', '<img class="phpinfo"', $cont);
99
 
100
                                // phpinfo() sets the link colors. We don't want that
101
                                $cont = preg_replace('@a:.+ {.+}@ismU', '', $cont);
102
 
103
                                // phpinfo() sets "h1 {font-size: 150%;}" and "h2 {font-size: 125%;}"
104
                                $cont = preg_replace('@(h1|h2|h3|h4|h5) {.+}@ismU', '', $cont);
105
 
987 daniel-mar 106
                                // Make compatible for dark themes by removing all foreground and background colors
1047 daniel-mar 107
                                $cont = preg_replace('@(body) {.+}@ismU', '', $cont, 1);
108
                                $cont = preg_replace('@background-color:(.+)[\\};]@ismU', '', $cont);
987 daniel-mar 109
                                $cont = '<span style="font-family: sans-serif;">'.$cont.'</span>';
110
 
1161 daniel-mar 111
                                // Prevent that dark-color scheme makes the font white in a non-dark-color OIDplus
112
                                $cont = str_replace('prefers-color-scheme', 'xxx', $cont);
113
 
987 daniel-mar 114
                                // Font sizes
115
                                $cont = preg_replace('@font-size:\\s*75%;@', '', $cont);
116
                                for ($i=5; $i>=1; $i--) {
117
                                        $cont = str_replace('<h'.$i, '<h'.($i+1), $cont);
118
                                        $cont = str_replace('</h'.$i, '</h'.($i+1), $cont);
119
                                }
120
 
795 daniel-mar 121
                                $out['text'] .= $cont;
122
                        }
123
                }
124
                else if ($id === 'oidplus:systeminfo') {
125
                        $handled = true;
635 daniel-mar 126
                        $out['title'] = _L('System information');
801 daniel-mar 127
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 128
 
129
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
1266 daniel-mar 130
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
635 daniel-mar 131
                        }
132
 
133
                        $out['text']  = '';
134
 
135
                        # ---
136
 
1186 daniel-mar 137
                        $out['text'] .= '<h2>'._L('OIDplus 2.0').'</h2>';
635 daniel-mar 138
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
139
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 140
                        $out['text'] .= '<thead>';
635 daniel-mar 141
                        $out['text'] .= '       <tr>';
142
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
143
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
144
                        $out['text'] .= '       </tr>';
1138 daniel-mar 145
                        $out['text'] .= '</thead>';
146
                        $out['text'] .= '<tbody>';
688 daniel-mar 147
 
148
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 149
                        $out['text'] .= '       <tr>';
688 daniel-mar 150
                        $out['text'] .= '               <td>'._L('System title').'</td>';
151
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
152
                        $out['text'] .= '       </tr>';
635 daniel-mar 153
 
688 daniel-mar 154
                        $out['text'] .= '       <tr>';
155
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
156
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
157
                        $out['text'] .= '       </tr>';
158
 
1165 daniel-mar 159
                        $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
160
                        $out['text'] .= '       <tr>';
161
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
162
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
163
                        $out['text'] .= '       </tr>';
164
 
635 daniel-mar 165
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 166
                        $out['text'] .= '       <tr>';
1073 daniel-mar 167
                        $out['text'] .= '               <td>'._L('System OID').' <abbr title="'._L('OID based on the public key of your OIDplus system. The last arc is also called OIDplus System ID.').'">(?)</abbr></td>';
635 daniel-mar 168
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
169
                        $out['text'] .= '       </tr>';
170
 
1073 daniel-mar 171
                        $sysid_guid = OIDplus::getSystemGuid();
172
                        $out['text'] .= '       <tr>';
1336 daniel-mar 173
                        $out['text'] .= '               <td>'._L('System GUID').' <abbr title="'._L('UUIDv8 based on the System ID of your OIDplus system.').'">(?)</abbr></td>';
1073 daniel-mar 174
                        $out['text'] .= '               <td>'.(!$sysid_guid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_guid)).'</td>';
175
                        $out['text'] .= '       </tr>';
176
 
1078 daniel-mar 177
                        $sysid = OIDplus::getSystemId(false);
1116 daniel-mar 178
                        $sysid_aid = $sysid ? 'D276000186B20005'.strtoupper(str_pad(dechex((int)$sysid),8,'0',STR_PAD_LEFT)) : '';
1078 daniel-mar 179
                        $out['text'] .= '       <tr>';
180
                        $out['text'] .= '               <td>'._L('System AID').' <abbr title="'._L('Application Identifier (ISO/IEC 7816) based on the system ID (which is based on the hash of the public key of your OIDplus system).').'">(?)</abbr></td>';
181
                        $out['text'] .= '               <td>'.(!$sysid_aid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L('No PIX allowed').')</td>';
182
                        $out['text'] .= '       </tr>';
183
 
1396 daniel-mar 184
                        $out['text'] .= '       <tr>';
185
                        $out['text'] .= '               <td>'._L('X.500 Relative Distinguished Name').'</td>';
186
                        $out['text'] .= '               <td>'.(!$sysid ? '<i>'._L('unknown').'</i>' : '1.3.6.1.4.1.37476.2.5.2.9.4.1='.$sysid.'<span style="opacity: 0.5">, CN=OidPlus, DC=example, DC=com</span>').'</td>';
187
                        $out['text'] .= '       </tr>';
188
 
635 daniel-mar 189
                        $sys_ver = OIDplus::getVersion();
190
                        $out['text'] .= '       <tr>';
191
                        $out['text'] .= '               <td>'._L('System version').'</td>';
192
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
193
                        $out['text'] .= '       </tr>';
194
 
195
                        $sys_install_type = OIDplus::getInstallType();
196
                        $out['text'] .= '       <tr>';
197
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
198
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
199
                        $out['text'] .= '       </tr>';
200
 
1138 daniel-mar 201
                        $out['text'] .= '</tbody>';
635 daniel-mar 202
                        $out['text'] .= '</table>';
203
                        $out['text'] .= '</div></div>';
204
 
205
                        # ---
206
 
1186 daniel-mar 207
                        $out['text'] .= '<h2>'._L('Webserver system').'</h2>';
635 daniel-mar 208
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
209
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 210
                        $out['text'] .= '<thead>';
635 daniel-mar 211
                        $out['text'] .= '       <tr>';
212
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
213
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
214
                        $out['text'] .= '       </tr>';
1138 daniel-mar 215
                        $out['text'] .= '</thead>';
216
                        $out['text'] .= '<tbody>';
1186 daniel-mar 217
 
218
                        // Operating system (of the webserver)
219
 
220
                        if (php_uname("m") == php_uname("n")) {
221
                                // At some hosts like Strato, php_uname() always returns the same string
222
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
223
                                $out['text'] .= '       <tr>';
224
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
225
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
226
                                $out['text'] .= '       </tr>';
227
                                $out['text'] .= '       <tr>';
228
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
229
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
230
                                $out['text'] .= '       </tr>';
231
                        } else {
232
                                $out['text'] .= '       <tr>';
233
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
234
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
235
                                $out['text'] .= '       </tr>';
236
                                $out['text'] .= '       <tr>';
237
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
238
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
239
                                $out['text'] .= '       </tr>';
240
                                $out['text'] .= '       <tr>';
241
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
242
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
243
                                $out['text'] .= '       </tr>';
244
                        }
635 daniel-mar 245
                        $out['text'] .= '       <tr>';
1186 daniel-mar 246
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
247
                        $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
635 daniel-mar 248
                        $out['text'] .= '       </tr>';
1186 daniel-mar 249
 
250
                        // The actual web server stuff
251
 
697 daniel-mar 252
                        $out['text'] .= '       <tr>';
1186 daniel-mar 253
                        $out['text'] .= '               <td>'._L('Web server software').'</td>';
254
                        $out['text'] .= '               <td>'.($_SERVER['SERVER_SOFTWARE'] ?? '<i>' . _L('unknown') . '</i>').'</td>';
794 daniel-mar 255
                        $out['text'] .= '       </tr>';
256
                        $out['text'] .= '       <tr>';
1186 daniel-mar 257
                        $out['text'] .= '               <td>'._L('Web server user account').'</td>';
1228 daniel-mar 258
                        $current_user = get_own_username();  // TODO: should we also show the group?
1186 daniel-mar 259
                        $out['text'] .= '               <td>'.($current_user === false ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
697 daniel-mar 260
                        $out['text'] .= '       </tr>';
635 daniel-mar 261
 
1186 daniel-mar 262
                        // PHP (at webserver)
635 daniel-mar 263
 
264
                        $out['text'] .= '       <tr>';
1186 daniel-mar 265
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
266
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
635 daniel-mar 267
                        $out['text'] .= '       </tr>';
268
                        $out['text'] .= '       <tr>';
1186 daniel-mar 269
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
270
                        $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
635 daniel-mar 271
                        $out['text'] .= '       </tr>';
662 daniel-mar 272
                        $out['text'] .= '       <tr>';
1186 daniel-mar 273
                        $out['text'] .= '               <td>'._L('PHP installed extensions').'</td>';
274
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
662 daniel-mar 275
                        $out['text'] .= '       </tr>';
1138 daniel-mar 276
                        $out['text'] .= '</tbody>';
635 daniel-mar 277
                        $out['text'] .= '</table>';
1186 daniel-mar 278
 
279
                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
280
 
635 daniel-mar 281
                        $out['text'] .= '</div></div>';
282
 
283
                        # ---
284
 
1186 daniel-mar 285
                        $out['text'] .= '<h2>'._L('Database system').'</h2>';
795 daniel-mar 286
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
287
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 288
                        $out['text'] .= '<thead>';
795 daniel-mar 289
                        $out['text'] .= '       <tr>';
290
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
291
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
292
                        $out['text'] .= '       </tr>';
1138 daniel-mar 293
                        $out['text'] .= '</thead>';
294
                        $out['text'] .= '<tbody>';
795 daniel-mar 295
 
296
                        $out['text'] .= '       <tr>';
297
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
298
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
299
                        $out['text'] .= '       </tr>';
300
 
301
                        $out['text'] .= '       <tr>';
302
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
303
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
304
                        $out['text'] .= '       </tr>';
305
 
306
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
307
                        $out['text'] .= '       <tr>';
308
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
309
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
310
                        $out['text'] .= '       </tr>';
311
                        $out['text'] .= '       <tr>';
312
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
1228 daniel-mar 313
                        // We use "from ###config" because Oracle DB requires a "from" statement.
314
                        // Instead of creating two queries (one with "select ..." and one with "select ... from dual"),
315
                        // we make this query. It is OK, because the table ###config is never empty and we are only fetching the first row.
316
                        $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp from ###config');
795 daniel-mar 317
                        if ($tmp) $tmp = $tmp->fetch_array();
1130 daniel-mar 318
                        $tmp = $tmp['tmp'] ?? _L('n/a');
1165 daniel-mar 319
                        $tmp = preg_replace('@\\.\\d{3}$@', '', $tmp); // remove milliseconds of Microsoft SQL Server
795 daniel-mar 320
                        $out['text'] .= '               <td>'.$tmp.'</td>';
321
                        $out['text'] .= '       </tr>';
1220 daniel-mar 322
 
323
                        $infos = OIDplus::db()->getExtendedInfo();
324
                        foreach ($infos as $name => $val) {
325
                                $out['text'] .= '       <tr>';
326
                                $out['text'] .= '               <td>' . htmlentities($name) . '</td>';
327
                                $out['text'] .= '               <td>' . htmlentities($val ?? '') . '</td>';
328
                                $out['text'] .= '       </tr>';
329
                        }
330
 
1138 daniel-mar 331
                        $out['text'] .= '</tbody>';
795 daniel-mar 332
                        $out['text'] .= '</table>';
333
                        $out['text'] .= '</div></div>';
334
 
335
                        # ---
336
 
635 daniel-mar 337
                }
338
        }
339
 
1116 daniel-mar 340
        /**
341
         * @param array $json
342
         * @param string|null $ra_email
343
         * @param bool $nonjs
344
         * @param string $req_goto
345
         * @return bool
346
         * @throws OIDplusException
347
         */
348
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 349
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
350
 
800 daniel-mar 351
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 352
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 353
                } else {
354
                        $tree_icon = null; // default icon (folder)
355
                }
356
 
800 daniel-mar 357
                if (file_exists(__DIR__.'/img/php_icon16.png')) {
801 daniel-mar 358
                        $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
799 daniel-mar 359
                } else {
360
                        $tree_icon_php = null; // default icon (folder)
361
                }
362
 
635 daniel-mar 363
                $json[] = array(
364
                        'id' => 'oidplus:systeminfo',
365
                        'icon' => $tree_icon,
799 daniel-mar 366
                        'text' => _L('System information'),
367
                        'children' => array(array(
368
                                'id' => 'oidplus:phpinfo',
369
                                'icon' => $tree_icon_php,
370
                                'text' => _L('PHP information')
371
                        ))
635 daniel-mar 372
                );
373
 
374
                return true;
375
        }
376
 
1116 daniel-mar 377
        /**
378
         * @param string $request
379
         * @return array|false
380
         */
381
        public function tree_search(string $request) {
635 daniel-mar 382
                return false;
383
        }
384
 
662 daniel-mar 385
}