Subversion Repositories oidplus

Rev

Rev 799 | Rev 801 | 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
5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
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
 
20
if (!defined('INSIDE_OIDPLUS')) die();
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');
800 daniel-mar 54
                        $out['icon']  = OIDplus::webpath(__DIR__,true).'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
 
795 daniel-mar 82
                                $out['text'] .= $cont;
83
                        }
84
                }
85
                else if ($id === 'oidplus:systeminfo') {
86
                        $handled = true;
635 daniel-mar 87
                        $out['title'] = _L('System information');
800 daniel-mar 88
                        $out['icon']  = OIDplus::webpath(__DIR__,true).'img/main_icon.png';
635 daniel-mar 89
 
90
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 91
                                $out['icon'] = 'img/error.png';
635 daniel-mar 92
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
93
                                return;
94
                        }
95
 
96
                        $out['text']  = '';
97
 
98
                        # ---
99
 
100
                        $out['text'] .= '<h2>'._L('OIDplus').'</h2>';
101
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
102
                        $out['text'] .= '<table class="table table-bordered table-striped">';
103
                        $out['text'] .= '       <tr>';
104
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
105
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
106
                        $out['text'] .= '       </tr>';
688 daniel-mar 107
 
108
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 109
                        $out['text'] .= '       <tr>';
688 daniel-mar 110
                        $out['text'] .= '               <td>'._L('System title').'</td>';
111
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
112
                        $out['text'] .= '       </tr>';
635 daniel-mar 113
 
688 daniel-mar 114
                        $out['text'] .= '       <tr>';
115
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
116
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
117
                        $out['text'] .= '       </tr>';
118
 
635 daniel-mar 119
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 120
                        $out['text'] .= '       <tr>';
635 daniel-mar 121
                        $out['text'] .= '               <td>'._L('System OID').'</td>';
122
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
123
                        $out['text'] .= '       </tr>';
124
 
125
                        $sys_url = OIDplus::webpath();
126
                        $out['text'] .= '       <tr>';
127
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
128
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
129
                        $out['text'] .= '       </tr>';
130
 
131
                        $sys_ver = OIDplus::getVersion();
132
                        $out['text'] .= '       <tr>';
133
                        $out['text'] .= '               <td>'._L('System version').'</td>';
134
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
135
                        $out['text'] .= '       </tr>';
136
 
137
                        $sys_install_type = OIDplus::getInstallType();
138
                        $out['text'] .= '       <tr>';
139
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
140
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
141
                        $out['text'] .= '       </tr>';
142
 
143
                        $out['text'] .= '</table>';
144
                        $out['text'] .= '</div></div>';
145
 
146
                        # ---
147
 
148
                        $out['text'] .= '<h2>'._L('PHP').'</h2>';
149
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
150
                        $out['text'] .= '<table class="table table-bordered table-striped">';
151
                        $out['text'] .= '       <tr>';
152
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
153
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
154
                        $out['text'] .= '       </tr>';
155
                        $out['text'] .= '       <tr>';
156
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
157
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
158
                        $out['text'] .= '       </tr>';
697 daniel-mar 159
                        $out['text'] .= '       <tr>';
794 daniel-mar 160
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
795 daniel-mar 161
                        $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
794 daniel-mar 162
                        $out['text'] .= '       </tr>';
163
                        $out['text'] .= '       <tr>';
697 daniel-mar 164
                        $out['text'] .= '               <td>'._L('Installed extensions').'</td>';
165
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
166
                        $out['text'] .= '       </tr>';
635 daniel-mar 167
                        $out['text'] .= '</table>';
799 daniel-mar 168
                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
635 daniel-mar 169
                        $out['text'] .= '</div></div>';
170
 
171
                        # ---
172
 
173
                        $out['text'] .= '<h2>'._L('Webserver').'</h2>';
174
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
175
                        $out['text'] .= '<table class="table table-bordered table-striped">';
176
                        $out['text'] .= '       <tr>';
177
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
178
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
179
                        $out['text'] .= '       </tr>';
180
                        $out['text'] .= '       <tr>';
181
                        $out['text'] .= '               <td>'._L('Server software').'</td>';
182
                        $out['text'] .= '               <td>'.(isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '<i>'._L('unknown').'</i>').'</td>';
183
                        $out['text'] .= '       </tr>';
662 daniel-mar 184
                        $out['text'] .= '       <tr>';
185
                        $out['text'] .= '               <td>'._L('User account').'</td>';
688 daniel-mar 186
                        $current_user = exec('whoami');
187
                        if ($current_user == '') {
188
                                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
189
                                        // Windows on an IIS server:
190
                                        //     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 )
191
                                        //     get_current_user()     DefaultAppPool
192
                                        //     exec('whoami')         iis apppool\defaultapppool
193
                                        // Windows with XAMPP:
194
                                        //     getenv('USERNAME')     dmarschall
195
                                        //     get_current_user()     dmarschall               (even if script has a different NTFS owner!)
196
                                        //     exec('whoami')         hickelsoft\dmarschall
197
                                        $current_user = get_current_user();
198
                                        if ($current_user == '') $current_user = getenv('USERNAME');
199
                                } else {
200
                                        // On Linux:
201
                                        // get_current_user() will get the owner of the PHP script, not the process owner!
202
                                        // We want the process owner, so we use posix_geteuid().
720 daniel-mar 203
                                        if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
204
                                                $uid = posix_geteuid();
205
                                                $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
206
                                        } else {
207
                                                $uid = -1;
208
                                        }
688 daniel-mar 209
                                        if ($current_user == '') $current_user = get_current_user();
720 daniel-mar 210
                                        if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
688 daniel-mar 211
                                }
685 daniel-mar 212
                        }
688 daniel-mar 213
                        $out['text'] .= '               <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
662 daniel-mar 214
                        $out['text'] .= '       </tr>';
635 daniel-mar 215
                        $out['text'] .= '</table>';
216
                        $out['text'] .= '</div></div>';
217
 
218
                        # ---
219
 
795 daniel-mar 220
                        $out['text'] .= '<h2>'._L('Database').'</h2>';
221
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
222
                        $out['text'] .= '<table class="table table-bordered table-striped">';
223
                        $out['text'] .= '       <tr>';
224
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
225
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
226
                        $out['text'] .= '       </tr>';
227
 
228
                        $out['text'] .= '       <tr>';
229
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
230
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
231
                        $out['text'] .= '       </tr>';
232
 
233
                        $out['text'] .= '       <tr>';
234
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
235
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
236
                        $out['text'] .= '       </tr>';
237
 
238
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
239
                        $out['text'] .= '       <tr>';
240
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
241
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
242
                        $out['text'] .= '       </tr>';
243
                        $out['text'] .= '       <tr>';
244
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
245
                        $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
246
                        if ($tmp) $tmp = $tmp->fetch_array();
247
                        $tmp = isset($tmp['tmp']) ? $tmp['tmp'] :  _L('n/a');
248
                        $out['text'] .= '               <td>'.$tmp.'</td>';
249
                        $out['text'] .= '       </tr>';
250
                        $out['text'] .= '</table>';
251
                        $out['text'] .= '</div></div>';
252
 
253
                        // TODO: can we somehow get the DBMS version, connection string etc?
254
 
255
                        # ---
256
 
635 daniel-mar 257
                        $out['text'] .= '<h2>'._L('Operating System').'</h2>';
258
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
259
                        $out['text'] .= '<table class="table table-bordered table-striped">';
260
                        $out['text'] .= '       <tr>';
261
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
262
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
263
                        $out['text'] .= '       </tr>';
264
                        if (php_uname("m") == php_uname("n")) {
265
                                // At some hosts like Strato, php_uname() always returns the same string
266
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
267
                                $out['text'] .= '       <tr>';
268
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
269
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
270
                                $out['text'] .= '       </tr>';
271
                                $out['text'] .= '       <tr>';
272
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
273
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
274
                                $out['text'] .= '       </tr>';
275
                        } else {
276
                                $out['text'] .= '       <tr>';
277
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
278
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
279
                                $out['text'] .= '       </tr>';
280
                                $out['text'] .= '       <tr>';
281
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
282
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
283
                                $out['text'] .= '       </tr>';
284
                                $out['text'] .= '       <tr>';
285
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
286
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
287
                                $out['text'] .= '       </tr>';
288
                        }
798 daniel-mar 289
                        $out['text'] .= '       <tr>';
290
                        $out['text'] .= '               <td>'._L('Server time').'</td>';
291
                        $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
292
                        $out['text'] .= '       </tr>';
635 daniel-mar 293
                        $out['text'] .= '</table>';
294
                        $out['text'] .= '</div></div>';
295
 
296
                        # ---
297
 
298
                }
299
        }
300
 
301
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
302
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
303
 
800 daniel-mar 304
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
305
                        $tree_icon = OIDplus::webpath(__DIR__,true).'img/main_icon16.png';
635 daniel-mar 306
                } else {
307
                        $tree_icon = null; // default icon (folder)
308
                }
309
 
800 daniel-mar 310
                if (file_exists(__DIR__.'/img/php_icon16.png')) {
311
                        $tree_icon_php = OIDplus::webpath(__DIR__,true).'img/php_icon16.png';
799 daniel-mar 312
                } else {
313
                        $tree_icon_php = null; // default icon (folder)
314
                }
315
 
635 daniel-mar 316
                $json[] = array(
317
                        'id' => 'oidplus:systeminfo',
318
                        'icon' => $tree_icon,
799 daniel-mar 319
                        'text' => _L('System information'),
320
                        'children' => array(array(
321
                                'id' => 'oidplus:phpinfo',
322
                                'icon' => $tree_icon_php,
323
                                'text' => _L('PHP information')
324
                        ))
635 daniel-mar 325
                );
326
 
327
                return true;
328
        }
329
 
330
        public function tree_search($request) {
331
                return false;
332
        }
333
 
334
        public function implementsFeature($id) {
335
                return false;
336
        }
662 daniel-mar 337
}