Subversion Repositories oidplus

Rev

Rev 1078 | Rev 1116 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPageAdminSysteminfo extends OIDplusPagePluginAdmin {
  27.  
  28.         public function action($actionID, $params) {
  29.         }
  30.  
  31.         public function init($html=true) {
  32.         }
  33.  
  34.         private function getLoadedInis() {
  35.                 $s_inis = '';
  36.  
  37.                 $inis = array();
  38.                 $main_ini = php_ini_loaded_file();
  39.                 if ($main_ini !== false) $s_inis = '<b>'.htmlentities($main_ini).'</b>';
  40.  
  41.                 $more_ini = php_ini_scanned_files();
  42.                 if ($more_ini !== false) {
  43.                         $inis = explode(',', $more_ini);
  44.                         foreach ($inis as $ini) {
  45.                                 $s_inis .= '<br>'.htmlentities($ini);
  46.                         }
  47.                 }
  48.  
  49.                 if ($s_inis == '') $s_inis = _L('n/a');
  50.  
  51.                 return $s_inis;
  52.         }
  53.  
  54.         public function gui($id, &$out, &$handled) {
  55.                 if ($id === 'oidplus:phpinfo') {
  56.                         $handled = true;
  57.                         $out['title'] = _L('PHP information');
  58.                         $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon.png';
  59.  
  60.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  61.                                 $out['icon'] = 'img/error.png';
  62.                                 $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
  63.                                 return;
  64.                         }
  65.  
  66.                         $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>';
  67.  
  68.                         ob_start();
  69.                         $res = phpinfo();
  70.                         $cont = ob_get_contents();
  71.                         ob_end_clean();
  72.  
  73.                         if (!$res) {
  74.                                 $out['text'] .= '<p><font color="red">'._L('phpinfo() could not be called').'</font></p>';
  75.                         } else {
  76.                                 // phpinfo() sets "img {float: right; border: 0;}". We don't want that.
  77.                                 $cont = str_replace('img {', 'img.phpinfo {', $cont);
  78.                                 $cont = str_replace('<img', '<img class="phpinfo"', $cont);
  79.  
  80.                                 // phpinfo() sets the link colors. We don't want that
  81.                                 $cont = preg_replace('@a:.+ {.+}@ismU', '', $cont);
  82.  
  83.                                 // phpinfo() sets "h1 {font-size: 150%;}" and "h2 {font-size: 125%;}"
  84.                                 $cont = preg_replace('@(h1|h2|h3|h4|h5) {.+}@ismU', '', $cont);
  85.  
  86.                                 // Make compatible for dark themes by removing all foreground and background colors
  87.                                 $cont = preg_replace('@(body) {.+}@ismU', '', $cont, 1);
  88.                                 $cont = preg_replace('@background-color:(.+)[\\};]@ismU', '', $cont);
  89.                                 $cont = '<span style="font-family: sans-serif;">'.$cont.'</span>';
  90.  
  91.                                 // Font sizes
  92.                                 $cont = preg_replace('@font-size:\\s*75%;@', '', $cont);
  93.                                 for ($i=5; $i>=1; $i--) {
  94.                                         $cont = str_replace('<h'.$i, '<h'.($i+1), $cont);
  95.                                         $cont = str_replace('</h'.$i, '</h'.($i+1), $cont);
  96.                                 }
  97.  
  98.                                 $out['text'] .= $cont;
  99.                         }
  100.                 }
  101.                 else if ($id === 'oidplus:systeminfo') {
  102.                         $handled = true;
  103.                         $out['title'] = _L('System information');
  104.                         $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
  105.  
  106.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  107.                                 $out['icon'] = 'img/error.png';
  108.                                 $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
  109.                                 return;
  110.                         }
  111.  
  112.                         $out['text']  = '';
  113.  
  114.                         # ---
  115.  
  116.                         $out['text'] .= '<h2>'._L('OIDplus').'</h2>';
  117.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  118.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  119.                         $out['text'] .= '       <tr>';
  120.                         $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
  121.                         $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
  122.                         $out['text'] .= '       </tr>';
  123.  
  124.                         $sys_title = OIDplus::config()->getValue('system_title');
  125.                         $out['text'] .= '       <tr>';
  126.                         $out['text'] .= '               <td>'._L('System title').'</td>';
  127.                         $out['text'] .= '               <td>'.htmlentities($sys_title).'</td>';
  128.                         $out['text'] .= '       </tr>';
  129.  
  130.                         $out['text'] .= '       <tr>';
  131.                         $out['text'] .= '               <td>'._L('System directory').'</td>';
  132.                         $out['text'] .= '               <td>'.(isset($_SERVER['SCRIPT_FILENAME']) ? htmlentities(dirname($_SERVER['SCRIPT_FILENAME'])) : '<i>'._L('unknown').'</i>').'</td>';
  133.                         $out['text'] .= '       </tr>';
  134.  
  135.                         $sysid_oid = OIDplus::getSystemId(true);
  136.                         $out['text'] .= '       <tr>';
  137.                         $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>';
  138.                         $out['text'] .= '               <td>'.(!$sysid_oid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_oid)).'</td>';
  139.                         $out['text'] .= '       </tr>';
  140.  
  141.                         $sysid_guid = OIDplus::getSystemGuid();
  142.                         $out['text'] .= '       <tr>';
  143.                         $out['text'] .= '               <td>'._L('System GUID').' <abbr title="'._L('SHA1-Namebased UUID based on the public key of your OIDplus system.').'">(?)</abbr></td>';
  144.                         $out['text'] .= '               <td>'.(!$sysid_guid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_guid)).'</td>';
  145.                         $out['text'] .= '       </tr>';
  146.  
  147.                         $sysid = OIDplus::getSystemId(false);
  148.                         $sysid_aid = $sysid ? 'D276000186B20005'.strtoupper(str_pad(dechex($sysid),8,'0',STR_PAD_LEFT)) : '';
  149.                         $out['text'] .= '       <tr>';
  150.                         $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>';
  151.                         $out['text'] .= '               <td>'.(!$sysid_aid ? '<i>'._L('unknown').'</i>' : htmlentities($sysid_aid)).' ('._L('No PIX allowed').')</td>';
  152.                         $out['text'] .= '       </tr>';
  153.  
  154.                         $sys_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
  155.                         $out['text'] .= '       <tr>';
  156.                         $out['text'] .= '               <td>'._L('System URL').'</td>';
  157.                         $out['text'] .= '               <td>'.htmlentities($sys_url).'</td>';
  158.                         $out['text'] .= '       </tr>';
  159.  
  160.                         $sys_ver = OIDplus::getVersion();
  161.                         $out['text'] .= '       <tr>';
  162.                         $out['text'] .= '               <td>'._L('System version').'</td>';
  163.                         $out['text'] .= '               <td>'.(!$sys_ver ? '<i>'._L('unknown').'</i>' : htmlentities($sys_ver)).'</td>';
  164.                         $out['text'] .= '       </tr>';
  165.  
  166.                         $sys_install_type = OIDplus::getInstallType();
  167.                         $out['text'] .= '       <tr>';
  168.                         $out['text'] .= '               <td>'._L('Installation type').'</td>';
  169.                         $out['text'] .= '               <td>'.htmlentities($sys_install_type).'</td>';
  170.                         $out['text'] .= '       </tr>';
  171.  
  172.                         $out['text'] .= '</table>';
  173.                         $out['text'] .= '</div></div>';
  174.  
  175.                         # ---
  176.  
  177.                         $out['text'] .= '<h2>'._L('PHP').'</h2>';
  178.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  179.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  180.                         $out['text'] .= '       <tr>';
  181.                         $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
  182.                         $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
  183.                         $out['text'] .= '       </tr>';
  184.                         $out['text'] .= '       <tr>';
  185.                         $out['text'] .= '               <td>'._L('PHP version').'</td>';
  186.                         $out['text'] .= '               <td>'.PHP_VERSION.'</td>';
  187.                         $out['text'] .= '       </tr>';
  188.                         $out['text'] .= '       <tr>';
  189.                         $out['text'] .= '               <td>'._L('PHP configuration file(s)').'</td>';
  190.                         $out['text'] .= '               <td>'.$this->getLoadedInis().'</td>';
  191.                         $out['text'] .= '       </tr>';
  192.                         $out['text'] .= '       <tr>';
  193.                         $out['text'] .= '               <td>'._L('Installed extensions').'</td>';
  194.                         $out['text'] .= '               <td>'.htmlentities(implode(', ',get_loaded_extensions())).'</td>';
  195.                         $out['text'] .= '       </tr>';
  196.                         $out['text'] .= '</table>';
  197.                         $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:phpinfo').'>'._L('Show PHP server configuration (phpinfo)').'</a></p>';
  198.                         $out['text'] .= '</div></div>';
  199.  
  200.                         # ---
  201.  
  202.                         $out['text'] .= '<h2>'._L('Webserver').'</h2>';
  203.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  204.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  205.                         $out['text'] .= '       <tr>';
  206.                         $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
  207.                         $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
  208.                         $out['text'] .= '       </tr>';
  209.                         $out['text'] .= '       <tr>';
  210.                         $out['text'] .= '               <td>'._L('Server software').'</td>';
  211.                         $out['text'] .= '               <td>'.(isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '<i>'._L('unknown').'</i>').'</td>';
  212.                         $out['text'] .= '       </tr>';
  213.                         $out['text'] .= '       <tr>';
  214.                         $out['text'] .= '               <td>'._L('User account').'</td>';
  215.                         $current_user = exec('whoami');
  216.                         if ($current_user == '') {
  217.                                 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  218.                                         // Windows on an IIS server:
  219.                                         //     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 )
  220.                                         //     get_current_user()     DefaultAppPool
  221.                                         //     exec('whoami')         iis apppool\defaultapppool
  222.                                         // Windows with XAMPP:
  223.                                         //     getenv('USERNAME')     dmarschall
  224.                                         //     get_current_user()     dmarschall               (even if script has a different NTFS owner!)
  225.                                         //     exec('whoami')         hickelsoft\dmarschall
  226.                                         $current_user = get_current_user();
  227.                                         if ($current_user == '') $current_user = getenv('USERNAME');
  228.                                 } else {
  229.                                         // On Linux:
  230.                                         // get_current_user() will get the owner of the PHP script, not the process owner!
  231.                                         // We want the process owner, so we use posix_geteuid().
  232.                                         if (function_exists('posix_geteuid') && function_exists('posix_getpwuid')) {
  233.                                                 $uid = posix_geteuid();
  234.                                                 $current_user = posix_getpwuid($uid); // receive username (required read access to /etc/passwd )
  235.                                         } else {
  236.                                                 $uid = -1;
  237.                                         }
  238.                                         if ($current_user == '') $current_user = get_current_user();
  239.                                         if (($current_user == '') && ($uid >= 0)) $current_user = '#'.$uid;
  240.                                 }
  241.                         }
  242.                         $out['text'] .= '               <td>'.($current_user == '' ? '<i>'._L('unknown').'</i>' : htmlentities($current_user)).'</td>';
  243.                         $out['text'] .= '       </tr>';
  244.                         $out['text'] .= '</table>';
  245.                         $out['text'] .= '</div></div>';
  246.  
  247.                         # ---
  248.  
  249.                         $out['text'] .= '<h2>'._L('Database').'</h2>';
  250.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  251.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  252.                         $out['text'] .= '       <tr>';
  253.                         $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
  254.                         $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
  255.                         $out['text'] .= '       </tr>';
  256.  
  257.                         $out['text'] .= '       <tr>';
  258.                         $out['text'] .= '               <td>'._L('Database provider').'</td>';
  259.                         $out['text'] .= '               <td>'.OIDplus::db()->getPlugin()->getManifest()->getName().'</td>';
  260.                         $out['text'] .= '       </tr>';
  261.  
  262.                         $out['text'] .= '       <tr>';
  263.                         $out['text'] .= '               <td>'._L('SQL slang').'</td>';
  264.                         $out['text'] .= '               <td>'.OIDplus::db()->getSlang()->getManifest()->getName().'</td>';
  265.                         $out['text'] .= '       </tr>';
  266.  
  267.                         $table_prefix = OIDplus::baseConfig()->getValue('TABLENAME_PREFIX');
  268.                         $out['text'] .= '       <tr>';
  269.                         $out['text'] .= '               <td>'._L('Table name prefix').'</td>';
  270.                         $out['text'] .= '               <td>'.(!empty($table_prefix) ? htmlentities($table_prefix) : '<i>'._L('none').'</i>').'</td>';
  271.                         $out['text'] .= '       </tr>';
  272.                         $out['text'] .= '       <tr>';
  273.                         $out['text'] .= '               <td>'._L('Server time').'</td>';
  274.                         $tmp = OIDplus::db()->query('select '.OIDplus::db()->sqlDate().' as tmp');
  275.                         if ($tmp) $tmp = $tmp->fetch_array();
  276.                         $tmp = isset($tmp['tmp']) ? $tmp['tmp'] :  _L('n/a');
  277.                         $out['text'] .= '               <td>'.$tmp.'</td>';
  278.                         $out['text'] .= '       </tr>';
  279.                         $out['text'] .= '</table>';
  280.                         $out['text'] .= '</div></div>';
  281.  
  282.                         // TODO: can we somehow get the DBMS version, connection string etc?
  283.  
  284.                         # ---
  285.  
  286.                         $out['text'] .= '<h2>'._L('Operating System').'</h2>';
  287.                         $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
  288.                         $out['text'] .= '<table class="table table-bordered table-striped">';
  289.                         $out['text'] .= '       <tr>';
  290.                         $out['text'] .= '               <th width="50%">'._L('Attribute').'</th>';
  291.                         $out['text'] .= '               <th width="50%">'._L('Value').'</th>';
  292.                         $out['text'] .= '       </tr>';
  293.                         if (php_uname("m") == php_uname("n")) {
  294.                                 // At some hosts like Strato, php_uname() always returns the same string
  295.                                 // "Linux localhost 3.10.0-1127.10.1.el7.x86_64 #1 SMP"
  296.                                 $out['text'] .= '       <tr>';
  297.                                 $out['text'] .= '               <td>'._L('Operating System').'</td>';
  298.                                 $out['text'] .= '               <td>'.htmlentities(PHP_OS).'</td>';
  299.                                 $out['text'] .= '       </tr>';
  300.                                 $out['text'] .= '       <tr>';
  301.                                 $out['text'] .= '               <td>'._L('Hostname').'</td>';
  302.                                 $out['text'] .= '               <td>'.htmlentities(gethostname()).'</td>';
  303.                                 $out['text'] .= '       </tr>';
  304.                         } else {
  305.                                 $out['text'] .= '       <tr>';
  306.                                 $out['text'] .= '               <td>'._L('Operating System').'</td>';
  307.                                 $out['text'] .= '               <td>'.htmlentities(php_uname("s").' '.php_uname("r").' '.php_uname("v")).'</td>';
  308.                                 $out['text'] .= '       </tr>';
  309.                                 $out['text'] .= '       <tr>';
  310.                                 $out['text'] .= '               <td>'._L('Machine type').'</td>';
  311.                                 $out['text'] .= '               <td>'.htmlentities(php_uname("m")).'</td>';
  312.                                 $out['text'] .= '       </tr>';
  313.                                 $out['text'] .= '       <tr>';
  314.                                 $out['text'] .= '               <td>'._L('Hostname').'</td>';
  315.                                 $out['text'] .= '               <td>'.htmlentities(php_uname("n")).'</td>';
  316.                                 $out['text'] .= '       </tr>';
  317.                         }
  318.                         $out['text'] .= '       <tr>';
  319.                         $out['text'] .= '               <td>'._L('Server time').'</td>';
  320.                         $out['text'] .= '               <td>'.htmlentities(date('Y-m-d H:i:s P')).'</td>';
  321.                         $out['text'] .= '       </tr>';
  322.                         $out['text'] .= '</table>';
  323.                         $out['text'] .= '</div></div>';
  324.  
  325.                         # ---
  326.  
  327.                 }
  328.         }
  329.  
  330.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  331.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  332.  
  333.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  334.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  335.                 } else {
  336.                         $tree_icon = null; // default icon (folder)
  337.                 }
  338.  
  339.                 if (file_exists(__DIR__.'/img/php_icon16.png')) {
  340.                         $tree_icon_php = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/php_icon16.png';
  341.                 } else {
  342.                         $tree_icon_php = null; // default icon (folder)
  343.                 }
  344.  
  345.                 $json[] = array(
  346.                         'id' => 'oidplus:systeminfo',
  347.                         'icon' => $tree_icon,
  348.                         'text' => _L('System information'),
  349.                         'children' => array(array(
  350.                                 'id' => 'oidplus:phpinfo',
  351.                                 'icon' => $tree_icon_php,
  352.                                 'text' => _L('PHP information')
  353.                         ))
  354.                 );
  355.  
  356.                 return true;
  357.         }
  358.  
  359.         public function tree_search($request) {
  360.                 return false;
  361.         }
  362.  
  363.         public function implementsFeature($id) {
  364.                 return false;
  365.         }
  366. }
  367.