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 );
00110
00111 $aRequiredPHPExtensions[] = 'bc_math';
00112
00113 $aRequiredPHPConfigs = array(
00114 'allow_url_fopen',
00115 'php4_compat',
00116 'request_uri',
00117 'ini_set',
00118 'register_globals',
00119 'memory_limit',
00120 'unicode_support'
00121 );
00122
00123 $aRequiredServerConfigs = array(
00124 'mod_rewrite'
00125 );
00126
00127
00128 $this->_aRequiredModules = array_fill_keys( $aRequiredPHPExtensions, 'php_extennsions' ) +
00129 array_fill_keys( $aRequiredPHPConfigs, 'php_config' ) +
00130 array_fill_keys( $aRequiredServerConfigs, 'server_config' );
00131 }
00132 return $this->_aRequiredModules;
00133 }
00134
00140 public function checkMbString()
00141 {
00142 return extension_loaded( 'mbstring' ) ? 2 : 1;
00143 }
00144
00150 public function checkModRewrite()
00151 {
00152 $iModStat = null;
00153 $sHost = $_SERVER['HTTP_HOST'];
00154 $sScript = $_SERVER['SCRIPT_NAME'];
00155 if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00156 $sScript = str_replace( basename($sScript), '../admin/test.php', $sScript );
00157
00158 $sReq = "POST $sScript HTTP/1.1\r\n";
00159 $sReq .= "Host: $sHost\r\n";
00160 $sReq .= "User-Agent: oxid setup\r\n";
00161 $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00162 $sReq .= "Content-Length: 0\r\n";
00163 $sReq .= "Connection: close\r\n\r\n";
00164
00165 $sOut = '';
00166 fwrite( $rFp, $sReq );
00167 while ( !feof( $rFp ) ) {
00168 $sOut .= fgets( $rFp, 100 );
00169 }
00170 fclose( $rFp );
00171
00172 $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00173 } else {
00174 if ( function_exists( 'apache_get_modules' ) ) {
00175
00176 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00177 } else {
00178 $iModStat = -1;
00179 }
00180 }
00181 return $iModStat;
00182 }
00183
00189 public function checkAllowUrlFopen()
00190 {
00191 $iModStat = @ini_get('allow_url_fopen');
00192 $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00193 if ( $iModStat == 1 ) {
00194 $iErrNo = 0;
00195 $sErrStr = '';
00196 if ( $oRes = @fsockopen( 'www.example.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00197 $iModStat = 2;
00198 fclose( $oRes );
00199 }
00200 }
00201 $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00202 return $iModStat;
00203 }
00204
00211 public function checkPhp4Compat()
00212 {
00213 $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00214 return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00215 }
00216
00223 public function checkPhpVersion()
00224 {
00225 $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00226 $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00227 return $iModStat;
00228 }
00229
00235 public function checkRequestUri()
00236 {
00237 return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00238 }
00239
00245 public function checkLibXml2()
00246 {
00247 return class_exists( 'DOMDocument' ) ? 2 : 0;
00248 }
00249
00255 public function checkPhpXml()
00256 {
00257 return class_exists( 'DOMDocument' ) ? 2 : 0;
00258 }
00259
00265 public function checkJSon()
00266 {
00267 return extension_loaded( 'json' ) ? 2 : 0;
00268 }
00269
00275 public function checkIConv()
00276 {
00277 return extension_loaded( 'iconv' ) ? 2 : 0;
00278 }
00279
00285 public function checkTokenizer()
00286 {
00287 return extension_loaded( 'tokenizer' ) ? 2 : 0;
00288 }
00289
00295 public function checkBcMath()
00296 {
00297 return extension_loaded( 'bcmath' ) ? 2 : 1;
00298 }
00299
00305 public function checkMysqlConnect()
00306 {
00307
00308 $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00309
00310 if ( $iModStat ) {
00311 $sClientVersion = mysql_get_client_info();
00312 if (version_compare( $sClientVersion, '5', '<' )) {
00313 $iModStat = 1;
00314 if (version_compare( $sClientVersion, '4', '<' )) {
00315 $iModStat = 0;
00316 }
00317 } elseif (version_compare($sClientVersion, '5.0.36', '>=') && version_compare($sClientVersion, '5.0.38', '<')) {
00318
00319 $iModStat = 0;
00320 }
00321 }
00322 return $iModStat;
00323 }
00324
00330 public function checkGdInfo()
00331 {
00332 $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00333 $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00334 $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00335 return $iModStat;
00336 }
00337
00343 public function checkIniSet()
00344 {
00345 return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00346 }
00347
00353 public function checkRegisterGlobals()
00354 {
00355 $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00356 return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00357 }
00358
00364 public function checkMemoryLimit()
00365 {
00366 if ( $sMemLimit = @ini_get('memory_limit') ) {
00367
00368 $sDefLimit = '14M';
00369 $sRecLimit = '30M';
00370
00371
00372 $iMemLimit = $this->_getBytes( $sMemLimit );
00373 $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00374 $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00375
00376 } else {
00377 $iModStat = -1;
00378 }
00379 return $iModStat;
00380 }
00381
00387 public function checkZendOptimizer()
00388 {
00389 $iMinStat = 0;
00390 $iModStat = extension_loaded( 'Zend Optimizer' ) ? 2 : $iMinStat;
00391 $sHost = $_SERVER['HTTP_HOST'];
00392 $sScript = $_SERVER['SCRIPT_NAME'];
00393 if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00394 $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00395
00396 $sReq = "POST $sScript HTTP/1.1\r\n";
00397 $sReq .= "Host: $sHost\r\n";
00398 $sReq .= "User-Agent: oxid setup\r\n";
00399 $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00400 $sReq .= "Content-Length: 0\r\n";
00401 $sReq .= "Connection: close\r\n\r\n";
00402
00403 $sOut = '';
00404 fwrite( $rFp, $sReq );
00405 while ( !feof( $rFp ) ) {
00406 $sOut .= fgets( $rFp, 100 );
00407 }
00408
00409 $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00410 fclose( $rFp );
00411 }
00412 if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00413 $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00414
00415 $sReq = "POST $sScript HTTP/1.1\r\n";
00416 $sReq .= "Host: $sHost\r\n";
00417 $sReq .= "User-Agent: oxid setup\r\n";
00418 $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00419 $sReq .= "Content-Length: 0\r\n";
00420 $sReq .= "Connection: close\r\n\r\n";
00421
00422 $sOut = '';
00423 fwrite( $rFp, $sReq );
00424 while ( !feof( $rFp ) ) {
00425 $sOut .= fgets( $rFp, 100 );
00426 }
00427 $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00428 fclose( $rFp );
00429 }
00430 return $iModStat;
00431 }
00432
00438 public function checkZendPlatformOrServer()
00439 {
00440 if (function_exists( 'output_cache_get' )) {
00441 return 2;
00442 }
00443 if (function_exists( 'zend_disk_cache_fetch' )) {
00444 return 2;
00445 }
00446 if (function_exists( 'zend_shm_cache_fetch' )) {
00447 return 2;
00448 }
00449 return 1;
00450 }
00451
00457 protected function _getAdditionalCheck()
00458 {
00459 $sSelect = '';
00460 foreach ( $this->_aException as $sTable => $sColumn ) {
00461 $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00462 }
00463 return $sSelect;
00464 }
00465
00471 public function checkCollation()
00472 {
00473 $myConfig = oxConfig::getInstance();
00474
00475 $aCollations = array();
00476 $sCollation = '';
00477
00478 $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00479 'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME ' .
00480 'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00481 'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00482 'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() .
00483 ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00484 $aRez = oxDb::getDb()->getAll($sSelect);
00485 foreach ( $aRez as $aRetTable ) {
00486 if ( !$sCollation ) {
00487 $sCollation = $aRetTable[2];
00488 } else {
00489 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00490 $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00491 }
00492 }
00493 }
00494
00495 if ( $this->_blSysReqStatus === null ) {
00496 $this->_blSysReqStatus = true;
00497 }
00498 if ( count($aCollations) > 0 ) {
00499 $this->_blSysReqStatus = false;
00500 }
00501 return $aCollations;
00502 }
00503
00509 public function checkDatabaseCluster()
00510 {
00511 return 2;
00512 }
00513
00519 public function checkUnicodeSupport()
00520 {
00521 return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00522 }
00523
00529 public function getSysReqStatus()
00530 {
00531 if ( $this->_blSysReqStatus == null ) {
00532 $this->_blSysReqStatus = true;
00533 $this->getSystemInfo();
00534 $this->checkCollation();
00535 }
00536 return $this->_blSysReqStatus;
00537 }
00538
00553 public function getSystemInfo()
00554 {
00555 $aSysInfo = array();
00556 $aRequiredModules = $this->getRequiredModules();
00557 $this->_blSysReqStatus = true;
00558 foreach ( $aRequiredModules as $sModule => $sGroup ) {
00559 if ( isset($aSysInfo[$sGroup]) && !$aSysInfo[$sGroup] ) {
00560 $aSysInfo[$sGroup] = array();
00561 }
00562 $iModuleState = $this->getModuleInfo( $sModule );
00563 $aSysInfo[$sGroup][$sModule] = $iModuleState;
00564 $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00565 }
00566 return $aSysInfo;
00567 }
00568
00576 public function getModuleInfo( $sModule = null )
00577 {
00578 if ( $sModule ) {
00579 $iModStat = null;
00580 $sCheckFunction = "check".str_replace(" ", "", ucwords(str_replace("_", " ", $sModule)));
00581 $iModStat = $this->$sCheckFunction();
00582
00583 return $iModStat;
00584 }
00585 }
00586
00594 protected function _getBytes( $sBytes )
00595 {
00596 $sBytes = trim( $sBytes );
00597 $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00598 switch( $sLast ) {
00599
00600 case 'g':
00601 $sBytes *= 1024;
00602 case 'm':
00603 $sBytes *= 1024;
00604 case 'k':
00605 $sBytes *= 1024;
00606 break;
00607 }
00608
00609 return $sBytes;
00610 }
00611 }