Subversion Repositories oidplus

Rev

Rev 720 | Rev 795 | 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
 
30
        public function gui($id, &$out, &$handled) {
31
                if ($id === 'oidplus:systeminfo') {
32
                        $handled = true;
33
                        $out['title'] = _L('System information');
34
                        $out['icon']  = OIDplus::webpath(__DIR__).'icon_big.png';
35
 
36
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
37
                                $out['icon'] = 'img/error_big.png';
38
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
39
                                return;
40
                        }
41
 
42
                        $out['text']  = '';
43
 
44
                        # ---
45
 
46
                        $out['text'] .= '<h2>'._L('OIDplus').'</h2>';
47
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
48
                        $out['text'] .= '<table class="table table-bordered table-striped">';
49
                        $out['text'] .= '       <tr>';
50
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
51
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
52
                        $out['text'] .= '       </tr>';
688 daniel-mar 53
 
54
                        $sys_title = OIDplus::config()->getValue('system_title');
635 daniel-mar 55
                        $out['text'] .= '       <tr>';
688 daniel-mar 56
                        $out['text'] .= '               <td>'._L('System title').'</td>';
57
                        $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
58
                        $out['text'] .= '       </tr>';
635 daniel-mar 59
 
688 daniel-mar 60
                        $out['text'] .= '       <tr>';
61
                        $out['text'] .= '               <td>'._L('System directory').'</td>';
62
                        $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
63
                        $out['text'] .= '       </tr>';
64
 
635 daniel-mar 65
                        $sysid_oid = OIDplus::getSystemId(true);
688 daniel-mar 66
                        $out['text'] .= '       <tr>';
635 daniel-mar 67
                        $out['text'] .= '               <td>'._L('System OID').'</td>';
68
                        $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
69
                        $out['text'] .= '       </tr>';
70
 
71
                        $sys_url = OIDplus::webpath();
72
                        $out['text'] .= '       <tr>';
73
                        $out['text'] .= '               <td>'._L('System URL').'</td>';
74
                        $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
75
                        $out['text'] .= '       </tr>';
76
 
77
                        $sys_ver = OIDplus::getVersion();
78
                        $out['text'] .= '       <tr>';
79
                        $out['text'] .= '               <td>'._L('System version').'</td>';
80
                        $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
81
                        $out['text'] .= '       </tr>';
82
 
83
                        $sys_install_type = OIDplus::getInstallType();
84
                        $out['text'] .= '       <tr>';
85
                        $out['text'] .= '               <td>'._L('Installation type').'</td>';
86
                        $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
87
                        $out['text'] .= '       </tr>';
88
 
89
                        $out['text'] .= '</table>';
90
                        $out['text'] .= '</div></div>';
91
 
92
                        # ---
93
 
94
                        $out['text'] .= '<h2>'._L('PHP').'</h2>';
95
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
96
                        $out['text'] .= '<table class="table table-bordered table-striped">';
97
                        $out['text'] .= '       <tr>';
98
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
99
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
100
                        $out['text'] .= '       </tr>';
101
                        $out['text'] .= '       <tr>';
102
                        $out['text'] .= '               <td>'._L('PHP version').'</td>';
103
                        $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
104
                        $out['text'] .= '       </tr>';
697 daniel-mar 105
                        $out['text'] .= '       <tr>';
794 daniel-mar 106
                        $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
107
 
108
                        $inis = array();
109
                        $main_ini = php_ini_loaded_file();
110
                        if ($main_ini !== false) $inis[] = $main_ini;
111
                        $more_ini = php_ini_scanned_files();
112
                        if ($more_ini !== false) $inis = array_merge($inis, $more_ini);
113
                        $s_inis = (count($inis) == 0) ? _L('n/a') : implode("<br>",$inis);
114
 
115
                        $out['text'] .= '               <td>'.htmlentities($s_inis).'</td>';
116
                        $out['text'] .= '       </tr>';
117
                        $out['text'] .= '       <tr>';
697 daniel-mar 118
                        $out['text'] .= '               <td>'._L('Installed extensions').'</td>';
119
                        $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
120
                        $out['text'] .= '       </tr>';
635 daniel-mar 121
                        $out['text'] .= '</table>';
122
                        $out['text'] .= '</div></div>';
123
 
124
                        # ---
125
 
126
                        $out['text'] .= '<h2>'._L('Webserver').'</h2>';
127
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
128
                        $out['text'] .= '<table class="table table-bordered table-striped">';
129
                        $out['text'] .= '       <tr>';
130
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
131
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
132
                        $out['text'] .= '       </tr>';
133
                        $out['text'] .= '       <tr>';
134
                        $out['text'] .= '               <td>'._L('Server software').'</td>';
135
                        $out['text'] .= '               <td>'.(isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '<i>'._L('unknown').'</i>').'</td>';
136
                        $out['text'] .= '       </tr>';
662 daniel-mar 137
                        $out['text'] .= '       <tr>';
138
                        $out['text'] .= '               <td>'._L('User account').'</td>';
688 daniel-mar 139
                        $current_user = exec('whoami');
140
                        if ($current_user == '') {
141
                                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
142
                                        // Windows on an IIS server:
143
                                        //     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 )
144
                                        //     get_current_user()     DefaultAppPool
145
                                        //     exec('whoami')         iis apppool\defaultapppool
146
                                        // Windows with XAMPP:
147
                                        //     getenv('USERNAME')     dmarschall
148
                                        //     get_current_user()     dmarschall               (even if script has a different NTFS owner!)
149
                                        //     exec('whoami')         hickelsoft\dmarschall
150
                                        $current_user = get_current_user();
151
                                        if ($current_user == '') $current_user = getenv('USERNAME');
152
                                } else {
153
                                        // On Linux:
154
                                        // get_current_user() will get the owner of the PHP script, not the process owner!
155
                                        // We want the process owner, so we use posix_geteuid().
720 daniel-mar 156
                                        if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
157
                                                $uid = posix_geteuid();
158
                                                $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
159
                                        } else {
160
                                                $uid = -1;
161
                                        }
688 daniel-mar 162
                                        if ($current_user == '') $current_user = get_current_user();
720 daniel-mar 163
                                        if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
688 daniel-mar 164
                                }
685 daniel-mar 165
                        }
688 daniel-mar 166
                        $out['text'] .= '               <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
662 daniel-mar 167
                        $out['text'] .= '       </tr>';
635 daniel-mar 168
                        $out['text'] .= '</table>';
169
                        $out['text'] .= '</div></div>';
170
 
171
                        # ---
172
 
173
                        $out['text'] .= '<h2>'._L('Operating System').'</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
                        if (php_uname("m") == php_uname("n")) {
181
                                // At some hosts like Strato, php_uname() always returns the same string
182
                                // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
183
                                $out['text'] .= '       <tr>';
184
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
185
                                $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
186
                                $out['text'] .= '       </tr>';
187
                                $out['text'] .= '       <tr>';
188
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
189
                                $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
190
                                $out['text'] .= '       </tr>';
191
                        } else {
192
                                $out['text'] .= '       <tr>';
193
                                $out['text'] .= '               <td>'._L('Operating System').'</td>';
194
                                $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
195
                                $out['text'] .= '       </tr>';
196
                                $out['text'] .= '       <tr>';
197
                                $out['text'] .= '               <td>'._L('Machine type').'</td>';
198
                                $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
199
                                $out['text'] .= '       </tr>';
200
                                $out['text'] .= '       <tr>';
201
                                $out['text'] .= '               <td>'._L('Hostname').'</td>';
202
                                $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
203
                                $out['text'] .= '       </tr>';
204
                        }
205
                        $out['text'] .= '</table>';
206
                        $out['text'] .= '</div></div>';
207
 
208
                        # ---
209
 
210
                        $out['text'] .= '<h2>'._L('Database').'</h2>';
211
                        $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
212
                        $out['text'] .= '<table class="table table-bordered table-striped">';
213
                        $out['text'] .= '       <tr>';
214
                        $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
215
                        $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
216
                        $out['text'] .= '       </tr>';
217
 
218
                        $out['text'] .= '       <tr>';
219
                        $out['text'] .= '               <td>'._L('Database provider').'</td>';
220
                        $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
221
                        $out['text'] .= '       </tr>';
222
 
223
                        $out['text'] .= '       <tr>';
224
                        $out['text'] .= '               <td>'._L('SQL slang').'</td>';
225
                        $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
226
                        $out['text'] .= '       </tr>';
227
 
228
                        $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
229
                        $out['text'] .= '       <tr>';
230
                        $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
231
                        $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
232
                        $out['text'] .= '       </tr>';
233
                        $out['text'] .= '</table>';
234
                        $out['text'] .= '</div></div>';
235
 
236
                        // TODO: can we somehow get the DBMS version, connection string etc?
237
 
238
                        # ---
239
 
240
                }
241
        }
242
 
243
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
244
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
245
 
246
                if (file_exists(__DIR__.'/treeicon.png')) {
247
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
248
                } else {
249
                        $tree_icon = null; // default icon (folder)
250
                }
251
 
252
                $json[] = array(
253
                        'id' => 'oidplus:systeminfo',
254
                        'icon' => $tree_icon,
255
                        'text' => _L('System information')
256
                );
257
 
258
                return true;
259
        }
260
 
261
        public function tree_search($request) {
262
                return false;
263
        }
264
 
265
        public function implementsFeature($id) {
266
                return false;
267
        }
662 daniel-mar 268
}