<?php
/*
* OIDplus 2.0
* Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace ViaThinkSoft\OIDplus;
// phpcs:disable PSR1.Files.SideEffects
// phpcs:enable PSR1.Files.SideEffects
class OIDplusPageAdminSysteminfo extends OIDplusPagePluginAdmin {
/**
* @param string $actionID
* @param array $params
* @return array
* @throws OIDplusException
*/
public function action
(string
$actionID, array $params): array {
return parent::action($actionID, $params);
}
/**
* @param bool $html
* @return void
*/
public function init(bool $html=true) {
}
/**
* @return array|mixed|string|string[]
*/
private function getLoadedInis() {
$s_inis = '';
if ($main_ini !== false) $s_inis = '<b>'.htmlentities($main_ini).'</b>';
if ($more_ini !== false) {
foreach ($inis as $ini) {
}
}
if ($s_inis == '') $s_inis = _L('n/a');
return $s_inis;
}
/**
* @param string $id
* @param array $out
* @param bool $handled
* @return void
* @throws OIDplusConfigInitializationException
* @throws OIDplusException
*/
public function gui
(string
$id, array &$out, bool
&$handled) {
if ($id === 'oidplus:phpinfo') {
$handled = true;
$out['title'] = _L('PHP information');
$out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon.png';
if (!OIDplus::authUtils()->isAdminLoggedIn()) {
$out['icon'] = 'img/error.png';
$out['text'] = '<p>'._L
('You need to <a %1>log in</a> as administrator.',OIDplus
::gui()->link('oidplus:login$admin')).'</p>';
return;
}
$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>';
if (!$res) {
$out['text'] .= '<p><font color="red">'._L('phpinfo() could not be called').'</font></p>';
} else {
// phpinfo() sets "img {float: right; border: 0;}". We don't want that.
$cont = str_replace('<img', '<img class="phpinfo"', $cont);
// phpinfo() sets the link colors. We don't want that
// phpinfo() sets "h1 {font-size: 150%;}" and "h2 {font-size: 125%;}"
$cont = preg_replace('@(h1|h2|h3|h4|h5) {.+}@ismU', '', $cont);
// Make compatible for dark themes by removing all foreground and background colors
$cont = preg_replace('@background-color:(.+)[\\};]@ismU', '', $cont);
$cont = '<span style="font-family: sans-serif;">'.$cont.'</span>';
// Font sizes
for ($i=5; $i>=1; $i--) {
}
$out['text'] .= $cont;
}
}
else if ($id === 'oidplus:systeminfo') {
$handled = true;
$out['title'] = _L('System information');
$out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
if (!OIDplus::authUtils()->isAdminLoggedIn()) {
$out['icon'] = 'img/error.png';
$out['text'] = '<p>'._L
('You need to <a %1>log in</a> as administrator.',OIDplus
::gui()->link('oidplus:login$admin')).'</p>';
return;
}
$out['text'] = '';
# ---
$out['text'] .= '<h2>'._L('OIDplus').'</h2>';
$out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
$out['text'] .= '<table class="table table-bordered table-striped">';
$out['text'] .= ' <tr>';
$out['text'] .= ' <th width="50%">'._L('Attribute').'</th>';
$out['text'] .= ' <th width="50%">'._L('Value').'</th>';
$out['text'] .= ' </tr>';
$sys_title = OIDplus::config()->getValue('system_title');
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('System title').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('System directory').'</td>';
$out['text'] .= ' <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ?
htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L
('unknown').'</i>').'</td>';
$out['text'] .= ' </tr>';
$sysid_oid = OIDplus::getSystemId(true);
$out['text'] .= ' <tr>';
$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>';
$out['text'] .= ' <td>'.(!$sysid_oid ?
'<i>'._L
('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
$out['text'] .= ' </tr>';
$sysid_guid = OIDplus::getSystemGuid();
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('System GUID').' <abbr title="'._L('SHA1-Namebased UUID based on the public key of your OIDplus system.').'">(?)</abbr></td>';
$out['text'] .= ' <td>'.(!$sysid_guid ?
'<i>'._L
('unknown').'</i>' : htmlentities($sysid_guid)).'</td>';
$out['text'] .= ' </tr>';
$sysid = OIDplus::getSystemId(false);
$out['text'] .= ' <tr>';
$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>';
$out['text'] .= ' <td>'.(!$sysid_aid ?
'<i>'._L
('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L
('No PIX allowed').')</td>';
$out['text'] .= ' </tr>';
$sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('System URL').'</td>';
$out['text'] .= ' </tr>';
$sys_ver = OIDplus::getVersion();
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('System version').'</td>';
$out['text'] .= ' <td>'.(!$sys_ver ?
'<i>'._L
('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
$out['text'] .= ' </tr>';
$sys_install_type = OIDplus::getInstallType();
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Installation type').'</td>';
$out['text'] .= ' <td>'.htmlentities($sys_install_type).'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= '</table>';
$out['text'] .= '</div></div>';
# ---
$out['text'] .= '<h2>'._L('PHP').'</h2>';
$out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
$out['text'] .= '<table class="table table-bordered table-striped">';
$out['text'] .= ' <tr>';
$out['text'] .= ' <th width="50%">'._L('Attribute').'</th>';
$out['text'] .= ' <th width="50%">'._L('Value').'</th>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('PHP version').'</td>';
$out['text'] .= ' <td>'.PHP_VERSION.'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('PHP configuration file(s)').'</td>';
$out['text'] .= ' <td>'.$this->getLoadedInis().'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Installed extensions').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= '</table>';
$out['text'] .= '<p><a '.OIDplus
::gui()->link('oidplus:phpinfo').'>'._L
('Show PHP server configuration (phpinfo)').'</a></p>';
$out['text'] .= '</div></div>';
# ---
$out['text'] .= '<h2>'._L('Webserver').'</h2>';
$out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
$out['text'] .= '<table class="table table-bordered table-striped">';
$out['text'] .= ' <tr>';
$out['text'] .= ' <th width="50%">'._L('Attribute').'</th>';
$out['text'] .= ' <th width="50%">'._L('Value').'</th>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Server software').'</td>';
$out['text'] .= ' <td>'.($_SERVER['SERVER_SOFTWARE'] ?? '<i>' . _L('unknown') . '</i>').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('User account').'</td>';
$current_user = exec('whoami');
if ($current_user == '') {
// Windows on an IIS server:
// 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 )
// get_current_user() DefaultAppPool
// exec('whoami') iis apppool\defaultapppool
// Windows with XAMPP:
// getenv('USERNAME') dmarschall
// get_current_user() dmarschall (even if script has a different NTFS owner!)
// exec('whoami') hickelsoft\dmarschall
if ($current_user == '') $current_user = getenv('USERNAME');
} else {
// On Linux:
// get_current_user() will get the owner of the PHP script, not the process owner!
// We want the process owner, so we use posix_geteuid().
$current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
} else {
$uid = -1;
}
if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
}
}
$out['text'] .= ' <td>'.($current_user == '' ?
'<i>'._L
('unknown').'</i>' : htmlentities($current_user)).'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= '</table>';
$out['text'] .= '</div></div>';
# ---
$out['text'] .= '<h2>'._L('Database').'</h2>';
$out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
$out['text'] .= '<table class="table table-bordered table-striped">';
$out['text'] .= ' <tr>';
$out['text'] .= ' <th width="50%">'._L('Attribute').'</th>';
$out['text'] .= ' <th width="50%">'._L('Value').'</th>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Database provider').'</td>';
$out['text'] .= ' <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('SQL slang').'</td>';
$out['text'] .= ' <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
$out['text'] .= ' </tr>';
$table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Table name prefix').'</td>';
$out['text'] .= ' <td>'.(!empty($table_prefix) ?
htmlentities($table_prefix) : '<i>'._L
('none').'</i>').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Server time').'</td>';
$tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
if ($tmp) $tmp = $tmp->fetch_array();
$tmp = $tmp['tmp'] ?? _L('n/a');
$out['text'] .= ' <td>'.$tmp.'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= '</table>';
$out['text'] .= '</div></div>';
// TODO: can we somehow get the DBMS version, connection string etc?
# ---
$out['text'] .= '<h2>'._L('Operating System').'</h2>';
$out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
$out['text'] .= '<table class="table table-bordered table-striped">';
$out['text'] .= ' <tr>';
$out['text'] .= ' <th width="50%">'._L('Attribute').'</th>';
$out['text'] .= ' <th width="50%">'._L('Value').'</th>';
$out['text'] .= ' </tr>';
// At some hosts like Strato, php_uname() always returns the same string
// "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Operating System').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Hostname').'</td>';
$out['text'] .= ' <td>'.htmlentities(gethostname
()).'</td>';
$out['text'] .= ' </tr>';
} else {
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Operating System').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Machine type').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Hostname').'</td>';
$out['text'] .= ' </tr>';
}
$out['text'] .= ' <tr>';
$out['text'] .= ' <td>'._L('Server time').'</td>';
$out['text'] .= ' </tr>';
$out['text'] .= '</table>';
$out['text'] .= '</div></div>';
# ---
}
}
/**
* @param array $json
* @param string|null $ra_email
* @param bool $nonjs
* @param string $req_goto
* @return bool
* @throws OIDplusException
*/
public function tree
(array &$json, string
$ra_email=null, bool
$nonjs=false, string
$req_goto=''): bool
{
if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
$tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
} else {
$tree_icon = null; // default icon (folder)
}
$tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
} else {
$tree_icon_php = null; // default icon (folder)
}
'id' => 'oidplus:systeminfo',
'icon' => $tree_icon,
'text' => _L('System information'),
'id' => 'oidplus:phpinfo',
'icon' => $tree_icon_php,
'text' => _L('PHP information')
))
);
return true;
}
/**
* @param string $request
* @return array|false
*/
public function tree_search(string $request) {
return false;
}
/**
* @param string $id
* @return bool
*/
public function implementsFeature(string $id): bool {
return false;
}
}