Source for file jInstallChecker.class.php

Documentation is available at jInstallChecker.class.php

  1. <?php
  2. /**
  3. * check a jelix installation
  4. *
  5. @package  jelix
  6. @subpackage core
  7. @author   Laurent Jouanneau
  8. @contributor Bastien Jaillot
  9. @contributor Olivier Demah, Brice Tence
  10. @copyright 2007-2011 Laurent Jouanneau, 2008 Bastien Jaillot, 2009 Olivier Demah, 2010 Brice Tence
  11. @link     http://www.jelix.org
  12. @licence  GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  13. @since 1.0b2
  14. */
  15.  
  16. /**
  17.  * check an installation of a jelix application
  18.  * @package  jelix
  19.  * @subpackage core
  20.  * @since 1.0b2
  21.  */
  22. class jInstallCheck {
  23.  
  24.     /**
  25.      * the object responsible of the results output
  26.      * @var jIInstallReporter 
  27.      */
  28.     protected $reporter;
  29.  
  30.     /**
  31.      * @var jInstallerMessageProvider 
  32.      */
  33.     public $messages;
  34.  
  35.     public $nbError = 0;
  36.     public $nbOk = 0;
  37.     public $nbWarning = 0;
  38.     public $nbNotice = 0;
  39.  
  40.     protected $buildProperties;
  41.  
  42.     public $verbose = false;
  43.  
  44.     public $checkForInstallation = false;
  45.  
  46.     function __construct ($reporter$lang=''){
  47.         $this->reporter = $reporter;
  48.         $this->messages = new jInstallerMessageProvider($lang);
  49.     }
  50.  
  51.     protected $otherExtensions = array();
  52.  
  53.     function addExtensionCheck($extension$required{
  54.         $this->otherExtensions[$extension$required;
  55.     }
  56.  
  57.     protected $otherPaths = array();
  58.  
  59.     /**
  60.      * @since 1.2.5
  61.      */
  62.     function addWritablePathCheck($pathOrFileName{
  63.         if (is_array($pathOrFileName))
  64.             $this->otherPaths = array_merge($this->otherPaths$pathOrFileName);
  65.         else
  66.             $this->otherPaths[$pathOrFileName;
  67.     }
  68.  
  69.     protected $databases = array();
  70.     protected $dbRequired = false;
  71.  
  72.     function addDatabaseCheck($databases$required{
  73.         $this->databases = $databases;
  74.         $this->dbRequired = $required;
  75.     }
  76.  
  77.     /**
  78.      * run the ckecking
  79.      */
  80.     function run(){
  81.         $this->nbError = 0;
  82.         $this->nbOk = 0;
  83.         $this->nbWarning = 0;
  84.         $this->nbNotice = 0;
  85.         $this->reporter->start();
  86.         try {
  87.             $this->checkAppPaths();
  88.             $this->loadBuildFile();
  89.             $this->checkPhpExtensions();
  90.             $this->checkPhpSettings();
  91.         }catch(Exception $e){
  92.             $this->error('cannot.continue',$e->getMessage());
  93.         }
  94.         $results array('error'=>$this->nbError'warning'=>$this->nbWarning'ok'=>$this->nbOk,'notice'=>$this->nbNotice);
  95.         $this->reporter->end($results);
  96.     }
  97.  
  98.     protected function error($msg$msgparams=array()$extraMsg=''){
  99.         if($this->reporter)
  100.             $this->reporter->message($this->messages->get($msg$msgparams).$extraMsg'error');
  101.         $this->nbError ++;
  102.     }
  103.  
  104.     protected function ok($msg$msgparams=array()){
  105.         if($this->reporter)
  106.             $this->reporter->message($this->messages->get($msg$msgparams)'ok');
  107.         $this->nbOk ++;
  108.     }
  109.     /**
  110.      * generate a warning
  111.      * @param string $msg  the key of the message to display
  112.      */
  113.     protected function warning($msg$msgparams=array()){
  114.         if($this->reporter)
  115.             $this->reporter->message($this->messages->get($msg$msgparams)'warning');
  116.         $this->nbWarning ++;
  117.     }
  118.  
  119.     protected function notice($msg$msgparams=array()){
  120.         if($this->reporter{
  121.             $this->reporter->message($this->messages->get($msg$msgparams)'notice');
  122.         }
  123.         $this->nbNotice ++;
  124.     }
  125.  
  126.     function checkPhpExtensions(){
  127.         $ok=true;
  128.         if(!version_compare($this->buildProperties['PHP_VERSION_TARGET']phpversion()'<=')){
  129.             $this->error('php.bad.version');
  130.             $notice $this->messages->get('php.version.required'$this->buildProperties['PHP_VERSION_TARGET']);
  131.             $notice.= '. '.$this->messages->get('php.version.current',phpversion());
  132.             $this->reporter->showNotice($notice);
  133.             $ok=false;
  134.         }
  135.         else if ($this->verbose{
  136.             $this->ok('php.ok.version'phpversion());
  137.         }
  138.  
  139.         $extensions array'dom''SPL''SimpleXML''pcre''session',
  140.             'tokenizer''iconv',);
  141.  
  142.         if($this->buildProperties['ENABLE_PHP_FILTER'== '1')
  143.             $extensions['filter';
  144.         if($this->buildProperties['ENABLE_PHP_JSON'== '1')
  145.             $extensions['json';
  146.         if($this->buildProperties['ENABLE_PHP_JELIX'== '1')
  147.             $extensions['jelix';
  148.  
  149.         foreach($extensions as $name){
  150.             if(!extension_loaded($name)){
  151.                 $this->error('extension.required.not.installed'$name);
  152.                 $ok=false;
  153.             }
  154.             else if ($this->verbose{
  155.                 $this->ok('extension.required.installed'$name);
  156.             }
  157.         }
  158.  
  159.         if($this->buildProperties['WITH_BYTECODE_CACHE'!= 'auto' &&
  160.            $this->buildProperties['WITH_BYTECODE_CACHE'!= ''{
  161.             if(!extension_loaded ('apc'&& !extension_loaded ('eaccelerator'&& !extension_loaded ('xcache')) {
  162.                 $this->error('extension.opcode.cache');
  163.                 $ok=false;
  164.             }
  165.         }
  166.  
  167.         if (count($this->databases)) {
  168.             $req ($this->dbRequired?'required':'optional');
  169.             $okdb false;
  170.             if (class_exists('PDO'))
  171.                 $pdodrivers PDO::getAvailableDrivers();
  172.             else
  173.                 $pdodrivers array();
  174.  
  175.             foreach($this->databases as $name){
  176.                 if(!extension_loaded($name&& !in_array($name$pdodrivers)){
  177.                     $this->notice('extension.not.installed'$name);
  178.                 }
  179.                 else {
  180.                     $okdb true;
  181.                     if ($this->verbose)
  182.                         $this->ok('extension.installed'$name);
  183.                 }
  184.             }
  185.             if ($this->dbRequired{
  186.                 if ($okdb{
  187.                     $this->ok('extension.database.ok');
  188.                 }
  189.                 else {
  190.                     $this->error('extension.database.missing');
  191.                     $ok false;
  192.                 }
  193.             }
  194.             else {
  195.                 if ($okdb{
  196.                     $this->ok('extension.database.ok2');
  197.                 }
  198.                 else {
  199.                     $this->notice('extension.database.missing2');
  200.                 }
  201.             }
  202.             
  203.         }
  204.  
  205.         foreach($this->otherExtensions as $name=>$required){
  206.             $req ($required?'required':'optional');
  207.             if(!extension_loaded($name)){
  208.                 if ($required{
  209.                     $this->error('extension.'.$req.'.not.installed'$name);
  210.                     $ok=false;
  211.                 }
  212.                 else {
  213.                     $this->notice('extension.'.$req.'.not.installed'$name);
  214.                 }
  215.             }
  216.             else if ($this->verbose{
  217.                 $this->ok('extension.'.$req.'.installed'$name);
  218.             }
  219.         }
  220.  
  221.         if($ok)
  222.             $this->ok('extensions.required.ok');
  223.  
  224.         return $ok;
  225.     }
  226.     function checkAppPaths(){
  227.         $ok true;
  228.         if(!defined('JELIX_LIB_PATH'|| !defined('JELIX_APP_PATH')){
  229.             throw new Exception($this->messages->get('path.core'));
  230.         }
  231.  
  232.         if(!file_exists(JELIX_APP_TEMP_PATH|| !is_writable(JELIX_APP_TEMP_PATH)){
  233.             $this->error('path.temp');
  234.             $ok=false;
  235.         }
  236.         if(!file_exists(JELIX_APP_LOG_PATH|| !is_writable(JELIX_APP_LOG_PATH)){
  237.             $this->error('path.log');
  238.             $ok=false;
  239.         }
  240.         if(!file_exists(JELIX_APP_VAR_PATH)){
  241.             $this->error('path.var');
  242.             $ok=false;
  243.         }
  244.         if(!file_exists(JELIX_APP_CONFIG_PATH)){
  245.             $this->error('path.config');
  246.             $ok=false;
  247.         }
  248.         elseif ($this->checkForInstallation{
  249.             if (!is_writable(JELIX_APP_CONFIG_PATH)) {
  250.                 $this->error('path.config.writable');
  251.                 $ok false;
  252.             }
  253.             if (file_exists(JELIX_APP_CONFIG_PATH.'dbprofils.ini.php')
  254.                 && !is_writable(JELIX_APP_CONFIG_PATH.'dbprofils.ini.php')) {
  255.                 $this->error('path.dbprofile.writable');
  256.                 $ok false;
  257.             }
  258.             if (file_exists(JELIX_APP_CONFIG_PATH.'defaultconfig.ini.php')
  259.                 && !is_writable(JELIX_APP_CONFIG_PATH.'defaultconfig.ini.php')) {
  260.                 $this->error('path.defaultconfig.writable');
  261.                 $ok false;
  262.             }
  263.             if (file_exists(JELIX_APP_CONFIG_PATH.'installer.ini.php')
  264.                 && !is_writable(JELIX_APP_CONFIG_PATH.'installer.ini.php')) {
  265.                 $this->error('path.installer.writable');
  266.                 $ok false;
  267.             }
  268.         }
  269.  
  270.         if(!file_exists(JELIX_APP_WWW_PATH)){
  271.             $this->error('path.www');
  272.             $ok=false;
  273.         }
  274.  
  275.         foreach($this->otherPaths as $path{
  276.             $realPath str_replace(array('app:','lib:','var:''www:')array(JELIX_APP_PATHLIB_PATHJELIX_APP_VAR_PATHJELIX_APP_WWW_PATH)$path);
  277.             if (!file_exists($realPath)) {
  278.                 $this->error('path.custom.not.exists'array($path));
  279.                 $ok false;
  280.             }
  281.             else if(!is_writable($realPath)) {
  282.                 $this->error('path.custom.writable'array($path));
  283.                 $ok false;
  284.             }
  285.             else
  286.                 $this->ok('path.custom.ok'array($path));
  287.         }
  288.  
  289.         if($ok)
  290.             $this->ok('paths.ok');
  291.         else
  292.             throw new Exception($this->messages->get('too.critical.error'));
  293.  
  294.         /*if(!isset($GLOBALS['config_file']) ||
  295.            empty($GLOBALS['config_file']) ||
  296.            !file_exists(JELIX_APP_CONFIG_PATH.$GLOBALS['config_file'])){
  297.             throw new Exception($this->messages->get('config.file'));
  298.         }*/
  299.  
  300.         return $ok;
  301.     }
  302.  
  303.     function loadBuildFile({
  304.         if (!file_exists(JELIX_LIB_PATH.'BUILD')){
  305.             throw new Exception($this->messages->get('build.not.found'));
  306.         else {
  307.             $this->buildProperties = parse_ini_file(JELIX_LIB_PATH.'BUILD');
  308.         }
  309.     }
  310.  
  311.     function checkPhpSettings(){
  312.         $ok true;
  313.         if (file_exists(JELIX_APP_CONFIG_PATH."defaultconfig.ini.php"))
  314.             $defaultconfig parse_ini_file(JELIX_APP_CONFIG_PATH."defaultconfig.ini.php"true);
  315.         else
  316.             $defaultconfig array();
  317.         if (file_exists(JELIX_APP_CONFIG_PATH."index/config.ini.php"))
  318.             $indexconfig parse_ini_file(JELIX_APP_CONFIG_PATH."index/config.ini.php"true);
  319.         else
  320.             $indexconfig array();
  321.  
  322.         if ((isset ($defaultconfig['coordplugins']['magicquotes']&& $defaultconfig['coordplugins']['magicquotes'== 1||
  323.             (isset ($indexconfig['coordplugins']['magicquotes']&& $indexconfig['coordplugins']['magicquotes'== 1)) {
  324.             if(ini_get('magic_quotes_gpc'== 1){
  325.                 $this->notice('ini.magic_quotes_gpc_with_plugin');
  326.             }
  327.             else {
  328.                 $this->error('ini.magicquotes_plugin_without_php');
  329.                 $ok=false;
  330.             }
  331.         }
  332.         else {
  333.             if(ini_get('magic_quotes_gpc'== 1){
  334.                 $this->warning('ini.magic_quotes_gpc');
  335.                 $ok=false;
  336.             }
  337.         }
  338.         if(ini_get('magic_quotes_runtime'== 1){
  339.             $this->error('ini.magic_quotes_runtime');
  340.             $ok=false;
  341.         }
  342.  
  343.         if(ini_get('session.auto_start'== 1){
  344.             $this->error('ini.session.auto_start');
  345.             $ok=false;
  346.         }
  347.  
  348.         if(ini_get('safe_mode'== 1){
  349.             $this->warning('safe_mode');
  350.             $ok=false;
  351.         }
  352.  
  353.         if(ini_get('register_globals'== 1){
  354.             $this->warning('ini.register_globals');
  355.             $ok=false;
  356.         }
  357.  
  358.         if(ini_get('asp_tags'== 1){
  359.             $this->notice('ini.asp_tags');
  360.         }
  361.         if(ini_get('short_open_tag'== 1){
  362.             $this->notice('ini.short_open_tag');
  363.         }
  364.         if($ok){
  365.             $this->ok('ini.ok');
  366.         }
  367.         return $ok;
  368.     }
  369. }

Documentation generated on Thu, 19 Sep 2013 00:05:43 +0200 by phpDocumentor 1.4.3