From 3fc7fbce576200052c7e5d701041bffc3a4ea517 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 23 Sep 2005 23:36:48 +0000 Subject: [PATCH] =?UTF-8?q?Qual:=20Meilleure=20gestion=20erreur=20en=20cas?= =?UTF-8?q?=20de=20param=E8tres=20saisis=20incorrects=20Suppression=20warn?= =?UTF-8?q?ing=20en=20mode=20safe=5Fmode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/install/etape1.php | 392 +++++++++++++++++--------------- htdocs/install/etape2.php | 8 +- htdocs/langs/en_US/install.lang | 2 + htdocs/langs/fr_FR/install.lang | 2 + 4 files changed, 214 insertions(+), 190 deletions(-) diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index 0e8354f32c9..fd1b9e6f08b 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -38,10 +38,25 @@ $langs->load("install"); pHeader($langs->trans("ConfigurationFile"),"etape2"); + +$ok=0; +$error = 0; $etape = 1; // Répertoire des pages dolibarr -$main_dir=isset($_POST["main_dir"])?$_POST["main_dir"]:''; +$main_dir=isset($_POST["main_dir"])?trim($_POST["main_dir"]):''; + +// On supprime / de fin dans main_dir +if (substr($main_dir, strlen($main_dir) -1) == "/") +{ + $main_dir = substr($main_dir, 0, strlen($main_dir)-1); +} + +// On supprime / de fin dans main_url +if (substr($_POST["main_url"], strlen($_POST["main_url"]) -1) == "/") +{ + $_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1); +} // Répertoire des documents générés (factures, etc...) $main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:''; @@ -49,153 +64,159 @@ if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; } +/* + * Actions + */ if ($_POST["action"] == "set") { - umask(0); - print '

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

'; + umask(0); - print ''; - $error=0; - $fp = fopen("$conffile", "w"); + print '

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

'; - if($fp) - { - if (substr($main_dir, strlen($main_dir) -1) == "/") - { - $main_dir = substr($main_dir, 0, strlen($main_dir)-1); - } - - if (substr($_POST["main_url"], strlen($_POST["main_url"]) -1) == "/") - { - $_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1); - } - - clearstatcache(); - - fwrite($fp, ''); - fclose($fp); - - if (file_exists("$conffile")) - { - include ("$conffile"); - print ""; - $error = 0; - } - else - { - $error = 1; - } - } - - if($dolibarr_main_db_type == "mysql") - { - include_once("../lib/mysql.lib.php"); - $choix=1; - } - else - { - include_once("../lib/pgsql.lib.php"); - $choix=2; - } - - - /*************************************************************************** - * - * Creation des répertoires - * - ***************************************************************************/ + print '
".$langs->trans("ConfigurationSaving")."".$langs->trans("OK")."
'; + // Verification validite parametre main_dir if ($error == 0) { - - // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés 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/societe"; - $dir[4] = "$main_data_dir/ficheinter"; - $dir[5] = "$main_data_dir/produit"; - $dir[6] = "$main_data_dir/rapport"; - $dir[7] = "$main_data_dir/rsscache"; - $dir[8] = "$main_data_dir/logo"; - if (! is_dir($main_dir)) { + dolibarr_syslog ("Le dossier '".$main_dir."' n'existe pas"); + print ""; + $error++; + } + } + + // Sauvegarde fichier configuration + if ($error == 0) + { + $fp = fopen("$conffile", "w"); + + if($fp) + { + clearstatcache(); + + fwrite($fp, ''); + fclose($fp); + + if (file_exists("$conffile")) + { + include ("$conffile"); + print ""; + } + else + { + $error++; + } + } + + if($dolibarr_main_db_type == "mysql") + { + $choix=1; + } + else + { + $choix=2; + } + + // Chargement driver acces bases + include_once("../lib/".$dolibarr_main_db_type.".lib.php"); + + } + + /*************************************************************************** + * + * Creation des répertoires + * + ***************************************************************************/ + + // Creation des sous-répertoires main_data_dir + if ($error == 0) + { + dolibarr_syslog ("Le dossier '".$main_dir."' existe"); + + // Répertoire des documents + if (! is_dir($main_data_dir)) + { + @mkdir($main_data_dir, 0755); + } + + if (! is_dir($main_data_dir)) + { + print ""; $error++; } else { - dolibarr_syslog ("Le dossier '".$main_dir."' existe"); - - // Répertoire des documents - if (! is_dir($main_data_dir)) + // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre téléchargés 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/societe"; + $dir[4] = "$main_data_dir/ficheinter"; + $dir[5] = "$main_data_dir/produit"; + $dir[6] = "$main_data_dir/rapport"; + $dir[7] = "$main_data_dir/rsscache"; + $dir[8] = "$main_data_dir/logo"; + + // Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas + for ($i = 0 ; $i < sizeof($dir) ; $i++) { - @mkdir($main_data_dir, 0755); - } - - if (! is_dir($main_data_dir)) - { - print "'; - $error++; - } - else - { - // Boucle sur chaque répertoire de dir[] pour les créer s'ils nexistent pas - for ($i = 0 ; $i < sizeof($dir) ; $i++) + if (is_dir($dir[$i])) { - if (is_dir($dir[$i])) + dolibarr_syslog ("Le dossier '".$dir[$i]."' existe"); + } + else + { + if (! @mkdir($dir[$i], 0755)) { - dolibarr_syslog ("Le dossier '".$dir[$i]."' existe"); + print ""; + $error++; } else { - if (! @mkdir($dir[$i], 0755)) - { - print ""; - $error++; - } - else - { - dolibarr_syslog ("Le dossier '".$dir[$i]."' a ete cree"); - } + dolibarr_syslog ("Le dossier '".$dir[$i]."' a ete cree"); } } } @@ -203,62 +224,60 @@ if ($_POST["action"] == "set") } - /* - * Base de données - * - */ + /* + * Base de données + * + */ if ($error == 0) { include_once($dolibarr_main_document_root . "/conf/conf.class.php"); - + $conf = new Conf(); $conf->db->type = trim($dolibarr_main_db_type); $conf->db->host = trim($dolibarr_main_db_host); $conf->db->name = trim($dolibarr_main_db_name); $conf->db->user = trim($dolibarr_main_db_user); $conf->db->pass = trim($dolibarr_main_db_pass); - + $userroot=isset($_POST["db_user_root"])?$_POST["db_user_root"]:""; $passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:""; - - $ok=0; - - + + /* - * Si creation utilisateur admin demandée, on le crée - */ + * Si creation utilisateur admin demandée, on le crée + */ if (isset($_POST["db_create_user"]) && $_POST["db_create_user"] == "on") { - dolibarr_syslog ("Creation de l'utilisateur: ".$dolibarr_main_db_user." choix base: ".$choix); - + dolibarr_syslog("Creation de l'utilisateur: ".$dolibarr_main_db_user." choix base: ".$choix); + if ($choix == 1) //choix 1=mysql { //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass; $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql'); - + if ($db->connected) { $sql = "INSERT INTO user "; $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)"; $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_user',password('$dolibarr_main_db_pass')"; $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');"; - + //print "$sql
\n"; - + $db->query($sql); - + $sql = "INSERT INTO db "; $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv)"; $sql.= " VALUES ('$dolibarr_main_db_host','$dolibarr_main_db_name','$dolibarr_main_db_user'"; $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y');"; - + //print "$sql
\n"; - + if ($db->query($sql)) { dolibarr_syslog("flush privileges"); $db->query("FLUSH Privileges;"); - + print ''; - print ""; + print '"; } } - + $db->close(); } else { @@ -296,14 +315,14 @@ if ($_POST["action"] == "set") print ''; print ''; print ''; - + // Affiche aide diagnostique print ''; - + $ok=-1; } } @@ -313,15 +332,15 @@ if ($_POST["action"] == "set") print $langs->trans("ThisPHPDoesNotSupportTypeBase",'pgsql'); $ok=0; } - - if ($ok) + + if ($ok) { $nom = $dolibarr_main_db_user; $con=pg_connect("host=".$dolibarr_main_db_host." dbname=".$dolibarr_main_db_name." user=postgres"); $query_str = "create user \"".$nom."\" with password '".$dolibarr_main_db_pass."';"; //print $query_str; $ret = pg_query($con,$query_str); - + if ($ret) { print ''; print ''; - + // Affiche aide diagnostique print ''; - + $ok=-1; } $db->close(); @@ -389,29 +408,29 @@ if ($_POST["action"] == "set") print ''; print ''; print ''; - + // Affiche aide diagnostique print ''; - + $ok=-1; } } // Fin si "creation database" - - + + /* - * On essaie l'accès par le user admin dolibarr - */ + * On essaie l'accès par le user admin dolibarr + */ if ($ok == 0) { dolibarr_syslog("connexion de type=".$conf->db->type." sur host=".$conf->db->host." user=".$conf->db->user." name=".$conf->db->name); //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." 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); - + if ($db->connected == 1) { // si accès serveur ok et accès base ok, tout est ok, on ne va pas plus loin, on a même pas utilisé le compte root. @@ -424,7 +443,7 @@ if ($_POST["action"] == "set") print ""; - + dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie"); print ""; - + $ok = 1; } else @@ -444,21 +463,21 @@ if ($_POST["action"] == "set") print ""; - + dolibarr_syslog("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué"); print ""; - + // Affiche aide diagnostique print ''; - + $ok = -1; } } @@ -468,25 +487,24 @@ if ($_POST["action"] == "set") print ""; - + // Affiche aide diagnostique print ''; - + $ok = -1; } } } + print '
"; - print $langs->trans("DirDoesNotExists",$main_dir); - print ""; + print $langs->trans("ErrorDirDoesNotExists",$main_dir).'
';; + print "Vous avez saisie une mauvaise valeur pour le paramètre '".$langs->trans("WebPagesDirectory")."'.
"; + print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; + print '
'; + print $langs->trans("Error"); + print "
".$langs->trans("ConfigurationSaving")."".$langs->trans("OK")."
Le dossier '$main_data_dir' n'existe pas ! "; + print "Vous devez créer ce dossier et permettre au serveur web d'écrire dans celui-ci"; + print ''; print $langs->trans("Error"); print "
Le dossier '$main_data_dir' n'existe pas ! "; - print "Vous devez créer ce dossier et permettre au serveur web d'écrire dans celui-ci"; - print 'Erreur
"; + print "Impossible de créer : ".$dir[$i]; + print ''; + print $langs->trans("Error"); + print "
"; - print "Impossible de créer : ".$dir[$i]; - print ""; - print $langs->trans("Error"); - print "
'; print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; @@ -283,10 +302,10 @@ if ($_POST["action"] == "set") print $langs->trans("UserCreation").' : '; print $dolibarr_main_db_user; print '".$langs->trans("Error").' '.$db->error()."
'.$langs->trans("Error").' '.$db->error()."
'.$langs->trans("Error").'

Vous avez demandé la création du login Dolibarr "'.$dolibarr_main_db_user.'", mais pour cela, '; print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'", mot de passe "'.$passroot.'".
'; print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. '; - print 'Revenez en arrière pour corriger les paramètres.

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

'; print '
'; @@ -342,19 +361,19 @@ if ($_POST["action"] == "set") } } } - + } // Fin si "creation utilisateur" - - + + /* - * Si creation database demandée, on la crée - */ + * Si creation database demandée, on la crée + */ if (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on") { dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name); - + $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot); - + if ($db->connected) { if ($db->create_db($dolibarr_main_db_name)) @@ -372,12 +391,12 @@ if ($_POST["action"] == "set") print $dolibarr_main_db_name; print ''.$langs->trans("Error").' '.$db->errno().'

La création de la base Dolibarr "'.$dolibarr_main_db_name.'" a échoué.'; print 'Si la base existe déjà, revenez en arrière et désactiver l\'option "Créer la base de donnée".
'; print '
'.$langs->trans("Error").'

Vous avez demandé la création de la base Dolibarr "'.$dolibarr_main_db_name.'", mais pour cela, '; print 'Dolibarr doit se connecter sur le serveur "'.$dolibarr_main_db_host.'" via le super utilisateur "'.$userroot.'", mot de passe "'.$passroot.'".
'; print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects. '; - print 'Revenez en arrière pour corriger les paramètres.

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

'; print '
"; print $langs->trans("OK"); print "
"; print $langs->trans("DatabaseConnection")." : "; @@ -432,7 +451,7 @@ if ($_POST["action"] == "set") print ""; print $langs->trans("OK"); print "
"; print $langs->trans("OK"); print "
"; print $langs->trans("DatabaseConnection")." : "; print $dolibarr_main_db_name; - print ""; + print ''; print $langs->trans("Error"); print "

Vérifier que le nom de base "'.$dolibarr_main_db_name.'" est correct.
'; print 'Si ce nom est correct et que cette base n\'existe pas déjà, vous devez cocher l\'option "Créer la base de donnée". '; - print 'Revenez en arrière pour corriger les paramètres.
'; + print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
"; print $langs->trans("ServerConnection")." : "; print $dolibarr_main_db_host; - print ""; + print ''; print $langs->trans("Error"); print "

Le serveur "'.$conf->db->host.'", nom de base "'.$conf->db->name.'", login "'.$conf->db->user.'", ou mot de passe "'.$conf->db->pass.'" de la base de donnée est peut-être incorrect ou la version du client PHP trop ancienne par rapport à la version de la base de donnée.
'; print 'Si le login n\'existe pas encore, vous devez cocher l\'option "Créer l\'utilisateur".
'; - print 'Revenez en arrière pour corriger les paramètres.
'; + print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; print '
'; } -?> - - diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php index 342522a281e..56f7cd28158 100644 --- a/htdocs/install/etape2.php +++ b/htdocs/install/etape2.php @@ -18,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -31,8 +30,11 @@ include_once("./inc.php"); // Cette page peut etre longue. On augmente le délai par défaut de 30 à 60. -set_time_limit(60); // Ne fonctionne que si on est pas en safe_mode - +// Ne fonctionne que si on est pas en safe_mode. +$err=error_reporting(); +error_reporting(0); +set_time_limit(60); +error_reporting($err); $setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:$langcode); $langs->defaultlang=$setuplang; diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 773bcbc6678..de48acdcb39 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -5,6 +5,8 @@ ConfFileExists=Configuration file conf.php exists. ConfFileCouldBeCreated=Configuration file conf.php could be created. ConfFileIsNotWritable=Configuration file conf.php is not writable, check its permissions, your web server must be granted to be able to write into this file during configuration process (chmod 666 for example on Unix like OS). ConfFileIsWritable=Configuration file conf.php is writable. +ErrorDirDoesNotExists=Directory %s does not exists. +ErrorGoBackAndCorrectParameters=Go backward and correct wrong parameters. YouCanContinue=You can continue... License=Using license ConfigurationFile=Configuration file diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index e303f1bea1d..2bd866a8b2f 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -5,6 +5,8 @@ ConfFileExists=Le fichier de configuration conf.php existe. ConfFileCouldBeCreated=Le fichier de configuration conf.php a pu être créé. ConfFileIsNotWritable=Le fichier conf.php n'est pas modifiable, vérifiez les permissions qui lui sont associées. Le serveur Web doit avoir le droit d'écrire dans ce fichier le temps de la configuration (chmod 666 par exemple sur un OS compatible Unix). ConfFileIsWritable=Le fichier conf.php est modifiable. +ErrorDirDoesNotExists=Le répertoire %s n'existe pas. +ErrorGoBackAndCorrectParameters=Revenez en arrière et corrigez les paramètres invalides. YouCanContinue=Vous pouvez continuer... License=Licence d'utilisation ConfigurationFile=Fichier de configuration