oxdiagnostics.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class oxDiagnostics
00010 {
00016     protected  $_sEdition          = "";
00017 
00023     protected $_sVersion          = "";
00024 
00030     protected $_sRevision         = "";
00031 
00037     protected $_sShopLink         = "";
00038 
00044     protected $_aFileCheckerPathList = array(
00045                                         'bootstrap.php',
00046                                         'index.php',
00047                                         'oxid.php',
00048                                         'oxseo.php',
00049                                         'admin/',
00050                                         'application/',
00051                                         'bin/',
00052                                         'core/',
00053                                         'modules/',
00054                                     );
00055 
00061     protected $_aFileCheckerExtensionList = array( 'php', 'tpl' );
00062 
00068     public function setFileCheckerPathList( $aPathList )
00069     {
00070         $this->_aFileCheckerPathList = $aPathList;
00071     }
00072 
00078     public function getFileCheckerPathList()
00079     {
00080         return $this->_aFileCheckerPathList;
00081     }
00082 
00088     public function setFileCheckerExtensionList( $aExtList )
00089     {
00090         $this->_aFileCheckerExtensionList = $aExtList;
00091     }
00092 
00098     public function getFileCheckerExtensionList()
00099     {
00100         return $this->_aFileCheckerExtensionList;
00101     }
00102 
00103 
00109     public function setVersion( $sVersion )
00110     {
00111         if ( !empty( $sVersion ) ) {
00112             $this->_sVersion = $sVersion;
00113         }
00114     }
00115 
00121     public function getVersion()
00122     {
00123         return $this->_sVersion;
00124     }
00125 
00131     public function setEdition( $sEdition )
00132     {
00133         if ( !empty( $sEdition ) ) {
00134             $this->_sEdition = $sEdition;
00135         }
00136     }
00137 
00143     public function getEdition()
00144     {
00145         return $this->_sEdition;
00146     }
00147 
00153     public function setRevision( $sRevision )
00154     {
00155         if ( !empty( $sRevision ) ) {
00156             $this->_sRevision = $sRevision;
00157         }
00158     }
00159 
00165     public function getRevision()
00166     {
00167         return $this->_sRevision;
00168     }
00169 
00170 
00176     public function setShopLink( $sShopLink )
00177     {
00178         if ( !empty( $sShopLink ) ) {
00179             $this->_sShopLink = $sShopLink;
00180         }
00181     }
00182 
00188     public function getShopLink()
00189     {
00190         return $this->_sShopLink;
00191     }
00192 
00198     public function getShopDetails()
00199     {
00200         $aShopDetails = array(
00201             'Date'                  =>  date( oxRegistry::getLang()->translateString( 'fullDateFormat' ), time() ),
00202             'URL'                   =>  $this->getShopLink(),
00203             'Edition'               =>  $this->getEdition(),
00204             'Version'               =>  $this->getVersion(),
00205             'Revision'              =>  $this->getRevision(),
00206             'Subshops (Total)'      =>  $this->_countRows( 'oxshops', true ),
00207             'Subshops (Active)'     =>  $this->_countRows( 'oxshops', false ),
00208             'Categories (Total)'    =>  $this->_countRows( 'oxcategories', true ),
00209             'Categories (Active)'   =>  $this->_countRows( 'oxcategories', false ),
00210             'Articles (Total)'      =>  $this->_countRows( 'oxarticles', true ),
00211             'Articles (Active)'     =>  $this->_countRows( 'oxarticles', false ),
00212             'Users (Total)'         =>  $this->_countRows( 'oxuser', true ),
00213         );
00214 
00215         return $aShopDetails;
00216     }
00217 
00225     protected function _countRows( $sTable, $blMode )
00226     {
00227         $oDb = oxDb::getDb();
00228         $sRequest = 'SELECT COUNT(*) FROM '.$sTable;
00229 
00230         if ( $blMode == false){
00231             $sRequest .= ' WHERE oxactive = 1';
00232         }
00233 
00234         $aRes = $oDb->execute( $sRequest)->fields(0);
00235         return $aRes[0];
00236     }
00237 
00238 
00239 
00245     public function getPhpSelection()
00246     {
00247         $aPhpIniParams = array(
00248             'allow_url_fopen',
00249             'display_errors',
00250             'file_uploads',
00251             'max_execution_time',
00252             'memory_limit',
00253             'post_max_size',
00254             'register_globals',
00255             'upload_max_filesize',
00256         );
00257 
00258         $aPhpIniConf = array();
00259 
00260         foreach ( $aPhpIniParams as $sParam ){
00261             $sValue = ini_get( $sParam );
00262             $aPhpIniConf[$sParam] = $sValue;
00263         }
00264 
00265         return $aPhpIniConf;
00266     }
00267 
00268 
00269 
00275     public function getPhpDecoder()
00276     {
00277         $sReturn = 'Zend ';
00278 
00279         if ( function_exists( 'zend_optimizer_version' ) )
00280         {
00281             $sReturn .= 'Optimizer';
00282         }
00283 
00284         if ( function_exists( 'zend_loader_enabled' ) )
00285         {
00286             $sReturn .= 'Guard Loader';
00287         }
00288 
00289         return $sReturn;
00290     }
00291 
00292 
00293 
00300     public function getServerInfo()
00301     {
00302         // init empty variables (can be filled if exec is allowed)
00303         $iCpuAmnt = $iCpuMhz = $iBogo = $iMemTotal = $iMemFree = $sCpuModelName = $sCpuModel = $sCpuFreq = $iCpuCores = null;
00304 
00305         // fill, if exec is allowed
00306         if ( $this->isExecAllowed())
00307         {
00308             $iCpuAmnt = $this->_getCpuAmount();
00309             $iCpuMhz = $this->_getCpuMhz();
00310             $iBogo = $this->_getBogoMips();
00311             $iMemTotal = $this->_getMemoryTotal();
00312             $iMemFree = $this->_getMemoryFree();
00313             $sCpuModelName = $this->_getCpuModel();
00314             $sCpuModel = $iCpuAmnt.'x '.$sCpuModelName;
00315             $sCpuFreq = $iCpuMhz.' MHz';
00316 
00317             // prevent "division by zero" error
00318             if ( $iBogo && $iCpuMhz ){
00319                 $iCpuCores = $iBogo / $iCpuMhz;
00320             }
00321         }
00322 
00323         $aServerInfo = array(
00324             'Server OS'     => @php_uname('s'),
00325             'VM'            => $this->_getVirtualizationSystem(),
00326             'PHP'           => $this->_getPhpVersion(),
00327             'MySQL'         => $this->_getMySqlServerInfo(),
00328             'Apache'        => $this->_getApacheVersion(),
00329             'Disk total'    => $this->_getDiskTotalSpace(),
00330             'Disk free'     => $this->_getDiskFreeSpace(),
00331             'Memory total'  => $iMemTotal,
00332             'Memory free'   => $iMemFree,
00333             'CPU Model'     => $sCpuModel,
00334             'CPU frequency' => $sCpuFreq,
00335             'CPU cores'     => round( $iCpuCores,0),
00336         );
00337 
00338         return $aServerInfo;
00339     }
00340 
00346     protected function _getApacheVersion()
00347     {
00348         if ( function_exists( 'apache_get_version' ) ){
00349             $sReturn = apache_get_version();
00350         } else {
00351             $sReturn = $_SERVER['SERVER_SOFTWARE'];
00352         }
00353 
00354         return $sReturn;
00355     }
00356 
00362     protected function _getVirtualizationSystem()
00363     {
00364         $sSystemType = '';
00365 
00366         if ( $this->isExecAllowed() ){
00367             //VMWare
00368             @$sDeviceList = $this->_getDeviceList( 'vmware' );
00369             if ( $sDeviceList ){
00370                 $sSystemType = 'VMWare';
00371                 unset( $sDeviceList );
00372             }
00373 
00374             //VirtualBox
00375             @$sDeviceList = $this->_getDeviceList( 'VirtualBox' );
00376             if( $sDeviceList ){
00377                 $sSystemType = 'VirtualBox';
00378                 unset( $sDeviceList );
00379             }
00380         }
00381 
00382         return $sSystemType;
00383      }
00384 
00390     public function isExecAllowed()
00391     {
00392         return function_exists( 'exec' );
00393     }
00394 
00401     protected function _getDeviceList( $sSystemType )
00402     {
00403         return exec( 'lspci | grep -i '. $sSystemType );
00404     }
00405 
00411     protected function _getCpuAmount()
00412     {
00413         // cat /proc/cpuinfo | grep "processor" | sort -u | cut -d: -f2');
00414         return exec('cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l');
00415     }
00416 
00422     protected function _getCpuMhz()
00423     {
00424         return round(exec('cat /proc/cpuinfo | grep "MHz" | sort -u | cut -d: -f2'),0);
00425     }
00426 
00432     protected function _getBogoMips()
00433     {
00434         return exec('cat /proc/cpuinfo | grep "bogomips" | sort -u | cut -d: -f2');
00435     }
00436 
00442     protected function _getMemoryTotal()
00443     {
00444         return exec('cat /proc/meminfo | grep "MemTotal" | sort -u | cut -d: -f2');
00445     }
00446 
00452     protected function _getMemoryFree()
00453     {
00454         return exec('cat /proc/meminfo | grep "MemFree" | sort -u | cut -d: -f2');
00455     }
00456 
00462     protected function _getCpuModel()
00463     {
00464         return exec('cat /proc/cpuinfo | grep "model name" | sort -u | cut -d: -f2');
00465     }
00466 
00472     protected function _getDiskTotalSpace()
00473     {
00474         return round( disk_total_space('/') / 1024 / 1024 , 0 ) .' GiB';
00475     }
00476 
00482     protected function _getDiskFreeSpace()
00483     {
00484         return round(disk_free_space('/') / 1024 / 1024, 0) . ' GiB';
00485     }
00486 
00492     protected function _getPhpVersion()
00493     {
00494         return phpversion();
00495     }
00496 
00502     protected function _getMySqlServerInfo()
00503     {
00504         return mysql_get_server_info();
00505     }
00506 
00507 
00508 }