Subversion Repositories oidplus

Rev

Rev 1047 | Rev 1073 | 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
1047 daniel-mar 5
 * Copyright 2019 - 2022 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
 
22
class OIDplusPageAdminSysteminfo extends OIDplusPagePluginAdmin {
23
 
24
        public function action($actionID, $params) {
25
        }
26
 
27
        public function init($html=true) {
28
        }
29
 
795 daniel-mar 30
        private function getLoadedInis() {
31
                $s_inis = '';
32
 
33
                $inis = array();
34
                $main_ini = php_ini_loaded_file();
35
                if ($main_ini !== false) $s_inis = '<b>'.htmlentities($main_ini).'</b>';
36
 
37
                $more_ini = php_ini_scanned_files();
38
                if ($more_ini !== false) {
39
                        $inis = explode(',', $more_ini);
40
                        foreach ($inis as $ini) {
41
                                $s_inis .= '<br>'.htmlentities($ini);
42
                        }
43
                }
44
 
45
                if ($s_inis == '') $s_inis = _L('n/a');
46
 
47
                return $s_inis;
48
        }
49
 
635 daniel-mar 50
        public function gui($id, &$out, &$handled) {
799 daniel-mar 51
                if ($id === 'oidplus:phpinfo') {
635 daniel-mar 52
                        $handled = true;
795 daniel-mar 53
                        $out['title'] = _L('PHP information');
801 daniel-mar 54
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon.png';
795 daniel-mar 55
 
56
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 57
                                $out['icon'] = 'img/error.png';
795 daniel-mar 58
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
59
                                return;
60
                        }
61
 
62
                        $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>';
63
 
64
                        ob_start();
65
                        $res = phpinfo();
66
                        $cont = ob_get_contents();
67
                        ob_end_clean();
68
 
69
                        if (!$res) {
70
                                $out['text'] .= '<p><font color="red">'._L('phpinfo() could not be called').'</font></p>';
71
                        } else {
796 daniel-mar 72
                                // phpinfo() sets "img {float: right; border: 0;}". We don't want that.
73
                                $cont = str_replace('img {', 'img.phpinfo {', $cont);
74
                                $cont = str_replace('<img', '<img class="phpinfo"', $cont);
75
 
76
                                // phpinfo() sets the link colors. We don't want that
77
                                $cont = preg_replace('@a:.+ {.+}@ismU', '', $cont);
78
 
79
                                // phpinfo() sets "h1 {font-size: 150%;}" and "h2 {font-size: 125%;}"
80
                                $cont = preg_replace('@(h1|h2|h3|h4|h5) {.+}@ismU', '', $cont);
81
 
987 daniel-mar 82
                                // Make compatible for dark themes by removing all foreground and background colors
1047 daniel-mar 83
                                $cont = preg_replace('@(body) {.+}@ismU', '', $cont, 1);
84
                                $cont = preg_replace('@background-color:(.+)[\\};]@ismU', '', $cont);
987 daniel-mar 85
                                $cont = '<span style="font-family: sans-serif;">'.$cont.'</span>';
86
 
87
                                // Font sizes
88
                                $cont = preg_replace('@font-size:\\s*75%;@', '', $cont);
89
                                for ($i=5; $i>=1; $i--) {
90
                                        $cont = str_replace('<h'.$i, '<h'.($i+1), $cont);
91
                                        $cont = str_replace('</h'.$i, '</h'.($i+1), $cont);
92
                                }
93
 
795 daniel-mar 94
                                $out['text'] .= $cont;
95
                        }
96
                }
97
                else if ($id === 'oidplus:systeminfo') {
98
                        $handled = true;
635 daniel-mar 99
                        $out['title'] = _L('System information');
801 daniel-mar 100
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 101
 
102
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 103
                                $out['icon'] = 'img/error.png';
635 daniel-mar 104
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
105
                                return;
106
                        }
107
 
108
                        $out['text']  = '';
109
 
110
                        # ---
111
 
112
                        $out['text'] .= '<h2>'._L('OIDplus').'</h2>';
113
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
114
                        $out['text'] .= '<table class="table table-bordered table-striped">';
115
                        $out['text'] .= '       <tr>';
116
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
117
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
118
                        $out['text'] .= '       </tr>';
688 daniel-mar 119
 
120
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 121
                        $out['text'] .= '       <tr>';
688 daniel-mar 122
                        $out['text'] .= '               <td>'._L('System title').'</td>';
123
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
124
                        $out['text'] .= '       </tr>';
635 daniel-mar 125
 
688 daniel-mar 126
                        $out['text'] .= '       <tr>';
127
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
128
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
129
                        $out['text'] .= '       </tr>';
130
 
635 daniel-mar 131
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 132
                        $out['text'] .= '       <tr>';
635 daniel-mar 133
                        $out['text'] .= '               <td>'._L('System OID').'</td>';
134
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
135
                        $out['text'] .= '       </tr>';
136
 
801 daniel-mar 137
                        $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
635 daniel-mar 138
                        $out['text'] .= '       <tr>';
139
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
140
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
141
                        $out['text'] .= '       </tr>';
142
 
143
                        $sys_ver = OIDplus::getVersion();
144
                        $out['text'] .= '       <tr>';
145
                        $out['text'] .= '               <td>'._L('System version').'</td>';
146
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
147
                        $out['text'] .= '       </tr>';
148
 
149
                        $sys_install_type = OIDplus::getInstallType();
150
                        $out['text'] .= '       <tr>';
151
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
152
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
153
                        $out['text'] .= '       </tr>';
154
 
155
                        $out['text'] .= '</table>';
156
                        $out['text'] .= '</div></div>';
157
 
158
                        # ---
159
 
160
                        $out['text'] .= '<h2>'._L('PHP').'</h2>';
161
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
162
                        $out['text'] .= '<table class="table table-bordered table-striped">';
163
                        $out['text'] .= '       <tr>';
164
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
165
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
166
                        $out['text'] .= '       </tr>';
167
                        $out['text'] .= '       <tr>';
168
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
169
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
170
                        $out['text'] .= '       </tr>';
697 daniel-mar 171
                        $out['text'] .= '       <tr>';
794 daniel-mar 172
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
795 daniel-mar 173
                        $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
794 daniel-mar 174
                        $out['text'] .= '       </tr>';
175
                        $out['text'] .= '       <tr>';
697 daniel-mar 176
                        $out['text'] .= '               <td>'._L('Installed extensions').'</td>';
177
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
178
                        $out['text'] .= '       </tr>';
635 daniel-mar 179
                        $out['text'] .= '</table>';
799 daniel-mar 180
                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
635 daniel-mar 181
                        $out['text'] .= '</div></div>';
182
 
183
                        # ---
184
 
185
                        $out['text'] .= '<h2>'._L('Webserver').'</h2>';
186
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
187
                        $out['text'] .= '<table class="table table-bordered table-striped">';
188
                        $out['text'] .= '       <tr>';
189
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
190
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
191
                        $out['text'] .= '       </tr>';
192
                        $out['text'] .= '       <tr>';
193
                        $out['text'] .= '               <td>'._L('Server software').'</td>';
194
                        $out['text'] .= '               <td>'.(isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '<i>'._L('unknown').'</i>').'</td>';
195
                        $out['text'] .= '       </tr>';
662 daniel-mar 196
                        $out['text'] .= '       <tr>';
197
                        $out['text'] .= '               <td>'._L('User account').'</td>';
688 daniel-mar 198
                        $current_user = exec('whoami');
199
                        if ($current_user == '') {
200
                                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
201
                                        // Windows on an IIS server:
202
                                        //     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 )
203
                                        //     get_current_user()     DefaultAppPool
204
                                        //     exec('whoami')         iis apppool\defaultapppool
205
                                        // Windows with XAMPP:
206
                                        //     getenv('USERNAME')     dmarschall
207
                                        //     get_current_user()     dmarschall               (even if script has a different NTFS owner!)
208
                                        //     exec('whoami')         hickelsoft\dmarschall
209
                                        $current_user = get_current_user();
210
                                        if ($current_user == '') $current_user = getenv('USERNAME');
211
                                } else {
212
                                        // On Linux:
213
                                        // get_current_user() will get the owner of the PHP script, not the process owner!
214
                                        // We want the process owner, so we use posix_geteuid().
720 daniel-mar 215
                                        if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
216
                                                $uid = posix_geteuid();
217
                                                $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
218
                                        } else {
219
                                                $uid = -1;
220
                                        }
688 daniel-mar 221
                                        if ($current_user == '') $current_user = get_current_user();
720 daniel-mar 222
                                        if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
688 daniel-mar 223
                                }
685 daniel-mar 224
                        }
688 daniel-mar 225
                        $out['text'] .= '               <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
662 daniel-mar 226
                        $out['text'] .= '       </tr>';
635 daniel-mar 227
                        $out['text'] .= '</table>';
228
                        $out['text'] .= '</div></div>';
229
 
230
                        # ---
231
 
795 daniel-mar 232
                        $out['text'] .= '<h2>'._L('Database').'</h2>';
233
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
234
                        $out['text'] .= '<table class="table table-bordered table-striped">';
235
                        $out['text'] .= '       <tr>';
236
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
237
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
238
                        $out['text'] .= '       </tr>';
239
 
240
                        $out['text'] .= '       <tr>';
241
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
242
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
243
                        $out['text'] .= '       </tr>';
244
 
245
                        $out['text'] .= '       <tr>';
246
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
247
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
248
                        $out['text'] .= '       </tr>';
249
 
250
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
251
                        $out['text'] .= '       <tr>';
252
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
253
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
254
                        $out['text'] .= '       </tr>';
255
                        $out['text'] .= '       <tr>';
256
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
257
                        $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
258
                        if ($tmp) $tmp = $tmp->fetch_array();
259
                        $tmp = isset($tmp['tmp']) ? $tmp['tmp'] :  _L('n/a');
260
                        $out['text'] .= '               <td>'.$tmp.'</td>';
261
                        $out['text'] .= '       </tr>';
262
                        $out['text'] .= '</table>';
263
                        $out['text'] .= '</div></div>';
264
 
265
                        // TODO: can we somehow get the DBMS version, connection string etc?
266
 
267
                        # ---
268
 
635 daniel-mar 269
                        $out['text'] .= '<h2>'._L('Operating System').'</h2>';
270
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
271
                        $out['text'] .= '<table class="table table-bordered table-striped">';
272
                        $out['text'] .= '       <tr>';
273
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
274
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
275
                        $out['text'] .= '       </tr>';
276
                        if (php_uname("m") == php_uname("n")) {
277
                                // At some hosts like Strato, php_uname() always returns the same string
278
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
279
                                $out['text'] .= '       <tr>';
280
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
281
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
282
                                $out['text'] .= '       </tr>';
283
                                $out['text'] .= '       <tr>';
284
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
285
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
286
                                $out['text'] .= '       </tr>';
287
                        } else {
288
                                $out['text'] .= '       <tr>';
289
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
290
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
291
                                $out['text'] .= '       </tr>';
292
                                $out['text'] .= '       <tr>';
293
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
294
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
295
                                $out['text'] .= '       </tr>';
296
                                $out['text'] .= '       <tr>';
297
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
298
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
299
                                $out['text'] .= '       </tr>';
300
                        }
798 daniel-mar 301
                        $out['text'] .= '       <tr>';
302
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
303
                        $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
304
                        $out['text'] .= '       </tr>';
635 daniel-mar 305
                        $out['text'] .= '</table>';
306
                        $out['text'] .= '</div></div>';
307
 
308
                        # ---
309
 
310
                }
311
        }
312
 
313
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
314
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
315
 
800 daniel-mar 316
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 317
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 318
                } else {
319
                        $tree_icon = null; // default icon (folder)
320
                }
321
 
800 daniel-mar 322
                if (file_exists(__DIR__.'/img/php_icon16.png')) {
801 daniel-mar 323
                        $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
799 daniel-mar 324
                } else {
325
                        $tree_icon_php = null; // default icon (folder)
326
                }
327
 
635 daniel-mar 328
                $json[] = array(
329
                        'id' => 'oidplus:systeminfo',
330
                        'icon' => $tree_icon,
799 daniel-mar 331
                        'text' => _L('System information'),
332
                        'children' => array(array(
333
                                'id' => 'oidplus:phpinfo',
334
                                'icon' => $tree_icon_php,
335
                                'text' => _L('PHP information')
336
                        ))
635 daniel-mar 337
                );
338
 
339
                return true;
340
        }
341
 
342
        public function tree_search($request) {
343
                return false;
344
        }
345
 
346
        public function implementsFeature($id) {
347
                return false;
348
        }
662 daniel-mar 349
}