eZ Publish  [trunk]
ezsetuptests.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00004  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00005  * @version //autogentag//
00006  * @package kernel
00007  */
00008 
00009 // This file holds the test functions that are used by step 1
00010 
00011 define( 'EZ_SETUP_TEST_SUCCESS', 1 );
00012 define( 'EZ_SETUP_TEST_FAILURE', 2 );
00013 
00014 function eZSetupTestTable()
00015 {
00016     return array( 'phpversion' => array( 'eZSetupTestPhpVersion' ),
00017                   'variables_order' => array( 'eZSetupTestVariablesOrder' ),
00018                   'php_session' => array( 'eZSetupTestExtension' ),
00019                   'directory_permissions' => array( 'eZSetupTestDirectoryPermissions' ),
00020                   'settings_permission' => array( 'eZSetupTestFilePermissions' ),
00021                   'database_extensions' => array( 'eZSetupTestExtension' ),
00022                   'database_all_extensions' => array( 'eZSetupTestExtension' ),
00023                   'php_magicquotes' => array( 'eZSetupCheckMagicQuotes' ),
00024                   'magic_quotes_runtime' => array( 'eZSetupCheckMagicQuotesRuntime' ),
00025                   'php_register_globals' => array( 'eZSetupCheckRegisterGlobals' ),
00026                   'mbstring_extension' => array( 'eZSetupMBStringExtension' ),
00027                   'curl_extension' => array( 'eZSetupTestExtension' ),
00028                   'zlib_extension' => array( 'eZSetupTestExtension' ),
00029                   'dom_extension' => array( 'eZSetupTestExtension' ),
00030                   'iconv_extension' => array( 'eZSetupTestExtension' ),
00031                   'file_upload' => array( 'eZSetupTestFileUpload' ),
00032                   'open_basedir' => array( 'eZSetupTestOpenBasedir' ),
00033                   'safe_mode' => array( 'eZSetupTestSafeMode' ),
00034                   'image_conversion' => array( 'eZSetupCheckTestFunctions' ),
00035                   'imagegd_extension' => array( 'eZSetupCheckGDVersion' ),
00036                   'texttoimage_functions' => array( 'eZSetupTestFunctionExists' ),
00037                   'imagemagick_program' => array( 'eZSetupCheckExecutable' ),
00038                   'memory_limit' => array( 'eZSetupTestMemLimit' ),
00039                   'execution_time' => array( 'eZSetupTestExecutionTime' ),
00040                   'allow_url_fopen' => array( 'eZSetupTestAllowURLFOpen' ),
00041                   'accept_path_info' => array( 'eZSetupTestAcceptPathInfo' ),
00042                   'timezone' => array( 'eZSetupTestTimeZone' ),
00043                   'ezcversion' => array( 'eZSetupTestComponentsVersion' ) );
00044 }
00045 
00046 function eZSetupConfigVariable( $type, $name )
00047 {
00048     $config = eZINI::instance( 'setup.ini' );
00049     return $config->variable( $type, $name );
00050 }
00051 
00052 function eZSetupImageConfigVariableArray( $type, $name )
00053 {
00054     $config = eZINI::instance( 'image.ini' );
00055     return $config->variableArray( $type, $name );
00056 }
00057 
00058 function eZSetupConfigVariableArray( $type, $name )
00059 {
00060     $config = eZINI::instance( 'setup.ini' );
00061     return $config->variableArray( $type, $name );
00062 }
00063 
00064 function eZSetupRunTests( $testList, $client, &$givenPersistentList )
00065 {
00066     eZSetupPrvtExtractExtraPaths( $givenPersistentList );
00067 
00068     $testTable = eZSetupTestTable();
00069 
00070     $testResults = array();
00071     $persistenceResults = array();
00072     $testResult = EZ_SETUP_TEST_SUCCESS;
00073     $successCount = 0;
00074     $http = eZHTTPTool::instance();
00075     foreach ( $testList as $testItem )
00076     {
00077         $testName = $testItem;
00078         $testElement = array();
00079         $testElement[0] = EZ_SETUP_TEST_FAILURE;
00080         if ( !isset( $testTable[$testItem] ) )
00081         {
00082             eZDebug::writeError( "The setup test '$testName' is not defined", $client );
00083             continue;
00084         }
00085         if ( $http->hasPostVariable( $testItem . '_Ignore' ) and
00086              $http->postVariable( $testItem . '_Ignore' ) != 0 )
00087         {
00088             continue;
00089         }
00090         $testInfo = $testTable[$testItem];
00091         $testFunction = $testInfo[0];
00092         if ( !function_exists( $testFunction ) )
00093             continue;
00094         $testResultArray = $testFunction( $testName );
00095         if ( $testResultArray['result'] )
00096         {
00097             $testElement[0] = EZ_SETUP_TEST_SUCCESS;
00098             ++$successCount;
00099         }
00100         else
00101             $testResult = EZ_SETUP_TEST_FAILURE;
00102         if ( isset( $testResultArray['persistent_data'] ) )
00103         {
00104             $persistenceResults[] = array( $testName, $testResultArray['persistent_data'] );
00105         }
00106         else if ( isset( $testResultArray['persistence_list'] ) )
00107         {
00108             $persistenceResults = array_merge( $persistenceResults, $testResultArray['persistence_list'] );
00109         }
00110         $testElement[1] = $testName;
00111         $testElement[2] = $testResultArray;
00112         $testResults[] = $testElement;
00113     }
00114     return array( 'result' => $testResult,
00115                   'results' => $testResults,
00116                   'persistence_list' => $persistenceResults,
00117                   'success_count' => $successCount );
00118 }
00119 
00120 function eZSetupCheckTestFunctions( $type )
00121 {
00122     $extensionList = eZSetupConfigVariableArray( $type, 'Extensions' );
00123     $testList = eZSetupConfigVariableArray( $type, 'TestList' );
00124     $requireType = eZSetupConfigVariable( $type, 'Require' );
00125 
00126     $dummy = null;
00127     $runResult = eZSetupRunTests( $testList, 'eZSetupCheckTestFunctions', $dummy );
00128     $testResults = $runResult['results'];
00129     $testResult = $runResult['result'];
00130     $successCount = $runResult['success_count'];
00131     $persistenceData = $runResult['persistence_list'];
00132 
00133     $result = true;
00134     if ( $requireType == 'one' )
00135     {
00136         if ( $successCount == 0 )
00137             $result = false;
00138     }
00139     else if ( $successCount < count( $extensionList ) )
00140         $result = false;
00141     return array( 'result' => $result,
00142                   'persistence_list' => $persistenceData,
00143                   'test_results' => $testResults );
00144 }
00145 
00146 function eZSetupTestFileUpload( $type )
00147 {
00148     $uploadEnabled = ini_get( 'file_uploads' ) != 0;
00149     $uploadDir = ini_get( 'upload_tmp_dir' );
00150     $uploadDirExists = true;
00151     $uploadDirWriteable = true;
00152     $uploadDirCreateFile = true;
00153     $uploadIsRoot = false;
00154     // Empty upload_tmp_dir variable means that the system
00155     // default is used. However the system default variable is hidden
00156     // from PHP code and must be guessed.
00157     // See: http://www.php.net/manual/en/ini.sect.file-uploads.php#ini.upload-tmp-dir
00158     if ( strlen( trim( $uploadDir ) ) == 0 )
00159     {
00160         $osType = eZSys::osType();
00161         if ( $osType == 'win32' )
00162         {
00163             // Windows machines use the TEMP and TMP env variable.
00164             // TEMP is checked first.
00165             $uploadDir = eZSys::hasEnvironmentVariable( 'TEMP' ) ? eZSys::environmentVariable( 'TEMP' ) : '';
00166             if ( $uploadDir === '' )
00167             {
00168                 $uploadDir = eZSys::hasEnvironmentVariable( 'TMP' ) ? eZSys::environmentVariable( 'TMP' ) : '';
00169             }
00170             // When TEMP/TMP is not set we have to guess the directory
00171             // The only valid guess is %SYSTEMROOT%/TEMP
00172             // If %SYSTEMROOT% is missing we keep the string empty
00173             if ( $uploadDir === '' )
00174             {
00175                 if ( eZSys::hasEnvironmentVariable( 'SYSTEMROOT' ) )
00176                 {
00177                     $uploadDir = eZSys::environmentVariable( 'SYSTEMROOT' ) . '/TEMP';
00178                 }
00179             }
00180         }
00181         else if ( $osType == 'unix' or
00182                   $osType == 'mac' )
00183         {
00184             $uploadDir = eZSys::hasEnvironmentVariable( 'TMPDIR' ) ? eZSys::environmentVariable( 'TMPDIR' ) : '';
00185             // When TMPDIR is not set we have to guess the directory
00186             // On Unix systems we expect /tmp to be used
00187             if ( strlen( $uploadDir ) == 0 )
00188             {
00189                 $uploadDir = '/tmp';
00190             }
00191         }
00192     }
00193     $uploadDirs = array();
00194     if ( strlen( $uploadDir ) > 0 )
00195     {
00196         $uploadDirExists = file_exists( $uploadDir );
00197         $uploadDirWriteable = eZDir::isWriteable( $uploadDir );
00198         if ( $uploadDirExists and $uploadDirWriteable )
00199         {
00200             $uploadDirCreateFile = false;
00201             $tmpFile = 'ezsetuptmp_' . md5( microtime() ) . '.tmp';
00202             $tmpFilePath = $uploadDir . '/' . $tmpFile;
00203             if ( $fd = @fopen( $tmpFilePath, 'w' ) )
00204             {
00205                 $uploadDirCreateFile = true;
00206                 @fclose( $fd );
00207                 unlink( $tmpFilePath );
00208             }
00209         }
00210         $splitDirs = explode( '/', trim( $uploadDir, '/' ) );
00211         $dirPath = '';
00212         foreach ( $splitDirs as $splitDir )
00213         {
00214             $dirPath .= '/' . $splitDir;
00215             $uploadDirs[] = $dirPath;
00216         }
00217         if ( substr( $uploadDir, 0, 5 ) == '/root' )
00218         {
00219             $uploadIsRoot = true;
00220         }
00221     }
00222     $result = ( $uploadEnabled and $uploadDirExists and
00223                 $uploadDirWriteable and $uploadDirCreateFile );
00224 
00225     $userInfo = eZSetupPrvPosixExtension();
00226     return array( 'result' => $result,
00227                   'php_upload_is_enabled' => $uploadEnabled,
00228                   'php_upload_is_root' => $uploadIsRoot,
00229                   'php_upload_dir' => $uploadDir,
00230                   'php_upload_split_dirs' => $uploadDirs,
00231                   'upload_dir_exists' => $uploadDirExists,
00232                   'upload_dir_writeable' => $uploadDirWriteable,
00233                   'upload_dir_create_file' => $uploadDirCreateFile,
00234                   'user_info' => $userInfo,
00235                   'persistent_data' => array( 'result' => array( 'value' => $result ) ) );
00236 }
00237 
00238 function eZSetupCheckMagicQuotesRuntime( $type )
00239 {
00240     $magicQuote = get_magic_quotes_runtime();
00241     $result = ( $magicQuote == 0 );
00242     return array( 'result' => $result,
00243                   'persistent_data' => array( 'result' => array( 'value' => $result ) ) );
00244 }
00245 
00246 function eZSetupCheckMagicQuotes( $type )
00247 {
00248     $magicQuote = get_magic_quotes_gpc();
00249     $result = ( $magicQuote == 0 );
00250     return array( 'result' => $result,
00251                   'persistent_data' => array( 'result' => array( 'value' => $result ) ) );
00252 }
00253 
00254 /*!
00255     Test if eZ Components version is greater than required version
00256     This is currently done by checking existence of class and function
00257     since ezc does not have an api to get version information atm.
00258 */
00259 function eZSetupTestComponentsVersion( $type )
00260 {
00261     $minVersion = eZSetupConfigVariable( $type, 'MinimumVersion' );
00262     $testClass = eZSetupConfigVariable( $type, 'TestClass' );
00263     $testFunction = eZSetupConfigVariable( $type, 'TestFunction' );
00264     $result = true;
00265     $ezcExists = true;
00266 
00267     if ( $testClass && class_exists( $testClass ) )
00268     {
00269         if ( $testFunction && !is_callable( array( $testClass, $testFunction ) ) )
00270         {
00271             $result = false;
00272         }
00273     }
00274     else if ( $testClass )
00275     {
00276         $result = false;
00277         $ezcExists = false;
00278     }
00279 
00280     return array( 'result' => $result,
00281                   'persistent_data' => array( 'result' => array( 'value' => $result ),
00282                                               'required' => array( 'value' => $minVersion ) ),
00283                   'needed_version' => $minVersion,
00284                   'class_exists' => !$ezcExists );
00285 }
00286 
00287 
00288 /*!
00289     Test if PHP version is equal or greater than required version
00290 */
00291 function eZSetupTestPhpVersion( $type )
00292 {
00293     $minVersion = eZSetupConfigVariable( $type, 'MinimumVersion' );
00294     $unstableVersionArray = eZSetupConfigVariableArray( $type, 'UnstableVersions' );
00295 
00296     /*
00297      // Get the operating systems name
00298     $operatingSystem = explode( ' ', php_uname() );
00299     $operatingSystem = strtolower( $operatingSystem[0] );
00300 
00301     // Find out if there is an os specific version needed
00302     if ( isset( $argArray["req"][$operatingSystem] ) )
00303         $neededVersion = $argArray["req"][$operatingSystem];
00304     else if ( isset( $argArray["req"] ) )
00305         $neededVersion = $argArray["req"];
00306     else
00307         $neededVersion = $argArray["req"];
00308     */
00309 
00310     $neededVersion = $minVersion;
00311 
00312     // compare the versions
00313     $currentVersion = phpversion();
00314     $currentVersionArray = explode( '.', $currentVersion );
00315     $neededVersionArray = explode( '.', $neededVersion );
00316 
00317     $warningVersion = false;
00318     $result = eZSetupPrvtVersionCompare( $currentVersionArray, $neededVersionArray ) >= 0;
00319 
00320     if ( $result )
00321     {
00322         foreach ( array_keys( $unstableVersionArray ) as $key )
00323         {
00324             $unstableVersion = explode( '.', $unstableVersionArray[$key] );
00325             if ( eZSetupPrvtVersionCompare( $currentVersionArray, $unstableVersion ) == 0 )
00326             {
00327                 $result = false;
00328                 $warningVersion = true;
00329                 break;
00330             }
00331         }
00332     }
00333 
00334     return array( 'result' => $result,
00335                   'persistent_data' => array( 'result' => array( 'value' => $result ),
00336                                               'found' => array( 'value' => $currentVersion ),
00337                                               'required' => array( 'value' => $neededVersion ) ),
00338                   'needed_version' => $neededVersion,
00339                   'current_version' => $currentVersion,
00340                   'warning_version' => $warningVersion );
00341 }
00342 
00343 function eZSetupTestVariablesOrder( $type )
00344 {
00345     $variablesOrder = ini_get( 'variables_order' );
00346     $result = strpos( $variablesOrder, 'E' ) !== false;
00347     return array(
00348         'result' => $result,
00349         'persistent_data' => array(
00350             'result' => array( 'value' => $result ),
00351             'found' => array( 'value' => $variablesOrder )
00352          )
00353     );
00354 }
00355 
00356 /*!
00357   Test if allowed to open URLs using fopen
00358 */
00359 function eZSetupTestAllowURLFOpen( $type )
00360 {
00361     $allowFOpen = ini_get( 'allow_url_fopen' ) != 0;
00362     return array( 'result' => $allowFOpen,
00363                   'persistent_data' => array( 'result' => array( 'value' => $allowFOpen ) ) );
00364 }
00365 
00366 /*!
00367   Test if Apache setting for AcceptPathInfo is enabled
00368 */
00369 function eZSetupTestAcceptPathInfo( $type )
00370 {
00371     // rl: this one works only if 'allow_url_fopen' is On
00372     // $allowFOpen = ini_get( 'allow_url_fopen' ) != 0;
00373     // todo: additional check for case of 'allow_url_fopen' is Off
00374 
00375     $testPath = $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '/eZ_accept_path_info_test';
00376     $protocol = 'http';
00377     /* We attempt to use the https protocol when the https port is used */
00378     if ( $_SERVER['SERVER_PORT'] == 443 )
00379     {
00380         $protocol = 'https';
00381     }
00382     $testPath = "{$protocol}://" . str_replace( '//', '/', $testPath );
00383     $fp = @fopen( $testPath, 'r' );
00384 
00385     return array( 'result' => ( $fp !== false ),
00386                   'persistent_data' => array( 'result' => array( 'value' => ( $fp !== false ) ) ) );
00387 }
00388 
00389 function eZSetupTestFunctionExists( $type )
00390 {
00391     $functionList = eZSetupConfigVariableArray( $type, 'Functions' );
00392     $requireType = eZSetupConfigVariable( $type, 'Require' );
00393     $foundFunctions = array();
00394     $failedFunctions = array();
00395     foreach ( $functionList as $function )
00396     {
00397         $function = strtolower( $function );
00398         if ( function_exists( $function ) )
00399         {
00400             $foundFunctions[] = $function;
00401         }
00402         else
00403         {
00404             $failedFunctions[] = $function;
00405         }
00406     }
00407     $result = true;
00408     if ( $requireType == 'one' )
00409     {
00410         if ( count( $foundFunctions ) == 0 )
00411             $result = false;
00412     }
00413     else if ( count( $foundFunctions ) < count( $functionList ) )
00414         $result = false;
00415 
00416     return array( 'result' => $result,
00417                   'persistent_data' => array( 'result' => array( 'value' => $result ),
00418                                               'found' => array( 'value' => $foundFunctions,
00419                                                                 'merge' => false,
00420                                                                 'unique' => true ),
00421                                               'checked' => array( 'value' => $functionList,
00422                                                                   'merge' => true,
00423                                                                   'unique' => true ) ),
00424                   'require_type' => $requireType,
00425                   'extension_list' => $functionList,
00426                   'failed_extensions' => $failedFunctions,
00427                   'found_extensions' => $foundFunctions );
00428 }
00429 
00430 /*!
00431     Test if the extensios are loaded
00432 */
00433 function eZSetupTestExtension( $type )
00434 {
00435     $extensionList = eZSetupConfigVariableArray( $type, 'Extensions' );
00436     $requireType = eZSetupConfigVariable( $type, 'Require' );
00437     $foundExtensions = array();
00438     $failedExtensions = array();
00439     foreach ( $extensionList as $extension )
00440     {
00441         if ( extension_loaded( $extension ) )
00442         {
00443             $foundExtensions[] = $extension;
00444         }
00445         else
00446         {
00447             $failedExtensions[] = $extension;
00448         }
00449     }
00450     $result = true;
00451     if ( $requireType == 'one' )
00452     {
00453         if ( count( $foundExtensions ) == 0 )
00454             $result = false;
00455     }
00456     else if ( count( $foundExtensions ) < count( $extensionList ) )
00457         $result = false;
00458 
00459     return array( 'result' => $result,
00460                   'persistent_data' => array( 'result' => array( 'value' => $result ),
00461                                               'found' => array( 'value' => $foundExtensions,
00462                                                                 'merge' => false,
00463                                                                 'unique' => true ),
00464                                               'checked' => array( 'value' => $extensionList,
00465                                                                   'merge' => true,
00466                                                                   'unique' => true ) ),
00467                   'require_type' => $requireType,
00468                   'extension_list' => $extensionList,
00469                   'failed_extensions' => $failedExtensions,
00470                   'found_extensions' => $foundExtensions );
00471 }
00472 
00473 
00474 /*!
00475     Test file permissions
00476 */
00477 
00478 function eZSetupTestDirectoryPermissions( $type )
00479 {
00480     $dirList = eZSetupConfigVariableArray( $type, 'CheckList' );
00481 
00482     $ini = eZINI::instance();
00483     $dirPermission = $ini->variable( 'FileSettings', 'StorageDirPermissions' );
00484 
00485     $result = true;
00486     $resultElements = array();
00487     $resultElementsByErrorCode = array();
00488 
00489     $rootDir = eZSys::rootDir();
00490     $dirPermOctal = octdec( $dirPermission );
00491 
00492     foreach ( $dirList as $dir )
00493     {
00494         if ( empty( $dir ) )
00495             continue;
00496 
00497         $resultElement = array();
00498         $resultElement['file']       = $dir;
00499         $resultElement['result']     = 1; // ok by default
00500         $resultElement['permission'] = false;
00501 
00502         $dir = eZDir::cleanPath( $dir );
00503 
00504         if ( !file_exists( $dir ) )
00505         {
00506             // if directory does not exist then try to create it
00507             if ( empty( $rootDir ) )
00508                 $dirPath = './' . $dir;
00509             else
00510                 $dirPath = $rootDir . '/' . $dir;
00511             $res = eZDir::mkdir( $dirPath, $dirPermOctal );
00512             if ( $res )
00513             {
00514                 $resultElement['permission'] = $dirPermission;
00515                 $resultElement['result'] = 1;
00516             }
00517             else
00518             {
00519                 $result = false;
00520                 $resultElement['result'] = 2; // unable to create unexistent dir
00521             }
00522         }
00523         else if ( is_dir( $dir ) )
00524         {
00525             $resultElement['permission'] = $dirPermission;
00526             if ( !eZSetupPrvtAreDirAndFilesWritable( $dir ) )
00527             {
00528                 $result = false;
00529                 $resultElement['result'] = 3; // dir has wrong permissions
00530             }
00531         }
00532         else if ( is_file( $dir ) )
00533         {
00534             $result = false;
00535             $resultElement['result'] = 4; // dir exists but it is a file
00536         }
00537         $resultElements[] = $resultElement;
00538         $resultElementsByErrorCode[ $resultElement['result'] ][] = $resultElement;
00539     }
00540     $safeMode = ini_get( 'safe_mode' ) != 0;
00541     $userInfo = eZSetupPrvPosixExtension();
00542 
00543     return array( 'result'          => $result,
00544                   'safe_mode'       => $safeMode,
00545                   'user_info'       => $userInfo,
00546                   'persistent_data' => array( 'result' => array( 'value' => $result ) ),
00547                   'current_path'    => realpath( '.' ),
00548                   'result_elements' => $resultElements,
00549                   'result_elements_by_error_code' => $resultElementsByErrorCode );
00550 }
00551 
00552 function eZSetupTestFilePermissions( $type )
00553 {
00554     $fileList = eZSetupConfigVariableArray( $type, 'CheckList' );
00555     $ini = eZINI::instance();
00556     $dirPermission = $ini->variable( 'FileSettings', 'StorageDirPermissions' );
00557     $filePermission = $ini->variable( 'FileSettings', 'StorageFilePermissions' );
00558 
00559     $result = true;
00560     $resultElements = array();
00561     foreach ( $fileList as $file )
00562     {
00563         if ( empty( $file ) )
00564             continue;
00565 
00566         $resultElement = array();
00567         $resultElement['file'] = $file;
00568         $resultElements[] = $resultElement;
00569 
00570         $file = eZDir::cleanPath( $file );
00571         if ( !file_exists( $file ) )
00572         {
00573             continue;
00574         }
00575         if ( is_dir( $file ) )
00576         {
00577             $resultElement['permission'] = $dirPermission;
00578             $dir = $file;
00579 
00580             if ( !eZSetupPrvtAreDirAndFilesWritable( $dir ) )
00581             {
00582                 $result     = false;
00583                 $resultElement['result'] = false;
00584             }
00585         }
00586         else if ( is_file( $file ) )
00587         {
00588             $resultElement['permission'] = $filePermission;
00589 
00590             if ( !eZFile::isWriteable( $file ) )
00591             {
00592                 $result = false;
00593                 $resultElement['result'] = false;
00594             }
00595         }
00596     }
00597     $safeMode = ini_get( 'safe_mode' ) != 0;
00598     $userInfo = eZSetupPrvPosixExtension();
00599 
00600     return array( 'result' => $result,
00601                   'safe_mode' => $safeMode,
00602                   'user_info' => $userInfo,
00603                   'persistent_data' => array( 'result' => array( 'value' => $result ) ),
00604                   'current_path' => realpath( '.' ),
00605                   'result_elements'   => $resultElements );
00606 }
00607 
00608 /*!
00609   Figures out current user and group running the system by
00610   using the \c posix extension. If this is not available
00611   \c has_extension is set to \c false.
00612   \return An array with information, if no extension is found only \c has_extension is set.
00613 */
00614 function eZSetupPrvPosixExtension()
00615 {
00616     $userInfo = array( 'has_extension' => false );
00617     if ( extension_loaded( 'posix' ) )
00618     {
00619         $userInfo['has_extension'] = true;
00620         $uinfo = posix_getpwuid( posix_getuid() );
00621         $ginfo = posix_getgrgid( posix_getgid() );
00622         $userInfo['user_name'] = $uinfo['name'];
00623         $userInfo['user_id'] = $uinfo['uid'];
00624         $userInfo['group_name'] = $ginfo['name'];
00625         $userInfo['group_id'] = $ginfo['gid'];
00626         $userInfo['group_members'] = $ginfo['members'];
00627         $userInfo['script_user_id'] = getmyuid();
00628         $userInfo['script_group_id'] = getmygid();
00629     }
00630     return $userInfo;
00631 }
00632 
00633 
00634 /*!
00635     Test if a program can be found in our path and is executable
00636 */
00637 function eZSetupCheckExecutable( $type )
00638 {
00639     $http = eZHTTPTool::instance();
00640 
00641     $filesystemType = eZSys::filesystemType();
00642     $envSeparator = eZSys::envSeparator();
00643     $programs = eZSetupConfigVariableArray( $type, $filesystemType . '_Executable' );
00644     $systemSearchPaths = explode( $envSeparator, eZSys::path( true ) );
00645     $additionalSearchPaths = eZSetupConfigVariableArray( $type, $filesystemType . '_SearchPaths' );
00646     $excludePaths = eZSetupConfigVariableArray( $type, $filesystemType . '_ExcludePaths' );
00647     $imageIniPath = eZSetupImageConfigVariableArray( 'ShellSettings', 'ConvertPath' );
00648 
00649     /*
00650      We save once entered extra path in the persistent data list
00651      to keep it within setup steps.
00652 
00653      This trick is needed, for example, in "registration" step,
00654      where user has no chance to enter extra path again
00655      due to missing input field for this purpose.
00656      */
00657 
00658     // compute extra path
00659     $extraPath = array();
00660     if ( $http->hasPostVariable( $type . '_ExtraPath' ) )
00661     {
00662         $GLOBALS['eZSetupCheckExecutable_'.$type.'_ExtraPath'] = $http->postVariable( $type . '_ExtraPath' );
00663         $extraPath = explode( $envSeparator, $http->postVariable( $type . '_ExtraPath' ) );
00664     }
00665     else if ( isset( $GLOBALS['eZSetupCheckExecutable_'.$type.'_ExtraPath'] ) )
00666         $extraPath = explode( $envSeparator, $GLOBALS['eZSetupCheckExecutable_'.$type.'_ExtraPath'] );
00667 
00668     // if extra path was given in any way
00669     if ( $extraPath )
00670     {
00671         // remove program from path name if entered
00672         foreach ( $extraPath as $path )
00673         {
00674             foreach ( $programs as $program )
00675             {
00676                 if ( strpos( $path, $program) == strlen( $path ) - strlen( $program ) )
00677                 {
00678                     $extraPath[] = substr( $path, strpos( $path, $program) );
00679                 }
00680             }
00681         }
00682     }
00683 
00684     $searchPaths = array_merge( $systemSearchPaths, $additionalSearchPaths, $extraPath, $imageIniPath );
00685 
00686     $result = false;
00687     $correctPath = false;
00688     $correctProgram = false;
00689     foreach ( $programs as $program )
00690     {
00691         foreach( $searchPaths as $path )
00692         {
00693             $pathProgram = eZDir::path( array( $path, $program ) );
00694             if ( file_exists( $pathProgram ) )
00695             {
00696                 if ( $filesystemType == 'unix' )
00697                 {
00698                     $relativePath = $path;
00699                     if ( preg_match( "#^/(.+)$#", $path, $matches ) )
00700                         $relativePath = $matches[1];
00701                     $relativePath = eZDir::cleanPath( $relativePath );
00702                 }
00703                 else // windows
00704                 {
00705                     $relativePath = $path;
00706                     if ( preg_match( "#^[a-zA-Z]:[/\\\\](.+)$#", $path, $matches ) )
00707                         $relativePath = $matches[1];
00708                     $relativePath = eZDir::cleanPath( $relativePath );
00709                 }
00710                 $exclude = false;
00711                 foreach ( $excludePaths as $excludePath )
00712                 {
00713                     $excludePath = strtolower( $excludePath );
00714                     $match = strtolower( $program . "@" . $relativePath );
00715                     if ( $match == $excludePath )
00716                     {
00717                         $exclude = true;
00718                         break;
00719                     }
00720                     else if ( $relativePath == $excludePath )
00721                     {
00722                         $exclude = true;
00723                         break;
00724                     }
00725                 }
00726                 if ( $exclude )
00727                     continue;
00728                 if ( function_exists( "is_executable" ) )
00729                 {
00730                     if ( is_executable( $pathProgram ) )
00731                     {
00732                         $result = true;
00733                         $correctPath = $path;
00734                         $correctProgram = $program;
00735                         break;
00736                     }
00737                 }
00738                 else
00739                 {
00740                     // Windows system
00741                     $result = true;
00742                     $correctPath = $path;
00743                     $correctProgram = $program;
00744                     break;
00745                 }
00746             }
00747         }
00748         if ( $result )
00749             break;
00750     }
00751 
00752     $extraPathAsString = implode( $envSeparator, $extraPath );
00753 
00754     return array( 'result' => $result,
00755                   'persistent_data' => array( 'path' => array( 'value' => $correctPath ),
00756                                               'program' => array( 'value' => $correctProgram ),
00757                                               'extra_path' => array( 'value' => $extraPathAsString,
00758                                                                      'merge' => TRUE ),
00759                                               'result' => array( 'value' => $result ) ),
00760                   'env_separator' => $envSeparator,
00761                   'filesystem_type' => $filesystemType,
00762                   'extra_path' => $extraPath,
00763                   'correct_path' => $correctPath,
00764                   'system_search_path' => $systemSearchPaths,
00765                   'additional_search_path' => $additionalSearchPaths );
00766 }
00767 
00768 
00769 
00770 /*!
00771     Test php ini settings
00772 */
00773 function testPHPIni( $parameters )
00774 {
00775     $setting = $parameters["setting"];
00776     $state = $parameters["state"];
00777 
00778     if ( (bool) ini_get( $setting ) == $state )
00779         $pass = true;
00780     else
00781         $pass = false;
00782 
00783     $status = $pass;
00784     return array( "status" => $status, "pass" => $pass );
00785 }
00786 
00787 
00788 /*!
00789   Test GD version
00790 */
00791 function eZSetupCheckGDVersion( $type )
00792 {
00793     $result = function_exists( 'imagegd2' );
00794     return array( 'result' => $result,
00795                   'persistent_data' => array( 'result' => array( 'value' => $result ) ) );
00796 }
00797 
00798 /*!
00799     Test if mbstring is available
00800 */
00801 function eZSetupMBStringExtension( $type )
00802 {
00803     $result = eZMBStringMapper::hasMBStringExtension();
00804     $charsetList = eZMBStringMapper::charsetList();
00805     return array( 'result' => $result,
00806                   'persistent_data' => array( 'result' => array( 'value' => $result ) ),
00807                   'charset_list' => $charsetList );
00808 }
00809 
00810 
00811 function eZSetupCheckRegisterGlobals( $type )
00812 {
00813     $registerGlobals = ini_get( 'register_globals' ) != 0;
00814     $result = !$registerGlobals;
00815     return array( 'result' => $result,
00816                   'persistent_data' => array() );
00817 }
00818 
00819 /*!
00820  Check the php.ini file to get timeout limit
00821 */
00822 function eZSetupTestExecutionTime( $type )
00823 {
00824     $minExecutionTime = eZSetupConfigVariable( $type, 'MinExecutionTime' );
00825     $execTimeLimit = ini_get( 'max_execution_time' );
00826 
00827     if ( $execTimeLimit == false )
00828     {
00829         return array( 'result' => true,
00830                       'persistent_data' => array( 'result' => array( 'value' => true ) ) );
00831     }
00832 
00833     if ( $minExecutionTime <= $execTimeLimit )
00834         return array( 'result' => true,
00835                       'persistent_data' => array( 'result' => array( 'value' => true ) ) );
00836 
00837     return array( 'result' => false,
00838                   'persistent_data' => array( 'result' => array( 'value' => false ) ),
00839                   'required_execution_time' => $minExecutionTime,
00840                   'current_execution_time' => $execTimeLimit );
00841 }
00842 
00843 /*!
00844  Checks the php.ini file to see if the memory limit is set high enough
00845 */
00846 function eZSetupTestMemLimit( $type )
00847 {
00848     $minMemory = eZSetupConfigVariable( $type, 'MinMemoryLimit' );
00849     $memoryLimit = ini_get( 'memory_limit' );
00850     if ( $memoryLimit === '' || $memoryLimit == -1 )
00851     {
00852         return array( 'result' => true,
00853                       'persistent_data' => array( 'result' => array( 'value' => true ) ) );
00854     }
00855 
00856     $byteMinMem = intval( $minMemory );
00857     switch ( $minMemory{strlen( $minMemory ) - 1} )
00858     {
00859         case 'G':
00860             $byteMinMem *= 1024;
00861         case 'M':
00862             $byteMinMem *= 1024;
00863         case 'K':
00864             $byteMinMem *= 1024;
00865     }
00866 
00867     $byteMemLimit = intval( $memoryLimit );
00868     switch ( $memoryLimit{strlen( $memoryLimit ) - 1} )
00869     {
00870         case 'G':
00871             $byteMemLimit *= 1024;
00872         case 'M':
00873             $byteMemLimit *= 1024;
00874         case 'K':
00875             $byteMemLimit *= 1024;
00876     }
00877 
00878     if ( $byteMinMem <= $byteMemLimit )
00879         return array( 'result' => true,
00880                       'persistent_data' => array( 'result' => array( 'value' => true ) ) );
00881 
00882     return array( 'result' => false,
00883                   'persistent_data' => array( 'result' => array( 'value' => false ) ),
00884                   'required_memory' => $minMemory,
00885                   'current_memory' => $memoryLimit );
00886 }
00887 
00888 function eZSetupTestOpenBasedir( $type )
00889 {
00890     $openBasedir = ini_get( 'open_basedir' );
00891     $returnData = array( 'result' => true,
00892                          'persistent_data' => array() );
00893     if ( $openBasedir != '' and
00894          $openBasedir != '.' )
00895     {
00896         $returnData['result'] = false;
00897         $returnData['warnings'] = array( array( 'name' => 'open_basedir',
00898                                                 'text' => array( 'open_basedir is in use and can give problems running eZ Publish due to bugs in some PHP versions.',
00899                                                                  'It\'s recommended that it is turned off if you experience problems running eZ Publish.' ) ) );
00900     }
00901     return $returnData;
00902 }
00903 
00904 /*!
00905  Check if setup is installed using windows or linux installer
00906 
00907  \return 'linux' if using linux installer,
00908          'windows' if using windows installer,
00909          false if not using any installer
00910 */
00911 function eZSetupTestInstaller()
00912 {
00913     if ( file_exists( '.linux' ) )
00914     {
00915         return 'linux';
00916     }
00917     else if ( file_exists( '.windows' ) )
00918     {
00919         return 'windows';
00920     }
00921     return false;
00922 }
00923 
00924 function eZSetupTestSafeMode( $type )
00925 {
00926     $safeMode = ini_get( 'safe_mode' ) != 0;
00927     $result = !$safeMode;
00928     return array( 'result' => $result,
00929                   'current_path' => realpath( '.' ),
00930                   'persistent_data' => array() );
00931 }
00932 
00933 /*!
00934  Check if two version arrays are equel, greater or less than each other
00935 
00936  \param user first version array
00937  \param second version array
00938 
00939  \return < 0 if 1. version less than 2. version
00940            0 if versions are equal
00941          > 0 if 1. version is greater than 2. version
00942 */
00943 function eZSetupPrvtVersionCompare( $versionArray1, $versionArray2 )
00944 {
00945     $equal = false;
00946     $count = min( count( $versionArray1 ), count( $versionArray2 ) );
00947     for ( $i = 0; $i < $count; ++$i )
00948     {
00949         $equal = false;
00950         if ( (int) $versionArray1[$i] > (int) $versionArray2[$i] )
00951         {
00952             return 1;
00953         }
00954         else if ( (int) $versionArray1[$i] < (int) $versionArray2[$i] )
00955         {
00956             return -1;
00957         }
00958         $equal = true;
00959     }
00960     if ( $equal )
00961         return 0;
00962 }
00963 
00964 
00965 /* Find previously saved extra paths and export them
00966  * to global variables.
00967  */
00968 function eZSetupPrvtExtractExtraPaths( &$givenPersistentList )
00969 {
00970     if( !$givenPersistentList ) // null or empty array
00971         return;
00972 
00973     foreach( $givenPersistentList as $key => $val )
00974     {
00975         if( isset( $val['extra_path'] ) )
00976             $GLOBALS['eZSetupCheckExecutable_'.$key.'_ExtraPath'] = $val['extra_path'];
00977     }
00978 }
00979 
00980 /*! Check if a given directory and all files within that directory
00981  * are writable
00982  */
00983 function eZSetupPrvtAreDirAndFilesWritable( $dir )
00984 {
00985     if ( !eZDir::isWriteable( $dir ) )
00986         return FALSE;
00987 
00988    // Check if all files within a given directory are writeable
00989    $files = eZDir::findSubitems( $dir, 'f' ); // find only files, skip dirs and symlinks
00990    $fileSeparator = eZSys::fileSeparator();
00991 
00992    foreach ( $files as $file )
00993    {
00994        if ( !eZFile::isWriteable( $dir . $fileSeparator . $file ) )
00995            return FALSE;
00996    }
00997 
00998    return TRUE;
00999 }
01000 
01001 function eZSetupTestTimeZone( $something )
01002 {
01003     $result = true;
01004     if ( date_default_timezone_get() == "UTC" )
01005     {
01006         $result = false;
01007     }
01008 
01009     return array( 'result' => $result );
01010 }
01011 
01012 ?>