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/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";
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
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
00299 $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00300
00301 if ( $iModStat ) {
00302 $sClientVersion = mysql_get_client_info();
00303 $iModStat = version_compare( mysql_get_client_info(), '5', '>=' ) ? $iModStat : 1;
00304
00305 if ( $iModStat == 1) {
00306 $iModStat = version_compare( mysql_get_client_info(), '4', '>=' ) ? $iModStat : 0;
00307 }
00308 }
00309 return $iModStat;
00310 }
00311
00317 public function checkGdInfo()
00318 {
00319 $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00320 $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00321 $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00322 return $iModStat;
00323 }
00324
00330 public function checkIniSet()
00331 {
00332 return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00333 }
00334
00340 public function checkRegisterGlobals()
00341 {
00342 $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00343 return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00344 }
00345
00351 public function checkMemoryLimit()
00352 {
00353 if ( $sMemLimit = @ini_get('memory_limit') ) {
00354
00355 $sDefLimit = '14M';
00356 $sRecLimit = '30M';
00357
00358
00359 $iMemLimit = $this->_getBytes( $sMemLimit );
00360 $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00361 $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00362
00363 } else {
00364 $iModStat = -1;
00365 }
00366 return $iModStat;
00367 }
00368
00374 public function checkZendOptimizer()
00375 {
00376 return extension_loaded( 'Zend Optimizer' ) ? 2 : 0;
00377 }
00378
00384 public function checkZendPlatform()
00385 {
00386 return function_exists( 'output_cache_get' ) ? 2 : 1;
00387 }
00388
00394 protected function _getAdditionalCheck()
00395 {
00396 $sSelect = '';
00397 foreach ( $this->_aException as $sTable => $sColumn ) {
00398 $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00399 }
00400 return $sSelect;
00401 }
00402
00408 public function checkCollation()
00409 {
00410 $myConfig = oxConfig::getInstance();
00411
00412 $aCollations = array();
00413 $sCollation = '';
00414
00415 $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00416 'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME ' .
00417 'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00418 'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00419 'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() .
00420 ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00421 $aRez = oxDb::getDb()->getAll($sSelect);
00422 foreach ( $aRez as $aRetTable ) {
00423 if ( !$sCollation ) {
00424 $sCollation = $aRetTable[2];
00425 } else {
00426 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00427 $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00428 }
00429 }
00430 }
00431
00432 $this->_blSysReqStatus = true;
00433 if ( count($aCollations) > 0 ) {
00434 $this->_blSysReqStatus = false;
00435 }
00436 return $aCollations;
00437 }
00438
00444 public function checkDatabaseCluster()
00445 {
00446 return 2;
00447 }
00448
00454 public function checkUnicodeSupport()
00455 {
00456 return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00457 }
00458
00464 public function getSysReqStatus()
00465 {
00466 if ( $this->_blSysReqStatus == null ) {
00467 $this->getSystemInfo();
00468 $this->checkCollation();
00469 }
00470 return $this->_blSysReqStatus;
00471 }
00472
00487 public function getSystemInfo()
00488 {
00489 $aSysInfo = array();
00490 $aRequiredModules = $this->getRequiredModules();
00491 $this->_blSysReqStatus = true;
00492 foreach ( $aRequiredModules as $sModule => $sGroup ) {
00493 if ( !$aSysInfo[$sGroup] ) {
00494 $aSysInfo[$sGroup] = array();
00495 }
00496 $iModuleState = $this->getModuleInfo( $sModule );
00497 $aSysInfo[$sGroup][$sModule] = $iModuleState;
00498 $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00499 }
00500 return $aSysInfo;
00501 }
00502
00510 public function getModuleInfo( $sModule = null )
00511 {
00512 if ( $sModule ) {
00513 $iModStat = null;
00514 switch ( $sModule ) {
00515 case 'mb_string':
00516 $iModStat = $this->checkMbString();
00517 break;
00518 case 'mod_rewrite':
00519 $iModStat = $this->checkModRewrite();
00520 break;
00521 case 'allow_url_fopen':
00522 $iModStat = $this->checkAllowUrlFopen();
00523 break;
00524 case 'php4_compat':
00525 $iModStat = $this->checkPhp4Compat();
00526 break;
00527 case 'phpversion':
00528 $iModStat = $this->checkPhp4Compat();
00529 break;
00530 case 'request_uri':
00531 $iModStat = $this->checkRequestUri();
00532 break;
00533 case 'libxml2':
00534 $iModStat = $this->checkLibXml2();
00535 break;
00536 case 'php-xml':
00537 $iModStat = $this->checkPhpXml();
00538 break;
00539 case 'json':
00540 $iModStat = $this->checkJSon();
00541 break;
00542 case 'iconv':
00543 $iModStat = $this->checkIConv();
00544 break;
00545 case 'tokenizer':
00546 $iModStat = $this->checkTokenizer();
00547 break;
00548 case 'bcmath':
00549 $iModStat = $this->checkBcMath();
00550 break;
00551 case 'mysql_connect':
00552 $iModStat = $this->checkMysqlConnect();
00553 break;
00554 case 'gd_info':
00555 $iModStat = $this->checkGdInfo();
00556 break;
00557 case 'ini_set':
00558 $iModStat = $this->checkIniSet();
00559 break;
00560 case 'register_globals':
00561 $iModStat = $this->checkRegisterGlobals();
00562 break;
00563 case 'memory_limit':
00564 $iModStat = $this->checkMemoryLimit();
00565 break;
00566 case 'unicode_support':
00567 $iModStat = $this->checkUnicodeSupport();
00568 break;
00569 }
00570
00571
00572 return $iModStat;
00573 }
00574 }
00575
00583 protected function _getBytes( $sBytes )
00584 {
00585 $sBytes = trim( $sBytes );
00586 $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00587 switch( $sLast ) {
00588
00589 case 'g':
00590 $sBytes *= 1024;
00591 case 'm':
00592 $sBytes *= 1024;
00593 case 'k':
00594 $sBytes *= 1024;
00595 break;
00596 }
00597
00598 return $sBytes;
00599 }
00600
00601 }