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 );
00112
00113 $aRequiredServerConfigs = array(
00114 'mod_rewrite'
00115 );
00116
00117
00118 $this->_aRequiredModules = array_fill_keys($aRequiredPHPExtensions,'php_extennsions') +
00119 array_fill_keys($aRequiredPHPConfigs,'php_config') +
00120 array_fill_keys($aRequiredServerConfigs,'server_config');
00121 }
00122 return $this->_aRequiredModules;
00123 }
00124
00130 public function checkMbString()
00131 {
00132 return extension_loaded( 'mbstring' ) ? 2 : 1;
00133 }
00134
00140 public function checkModRewrite()
00141 {
00142 $iModStat = null;
00143 $sHost = $_SERVER['HTTP_HOST'];
00144 $sScript = $_SERVER['SCRIPT_NAME'];
00145 if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00146 $sScript = str_replace( basename($sScript), '../admin/test/test.php', $sScript );
00147
00148 $sReq = "POST $sScript HTTP/1.1\r\n";
00149 $sReq .= "Host: $sHost\r\n";
00150 $sReq .= "User-Agent: oxid setup\r\n";
00151 $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00152 $sReq .= "Content-Length: 0\r\n";
00153 $sReq .= "Connection: close\r\n\r\n";
00154
00155 $sOut = '';
00156 fwrite( $rFp, $sReq );
00157 while ( !feof( $rFp ) ) {
00158 $sOut .= fgets( $rFp, 100 );
00159 }
00160 fclose( $rFp );
00161
00162 $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00163 } else {
00164 if ( function_exists( 'apache_get_modules' ) ) {
00165
00166 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00167 } else {
00168 $iModStat = -1;
00169 }
00170 }
00171 return $iModStat;
00172 }
00173
00179 public function checkAllowUrlFopen()
00180 {
00181 $iModStat = @ini_get('allow_url_fopen');
00182 $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00183 if ( $iModStat == 1 ) {
00184 $iErrNo = 0;
00185 $sErrStr = '';
00186 if ( $oRes = @fsockopen( 'www.oxid-esales.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00187 $iModStat = 2;
00188 fclose( $oRes );
00189 }
00190 }
00191 $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00192 return $iModStat;
00193 }
00194
00201 public function checkPhp4Compat()
00202 {
00203 $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00204 return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00205 }
00206
00213 public function checkPhpVersion()
00214 {
00215 $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00216 $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00217 return $iModStat;
00218 }
00219
00225 public function checkRequestUri()
00226 {
00227 return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00228 }
00229
00235 public function checkLibXml2()
00236 {
00237 return class_exists( 'DOMDocument' ) ? 2 : 0;
00238 }
00239
00245 public function checkPhpXml()
00246 {
00247 return class_exists( 'DOMDocument' ) ? 2 : 0;
00248 }
00249
00255 public function checkJSon()
00256 {
00257 return extension_loaded( 'json' ) ? 2 : 0;
00258 }
00259
00265 public function checkIConv()
00266 {
00267 return extension_loaded( 'iconv' ) ? 2 : 0;
00268 }
00269
00275 public function checkTokenizer()
00276 {
00277 return extension_loaded( 'tokenizer' ) ? 2 : 0;
00278 }
00279
00285 public function checkBcMath()
00286 {
00287 return extension_loaded( 'bcmath' ) ? 2 : 1;
00288 }
00289
00295 public function checkMysqlConnect()
00296 {
00297
00298 $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00299
00300 if ( $iModStat ) {
00301 $sClientVersion = mysql_get_client_info();
00302 $iModStat = version_compare( mysql_get_client_info(), '5', '>=' ) ? $iModStat : 1;
00303
00304 if ( $iModStat == 1) {
00305 $iModStat = version_compare( mysql_get_client_info(), '4', '>=' ) ? $iModStat : 0;
00306 }
00307 }
00308 return $iModStat;
00309 }
00310
00316 public function checkGdInfo()
00317 {
00318 $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00319 $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00320 $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00321 return $iModStat;
00322 }
00323
00329 public function checkIniSet()
00330 {
00331 return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00332 }
00333
00339 public function checkRegisterGlobals()
00340 {
00341 $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00342 return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00343 }
00344
00350 public function checkMemoryLimit()
00351 {
00352 if ( $sMemLimit = @ini_get('memory_limit') ) {
00353
00354 $sDefLimit = '14M';
00355 $sRecLimit = '30M';
00356
00357
00358 $iMemLimit = $this->_getBytes( $sMemLimit );
00359 $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00360 $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00361
00362 } else {
00363 $iModStat = -1;
00364 }
00365 return $iModStat;
00366 }
00367
00373 public function checkZendOptimizer()
00374 {
00375 return extension_loaded( 'Zend Optimizer' ) ? 2 : 0;
00376 }
00377
00383 public function checkZendPlatform()
00384 {
00385 return function_exists( 'output_cache_get' ) ? 2 : 1;
00386 }
00387
00393 protected function _getAdditionalCheck()
00394 {
00395 $sSelect = '';
00396 foreach ( $this->_aException as $sTable => $sColumn ) {
00397 $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00398 }
00399 return $sSelect;
00400 }
00401
00407 public function checkCollation()
00408 {
00409 $myConfig = oxConfig::getInstance();
00410
00411 $aCollations = array();
00412 $sCollation = '';
00413
00414 $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00415 'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME ' .
00416 'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00417 'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00418 'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck();
00419 $aRez = oxDb::getDb()->getAll($sSelect);
00420 foreach ( $aRez as $aRetTable ) {
00421 if ( !$sCollation ) {
00422 $sCollation = $aRetTable[2];
00423 } else {
00424 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00425 $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00426 }
00427 }
00428 }
00429
00430 if ( count($aCollations) > 0 ) {
00431 $this->_blSysReqStatus = false;
00432 }
00433 return $aCollations;
00434 }
00435
00441 public function checkDatabaseCluster()
00442 {
00443 return 2;
00444 }
00445
00451 public function getSysReqStatus()
00452 {
00453 if ( $this->_blSysReqStatus == null ) {
00454 $this->getSystemInfo();
00455 $this->checkCollation();
00456 }
00457 return $this->_blSysReqStatus;
00458 }
00459
00474 public function getSystemInfo()
00475 {
00476 $aSysInfo = array();
00477 $aRequiredModules = $this->getRequiredModules();
00478 $this->_blSysReqStatus = true;
00479 foreach ( $aRequiredModules as $sModule => $sGroup ) {
00480 if ( !$aSysInfo[$sGroup] ) {
00481 $aSysInfo[$sGroup] = array();
00482 }
00483 $iModuleState = $this->getModuleInfo( $sModule );
00484 $aSysInfo[$sGroup][$sModule] = $iModuleState;
00485 $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00486 }
00487 return $aSysInfo;
00488 }
00489
00497 public function getModuleInfo( $sModule = null )
00498 {
00499 if ( $sModule ) {
00500 $iModStat = null;
00501 switch ( $sModule ) {
00502 case 'mb_string':
00503 $iModStat = $this->checkMbString();
00504 break;
00505 case 'mod_rewrite':
00506 $iModStat = $this->checkModRewrite();
00507 break;
00508 case 'allow_url_fopen':
00509 $iModStat = $this->checkAllowUrlFopen();
00510 break;
00511 case 'php4_compat':
00512 $iModStat = $this->checkPhp4Compat();
00513 break;
00514 case 'phpversion':
00515 $iModStat = $this->checkPhp4Compat();
00516 break;
00517 case 'request_uri':
00518 $iModStat = $this->checkRequestUri();
00519 break;
00520 case 'libxml2':
00521 $iModStat = $this->checkLibXml2();
00522 break;
00523 case 'php-xml':
00524 $iModStat = $this->checkPhpXml();
00525 break;
00526 case 'json':
00527 $iModStat = $this->checkJSon();
00528 break;
00529 case 'iconv':
00530 $iModStat = $this->checkIConv();
00531 break;
00532 case 'tokenizer':
00533 $iModStat = $this->checkTokenizer();
00534 break;
00535 case 'bcmath':
00536 $iModStat = $this->checkBcMath();
00537 break;
00538 case 'mysql_connect':
00539 $iModStat = $this->checkMysqlConnect();
00540 break;
00541 case 'gd_info':
00542 $iModStat = $this->checkGdInfo();
00543 break;
00544 case 'ini_set':
00545 $iModStat = $this->checkIniSet();
00546 break;
00547 case 'register_globals':
00548 $iModStat = $this->checkRegisterGlobals();
00549 break;
00550 case 'memory_limit':
00551 $iModStat = $this->checkMemoryLimit();
00552 break;
00553 }
00554
00555
00556 return $iModStat;
00557 }
00558 }
00559
00567 protected function _getBytes( $sBytes )
00568 {
00569 $sBytes = trim( $sBytes );
00570 $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00571 switch( $sLast ) {
00572
00573 case 'g':
00574 $sBytes *= 1024;
00575 case 'm':
00576 $sBytes *= 1024;
00577 case 'k':
00578 $sBytes *= 1024;
00579 }
00580
00581 return $sBytes;
00582 }
00583
00584 }