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, Julien Issler
  10. @copyright 2007-2011 Laurent Jouanneau, 2008 Bastien Jaillot, 2009 Olivier Demah, 2010 Brice Tence, 2011 Julien Issler
  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''filter''json');
  141.  
  142.         if($this->buildProperties['ENABLE_PHP_JELIX'== '1')
  143.             $extensions['jelix';
  144.  
  145.         foreach($extensions as $name){
  146.             if(!extension_loaded($name)){
  147.                 $this->error('extension.required.not.installed'$name);
  148.                 $ok=false;
  149.             }
  150.             else if ($this->verbose{
  151.                 $this->ok('extension.required.installed'$name);
  152.             }
  153.         }
  154.  
  155.         if($this->buildProperties['WITH_BYTECODE_CACHE'!= 'auto' &&
  156.            $this->buildProperties['WITH_BYTECODE_CACHE'!= ''{
  157.             if(!extension_loaded ('apc'&& !extension_loaded ('eaccelerator'&& !extension_loaded ('xcache')) {
  158.                 $this->error('extension.opcode.cache');
  159.                 $ok=false;
  160.             }
  161.         }
  162.  
  163.         if (count($this->databases)) {
  164.             $req ($this->dbRequired?'required':'optional');
  165.             $okdb false;
  166.             if (class_exists('PDO'))
  167.                 $pdodrivers PDO::getAvailableDrivers();
  168.             else
  169.                 $pdodrivers array();
  170.  
  171.             foreach($this->databases as $name){
  172.                 if(!extension_loaded($name&& !in_array($name$pdodrivers)){
  173.                     $this->notice('extension.not.installed'$name);
  174.                 }
  175.                 else {
  176.                     $okdb true;
  177.                     if ($this->verbose)
  178.                         $this->ok('extension.installed'$name);
  179.                 }
  180.             }
  181.             if ($this->dbRequired{
  182.                 if ($okdb{
  183.                     $this->ok('extension.database.ok');
  184.                 }
  185.                 else {
  186.                     $this->error('extension.database.missing');
  187.                     $ok false;
  188.                 }
  189.             }
  190.             else {
  191.                 if ($okdb{
  192.                     $this->ok('extension.database.ok2');
  193.                 }
  194.                 else {
  195.                     $this->notice('extension.database.missing2');
  196.                 }
  197.             }
  198.  
  199.         }
  200.  
  201.         foreach($this->otherExtensions as $name=>$required){
  202.             $req ($required?'required':'optional');
  203.             if(!extension_loaded($name)){
  204.                 if ($required{
  205.                     $this->error('extension.'.$req.'.not.installed'$name);
  206.                     $ok=false;
  207.                 }
  208.                 else {
  209.                     $this->notice('extension.'.$req.'.not.installed'$name);
  210.                 }
  211.             }
  212.             else if ($this->verbose{
  213.                 $this->ok('extension.'.$req.'.installed'$name);
  214.             }
  215.         }
  216.  
  217.         if($ok)
  218.             $this->ok('extensions.required.ok');
  219.  
  220.         return $ok;
  221.     }
  222.     function checkAppPaths(){
  223.         $ok true;
  224.         if(!defined('JELIX_LIB_PATH'|| !jApp::isInit()){
  225.             throw new Exception($this->messages->get('path.core'));
  226.         }
  227.  
  228.         if(!file_exists(jApp::tempBasePath()) || !is_writable(jApp::tempBasePath())){
  229.             $this->error('path.temp');
  230.             $ok=false;
  231.         }
  232.         if(!file_exists(jApp::logPath()) || !is_writable(jApp::logPath())){
  233.             $this->error('path.log');
  234.             $ok=false;
  235.         }
  236.         if(!file_exists(jApp::varPath())){
  237.             $this->error('path.var');
  238.             $ok=false;
  239.         }
  240.         if(!file_exists(jApp::configPath())){
  241.             $this->error('path.config');
  242.             $ok=false;
  243.         }
  244.         elseif ($this->checkForInstallation{
  245.             if (!is_writable(jApp::configPath())) {
  246.                 $this->error('path.config.writable');
  247.                 $ok false;
  248.             }
  249.             if (file_exists(jApp::configPath('profiles.ini.php'))
  250.                 && !is_writable(jApp::configPath('profiles.ini.php'))) {
  251.                 $this->error('path.profiles.writable');
  252.                 $ok false;
  253.             }
  254.             if (file_exists(jApp::configPath('defaultconfig.ini.php'))
  255.                 && !is_writable(jApp::configPath('defaultconfig.ini.php'))) {
  256.                 $this->error('path.defaultconfig.writable');
  257.                 $ok false;
  258.             }
  259.             if (file_exists(jApp::configPath('installer.ini.php'))
  260.                 && !is_writable(jApp::configPath('installer.ini.php'))) {
  261.                 $this->error('path.installer.writable');
  262.                 $ok false;
  263.             }
  264.         }
  265.  
  266.         if(!file_exists(jApp::wwwPath())){
  267.             $this->error('path.www');
  268.             $ok=false;
  269.         }
  270.  
  271.         foreach($this->otherPaths as $path{
  272.             $realPath str_replace(array('app:','lib:','var:''www:')array(jApp::appPath()LIB_PATHjApp::varPath()jApp::wwwPath())$path);
  273.             if (!file_exists($realPath)) {
  274.                 $this->error('path.custom.not.exists'array($path));
  275.                 $ok false;
  276.             }
  277.             else if(!is_writable($realPath)) {
  278.                 $this->error('path.custom.writable'array($path));
  279.                 $ok false;
  280.             }
  281.             else
  282.                 $this->ok('path.custom.ok'array($path));
  283.         }
  284.  
  285.         if($ok)
  286.             $this->ok('paths.ok');
  287.         else
  288.             throw new Exception($this->messages->get('too.critical.error'));
  289.  
  290.         /*if(!isset($GLOBALS['config_file']) ||
  291.            empty($GLOBALS['config_file']) ||
  292.            !file_exists(jApp::configPath($GLOBALS['config_file']))){
  293.             throw new Exception($this->messages->get('config.file'));
  294.         }*/
  295.  
  296.         return $ok;
  297.     }
  298.  
  299.     function loadBuildFile({
  300.         if (!file_exists(JELIX_LIB_PATH.'BUILD')){
  301.             throw new Exception($this->messages->get('build.not.found'));
  302.         else {
  303.             $this->buildProperties = parse_ini_file(JELIX_LIB_PATH.'BUILD');
  304.         }
  305.     }
  306.  
  307.     function checkPhpSettings(){
  308.         $ok true;
  309.         if (file_exists(jApp::configPath("defaultconfig.ini.php")))
  310.             $defaultconfig parse_ini_file(jApp::configPath("defaultconfig.ini.php")true);
  311.         else
  312.             $defaultconfig array();
  313.         if (file_exists(jApp::configPath("index/config.ini.php")))
  314.             $indexconfig parse_ini_file(jApp::configPath("index/config.ini.php")true);
  315.         else
  316.             $indexconfig array();
  317.  
  318.         if ((isset ($defaultconfig['coordplugins']['magicquotes']&& $defaultconfig['coordplugins']['magicquotes'== 1||
  319.             (isset ($indexconfig['coordplugins']['magicquotes']&& $indexconfig['coordplugins']['magicquotes'== 1)) {
  320.             if(ini_get('magic_quotes_gpc'== 1){
  321.                 $this->notice('ini.magic_quotes_gpc_with_plugin');
  322.             }
  323.             else {
  324.                 $this->error('ini.magicquotes_plugin_without_php');
  325.                 $ok=false;
  326.             }
  327.         }
  328.         else {
  329.             if(ini_get('magic_quotes_gpc'== 1){
  330.                 $this->warning('ini.magic_quotes_gpc');
  331.                 $ok=false;
  332.             }
  333.         }
  334.         if(ini_get('magic_quotes_runtime'== 1){
  335.             $this->error('ini.magic_quotes_runtime');
  336.             $ok=false;
  337.         }
  338.  
  339.         if(ini_get('session.auto_start'== 1){
  340.             $this->error('ini.session.auto_start');
  341.             $ok=false;
  342.         }
  343.  
  344.         if(ini_get('safe_mode'== 1){
  345.             $this->warning('safe_mode');
  346.             $ok=false;
  347.         }
  348.  
  349.         if(ini_get('register_globals'== 1){
  350.             $this->warning('ini.register_globals');
  351.             $ok=false;
  352.         }
  353.  
  354.         if(ini_get('asp_tags'== 1){
  355.             $this->notice('ini.asp_tags');
  356.         }
  357.         if(ini_get('short_open_tag'== 1){
  358.             $this->notice('ini.short_open_tag');
  359.         }
  360.         if($ok){
  361.             $this->ok('ini.ok');
  362.         }
  363.         return $ok;
  364.     }
  365. }

Documentation generated on Wed, 24 Sep 2014 22:00:20 +0200 by phpDocumentor 1.4.3