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