* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2005-2011 Regis Houssin * * 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 2 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/etape1.php * \ingroup install * \brief Build conf file on disk * \version $Id: etape1.php,v 1.137 2011/08/04 13:19:26 eldy Exp $ */ define('DONOTLOADCONF',1); // To avoid loading conf by file inc.php include("./inc.php"); $action=GETPOST('action'); $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); $langs->setDefaultLang($setuplang); $langs->load("admin"); $langs->load("install"); // Init "forced values" to nothing. "forced values" are used after an doliwamp install wizard. $useforcedwizard=false; if (file_exists("./install.forced.php")) { $useforcedwizard=true; include_once("./install.forced.php"); } else if (file_exists("/etc/dolibarr/install.forced.php")) { $useforcedwizard=include_once("/etc/dolibarr/install.forced.php"); } dolibarr_install_syslog("--- etape1: Entering etape1.php page"); /* * View */ pHeader($langs->trans("ConfigurationFile"),"etape2"); // Test if we can run a first install process if (! is_writable($conffile)) { print $langs->trans("ConfFileIsNotWritable",$conffiletoshow); pFooter(1,$setuplang,'jscheckparam'); exit; } $error = 0; // Repertoire des pages dolibarr $main_dir=isset($_POST["main_dir"])?trim($_POST["main_dir"]):''; // Remove last / into dans main_dir if (substr($main_dir, dol_strlen($main_dir) -1) == "/") { $main_dir = substr($main_dir, 0, dol_strlen($main_dir)-1); } // Remove last / into dans main_url if (! empty($_POST["main_url"]) && substr($_POST["main_url"], dol_strlen($_POST["main_url"]) -1) == "/") { $_POST["main_url"] = substr($_POST["main_url"], 0, dol_strlen($_POST["main_url"])-1); } // Directory for generated documents (invoices, orders, ecm, etc...) $main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:''; if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; } if ($action == "set") { umask(0); foreach($_POST as $cle=>$valeur) { if (! preg_match('/^db_pass/i',$cle)) dolibarr_install_syslog("Choice for ".$cle." = ".$valeur); } // Show title of step print '

'.$langs->trans("ConfigurationFile").'

'; print ''; // Check parameter main_dir if (! $error) { if (! is_dir($main_dir)) { dolibarr_install_syslog("etape1: Repertoire '".$main_dir."' inexistant ou non accessible"); print ""; $error++; } } // Chargement driver acces bases if (! $error) { dolibarr_install_syslog("etape1: Directory '".$main_dir."' exists"); require_once($main_dir."/lib/databases/".$_POST["db_type"].".lib.php"); } /*************************************************************************** * Create directories ***************************************************************************/ // Create subdirectory main_data_dir if (! $error) { // Create directory for documents if (! is_dir($main_data_dir)) { create_exdir($main_data_dir); } if (! is_dir($main_data_dir)) { print ""; print ''; $error++; } else { // Create .htaccess file in document directory $pathhtaccess=$main_data_dir.'/.htaccess'; if (! file_exists($pathhtaccess)) { dolibarr_install_syslog("etape1: .htaccess file does not exists, we create it in '".$main_data_dir."'"); $handlehtaccess=@fopen($pathhtaccess,'w'); if ($handlehtaccess) { fwrite($handlehtaccess,'Order allow,deny'."\n"); fwrite($handlehtaccess,'Deny from all'."\n"); fclose($handlehtaccess); dolibarr_install_syslog("etape1: .htaccess file created"); } } // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre telecharges en passant outre l'authentification $dir[0] = "$main_data_dir/facture"; $dir[1] = "$main_data_dir/users"; $dir[2] = "$main_data_dir/propale"; $dir[3] = "$main_data_dir/mycompany"; $dir[4] = "$main_data_dir/ficheinter"; $dir[5] = "$main_data_dir/produit"; $dir[6] = "$main_data_dir/rapport"; // Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas for ($i = 0 ; $i < sizeof($dir) ; $i++) { if (is_dir($dir[$i])) { dolibarr_install_syslog("etape1: Directory '".$dir[$i]."' exists"); } else { if (create_exdir($dir[$i]) < 0) { print ""; $error++; } else { dolibarr_install_syslog("etape1: Directory '".$dir[$i]."' created"); } } } if ($error) { print ""; print ''; } } } // Force https $main_force_https = ( (GETPOST("main_force_https") && ( GETPOST("main_force_https") == "on" || GETPOST("main_force_https") == 1) ) ? '1' : '0'); // Use alternative directory $main_use_alt_dir = ( (GETPOST("main_use_alt_dir") && ( GETPOST("main_use_alt_dir") == "on" || GETPOST("main_use_alt_dir") == 1) ) ? '' : '#'); // Alternative root directory name $main_alt_dir_name = ( (GETPOST("main_alt_dir_name") && GETPOST("main_alt_dir_name") != '') ? GETPOST("main_alt_dir_name") : 'custom'); /** * Write conf file on disk */ if (! $error) { // Save old conf file on disk if (file_exists("$conffile")) { // We must ignore errors as an existing old file may already exists and not be replacable or // the installer (like for ubuntu) may not have permission to create another file than conf.php. // Also no other process must be able to read file or we expose the new file so content with password. @dol_copy($conffile, $conffile.'.old', '0400'); } $error+=write_conf_file($conffile); } /** * Create database and admin user database */ if (! $error) { // We reload configuration file conf($dolibarr_main_document_root); print ''; print ''; $userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:""; $passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:""; /** * Si creation utilisateur admin demandee, on le cree */ if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on") { dolibarr_install_syslog("etape1: Create database user: ".$dolibarr_main_db_user); //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port; $databasefortest=$conf->db->name; if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { $databasefortest='mysql'; } else if ($conf->db->type == 'pgsql') { $databasefortest='postgres'; } else if ($conf->db->type == 'mssql') { $databasefortest='mssql'; } // Creation handler de base, verification du support et connexion $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest,$conf->db->port); if ($db->error) { print '
'.$db->error.'
'; $error++; } if (! $error) { if ($db->connected) { $result=$db->DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name); if ($result > 0) { print ''; print ''; } else { if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS' || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS') { dolibarr_install_syslog("etape1: User already exists"); print ''; print ''; } else { dolibarr_install_syslog("etape1: Failed to create user"); print ''; print '"; } } $db->close(); } else { print ''; print ''; print ''; // Affiche aide diagnostique print ''; $error++; } } } // Fin si "creation utilisateur" /* * If database creation is asked, we create it */ if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on")) { dolibarr_install_syslog("etape1: Create database : ".$dolibarr_main_db_name, LOG_DEBUG); $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port); if ($db->connected) { $result=$db->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user); if ($result) { print ''; print ""; $check1=$db->getDefaultCharacterSetDatabase(); $check2=$db->getDefaultCollationDatabase(); dolibarr_install_syslog('etape1: Note that default server was charset='.$check1.' collation='.$check2, LOG_DEBUG); // If values differs, we save conf file again //if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('etape1: Value for character_set is not the one asked for database creation', LOG_WARNING); //if ($check2 != $dolibarr_main_db_collation) dolibarr_install_syslog('etape1: Value for collation is not the one asked for database creation', LOG_WARNING); } else { // Affiche aide diagnostique print ''; dolibarr_install_syslog('etape1: Failed to create database '.$dolibarr_main_db_name.' '.$db->lasterrno().' '.$db->lasterror(), LOG_ERR); $error++; } $db->close(); } else { print ''; print ''; print ''; // Affiche aide diagnostique print ''; $error++; } } // Fin si "creation database" /* * We testOn test maintenant l'acces par le user base dolibarr */ if (! $error) { dolibarr_install_syslog("etape1: connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name, LOG_DEBUG); //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->connected == 1) { // si acces serveur ok et acces base ok, tout est ok, on ne va pas plus loin, on a meme pas utilise le compte root. if ($db->database_selected == 1) { dolibarr_install_syslog("etape1: connexion to server by user ".$conf->db->user." is ok", LOG_DEBUG); print ""; dolibarr_install_syslog("etape1: connexion to database : ".$conf->db->name.", by user : ".$conf->db->user." is ok", LOG_DEBUG); print ""; $error = 0; } else { dolibarr_install_syslog("etape1: connexion to server by user ".$conf->db->user." is ok", LOG_DEBUG); print ""; dolibarr_install_syslog("etape1: connexion to database ".$conf->db->name.", by user : ".$conf->db->user." has failed", LOG_ERR); print ""; // Affiche aide diagnostique print ''; $error++; } } else { dolibarr_install_syslog("etape1: la connexion au serveur par le user ".$conf->db->user." est rate"); print ""; // Affiche aide diagnostique print ''; $error++; } } } print '
"; print $langs->trans("ErrorDirDoesNotExists",$main_dir).'
'; print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'
'; print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
'; print $langs->trans("Error"); print "
".$langs->trans("ErrorDirDoesNotExists",$main_data_dir); print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite"); print ''; print ''.$langs->trans("Error").''; print "

'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'
"; print "Failed to create directory: ".$dir[$i]; print ''; print $langs->trans("Error"); print "
".$langs->trans("ErrorDirDoesNotExists",$main_data_dir); print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite"); print ''; print ''.$langs->trans("Error").''; print "

'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'
'; print $langs->trans("ConfFileReload"); print ''.$langs->trans("OK").'
'; print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; print ''.$langs->trans("OK").'
'; print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; print ''.$langs->trans("LoginAlreadyExists").'
'; print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; print ''.$langs->trans("Error").' '.$db->error()."
'; print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; print ''.$langs->trans("Error").'

'; print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot); print '
'; print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'

'; print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
'; print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : "; print $dolibarr_main_db_name; print '".$langs->trans("OK")."

'; print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'
'; print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate"); print '
'; print '
'; print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : "; print $dolibarr_main_db_name; print ''.$langs->trans("Error").'

'; print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot); print '
'; print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'

'; print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
"; print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : "; print $dolibarr_main_db_host; print ""; print $langs->trans("OK"); print "
"; print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : "; print $dolibarr_main_db_name; print ""; print $langs->trans("OK"); print "
"; print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : "; print $dolibarr_main_db_host; print ""; print $langs->trans("OK"); print "
"; print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : "; print $dolibarr_main_db_name; print ''; print $langs->trans("Error"); print "

'; print $langs->trans('CheckThatDatabasenameIsCorrect',$dolibarr_main_db_name).'
'; print $langs->trans('IfAlreadyExistsCheckOption').'
'; print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
"; print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : "; print $dolibarr_main_db_host; print ''; print ''.$db->error.''; print "

'; print $langs->trans("ErrorConnection",$conf->db->host,$conf->db->name,$conf->db->user); print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'
'; print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
'; } ?> '); fclose($fp); if (file_exists("$conffile")) { include("$conffile"); // On force rechargement. Ne pas mettre include_once ! conf($dolibarr_main_document_root); print ""; print $langs->trans("SaveConfigurationFile"); print ' '.$conffile.''; print ""; print $langs->trans("OK"); print ""; } else { $error++; } } return $error; } ?>