* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013-2014 Juanjo Menent * Copyright (C) 2014 Marcos García * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/install/check.php * \ingroup install * \brief Test if file conf can be modified and if does not exists, test if install process can create it */ include_once 'inc.php'; $err = 0; $allowinstall = 0; $allowupgrade = 0; $checksok = 1; $setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):$langs->getDefaultLang(); $langs->setDefaultLang($setuplang); $langs->load("install"); // Now we load forced value from install.forced.php file. $useforcedwizard=false; $forcedfile="./install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; if (@file_exists($forcedfile)) { $useforcedwizard=true; include_once $forcedfile; } dolibarr_install_syslog("--- check: Dolibarr install/upgrade process started"); /* * View */ pHeader('',''); // No next step for navigation buttons. Next step is defined by clik on links. //print "
\n"; //print $langs->trans("InstallEasy")."

\n"; print '

'.$langs->trans("MiscellaneousChecks").":

\n"; // Check browser $useragent=$_SERVER['HTTP_USER_AGENT']; if (! empty($useragent)) { $tmp=getBrowserInfo($_SERVER["HTTP_USER_AGENT"]); $browserversion=$tmp['browserversion']; $browsername=$tmp['browsername']; if ($browsername == 'ie' && $browserversion < 7) print 'Error '.$langs->trans("WarningBrowserTooOld")."
\n"; } // Check PHP version if (versioncompare(versionphparray(),array(5,2,3)) < 0) // Minimum to use (error if lower) { print 'Error '.$langs->trans("ErrorPHPVersionTooLow",'5.2.3'); $checksok=0; // 0=error, 1=warning } else if (versioncompare(versionphparray(),array(5,3,0)) < 0) // Minimum supported (warning if lower) { print 'Error '.$langs->trans("ErrorPHPVersionTooLow",'5.3.0'); $checksok=0; // 0=error, 1=warning } else { print 'Ok '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray()); } if (empty($force_install_nophpinfo)) print ' ('.$langs->trans("MoreInformation").')'; print "
\n"; // Check PHP support for $_POST if (! isset($_GET["testget"]) && ! isset($_POST["testpost"])) { print 'Warning '.$langs->trans("PHPSupportPOSTGETKo"); print ' ('.$langs->trans("Recheck").')'; print "
\n"; $checksok=0; } else { print 'Ok '.$langs->trans("PHPSupportPOSTGETOk")."
\n"; } // Check if sessions enabled if (! function_exists("session_id")) { print 'Error '.$langs->trans("ErrorPHPDoesNotSupportSessions")."
\n"; $checksok=0; } else { print 'Ok '.$langs->trans("PHPSupportSessions")."
\n"; } // Check if GD supported if (! function_exists("imagecreate")) { $langs->load("errors"); print 'Error '.$langs->trans("ErrorPHPDoesNotSupportGD")."
\n"; // $checksok=0; // If image ko, just warning. So check must still be 1 (otherwise no way to install) } else { print 'Ok '.$langs->trans("PHPSupportGD")."
\n"; } // Check if UTF8 supported if (! function_exists("utf8_encode")) { $langs->load("errors"); print 'Error '.$langs->trans("ErrorPHPDoesNotSupportUTF8")."
\n"; // $checksok=0; // If image ko, just warning. So check must still be 1 (otherwise no way to install) } else { print 'Ok '.$langs->trans("PHPSupportUTF8")."
\n"; } // Check memory $memrequiredorig='64M'; $memrequired=64*1024*1024; $memmaxorig=@ini_get("memory_limit"); $memmax=@ini_get("memory_limit"); if ($memmaxorig != '') { preg_match('/([0-9]+)([a-zA-Z]*)/i',$memmax,$reg); if ($reg[2]) { if (strtoupper($reg[2]) == 'G') $memmax=$reg[1]*1024*1024*1024; if (strtoupper($reg[2]) == 'M') $memmax=$reg[1]*1024*1024; if (strtoupper($reg[2]) == 'K') $memmax=$reg[1]*1024; } if ($memmax >= $memrequired || $memmax == -1) { print 'Ok '.$langs->trans("PHPMemoryOK",$memmaxorig,$memrequiredorig)."
\n"; } else { print 'Warning '.$langs->trans("PHPMemoryTooLow",$memmaxorig,$memrequiredorig)."
\n"; } } // If config file present and filled clearstatcache(); if (is_readable($conffile) && filesize($conffile) > 8) { dolibarr_install_syslog("check: conf file '" . $conffile . "' already defined"); $confexists=1; include_once $conffile; $databaseok=1; if ($databaseok) { // Already installed for all parts (config and database). We can propose upgrade. $allowupgrade=1; } else { $allowupgrade=0; } } else { // If not, we create it dolibarr_install_syslog("check: we try to create conf file '" . $conffile . "'"); $confexists=0; // First we try by copying example if (@copy($conffile.".example", $conffile)) { // Success dolibarr_install_syslog("check: successfully copied file " . $conffile . ".example into " . $conffile); } else { // If failed, we try to create an empty file dolibarr_install_syslog("check: failed to copy file " . $conffile . ".example into " . $conffile . ". We try to create it.", LOG_WARNING); $fp = @fopen($conffile, "w"); if ($fp) { @fwrite($fp, ' '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated",$conffiletoshow); print "

"; print $langs->trans("YouMustCreateWithPermission",$conffiletoshow); print "

"; print $langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok'); $err++; } else { // File exists but can't be modified if (!is_writable($conffile)) { if ($confexists) { print 'Ok '.$langs->trans("ConfFileExists",$conffiletoshow); } else { print 'Ok '.$langs->trans("ConfFileCouldBeCreated",$conffiletoshow); } print "
"; print 'Warning '.$langs->trans("ConfFileIsNotWritable",$conffiletoshow); print "
\n"; $allowinstall=0; } // File exists and can be modified else { if ($confexists) { print 'Ok '.$langs->trans("ConfFileExists",$conffiletoshow); } else { print 'Ok '.$langs->trans("ConfFileCouldBeCreated",$conffiletoshow); } print "
"; print 'Ok '.$langs->trans("ConfFileIsWritable",$conffiletoshow); print "
\n"; $allowinstall=1; } print "
\n"; // Requirements ok, we display the next step button if ($checksok) { $ok=0; // Try to create db connection if (file_exists($conffile)) { include_once $conffile; if (! empty($dolibarr_main_db_type) && ! empty($dolibarr_main_document_root)) { if (! file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) { print 'A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.
'."\n"; dol_syslog("A '" . $conffiletoshow . "' file exists with a dolibarr_main_document_root to " . $dolibarr_main_document_root . " that seems wrong. Try to fix or remove the '" . $conffiletoshow . "' file.", LOG_WARNING); } else { require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; // $conf is already instancied inside inc.php $conf->db->type = $dolibarr_main_db_type; $conf->db->host = $dolibarr_main_db_host; $conf->db->port = $dolibarr_main_db_port; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->connected && $db->database_selected) { $ok=true; } } } } // If a database access is available, we set more variable if ($ok) { if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0; $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey=''; $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; $conf->setValues($db); // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE // Version to install is DOL_VERSION $dolibarrlastupgradeversionarray=preg_split('/[\.-]/',isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL)?$conf->global->MAIN_VERSION_LAST_INSTALL:'')); $dolibarrversiontoinstallarray=versiondolibarrarray(); } // Show title if (! empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ! empty($conf->global->MAIN_VERSION_LAST_INSTALL)) { print $langs->trans("VersionLastUpgrade").': '.(empty($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_INSTALL:$conf->global->MAIN_VERSION_LAST_UPGRADE).'
'; print $langs->trans("VersionProgram").': '.DOL_VERSION.''; //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired")); print '
'; print '
'; } else print "
\n"; print $langs->trans("InstallEasy")." "; print $langs->trans("ChooseYourSetupMode"); print '

'; $foundrecommandedchoice=0; $available_choices = array(); $notavailable_choices = array(); // Show first install line $choice = ''.$langs->trans("FreshInstall").''; $choice .= ''; $choice .= ''; $choice .= $langs->trans("FreshInstallDesc"); if (empty($dolibarr_main_db_host)) // This means install process was not run { $choice .= '
'; //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); $choice .= '
'.$langs->trans("InstallChoiceSuggested").'
'; // Ok '; $foundrecommandedchoice=1; // To show only once } $choice .= ''; $choice .= ''; if ($allowinstall) { $choice .= ''.$langs->trans("Start").''; } else { $choice .= $langs->trans("InstallNotAllowed"); } $choice .= ''; $choice .= ''."\n"; if ($allowinstall) { $available_choices[] = $choice; } else { $notavailable_choices[] = $choice; } // Show upgrade lines $allowupgrade=true; if (empty($dolibarr_main_db_host)) // This means install process was not run { $allowupgrade=false; } if (defined("MAIN_NOT_INSTALLED")) $allowupgrade=false; $migrationscript=array( array('from'=>'3.0.0', 'to'=>'3.1.0'), array('from'=>'3.1.0', 'to'=>'3.2.0'), array('from'=>'3.2.0', 'to'=>'3.3.0'), array('from'=>'3.3.0', 'to'=>'3.4.0'), array('from'=>'3.4.0', 'to'=>'3.5.0'), array('from'=>'3.5.0', 'to'=>'3.6.0'), array('from'=>'3.6.0', 'to'=>'3.7.0'), array('from'=>'3.7.0', 'to'=>'3.8.0') ); $count=0; foreach ($migrationscript as $migarray) { $choice = ''; $count++; $recommended_choice = false; $version=DOL_VERSION; $versionfrom=$migarray['from']; $versionto=$migarray['to']; $versionarray=preg_split('/[\.-]/',$version); $dolibarrversionfromarray=preg_split('/[\.-]/',$versionfrom); $dolibarrversiontoarray=preg_split('/[\.-]/',$versionto); // Define string newversionxxx that are used for text to show $newversionfrom=preg_replace('/(\.[0-9]+)$/i','.*',$versionfrom); $newversionto=preg_replace('/(\.[0-9]+)$/i','.*',$versionto); $newversionfrombis=''; if (versioncompare($dolibarrversiontoarray,$versionarray) < -2) // From x.y.z -> x.y.z+1 { $newversionfrombis=' '.$langs->trans("or").' '.$versionto; } if ($ok) { if (count($dolibarrlastupgradeversionarray) >= 2) // If a database access is available and last upgrade version is known { // Now we check if this is the first qualified choice if ($allowupgrade && empty($foundrecommandedchoice) && (versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray,$versionarray) < -2) ) { $foundrecommandedchoice=1; // To show only once $recommended_choice = true; } } else { // We can not recommand a choice. // A version of install may be known, but we need last upgrade. } } $choice .= ''; $choice .= ''.$langs->trans("Upgrade").'
'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'
'; $choice .= ''; $choice .= $langs->trans("UpgradeDesc"); if ($recommended_choice) { $choice .= '
'; //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); $choice .= '
'.$langs->trans("InstallChoiceSuggested").'
'; if ($count < count($migarray)) // There is other choices after { print $langs->trans("MigrateIsDoneStepByStep",DOL_VERSION); } $choice .= '
'; } $choice .= ''; $choice .= ''; if ($allowupgrade) { // If it's not last updagre script, action = upgrade_tmp, if last action = upgrade $choice .= ''.$langs->trans("Start").''; } else { $choice .= $langs->trans("NotAvailable"); } $choice .= ''; $choice .= ''."\n"; if ($allowupgrade) { $available_choices[] = $choice; } else { $notavailable_choices[] = $choice; } } // If there is no choice at all, we show all of them. if (empty($available_choices)) { $available_choices=$notavailable_choices; $notavailable_choices=array(); } // Array of install choices print ''; foreach ($available_choices as $choice) { print $choice; } print '
'; if (count($notavailable_choices)) { print '
'; print ''; print ''; } } } print ''; dolibarr_install_syslog("--- check: end"); pFooter(true); // Never display next button