Subversion Repositories oidplus

Rev

Rev 1130 | Rev 1138 | 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()) {
800 daniel-mar 83
                                $out['icon'] = 'img/error.png';
795 daniel-mar 84
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
85
                                return;
86
                        }
87
 
88
                        $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>';
89
 
90
                        ob_start();
91
                        $res = phpinfo();
92
                        $cont = ob_get_contents();
93
                        ob_end_clean();
94
 
95
                        if (!$res) {
96
                                $out['text'] .= '<p><font color="red">'._L('phpinfo() could not be called').'</font></p>';
97
                        } else {
796 daniel-mar 98
                                // phpinfo() sets "img {float: right; border: 0;}". We don't want that.
99
                                $cont = str_replace('img {', 'img.phpinfo {', $cont);
100
                                $cont = str_replace('<img', '<img class="phpinfo"', $cont);
101
 
102
                                // phpinfo() sets the link colors. We don't want that
103
                                $cont = preg_replace('@a:.+ {.+}@ismU', '', $cont);
104
 
105
                                // phpinfo() sets "h1 {font-size: 150%;}" and "h2 {font-size: 125%;}"
106
                                $cont = preg_replace('@(h1|h2|h3|h4|h5) {.+}@ismU', '', $cont);
107
 
987 daniel-mar 108
                                // Make compatible for dark themes by removing all foreground and background colors
1047 daniel-mar 109
                                $cont = preg_replace('@(body) {.+}@ismU', '', $cont, 1);
110
                                $cont = preg_replace('@background-color:(.+)[\\};]@ismU', '', $cont);
987 daniel-mar 111
                                $cont = '<span style="font-family: sans-serif;">'.$cont.'</span>';
112
 
113
                                // Font sizes
114
                                $cont = preg_replace('@font-size:\\s*75%;@', '', $cont);
115
                                for ($i=5; $i>=1; $i--) {
116
                                        $cont = str_replace('<h'.$i, '<h'.($i+1), $cont);
117
                                        $cont = str_replace('</h'.$i, '</h'.($i+1), $cont);
118
                                }
119
 
795 daniel-mar 120
                                $out['text'] .= $cont;
121
                        }
122
                }
123
                else if ($id === 'oidplus:systeminfo') {
124
                        $handled = true;
635 daniel-mar 125
                        $out['title'] = _L('System information');
801 daniel-mar 126
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 127
 
128
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 129
                                $out['icon'] = 'img/error.png';
635 daniel-mar 130
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
131
                                return;
132
                        }
133
 
134
                        $out['text']  = '';
135
 
136
                        # ---
137
 
138
                        $out['text'] .= '<h2>'._L('OIDplus').'</h2>';
139
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
140
                        $out['text'] .= '<table class="table table-bordered table-striped">';
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>';
688 daniel-mar 145
 
146
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 147
                        $out['text'] .= '       <tr>';
688 daniel-mar 148
                        $out['text'] .= '               <td>'._L('System title').'</td>';
149
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
150
                        $out['text'] .= '       </tr>';
635 daniel-mar 151
 
688 daniel-mar 152
                        $out['text'] .= '       <tr>';
153
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
154
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
155
                        $out['text'] .= '       </tr>';
156
 
635 daniel-mar 157
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 158
                        $out['text'] .= '       <tr>';
1073 daniel-mar 159
                        $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 160
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
161
                        $out['text'] .= '       </tr>';
162
 
1073 daniel-mar 163
                        $sysid_guid = OIDplus::getSystemGuid();
164
                        $out['text'] .= '       <tr>';
165
                        $out['text'] .= '               <td>'._L('System GUID').' <abbr title="'._L('SHA1-Namebased UUID based on the public key of your OIDplus system.').'">(?)</abbr></td>';
166
                        $out['text'] .= '               <td>'.(!$sysid_guid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_guid)).'</td>';
167
                        $out['text'] .= '       </tr>';
168
 
1078 daniel-mar 169
                        $sysid = OIDplus::getSystemId(false);
1116 daniel-mar 170
                        $sysid_aid = $sysid ? 'D276000186B20005'.strtoupper(str_pad(dechex((int)$sysid),8,'0',STR_PAD_LEFT)) : '';
1078 daniel-mar 171
                        $out['text'] .= '       <tr>';
172
                        $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>';
173
                        $out['text'] .= '               <td>'.(!$sysid_aid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L('No PIX allowed').')</td>';
174
                        $out['text'] .= '       </tr>';
175
 
801 daniel-mar 176
                        $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
635 daniel-mar 177
                        $out['text'] .= '       <tr>';
178
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
179
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
180
                        $out['text'] .= '       </tr>';
181
 
182
                        $sys_ver = OIDplus::getVersion();
183
                        $out['text'] .= '       <tr>';
184
                        $out['text'] .= '               <td>'._L('System version').'</td>';
185
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
186
                        $out['text'] .= '       </tr>';
187
 
188
                        $sys_install_type = OIDplus::getInstallType();
189
                        $out['text'] .= '       <tr>';
190
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
191
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
192
                        $out['text'] .= '       </tr>';
193
 
194
                        $out['text'] .= '</table>';
195
                        $out['text'] .= '</div></div>';
196
 
197
                        # ---
198
 
199
                        $out['text'] .= '<h2>'._L('PHP').'</h2>';
200
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
201
                        $out['text'] .= '<table class="table table-bordered table-striped">';
202
                        $out['text'] .= '       <tr>';
203
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
204
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
205
                        $out['text'] .= '       </tr>';
206
                        $out['text'] .= '       <tr>';
207
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
208
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
209
                        $out['text'] .= '       </tr>';
697 daniel-mar 210
                        $out['text'] .= '       <tr>';
794 daniel-mar 211
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
795 daniel-mar 212
                        $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
794 daniel-mar 213
                        $out['text'] .= '       </tr>';
214
                        $out['text'] .= '       <tr>';
697 daniel-mar 215
                        $out['text'] .= '               <td>'._L('Installed extensions').'</td>';
216
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
217
                        $out['text'] .= '       </tr>';
635 daniel-mar 218
                        $out['text'] .= '</table>';
799 daniel-mar 219
                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
635 daniel-mar 220
                        $out['text'] .= '</div></div>';
221
 
222
                        # ---
223
 
224
                        $out['text'] .= '<h2>'._L('Webserver').'</h2>';
225
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
226
                        $out['text'] .= '<table class="table table-bordered table-striped">';
227
                        $out['text'] .= '       <tr>';
228
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
229
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
230
                        $out['text'] .= '       </tr>';
231
                        $out['text'] .= '       <tr>';
232
                        $out['text'] .= '               <td>'._L('Server software').'</td>';
1130 daniel-mar 233
                        $out['text'] .= '               <td>'.($_SERVER['SERVER_SOFTWARE'] ?? '<i>' . _L('unknown') . '</i>').'</td>';
635 daniel-mar 234
                        $out['text'] .= '       </tr>';
662 daniel-mar 235
                        $out['text'] .= '       <tr>';
236
                        $out['text'] .= '               <td>'._L('User account').'</td>';
688 daniel-mar 237
                        $current_user = exec('whoami');
238
                        if ($current_user == '') {
239
                                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
240
                                        // Windows on an IIS server:
241
                                        //     getenv('USERNAME')     MARSCHALL$                (That is the "machine account", see https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities#accessing-the-network )
242
                                        //     get_current_user()     DefaultAppPool
243
                                        //     exec('whoami')         iis apppool\defaultapppool
244
                                        // Windows with XAMPP:
245
                                        //     getenv('USERNAME')     dmarschall
246
                                        //     get_current_user()     dmarschall               (even if script has a different NTFS owner!)
247
                                        //     exec('whoami')         hickelsoft\dmarschall
248
                                        $current_user = get_current_user();
249
                                        if ($current_user == '') $current_user = getenv('USERNAME');
250
                                } else {
251
                                        // On Linux:
252
                                        // get_current_user() will get the owner of the PHP script, not the process owner!
253
                                        // We want the process owner, so we use posix_geteuid().
720 daniel-mar 254
                                        if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
255
                                                $uid = posix_geteuid();
256
                                                $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
257
                                        } else {
258
                                                $uid = -1;
259
                                        }
688 daniel-mar 260
                                        if ($current_user == '') $current_user = get_current_user();
720 daniel-mar 261
                                        if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
688 daniel-mar 262
                                }
685 daniel-mar 263
                        }
688 daniel-mar 264
                        $out['text'] .= '               <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
662 daniel-mar 265
                        $out['text'] .= '       </tr>';
635 daniel-mar 266
                        $out['text'] .= '</table>';
267
                        $out['text'] .= '</div></div>';
268
 
269
                        # ---
270
 
795 daniel-mar 271
                        $out['text'] .= '<h2>'._L('Database').'</h2>';
272
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
273
                        $out['text'] .= '<table class="table table-bordered table-striped">';
274
                        $out['text'] .= '       <tr>';
275
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
276
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
277
                        $out['text'] .= '       </tr>';
278
 
279
                        $out['text'] .= '       <tr>';
280
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
281
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
282
                        $out['text'] .= '       </tr>';
283
 
284
                        $out['text'] .= '       <tr>';
285
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
286
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
287
                        $out['text'] .= '       </tr>';
288
 
289
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
290
                        $out['text'] .= '       <tr>';
291
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
292
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
293
                        $out['text'] .= '       </tr>';
294
                        $out['text'] .= '       <tr>';
295
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
296
                        $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
297
                        if ($tmp) $tmp = $tmp->fetch_array();
1130 daniel-mar 298
                        $tmp = $tmp['tmp'] ?? _L('n/a');
795 daniel-mar 299
                        $out['text'] .= '               <td>'.$tmp.'</td>';
300
                        $out['text'] .= '       </tr>';
301
                        $out['text'] .= '</table>';
302
                        $out['text'] .= '</div></div>';
303
 
304
                        // TODO: can we somehow get the DBMS version, connection string etc?
305
 
306
                        # ---
307
 
635 daniel-mar 308
                        $out['text'] .= '<h2>'._L('Operating System').'</h2>';
309
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
310
                        $out['text'] .= '<table class="table table-bordered table-striped">';
311
                        $out['text'] .= '       <tr>';
312
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
313
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
314
                        $out['text'] .= '       </tr>';
315
                        if (php_uname("m") == php_uname("n")) {
316
                                // At some hosts like Strato, php_uname() always returns the same string
317
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
318
                                $out['text'] .= '       <tr>';
319
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
320
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
321
                                $out['text'] .= '       </tr>';
322
                                $out['text'] .= '       <tr>';
323
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
324
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
325
                                $out['text'] .= '       </tr>';
326
                        } else {
327
                                $out['text'] .= '       <tr>';
328
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
329
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
330
                                $out['text'] .= '       </tr>';
331
                                $out['text'] .= '       <tr>';
332
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
333
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
334
                                $out['text'] .= '       </tr>';
335
                                $out['text'] .= '       <tr>';
336
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
337
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
338
                                $out['text'] .= '       </tr>';
339
                        }
798 daniel-mar 340
                        $out['text'] .= '       <tr>';
341
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
342
                        $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
343
                        $out['text'] .= '       </tr>';
635 daniel-mar 344
                        $out['text'] .= '</table>';
345
                        $out['text'] .= '</div></div>';
346
 
347
                        # ---
348
 
349
                }
350
        }
351
 
1116 daniel-mar 352
        /**
353
         * @param array $json
354
         * @param string|null $ra_email
355
         * @param bool $nonjs
356
         * @param string $req_goto
357
         * @return bool
358
         * @throws OIDplusException
359
         */
360
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 361
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
362
 
800 daniel-mar 363
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 364
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 365
                } else {
366
                        $tree_icon = null; // default icon (folder)
367
                }
368
 
800 daniel-mar 369
                if (file_exists(__DIR__.'/img/php_icon16.png')) {
801 daniel-mar 370
                        $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
799 daniel-mar 371
                } else {
372
                        $tree_icon_php = null; // default icon (folder)
373
                }
374
 
635 daniel-mar 375
                $json[] = array(
376
                        'id' => 'oidplus:systeminfo',
377
                        'icon' => $tree_icon,
799 daniel-mar 378
                        'text' => _L('System information'),
379
                        'children' => array(array(
380
                                'id' => 'oidplus:phpinfo',
381
                                'icon' => $tree_icon_php,
382
                                'text' => _L('PHP information')
383
                        ))
635 daniel-mar 384
                );
385
 
386
                return true;
387
        }
388
 
1116 daniel-mar 389
        /**
390
         * @param string $request
391
         * @return array|false
392
         */
393
        public function tree_search(string $request) {
635 daniel-mar 394
                return false;
395
        }
396
 
662 daniel-mar 397
}