Rev 1073 | Rev 1086 | 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>'; |
1073 | daniel-mar | 133 | $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 | 134 | $out['text'] .= ' <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>'; |
135 | $out['text'] .= ' </tr>'; |
||
136 | |||
1073 | daniel-mar | 137 | $sysid_guid = OIDplus::getSystemGuid(); |
138 | $out['text'] .= ' <tr>'; |
||
139 | $out['text'] .= ' <td>'._L('System GUID').' <abbr title="'._L('SHA1-Namebased UUID based on the public key of your OIDplus system.').'">(?)</abbr></td>'; |
||
140 | $out['text'] .= ' <td>'.(!$sysid_guid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_guid)).'</td>'; |
||
141 | $out['text'] .= ' </tr>'; |
||
142 | |||
1078 | daniel-mar | 143 | $sysid = OIDplus::getSystemId(false); |
144 | $sysid_aid = $sysid ? 'D276000186B20005'.strtoupper(str_pad(dechex($sysid),8,'0',STR_PAD_LEFT)) : ''; |
||
145 | $out['text'] .= ' <tr>'; |
||
146 | $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>'; |
||
147 | $out['text'] .= ' <td>'.(!$sysid_aid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L('No PIX allowed').')</td>'; |
||
148 | $out['text'] .= ' </tr>'; |
||
149 | |||
801 | daniel-mar | 150 | $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL); |
635 | daniel-mar | 151 | $out['text'] .= ' <tr>'; |
152 | $out['text'] .= ' <td>'._L('System URL').'</td>'; |
||
153 | $out['text'] .= ' <td>'.htmlentities($sys_url).'</td>'; |
||
154 | $out['text'] .= ' </tr>'; |
||
155 | |||
156 | $sys_ver = OIDplus::getVersion(); |
||
157 | $out['text'] .= ' <tr>'; |
||
158 | $out['text'] .= ' <td>'._L('System version').'</td>'; |
||
159 | $out['text'] .= ' <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>'; |
||
160 | $out['text'] .= ' </tr>'; |
||
161 | |||
162 | $sys_install_type = OIDplus::getInstallType(); |
||
163 | $out['text'] .= ' <tr>'; |
||
164 | $out['text'] .= ' <td>'._L('Installation type').'</td>'; |
||
165 | $out['text'] .= ' <td>'.htmlentities($sys_install_type).'</td>'; |
||
166 | $out['text'] .= ' </tr>'; |
||
167 | |||
168 | $out['text'] .= '</table>'; |
||
169 | $out['text'] .= '</div></div>'; |
||
170 | |||
171 | # --- |
||
172 | |||
173 | $out['text'] .= '<h2>'._L('PHP').'</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('PHP version').'</td>'; |
||
182 | $out['text'] .= ' <td>'.PHP_VERSION.'</td>'; |
||
183 | $out['text'] .= ' </tr>'; |
||
697 | daniel-mar | 184 | $out['text'] .= ' <tr>'; |
794 | daniel-mar | 185 | $out['text'] .= ' <td>'._L('PHP configuration file(s)').'</td>'; |
795 | daniel-mar | 186 | $out['text'] .= ' <td>'.$this->getLoadedInis().'</td>'; |
794 | daniel-mar | 187 | $out['text'] .= ' </tr>'; |
188 | $out['text'] .= ' <tr>'; |
||
697 | daniel-mar | 189 | $out['text'] .= ' <td>'._L('Installed extensions').'</td>'; |
190 | $out['text'] .= ' <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>'; |
||
191 | $out['text'] .= ' </tr>'; |
||
635 | daniel-mar | 192 | $out['text'] .= '</table>'; |
799 | daniel-mar | 193 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>'; |
635 | daniel-mar | 194 | $out['text'] .= '</div></div>'; |
195 | |||
196 | # --- |
||
197 | |||
198 | $out['text'] .= '<h2>'._L('Webserver').'</h2>'; |
||
199 | $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
200 | $out['text'] .= '<table class="table table-bordered table-striped">'; |
||
201 | $out['text'] .= ' <tr>'; |
||
202 | $out['text'] .= ' <th width="50%">'._L('Attribute').'</th>'; |
||
203 | $out['text'] .= ' <th width="50%">'._L('Value').'</th>'; |
||
204 | $out['text'] .= ' </tr>'; |
||
205 | $out['text'] .= ' <tr>'; |
||
206 | $out['text'] .= ' <td>'._L('Server software').'</td>'; |
||
207 | $out['text'] .= ' <td>'.(isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '<i>'._L('unknown').'</i>').'</td>'; |
||
208 | $out['text'] .= ' </tr>'; |
||
662 | daniel-mar | 209 | $out['text'] .= ' <tr>'; |
210 | $out['text'] .= ' <td>'._L('User account').'</td>'; |
||
688 | daniel-mar | 211 | $current_user = exec('whoami'); |
212 | if ($current_user == '') { |
||
213 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
||
214 | // Windows on an IIS server: |
||
215 | // 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 ) |
||
216 | // get_current_user() DefaultAppPool |
||
217 | // exec('whoami') iis apppool\defaultapppool |
||
218 | // Windows with XAMPP: |
||
219 | // getenv('USERNAME') dmarschall |
||
220 | // get_current_user() dmarschall (even if script has a different NTFS owner!) |
||
221 | // exec('whoami') hickelsoft\dmarschall |
||
222 | $current_user = get_current_user(); |
||
223 | if ($current_user == '') $current_user = getenv('USERNAME'); |
||
224 | } else { |
||
225 | // On Linux: |
||
226 | // get_current_user() will get the owner of the PHP script, not the process owner! |
||
227 | // We want the process owner, so we use posix_geteuid(). |
||
720 | daniel-mar | 228 | if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) { |
229 | $uid = posix_geteuid(); |
||
230 | $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd ) |
||
231 | } else { |
||
232 | $uid = -1; |
||
233 | } |
||
688 | daniel-mar | 234 | if ($current_user == '') $current_user = get_current_user(); |
720 | daniel-mar | 235 | if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid; |
688 | daniel-mar | 236 | } |
685 | daniel-mar | 237 | } |
688 | daniel-mar | 238 | $out['text'] .= ' <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>'; |
662 | daniel-mar | 239 | $out['text'] .= ' </tr>'; |
635 | daniel-mar | 240 | $out['text'] .= '</table>'; |
241 | $out['text'] .= '</div></div>'; |
||
242 | |||
243 | # --- |
||
244 | |||
795 | daniel-mar | 245 | $out['text'] .= '<h2>'._L('Database').'</h2>'; |
246 | $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
247 | $out['text'] .= '<table class="table table-bordered table-striped">'; |
||
248 | $out['text'] .= ' <tr>'; |
||
249 | $out['text'] .= ' <th width="50%">'._L('Attribute').'</th>'; |
||
250 | $out['text'] .= ' <th width="50%">'._L('Value').'</th>'; |
||
251 | $out['text'] .= ' </tr>'; |
||
252 | |||
253 | $out['text'] .= ' <tr>'; |
||
254 | $out['text'] .= ' <td>'._L('Database provider').'</td>'; |
||
255 | $out['text'] .= ' <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>'; |
||
256 | $out['text'] .= ' </tr>'; |
||
257 | |||
258 | $out['text'] .= ' <tr>'; |
||
259 | $out['text'] .= ' <td>'._L('SQL slang').'</td>'; |
||
260 | $out['text'] .= ' <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>'; |
||
261 | $out['text'] .= ' </tr>'; |
||
262 | |||
263 | $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX'); |
||
264 | $out['text'] .= ' <tr>'; |
||
265 | $out['text'] .= ' <td>'._L('Table name prefix').'</td>'; |
||
266 | $out['text'] .= ' <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>'; |
||
267 | $out['text'] .= ' </tr>'; |
||
268 | $out['text'] .= ' <tr>'; |
||
269 | $out['text'] .= ' <td>'._L('Server time').'</td>'; |
||
270 | $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp'); |
||
271 | if ($tmp) $tmp = $tmp->fetch_array(); |
||
272 | $tmp = isset($tmp['tmp']) ? $tmp['tmp'] : _L('n/a'); |
||
273 | $out['text'] .= ' <td>'.$tmp.'</td>'; |
||
274 | $out['text'] .= ' </tr>'; |
||
275 | $out['text'] .= '</table>'; |
||
276 | $out['text'] .= '</div></div>'; |
||
277 | |||
278 | // TODO: can we somehow get the DBMS version, connection string etc? |
||
279 | |||
280 | # --- |
||
281 | |||
635 | daniel-mar | 282 | $out['text'] .= '<h2>'._L('Operating System').'</h2>'; |
283 | $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
284 | $out['text'] .= '<table class="table table-bordered table-striped">'; |
||
285 | $out['text'] .= ' <tr>'; |
||
286 | $out['text'] .= ' <th width="50%">'._L('Attribute').'</th>'; |
||
287 | $out['text'] .= ' <th width="50%">'._L('Value').'</th>'; |
||
288 | $out['text'] .= ' </tr>'; |
||
289 | if (php_uname("m") == php_uname("n")) { |
||
290 | // At some hosts like Strato, php_uname() always returns the same string |
||
291 | // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP" |
||
292 | $out['text'] .= ' <tr>'; |
||
293 | $out['text'] .= ' <td>'._L('Operating System').'</td>'; |
||
294 | $out['text'] .= ' <td>'.htmlentities(PHP_OS).'</td>'; |
||
295 | $out['text'] .= ' </tr>'; |
||
296 | $out['text'] .= ' <tr>'; |
||
297 | $out['text'] .= ' <td>'._L('Hostname').'</td>'; |
||
298 | $out['text'] .= ' <td>'.htmlentities(gethostname()).'</td>'; |
||
299 | $out['text'] .= ' </tr>'; |
||
300 | } else { |
||
301 | $out['text'] .= ' <tr>'; |
||
302 | $out['text'] .= ' <td>'._L('Operating System').'</td>'; |
||
303 | $out['text'] .= ' <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>'; |
||
304 | $out['text'] .= ' </tr>'; |
||
305 | $out['text'] .= ' <tr>'; |
||
306 | $out['text'] .= ' <td>'._L('Machine type').'</td>'; |
||
307 | $out['text'] .= ' <td>'.htmlentities(php_uname("m")).'</td>'; |
||
308 | $out['text'] .= ' </tr>'; |
||
309 | $out['text'] .= ' <tr>'; |
||
310 | $out['text'] .= ' <td>'._L('Hostname').'</td>'; |
||
311 | $out['text'] .= ' <td>'.htmlentities(php_uname("n")).'</td>'; |
||
312 | $out['text'] .= ' </tr>'; |
||
313 | } |
||
798 | daniel-mar | 314 | $out['text'] .= ' <tr>'; |
315 | $out['text'] .= ' <td>'._L('Server time').'</td>'; |
||
316 | $out['text'] .= ' <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>'; |
||
317 | $out['text'] .= ' </tr>'; |
||
635 | daniel-mar | 318 | $out['text'] .= '</table>'; |
319 | $out['text'] .= '</div></div>'; |
||
320 | |||
321 | # --- |
||
322 | |||
323 | } |
||
324 | } |
||
325 | |||
326 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
327 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
328 | |||
800 | daniel-mar | 329 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 330 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 331 | } else { |
332 | $tree_icon = null; // default icon (folder) |
||
333 | } |
||
334 | |||
800 | daniel-mar | 335 | if (file_exists(__DIR__.'/img/php_icon16.png')) { |
801 | daniel-mar | 336 | $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png'; |
799 | daniel-mar | 337 | } else { |
338 | $tree_icon_php = null; // default icon (folder) |
||
339 | } |
||
340 | |||
635 | daniel-mar | 341 | $json[] = array( |
342 | 'id' => 'oidplus:systeminfo', |
||
343 | 'icon' => $tree_icon, |
||
799 | daniel-mar | 344 | 'text' => _L('System information'), |
345 | 'children' => array(array( |
||
346 | 'id' => 'oidplus:phpinfo', |
||
347 | 'icon' => $tree_icon_php, |
||
348 | 'text' => _L('PHP information') |
||
349 | )) |
||
635 | daniel-mar | 350 | ); |
351 | |||
352 | return true; |
||
353 | } |
||
354 | |||
355 | public function tree_search($request) { |
||
356 | return false; |
||
357 | } |
||
358 | |||
359 | public function implementsFeature($id) { |
||
360 | return false; |
||
361 | } |
||
662 | daniel-mar | 362 | } |