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 getRequiredModules()
00088     {
00089         if ( $this->_aRequiredModules == null ) {
00090             $aRequiredPHPExtensions = array(
00091                                           'phpversion',
00092                                           'libxml2',
00093                                           'php-xml',
00094                                           'json',
00095                                           'iconv',
00096                                           'tokenizer',
00097                                           'mysql_connect',
00098                                           'gd_info',
00099                                           'mb_string',
00100                                       );
00101 
00102                 $aRequiredPHPExtensions[] = 'bcmath';
00103 
00104             $aRequiredPHPConfigs = array(
00105                                        'allow_url_fopen',
00106                                        'php4_compat',
00107                                        'request_uri',
00108                                        'ini_set',
00109                                        'register_globals',
00110                                        'memory_limit',
00111                                        'unicode_support'
00112                                    );
00113 
00114             $aRequiredServerConfigs = array(
00115                                           'mod_rewrite'
00116                                       );
00117 
00118 
00119             $this->_aRequiredModules = array_fill_keys( $aRequiredPHPExtensions, 'php_extennsions' ) +
00120                                        array_fill_keys( $aRequiredPHPConfigs, 'php_config' ) +
00121                                        array_fill_keys( $aRequiredServerConfigs, 'server_config' );
00122         }
00123         return $this->_aRequiredModules;
00124     }
00125 
00131     public function checkMbString()
00132     {
00133         return extension_loaded( 'mbstring' ) ? 2 : 1;
00134     }
00135 
00141     public function checkModRewrite()
00142     {
00143         $iModStat = null;
00144         $sHost   = $_SERVER['HTTP_HOST'];
00145         $sScript = $_SERVER['SCRIPT_NAME'];
00146         if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00147             $sScript = str_replace( basename($sScript), '../admin/test.php', $sScript );
00148 
00149             $sReq  = "POST $sScript HTTP/1.1\r\n";
00150             $sReq .= "Host: $sHost\r\n";
00151             $sReq .= "User-Agent: oxid setup\r\n";
00152             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00153             $sReq .= "Content-Length: 0\r\n"; // empty post
00154             $sReq .= "Connection: close\r\n\r\n";
00155 
00156             $sOut = '';
00157             fwrite( $rFp, $sReq );
00158             while ( !feof( $rFp ) ) {
00159                 $sOut .= fgets( $rFp, 100 );
00160             }
00161             fclose( $rFp );
00162 
00163             $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00164         } else {
00165             if ( function_exists( 'apache_get_modules' ) ) {
00166                 // it does not assure that mod_rewrite is enabled on current host, so setting 1
00167                 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00168             } else {
00169                 $iModStat = -1;
00170             }
00171         }
00172         return $iModStat;
00173     }
00174 
00180     public function checkAllowUrlFopen()
00181     {
00182         $iModStat = @ini_get('allow_url_fopen');
00183         $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00184         if ( $iModStat == 1 ) {
00185             $iErrNo  = 0;
00186             $sErrStr = '';
00187             if ( $oRes = @fsockopen( 'www.oxid-esales.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00188                 $iModStat = 2;
00189                 fclose( $oRes );
00190             }
00191         }
00192         $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00193         return $iModStat;
00194     }
00195 
00202     public function checkPhp4Compat()
00203     {
00204         $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00205         return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00206     }
00207 
00214     public function checkPhpVersion()
00215     {
00216         $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00217         $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00218         return $iModStat;
00219     }
00220 
00226     public function checkRequestUri()
00227     {
00228         return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00229     }
00230 
00236     public function checkLibXml2()
00237     {
00238         return class_exists( 'DOMDocument' ) ? 2 : 0;
00239     }
00240 
00246     public function checkPhpXml()
00247     {
00248         return class_exists( 'DOMDocument' ) ? 2 : 0;
00249     }
00250 
00256     public function checkJSon()
00257     {
00258         return extension_loaded( 'json' ) ? 2 : 0;
00259     }
00260 
00266     public function checkIConv()
00267     {
00268         return extension_loaded( 'iconv' ) ? 2 : 0;
00269     }
00270 
00276     public function checkTokenizer()
00277     {
00278         return extension_loaded( 'tokenizer' ) ? 2 : 0;
00279     }
00280 
00286     public function checkBcMath()
00287     {
00288         return extension_loaded( 'bcmath' ) ? 2 : 1;
00289     }
00290 
00296     public function checkMysqlConnect()
00297     {
00298         // MySQL module for MySQL5
00299         $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00300         // client version must be >=5
00301         if ( $iModStat ) {
00302             $sClientVersion = mysql_get_client_info();
00303             if (version_compare( $sClientVersion, '5', '<' )) {
00304                 $iModStat = 1;
00305                 if (version_compare( $sClientVersion, '4', '<' )) {
00306                     $iModStat = 0;
00307                 }
00308             } elseif (version_compare($sClientVersion, '5.0.36', '>=') && version_compare($sClientVersion, '5.0.38', '<')) {
00309                 // mantis#0001003: Problems with MySQL version 5.0.37
00310                 $iModStat = 0;
00311             }
00312         }
00313         return $iModStat;
00314     }
00315 
00321     public function checkGdInfo()
00322     {
00323         $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00324         $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00325         $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00326         return $iModStat;
00327     }
00328 
00334     public function checkIniSet()
00335     {
00336         return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00337     }
00338 
00344     public function checkRegisterGlobals()
00345     {
00346         $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00347         return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00348     }
00349 
00355     public function checkMemoryLimit()
00356     {
00357         if ( $sMemLimit = @ini_get('memory_limit') ) {
00358                 // CE - PE at least to 14 MB. We recomend a memory_limit of 30MB.
00359                 $sDefLimit = '14M';
00360                 $sRecLimit = '30M';
00361 
00362 
00363             $iMemLimit = $this->_getBytes( $sMemLimit );
00364             $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00365             $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00366 
00367         } else {
00368             $iModStat = -1;
00369         }
00370         return $iModStat;
00371     }
00372 
00378     public function checkZendOptimizer()
00379     {
00380         $iModStat = extension_loaded( 'Zend Optimizer' ) ? 2 : 0;
00381         $sHost   = $_SERVER['HTTP_HOST'];
00382         $sScript = $_SERVER['SCRIPT_NAME'];
00383         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00384             $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00385 
00386             $sReq  = "POST $sScript HTTP/1.1\r\n";
00387             $sReq .= "Host: $sHost\r\n";
00388             $sReq .= "User-Agent: oxid setup\r\n";
00389             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00390             $sReq .= "Content-Length: 0\r\n"; // empty post
00391             $sReq .= "Connection: close\r\n\r\n";
00392 
00393             $sOut = '';
00394             fwrite( $rFp, $sReq );
00395             while ( !feof( $rFp ) ) {
00396                 $sOut .= fgets( $rFp, 100 );
00397             }
00398 
00399             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00400             fclose( $rFp );
00401         }
00402         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00403             $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00404 
00405             $sReq  = "POST $sScript HTTP/1.1\r\n";
00406             $sReq .= "Host: $sHost\r\n";
00407             $sReq .= "User-Agent: oxid setup\r\n";
00408             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00409             $sReq .= "Content-Length: 0\r\n"; // empty post
00410             $sReq .= "Connection: close\r\n\r\n";
00411 
00412             $sOut = '';
00413             fwrite( $rFp, $sReq );
00414             while ( !feof( $rFp ) ) {
00415                 $sOut .= fgets( $rFp, 100 );
00416             }
00417             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00418             fclose( $rFp );
00419         }
00420         return $iModStat;
00421     }
00422 
00428     public function checkZendPlatform()
00429     {
00430         return function_exists( 'output_cache_get' ) ? 2 : 1;
00431     }
00432 
00438     protected function _getAdditionalCheck()
00439     {
00440         $sSelect = '';
00441         foreach ( $this->_aException as $sTable => $sColumn ) {
00442             $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00443         }
00444         return $sSelect;
00445     }
00446 
00452     public function checkCollation()
00453     {
00454         $myConfig = oxConfig::getInstance();
00455 
00456         $aCollations = array();
00457         $sCollation = '';
00458 
00459         $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00460                    'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME  ' .
00461                    'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00462                    'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00463                    'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() . 
00464                    ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00465         $aRez = oxDb::getDb()->getAll($sSelect);
00466         foreach ( $aRez as $aRetTable ) {
00467             if ( !$sCollation ) {
00468                 $sCollation = $aRetTable[2];
00469             } else {
00470                 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00471                     $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00472                 }
00473             }
00474         }
00475 
00476         if ( $this->_blSysReqStatus === null ) {
00477             $this->_blSysReqStatus = true;
00478         }
00479         if ( count($aCollations) > 0 ) {
00480             $this->_blSysReqStatus = false;
00481         }
00482         return $aCollations;
00483     }
00484 
00490     public function checkDatabaseCluster()
00491     {
00492         return 2;
00493     }
00494 
00500     public function checkUnicodeSupport()
00501     {
00502         return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00503     }
00504 
00510     public function getSysReqStatus()
00511     {
00512         if ( $this->_blSysReqStatus == null ) {
00513             $this->_blSysReqStatus = true;
00514             $this->getSystemInfo();
00515             $this->checkCollation();
00516         }
00517         return $this->_blSysReqStatus;
00518     }
00519 
00534     public function getSystemInfo()
00535     {
00536         $aSysInfo = array();
00537         $aRequiredModules = $this->getRequiredModules();
00538         $this->_blSysReqStatus = true;
00539         foreach ( $aRequiredModules as $sModule => $sGroup ) {
00540             if ( !$aSysInfo[$sGroup] ) {
00541                 $aSysInfo[$sGroup] = array();
00542             }
00543             $iModuleState = $this->getModuleInfo( $sModule );
00544             $aSysInfo[$sGroup][$sModule] = $iModuleState;
00545             $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00546         }
00547         return $aSysInfo;
00548     }
00549 
00557     public function getModuleInfo( $sModule = null )
00558     {
00559         if ( $sModule ) {
00560             $iModStat = null;
00561             switch ( $sModule ) {
00562                 case 'mb_string':
00563                     $iModStat = $this->checkMbString();
00564                     break;
00565                 case 'mod_rewrite':
00566                     $iModStat = $this->checkModRewrite();
00567                     break;
00568                 case 'allow_url_fopen':
00569                     $iModStat = $this->checkAllowUrlFopen();
00570                     break;
00571                 case 'php4_compat':
00572                     $iModStat = $this->checkPhp4Compat();
00573                     break;
00574                 case 'phpversion':
00575                     $iModStat = $this->checkPhp4Compat();
00576                     break;
00577                 case 'request_uri':
00578                     $iModStat = $this->checkRequestUri();
00579                     break;
00580                 case 'libxml2':
00581                     $iModStat = $this->checkLibXml2();
00582                     break;
00583                 case 'php-xml':
00584                     $iModStat = $this->checkPhpXml();
00585                     break;
00586                 case 'json':
00587                     $iModStat = $this->checkJSon();
00588                     break;
00589                 case 'iconv':
00590                     $iModStat = $this->checkIConv();
00591                     break;
00592                 case 'tokenizer':
00593                     $iModStat = $this->checkTokenizer();
00594                     break;
00595                 case 'bcmath':
00596                     $iModStat = $this->checkBcMath();
00597                     break;
00598                 case 'mysql_connect':
00599                     $iModStat = $this->checkMysqlConnect();
00600                     break;
00601                 case 'gd_info':
00602                     $iModStat = $this->checkGdInfo();
00603                     break;
00604                 case 'ini_set':
00605                     $iModStat = $this->checkIniSet();
00606                     break;
00607                 case 'register_globals':
00608                     $iModStat = $this->checkRegisterGlobals();
00609                     break;
00610                 case 'memory_limit':
00611                     $iModStat = $this->checkMemoryLimit();
00612                     break;
00613                 case 'unicode_support':
00614                     $iModStat = $this->checkUnicodeSupport();
00615                     break;
00616             }
00617 
00618 
00619             return $iModStat;
00620         }
00621     }
00622 
00630     protected function _getBytes( $sBytes )
00631     {
00632         $sBytes = trim( $sBytes );
00633         $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00634         switch( $sLast ) {
00635             // The 'G' modifier is available since PHP 5.1.0
00636             case 'g':
00637                 $sBytes *= 1024;
00638             case 'm':
00639                 $sBytes *= 1024;
00640             case 'k':
00641                 $sBytes *= 1024;
00642                 break;
00643         }
00644 
00645         return $sBytes;
00646     }
00647 
00648 }

Generated on Wed Jun 17 12:09:02 2009 for OXID eShop CE by  doxygen 1.5.5