oxdiagnostics.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class oxDiagnostics
00010 {
00011 
00017     protected $_sEdition = "";
00018 
00024     protected $_sVersion = "";
00025 
00031     protected $_sRevision = "";
00032 
00038     protected $_sShopLink = "";
00039 
00045     protected $_aFileCheckerPathList = array(
00046         'bootstrap.php',
00047         'index.php',
00048         'oxid.php',
00049         'oxseo.php',
00050         'admin/',
00051         'application/',
00052         'bin/',
00053         'core/',
00054         'modules/',
00055     );
00056 
00062     protected $_aFileCheckerExtensionList = array('php', 'tpl');
00063 
00069     public function setFileCheckerPathList($aPathList)
00070     {
00071         $this->_aFileCheckerPathList = $aPathList;
00072     }
00073 
00079     public function getFileCheckerPathList()
00080     {
00081         return $this->_aFileCheckerPathList;
00082     }
00083 
00089     public function setFileCheckerExtensionList($aExtList)
00090     {
00091         $this->_aFileCheckerExtensionList = $aExtList;
00092     }
00093 
00099     public function getFileCheckerExtensionList()
00100     {
00101         return $this->_aFileCheckerExtensionList;
00102     }
00103 
00104 
00110     public function setVersion($sVersion)
00111     {
00112         if (!empty($sVersion)) {
00113             $this->_sVersion = $sVersion;
00114         }
00115     }
00116 
00122     public function getVersion()
00123     {
00124         return $this->_sVersion;
00125     }
00126 
00132     public function setEdition($sEdition)
00133     {
00134         if (!empty($sEdition)) {
00135             $this->_sEdition = $sEdition;
00136         }
00137     }
00138 
00144     public function getEdition()
00145     {
00146         return $this->_sEdition;
00147     }
00148 
00154     public function setRevision($sRevision)
00155     {
00156         if (!empty($sRevision)) {
00157             $this->_sRevision = $sRevision;
00158         }
00159     }
00160 
00166     public function getRevision()
00167     {
00168         return $this->_sRevision;
00169     }
00170 
00171 
00177     public function setShopLink($sShopLink)
00178     {
00179         if (!empty($sShopLink)) {
00180             $this->_sShopLink = $sShopLink;
00181         }
00182     }
00183 
00189     public function getShopLink()
00190     {
00191         return $this->_sShopLink;
00192     }
00193 
00199     public function getShopDetails()
00200     {
00201         $aShopDetails = array(
00202             'Date'                => date(oxRegistry::getLang()->translateString('fullDateFormat'), time()),
00203             'URL'                 => $this->getShopLink(),
00204             'Edition'             => $this->getEdition(),
00205             'Version'             => $this->getVersion(),
00206             'Revision'            => $this->getRevision(),
00207             'Subshops (Total)'    => $this->_countRows('oxshops', true),
00208             'Subshops (Active)'   => $this->_countRows('oxshops', false),
00209             'Categories (Total)'  => $this->_countRows('oxcategories', true),
00210             'Categories (Active)' => $this->_countRows('oxcategories', false),
00211             'Articles (Total)'    => $this->_countRows('oxarticles', true),
00212             'Articles (Active)'   => $this->_countRows('oxarticles', false),
00213             'Users (Total)'       => $this->_countRows('oxuser', true),
00214         );
00215 
00216         return $aShopDetails;
00217     }
00218 
00227     protected function _countRows($sTable, $blMode)
00228     {
00229         $oDb = oxDb::getDb();
00230         $sRequest = 'SELECT COUNT(*) FROM ' . $sTable;
00231 
00232         if ($blMode == false) {
00233             $sRequest .= ' WHERE oxactive = 1';
00234         }
00235 
00236         $aRes = $oDb->execute($sRequest)->fields(0);
00237 
00238         return $aRes[0];
00239     }
00240 
00241 
00247     public function getPhpSelection()
00248     {
00249         $aPhpIniParams = array(
00250             'allow_url_fopen',
00251             'display_errors',
00252             'file_uploads',
00253             'max_execution_time',
00254             'memory_limit',
00255             'post_max_size',
00256             'register_globals',
00257             'upload_max_filesize',
00258         );
00259 
00260         $aPhpIniConf = array();
00261 
00262         foreach ($aPhpIniParams as $sParam) {
00263             $sValue = ini_get($sParam);
00264             $aPhpIniConf[$sParam] = $sValue;
00265         }
00266 
00267         return $aPhpIniConf;
00268     }
00269 
00270 
00276     public function getPhpDecoder()
00277     {
00278         $sReturn = 'Zend ';
00279 
00280         if (function_exists('zend_optimizer_version')) {
00281             $sReturn .= 'Optimizer';
00282         }
00283 
00284         if (function_exists('zend_loader_enabled')) {
00285             $sReturn .= 'Guard Loader';
00286         }
00287 
00288         return $sReturn;
00289     }
00290 
00291 
00298     public function getServerInfo()
00299     {
00300         // init empty variables (can be filled if exec is allowed)
00301         $iCpuAmnt = $iCpuMhz = $iBogo = $iMemTotal = $iMemFree = $sCpuModelName = $sCpuModel = $sCpuFreq = $iCpuCores = null;
00302 
00303         // fill, if exec is allowed
00304         if ($this->isExecAllowed()) {
00305             $iCpuAmnt = $this->_getCpuAmount();
00306             $iCpuMhz = $this->_getCpuMhz();
00307             $iBogo = $this->_getBogoMips();
00308             $iMemTotal = $this->_getMemoryTotal();
00309             $iMemFree = $this->_getMemoryFree();
00310             $sCpuModelName = $this->_getCpuModel();
00311             $sCpuModel = $iCpuAmnt . 'x ' . $sCpuModelName;
00312             $sCpuFreq = $iCpuMhz . ' MHz';
00313 
00314             // prevent "division by zero" error
00315             if ($iBogo && $iCpuMhz) {
00316                 $iCpuCores = $iBogo / $iCpuMhz;
00317             }
00318         }
00319 
00320         $aServerInfo = array(
00321             'Server OS'     => @php_uname('s'),
00322             'VM'            => $this->_getVirtualizationSystem(),
00323             'PHP'           => $this->_getPhpVersion(),
00324             'MySQL'         => $this->_getMySqlServerInfo(),
00325             'Apache'        => $this->_getApacheVersion(),
00326             'Disk total'    => $this->_getDiskTotalSpace(),
00327             'Disk free'     => $this->_getDiskFreeSpace(),
00328             'Memory total'  => $iMemTotal,
00329             'Memory free'   => $iMemFree,
00330             'CPU Model'     => $sCpuModel,
00331             'CPU frequency' => $sCpuFreq,
00332             'CPU cores'     => round($iCpuCores, 0),
00333         );
00334 
00335         return $aServerInfo;
00336     }
00337 
00343     protected function _getApacheVersion()
00344     {
00345         if (function_exists('apache_get_version')) {
00346             $sReturn = apache_get_version();
00347         } else {
00348             $sReturn = $_SERVER['SERVER_SOFTWARE'];
00349         }
00350 
00351         return $sReturn;
00352     }
00353 
00359     protected function _getVirtualizationSystem()
00360     {
00361         $sSystemType = '';
00362 
00363         if ($this->isExecAllowed()) {
00364             //VMWare
00365             @$sDeviceList = $this->_getDeviceList('vmware');
00366             if ($sDeviceList) {
00367                 $sSystemType = 'VMWare';
00368                 unset($sDeviceList);
00369             }
00370 
00371             //VirtualBox
00372             @$sDeviceList = $this->_getDeviceList('VirtualBox');
00373             if ($sDeviceList) {
00374                 $sSystemType = 'VirtualBox';
00375                 unset($sDeviceList);
00376             }
00377         }
00378 
00379         return $sSystemType;
00380     }
00381 
00387     public function isExecAllowed()
00388     {
00389         return function_exists('exec');
00390     }
00391 
00399     protected function _getDeviceList($sSystemType)
00400     {
00401         return exec('lspci | grep -i ' . $sSystemType);
00402     }
00403 
00409     protected function _getCpuAmount()
00410     {
00411         // cat /proc/cpuinfo | grep "processor" | sort -u | cut -d: -f2');
00412         return exec('cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l');
00413     }
00414 
00420     protected function _getCpuMhz()
00421     {
00422         return round(exec('cat /proc/cpuinfo | grep "MHz" | sort -u | cut -d: -f2'), 0);
00423     }
00424 
00430     protected function _getBogoMips()
00431     {
00432         return exec('cat /proc/cpuinfo | grep "bogomips" | sort -u | cut -d: -f2');
00433     }
00434 
00440     protected function _getMemoryTotal()
00441     {
00442         return exec('cat /proc/meminfo | grep "MemTotal" | sort -u | cut -d: -f2');
00443     }
00444 
00450     protected function _getMemoryFree()
00451     {
00452         return exec('cat /proc/meminfo | grep "MemFree" | sort -u | cut -d: -f2');
00453     }
00454 
00460     protected function _getCpuModel()
00461     {
00462         return exec('cat /proc/cpuinfo | grep "model name" | sort -u | cut -d: -f2');
00463     }
00464 
00470     protected function _getDiskTotalSpace()
00471     {
00472         return round(disk_total_space('/') / 1024 / 1024, 0) . ' GiB';
00473     }
00474 
00480     protected function _getDiskFreeSpace()
00481     {
00482         return round(disk_free_space('/') / 1024 / 1024, 0) . ' GiB';
00483     }
00484 
00490     protected function _getPhpVersion()
00491     {
00492         return phpversion();
00493     }
00494 
00500     protected function _getMySqlServerInfo()
00501     {
00502         $aResult = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow("SHOW VARIABLES LIKE 'version'");
00503 
00504         return $aResult['Value'];
00505     }
00506 }