Subversion Repositories oidplus

Rev

Rev 1180 | Rev 1206 | 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
 
1161 daniel-mar 113
                                // Prevent that dark-color scheme makes the font white in a non-dark-color OIDplus
114
                                $cont = str_replace('prefers-color-scheme', 'xxx', $cont);
115
 
987 daniel-mar 116
                                // Font sizes
117
                                $cont = preg_replace('@font-size:\\s*75%;@', '', $cont);
118
                                for ($i=5; $i>=1; $i--) {
119
                                        $cont = str_replace('<h'.$i, '<h'.($i+1), $cont);
120
                                        $cont = str_replace('</h'.$i, '</h'.($i+1), $cont);
121
                                }
122
 
795 daniel-mar 123
                                $out['text'] .= $cont;
124
                        }
125
                }
126
                else if ($id === 'oidplus:systeminfo') {
127
                        $handled = true;
635 daniel-mar 128
                        $out['title'] = _L('System information');
801 daniel-mar 129
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 130
 
131
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 132
                                $out['icon'] = 'img/error.png';
635 daniel-mar 133
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
134
                                return;
135
                        }
136
 
137
                        $out['text']  = '';
138
 
139
                        # ---
140
 
1186 daniel-mar 141
                        $out['text'] .= '<h2>'._L('OIDplus 2.0').'</h2>';
635 daniel-mar 142
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
143
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 144
                        $out['text'] .= '<thead>';
635 daniel-mar 145
                        $out['text'] .= '       <tr>';
146
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
147
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
148
                        $out['text'] .= '       </tr>';
1138 daniel-mar 149
                        $out['text'] .= '</thead>';
150
                        $out['text'] .= '<tbody>';
688 daniel-mar 151
 
152
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 153
                        $out['text'] .= '       <tr>';
688 daniel-mar 154
                        $out['text'] .= '               <td>'._L('System title').'</td>';
155
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
156
                        $out['text'] .= '       </tr>';
635 daniel-mar 157
 
688 daniel-mar 158
                        $out['text'] .= '       <tr>';
159
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
160
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
161
                        $out['text'] .= '       </tr>';
162
 
1165 daniel-mar 163
                        $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
164
                        $out['text'] .= '       <tr>';
165
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
166
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
167
                        $out['text'] .= '       </tr>';
168
 
635 daniel-mar 169
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 170
                        $out['text'] .= '       <tr>';
1073 daniel-mar 171
                        $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 172
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
173
                        $out['text'] .= '       </tr>';
174
 
1073 daniel-mar 175
                        $sysid_guid = OIDplus::getSystemGuid();
176
                        $out['text'] .= '       <tr>';
177
                        $out['text'] .= '               <td>'._L('System GUID').' <abbr title="'._L('SHA1-Namebased UUID based on the public key of your OIDplus system.').'">(?)</abbr></td>';
178
                        $out['text'] .= '               <td>'.(!$sysid_guid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_guid)).'</td>';
179
                        $out['text'] .= '       </tr>';
180
 
1078 daniel-mar 181
                        $sysid = OIDplus::getSystemId(false);
1116 daniel-mar 182
                        $sysid_aid = $sysid ? 'D276000186B20005'.strtoupper(str_pad(dechex((int)$sysid),8,'0',STR_PAD_LEFT)) : '';
1078 daniel-mar 183
                        $out['text'] .= '       <tr>';
184
                        $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>';
185
                        $out['text'] .= '               <td>'.(!$sysid_aid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L('No PIX allowed').')</td>';
186
                        $out['text'] .= '       </tr>';
187
 
635 daniel-mar 188
                        $sys_ver = OIDplus::getVersion();
189
                        $out['text'] .= '       <tr>';
190
                        $out['text'] .= '               <td>'._L('System version').'</td>';
191
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
192
                        $out['text'] .= '       </tr>';
193
 
194
                        $sys_install_type = OIDplus::getInstallType();
195
                        $out['text'] .= '       <tr>';
196
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
197
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
198
                        $out['text'] .= '       </tr>';
199
 
1138 daniel-mar 200
                        $out['text'] .= '</tbody>';
635 daniel-mar 201
                        $out['text'] .= '</table>';
202
                        $out['text'] .= '</div></div>';
203
 
204
                        # ---
205
 
1186 daniel-mar 206
                        $out['text'] .= '<h2>'._L('Webserver system').'</h2>';
635 daniel-mar 207
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
208
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 209
                        $out['text'] .= '<thead>';
635 daniel-mar 210
                        $out['text'] .= '       <tr>';
211
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
212
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
213
                        $out['text'] .= '       </tr>';
1138 daniel-mar 214
                        $out['text'] .= '</thead>';
215
                        $out['text'] .= '<tbody>';
1186 daniel-mar 216
 
217
                        // Operating system (of the webserver)
218
 
219
                        if (php_uname("m") == php_uname("n")) {
220
                                // At some hosts like Strato, php_uname() always returns the same string
221
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
222
                                $out['text'] .= '       <tr>';
223
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
224
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
225
                                $out['text'] .= '       </tr>';
226
                                $out['text'] .= '       <tr>';
227
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
228
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
229
                                $out['text'] .= '       </tr>';
230
                        } else {
231
                                $out['text'] .= '       <tr>';
232
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
233
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
234
                                $out['text'] .= '       </tr>';
235
                                $out['text'] .= '       <tr>';
236
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
237
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
238
                                $out['text'] .= '       </tr>';
239
                                $out['text'] .= '       <tr>';
240
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
241
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
242
                                $out['text'] .= '       </tr>';
243
                        }
635 daniel-mar 244
                        $out['text'] .= '       <tr>';
1186 daniel-mar 245
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
246
                        $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
635 daniel-mar 247
                        $out['text'] .= '       </tr>';
1186 daniel-mar 248
 
249
                        // The actual web server stuff
250
 
697 daniel-mar 251
                        $out['text'] .= '       <tr>';
1186 daniel-mar 252
                        $out['text'] .= '               <td>'._L('Web server software').'</td>';
253
                        $out['text'] .= '               <td>'.($_SERVER['SERVER_SOFTWARE'] ?? '<i>' . _L('unknown') . '</i>').'</td>';
794 daniel-mar 254
                        $out['text'] .= '       </tr>';
255
                        $out['text'] .= '       <tr>';
1186 daniel-mar 256
                        $out['text'] .= '               <td>'._L('Web server user account').'</td>';
257
                        $current_user = get_own_username();
258
                        $out['text'] .= '               <td>'.($current_user === false ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
697 daniel-mar 259
                        $out['text'] .= '       </tr>';
635 daniel-mar 260
 
1186 daniel-mar 261
                        // PHP (at webserver)
635 daniel-mar 262
 
263
                        $out['text'] .= '       <tr>';
1186 daniel-mar 264
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
265
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
635 daniel-mar 266
                        $out['text'] .= '       </tr>';
267
                        $out['text'] .= '       <tr>';
1186 daniel-mar 268
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
269
                        $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
635 daniel-mar 270
                        $out['text'] .= '       </tr>';
662 daniel-mar 271
                        $out['text'] .= '       <tr>';
1186 daniel-mar 272
                        $out['text'] .= '               <td>'._L('PHP installed extensions').'</td>';
273
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
662 daniel-mar 274
                        $out['text'] .= '       </tr>';
1138 daniel-mar 275
                        $out['text'] .= '</tbody>';
635 daniel-mar 276
                        $out['text'] .= '</table>';
1186 daniel-mar 277
 
278
                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
279
 
635 daniel-mar 280
                        $out['text'] .= '</div></div>';
281
 
282
                        # ---
283
 
1186 daniel-mar 284
                        $out['text'] .= '<h2>'._L('Database system').'</h2>';
795 daniel-mar 285
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
286
                        $out['text'] .= '<table class="table table-bordered table-striped">';
1138 daniel-mar 287
                        $out['text'] .= '<thead>';
795 daniel-mar 288
                        $out['text'] .= '       <tr>';
289
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
290
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
291
                        $out['text'] .= '       </tr>';
1138 daniel-mar 292
                        $out['text'] .= '</thead>';
293
                        $out['text'] .= '<tbody>';
795 daniel-mar 294
 
295
                        $out['text'] .= '       <tr>';
296
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
297
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
298
                        $out['text'] .= '       </tr>';
299
 
300
                        $out['text'] .= '       <tr>';
301
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
302
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
303
                        $out['text'] .= '       </tr>';
304
 
305
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
306
                        $out['text'] .= '       <tr>';
307
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
308
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
309
                        $out['text'] .= '       </tr>';
310
                        $out['text'] .= '       <tr>';
311
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
312
                        $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
313
                        if ($tmp) $tmp = $tmp->fetch_array();
1130 daniel-mar 314
                        $tmp = $tmp['tmp'] ?? _L('n/a');
1165 daniel-mar 315
                        $tmp = preg_replace('@\\.\\d{3}$@', '', $tmp); // remove milliseconds of Microsoft SQL Server
795 daniel-mar 316
                        $out['text'] .= '               <td>'.$tmp.'</td>';
317
                        $out['text'] .= '       </tr>';
1138 daniel-mar 318
                        $out['text'] .= '</tbody>';
795 daniel-mar 319
                        $out['text'] .= '</table>';
320
                        $out['text'] .= '</div></div>';
321
 
322
                        // TODO: can we somehow get the DBMS version, connection string etc?
323
 
324
                        # ---
325
 
635 daniel-mar 326
                }
327
        }
328
 
1116 daniel-mar 329
        /**
330
         * @param array $json
331
         * @param string|null $ra_email
332
         * @param bool $nonjs
333
         * @param string $req_goto
334
         * @return bool
335
         * @throws OIDplusException
336
         */
337
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 338
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
339
 
800 daniel-mar 340
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 341
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 342
                } else {
343
                        $tree_icon = null; // default icon (folder)
344
                }
345
 
800 daniel-mar 346
                if (file_exists(__DIR__.'/img/php_icon16.png')) {
801 daniel-mar 347
                        $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
799 daniel-mar 348
                } else {
349
                        $tree_icon_php = null; // default icon (folder)
350
                }
351
 
635 daniel-mar 352
                $json[] = array(
353
                        'id' => 'oidplus:systeminfo',
354
                        'icon' => $tree_icon,
799 daniel-mar 355
                        'text' => _L('System information'),
356
                        'children' => array(array(
357
                                'id' => 'oidplus:phpinfo',
358
                                'icon' => $tree_icon_php,
359
                                'text' => _L('PHP information')
360
                        ))
635 daniel-mar 361
                );
362
 
363
                return true;
364
        }
365
 
1116 daniel-mar 366
        /**
367
         * @param string $request
368
         * @return array|false
369
         */
370
        public function tree_search(string $request) {
635 daniel-mar 371
                return false;
372
        }
373
 
662 daniel-mar 374
}