oxsysrequirements.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxSysRequirements
00007 {
00013     protected $_aRequiredModules = null;
00014 
00020     protected $_blSysReqStatus = null;
00021 
00027     protected $_aException = array( 'OXDELIVERY'   => 'OXDELTYPE',
00028                                     'OXSELECTLIST' => 'OXIDENT');
00029 
00035     protected $_aColumns = array( 'OXID',
00036                                   'OXOBJECTID',
00037                                   'OXARTICLENID',
00038                                   'OXACTIONID',
00039                                   'OXARTID',
00040                                   'OXUSERID',
00041                                   'OXADDRESSUSERID',
00042                                   'OXCOUNTRYID',
00043                                   'OXSESSID',
00044                                   'OXITMID',
00045                                   'OXPARENTID',
00046                                   'OXAMITEMID',
00047                                   'OXAMTASKID',
00048                                   'OXVENDORID',
00049                                   'OXMANUFACTURERID',
00050                                   'OXROOTID',
00051                                   'OXATTRID',
00052                                   'OXCATID',
00053                                   'OXDELID',
00054                                   'OXDELSETID',
00055                                   'OXITMARTID',
00056                                   'OXFIELDID',
00057                                   'OXROLEID',
00058                                   'OXCNID',
00059                                   'OXANID',
00060                                   'OXARTICLENID',
00061                                   'OXCATNID',
00062                                   'OXDELIVERYID',
00063                                   'OXDISCOUNTID',
00064                                   'OXGROUPSID',
00065                                   'OXLISTID',
00066                                   'OXPAYMENTID',
00067                                   'OXDELTYPE',
00068                                   'OXROLEID',
00069                                   'OXSELNID',
00070                                   'OXBILLCOUNTRYID',
00071                                   'OXDELCOUNTRYID',
00072                                   'OXPAYMENTID',
00073                                   'OXCARDID',
00074                                   'OXPAYID',
00075                                   'OXIDENT',
00076                                   'OXDEFCAT',
00077                                   'OXBASKETID',
00078                                   'OXPAYMENTSID',
00079                                   'OXORDERID',
00080                                   'OXVOUCHERSERIEID');
00081 
00087     public function __construct()
00088     {
00089     }
00090 
00096     public function getRequiredModules()
00097     {
00098         if ( $this->_aRequiredModules == null ) {
00099             $aRequiredPHPExtensions = array(
00100                                           'php_version',
00101                                           'lib_xml2',
00102                                           'php_xml',
00103                                           'j_son',
00104                                           'i_conv',
00105                                           'tokenizer',
00106                                           'mysql_connect',
00107                                           'gd_info',
00108                                           'mb_string',
00109                                           'curl',
00110                                       );
00111 
00112                 $aRequiredPHPExtensions[] = 'bc_math';
00113 
00114             $aRequiredPHPConfigs = array(
00115                                        'allow_url_fopen',
00116                                        'php4_compat',
00117                                        'request_uri',
00118                                        'ini_set',
00119                                        'register_globals',
00120                                        'memory_limit',
00121                                        'unicode_support'
00122                                    );
00123 
00124             $aRequiredServerConfigs = array(
00125                                           'mod_rewrite',
00126                                           'server_permissions'
00127                                       );
00128 
00129 
00130             if ( isAdmin() ) {
00131                 $aRequiredServerConfigs[] = 'mysql_version';
00132             }
00133             $this->_aRequiredModules = array_fill_keys( $aRequiredPHPExtensions, 'php_extennsions' ) +
00134                                        array_fill_keys( $aRequiredPHPConfigs, 'php_config' ) +
00135                                        array_fill_keys( $aRequiredServerConfigs, 'server_config' );
00136         }
00137         return $this->_aRequiredModules;
00138     }
00139 
00145     public function checkCurl()
00146     {
00147         return extension_loaded( 'curl' ) ? 2 : 1;
00148     }
00149 
00155     public function checkMbString()
00156     {
00157         return extension_loaded( 'mbstring' ) ? 2 : 1;
00158     }
00159 
00168     public function checkServerPermissions( $sPath = null, $iMinPerm = 777 )
00169     {
00170         $sVerPrefix = '';
00171 
00172         clearstatcache();
00173         $sPath = $sPath ? $sPath : getShopBasePath();
00174 
00175         // special config file check
00176         $sFullPath = $sPath . "config.inc.php";
00177         if ( !is_readable( $sFullPath ) ||
00178              ( isAdmin() && is_writable( $sFullPath ) ) ||
00179              ( !isAdmin() && !is_writable( $sFullPath ) )
00180            ) {
00181             return 0;
00182         }
00183 
00184         $aPathsToCheck = array(
00185                             "out/pictures{$sVerPrefix}/",
00186                             "out/media/",
00187                             "out/basic/src/",
00188                             "log/",
00189                             "tmp{$sVerPrefix}/"
00190                             );
00191 
00192         $iModStat = 2;
00193         $sPathToCheck = reset( $aPathsToCheck );
00194         while ( $sPathToCheck ) {
00195             $sFullPath = $sPath.$sPathToCheck;
00196 
00197             // missing file/folder?
00198             if ( !file_exists( $sFullPath ) ) {
00199                 $iModStat = 0;
00200                 break;
00201             }
00202 
00203             if ( is_dir( $sFullPath ) ) {
00204                 // adding subfolders
00205                 foreach ( glob( $sFullPath."*", GLOB_ONLYDIR ) as $sNewFolder ) {
00206                     $aPathsToCheck[] = str_replace( $sPath, "", $sNewFolder ) . "/";
00207                 }
00208             }
00209 
00210             // testing if file permissions >= $iMinPerm
00211             //if ( ( (int) substr( decoct( fileperms( $sFullPath ) ), 2 ) ) < $iMinPerm ) {
00212             if ( !is_readable( $sFullPath ) || !is_writable( $sFullPath ) ) {
00213                 $iModStat = 0;
00214                 break;
00215             }
00216 
00217             $sPathToCheck = next( $aPathsToCheck );
00218         }
00219 
00220         return $iModStat;
00221     }
00222 
00228     public function checkModRewrite()
00229     {
00230         $iModStat = null;
00231         $sHost   = $_SERVER['HTTP_HOST'];
00232         $sScript = $_SERVER['SCRIPT_NAME'];
00233         if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00234             $sScript = str_replace( basename($sScript), '../oxseo.php?mod_rewrite_module_is=off', $sScript );
00235 
00236             $sReq  = "POST $sScript HTTP/1.1\r\n";
00237             $sReq .= "Host: $sHost\r\n";
00238             $sReq .= "User-Agent: oxid setup\r\n";
00239             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00240             $sReq .= "Content-Length: 0\r\n"; // empty post
00241             $sReq .= "Connection: close\r\n\r\n";
00242 
00243             $sOut = '';
00244             fwrite( $rFp, $sReq );
00245             while ( !feof( $rFp ) ) {
00246                 $sOut .= fgets( $rFp, 100 );
00247             }
00248             fclose( $rFp );
00249 
00250             $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00251         } else {
00252             if ( function_exists( 'apache_get_modules' ) ) {
00253                 // it does not assure that mod_rewrite is enabled on current host, so setting 1
00254                 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00255             } else {
00256                 $iModStat = -1;
00257             }
00258         }
00259         return $iModStat;
00260     }
00261 
00267     public function checkAllowUrlFopen()
00268     {
00269         $iModStat = @ini_get('allow_url_fopen');
00270         $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00271         if ( $iModStat == 1 ) {
00272             $iErrNo  = 0;
00273             $sErrStr = '';
00274             if ( $oRes = @fsockopen( 'www.example.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00275                 $iModStat = 2;
00276                 fclose( $oRes );
00277             }
00278         }
00279         $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00280         return $iModStat;
00281     }
00282 
00289     public function checkPhp4Compat()
00290     {
00291         $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00292         return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00293     }
00294 
00301     public function checkPhpVersion()
00302     {
00303         $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00304         $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00305         return $iModStat;
00306     }
00307 
00313     public function checkRequestUri()
00314     {
00315         return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00316     }
00317 
00323     public function checkLibXml2()
00324     {
00325         return class_exists( 'DOMDocument' ) ? 2 : 0;
00326     }
00327 
00333     public function checkPhpXml()
00334     {
00335         return class_exists( 'DOMDocument' ) ? 2 : 0;
00336     }
00337 
00343     public function checkJSon()
00344     {
00345         return extension_loaded( 'json' ) ? 2 : 0;
00346     }
00347 
00353     public function checkIConv()
00354     {
00355         return extension_loaded( 'iconv' ) ? 2 : 0;
00356     }
00357 
00363     public function checkTokenizer()
00364     {
00365         return extension_loaded( 'tokenizer' ) ? 2 : 0;
00366     }
00367 
00373     public function checkBcMath()
00374     {
00375         return extension_loaded( 'bcmath' ) ? 2 : 1;
00376     }
00377 
00383     public function checkMysqlConnect()
00384     {
00385         // MySQL module for MySQL5
00386         $iModStat = ( extension_loaded( 'mysql' ) || extension_loaded( 'mysqli' ) || extension_loaded( 'pdo_mysql' ) ) ? 2 : 0;
00387         // client version must be >=5
00388         if ( $iModStat ) {
00389             $sClientVersion = mysql_get_client_info();
00390             if (version_compare( $sClientVersion, '5', '<' )) {
00391                 $iModStat = 1;
00392                 if (version_compare( $sClientVersion, '4', '<' )) {
00393                     $iModStat = 0;
00394                 }
00395             } elseif (version_compare($sClientVersion, '5.0.36', '>=') && version_compare($sClientVersion, '5.0.38', '<')) {
00396                 // mantis#0001003: Problems with MySQL version 5.0.37
00397                 $iModStat = 0;
00398             }
00399             if (strpos($sClientVersion, 'mysqlnd') !== false) {
00400                 // PHP 5.3 includes new mysqlnd extension
00401                 $iModStat = 1;
00402             }
00403         }
00404         return $iModStat;
00405     }
00406 
00414     public function checkMysqlVersion( $sVersion = null )
00415     {
00416         if ( $sVersion === null ) {
00417             $aRez = oxDb::getDb()->getAll( "SHOW VARIABLES LIKE 'version'" );
00418             foreach ( $aRez as $aRecord ) {
00419                 $sVersion = $aRecord[1];
00420                 break;
00421             }
00422         }
00423 
00424         $iModStat = 0;
00425         if ( version_compare( $sVersion, '5', '>=' ) && version_compare( $sVersion, '5.0.37', '<>' ) ) {
00426             $iModStat = 2;
00427         }
00428 
00429         return $iModStat;
00430     }
00431 
00437     public function checkGdInfo()
00438     {
00439         $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00440         $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00441         $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00442         return $iModStat;
00443     }
00444 
00450     public function checkIniSet()
00451     {
00452         return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00453     }
00454 
00460     public function checkRegisterGlobals()
00461     {
00462         $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00463         return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00464     }
00465 
00471     public function checkMemoryLimit()
00472     {
00473         if ( $sMemLimit = @ini_get('memory_limit') ) {
00474                 // CE - PE at least to 14 MB. We recomend a memory_limit of 30MB.
00475                 $sDefLimit = '14M';
00476                 $sRecLimit = '30M';
00477 
00478 
00479             $iMemLimit = $this->_getBytes( $sMemLimit );
00480             $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00481             $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00482 
00483         } else {
00484             $iModStat = -1;
00485         }
00486         return $iModStat;
00487     }
00488 
00494     public function checkZendOptimizer()
00495     {
00496         $iMinStat = 0;
00497         $iModStat = (extension_loaded( 'Zend Optimizer' ) || (function_exists('zend_loader_enabled') && zend_loader_enabled())) ? 2 : $iMinStat;
00498         $sHost   = $_SERVER['HTTP_HOST'];
00499         $sScript = $_SERVER['SCRIPT_NAME'];
00500         if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00501             $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00502 
00503             $sReq  = "POST $sScript HTTP/1.1\r\n";
00504             $sReq .= "Host: $sHost\r\n";
00505             $sReq .= "User-Agent: oxid setup\r\n";
00506             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00507             $sReq .= "Content-Length: 0\r\n"; // empty post
00508             $sReq .= "Connection: close\r\n\r\n";
00509 
00510             $sOut = '';
00511             fwrite( $rFp, $sReq );
00512             while ( !feof( $rFp ) ) {
00513                 $sOut .= fgets( $rFp, 100 );
00514             }
00515 
00516             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00517             fclose( $rFp );
00518         }
00519         if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00520             $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00521 
00522             $sReq  = "POST $sScript HTTP/1.1\r\n";
00523             $sReq .= "Host: $sHost\r\n";
00524             $sReq .= "User-Agent: oxid setup\r\n";
00525             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00526             $sReq .= "Content-Length: 0\r\n"; // empty post
00527             $sReq .= "Connection: close\r\n\r\n";
00528 
00529             $sOut = '';
00530             fwrite( $rFp, $sReq );
00531             while ( !feof( $rFp ) ) {
00532                 $sOut .= fgets( $rFp, 100 );
00533             }
00534             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00535             fclose( $rFp );
00536         }
00537         return $iModStat;
00538     }
00539 
00545     public function checkZendPlatformOrServer()
00546     {
00547         if (function_exists( 'output_cache_get' )) {
00548             return 2;
00549         }
00550         if (function_exists( 'zend_disk_cache_fetch' )) {
00551             return 2;
00552         }
00553         if (function_exists( 'zend_shm_cache_fetch' )) {
00554             return 2;
00555         }
00556         return 1;
00557     }
00558 
00564     protected function _getAdditionalCheck()
00565     {
00566         $sSelect = '';
00567         foreach ( $this->_aException as $sTable => $sColumn ) {
00568             $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00569         }
00570         return $sSelect;
00571     }
00572 
00578     public function checkCollation()
00579     {
00580         $myConfig = oxConfig::getInstance();
00581 
00582         $aCollations = array();
00583         $sCollation = '';
00584 
00585         $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00586                    'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME  ' .
00587                    'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00588                    'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00589                    'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() .
00590                    ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00591         $aRez = oxDb::getDb()->getAll($sSelect);
00592         foreach ( $aRez as $aRetTable ) {
00593             if ( !$sCollation ) {
00594                 $sCollation = $aRetTable[2];
00595             } else {
00596                 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00597                     $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00598                 }
00599             }
00600         }
00601 
00602         if ( $this->_blSysReqStatus === null ) {
00603             $this->_blSysReqStatus = true;
00604         }
00605         if ( count($aCollations) > 0 ) {
00606             $this->_blSysReqStatus = false;
00607         }
00608         return $aCollations;
00609     }
00610 
00616     public function checkDatabaseCluster()
00617     {
00618         return 2;
00619     }
00620 
00626     public function checkUnicodeSupport()
00627     {
00628         return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00629     }
00630 
00636     public function getSysReqStatus()
00637     {
00638         if ( $this->_blSysReqStatus == null ) {
00639             $this->_blSysReqStatus = true;
00640             $this->getSystemInfo();
00641             $this->checkCollation();
00642         }
00643         return $this->_blSysReqStatus;
00644     }
00645 
00660     public function getSystemInfo()
00661     {
00662         $aSysInfo = array();
00663         $aRequiredModules = $this->getRequiredModules();
00664         $this->_blSysReqStatus = true;
00665         foreach ( $aRequiredModules as $sModule => $sGroup ) {
00666             if ( isset($aSysInfo[$sGroup]) && !$aSysInfo[$sGroup] ) {
00667                 $aSysInfo[$sGroup] = array();
00668             }
00669             $iModuleState = $this->getModuleInfo( $sModule );
00670             $aSysInfo[$sGroup][$sModule] = $iModuleState;
00671             $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00672         }
00673         return $aSysInfo;
00674     }
00675 
00683     public function getModuleInfo( $sModule = null )
00684     {
00685         if ( $sModule ) {
00686             $iModStat = null;
00687             $sCheckFunction = "check".str_replace(" ", "", ucwords(str_replace("_", " ", $sModule)));
00688             $iModStat = $this->$sCheckFunction();
00689 
00690             return $iModStat;
00691         }
00692     }
00693 
00701     protected function _getBytes( $sBytes )
00702     {
00703         $sBytes = trim( $sBytes );
00704         $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00705         switch( $sLast ) {
00706             // The 'G' modifier is available since PHP 5.1.0
00707             case 'g':
00708                 $sBytes *= 1024;
00709             case 'm':
00710                 $sBytes *= 1024;
00711             case 'k':
00712                 $sBytes *= 1024;
00713                 break;
00714         }
00715 
00716         return $sBytes;
00717     }
00718 }

Generated by  doxygen 1.6.2