From 7920f6186edd0614c006ba99460c9652b3ee8941 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 8 May 2007 21:54:11 +0000 Subject: [PATCH] New: Ajout methode DDLCreateUser --- htdocs/install/etape1.php | 873 +++++++++++++--------------- htdocs/lib/databases/mysql.lib.php | 42 ++ htdocs/lib/databases/mysqli.lib.php | 40 ++ htdocs/lib/databases/pgsql.lib.php | 21 + 4 files changed, 492 insertions(+), 484 deletions(-) diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index a0d278ad7ab..7e8d17355b3 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -23,9 +23,9 @@ */ /** - \file htdocs/install/etape1.php - \brief Génère le fichier conf.php avec les informations issues de l'étape précédente - \version $Revision$ + \file htdocs/install/etape1.php + \brief Génère le fichier conf.php avec les informations issues de l'étape précédente + \version $Revision$ */ define('DONOTLOADCONF',1); // To avoid loading conf by file inc..php @@ -48,13 +48,13 @@ $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); + $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); + $_POST["main_url"] = substr($_POST["main_url"], 0, strlen($_POST["main_url"])-1); } // Répertoire des documents générés (factures, etc...) @@ -62,502 +62,407 @@ $main_data_dir=isset($_POST["main_data_dir"])?$_POST["main_data_dir"]:''; if (! $main_data_dir) { $main_data_dir="$main_dir/documents"; } /* - * Actions - */ +* Actions +*/ if ($_POST["action"] == "set") { - umask(0); - print '

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

'; - print ''; - - // Verification validite parametre main_dir - if (! $error) - { - if (! is_dir($main_dir)) - { - dolibarr_syslog ("Repertoire '".$main_dir."' inexistant ou non accessible"); - - print ""; - $error++; - } - } - - // Sauvegarde fichier configuration - if (! $error) - { - $fp = fopen("$conffile", "w"); - - if($fp) - { - clearstatcache(); - - fputs($fp, ''.$langs->trans("SaveConfigurationFile").''; + print '
"; - print $langs->trans("ErrorDirDoesNotExists",$main_dir).'
'; - print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'
'; - print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
'; - print $langs->trans("Error"); - print "
'; - /* Preparation integration SMARTY */ - fputs($fp, '$dolibarr_smarty_libs_dir="";'); - fputs($fp,"\n"); - - fputs($fp, '$dolibarr_smarty_compile="";'); - fputs($fp,"\n"); + // Verification validite parametre main_dir + if (! $error) + { + if (! is_dir($main_dir)) + { + dolibarr_syslog ("Repertoire '".$main_dir."' inexistant ou non accessible"); + + print ""; + $error++; + } + } - fputs($fp, '$dolibarr_smarty_cache="";'); - fputs($fp,"\n"); - /* Fin Smarty*/ - - fputs($fp, '?>'); - fclose($fp); - - if (file_exists("$conffile")) - { - include("$conffile"); // On force rechargement. Ne pas mettre include_once ! - print ""; - } - else - { - $error++; - } - } - - if($dolibarr_main_db_type == "mysql") - { - $choix=1; - } - else - { - $choix=2; - } - - // Chargement driver acces bases - require_once($dolibarr_main_document_root."/lib/databases/".$dolibarr_main_db_type.".lib.php"); - - } - - /*************************************************************************** - * - * Creation des répertoires - * - ***************************************************************************/ - - // Creation des sous-répertoires main_data_dir - if (! $error) - { - dolibarr_syslog ("Le dossier '".$main_dir."' existe"); - - // Répertoire des documents - if (! is_dir($main_data_dir)) - { - create_exdir($main_data_dir); - } - - if (! is_dir($main_data_dir)) - { - print ""; - $error++; - } - else - { - // 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/rss"; - $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++) - { - if (is_dir($dir[$i])) - { - dolibarr_syslog ("Directory '".$dir[$i]."' exists"); - } - else - { - if (create_exdir($dir[$i]) < 0) - { - print ""; - $error++; - } - else - { - dolibarr_syslog("Directory '".$dir[$i]."' created"); - } - } - } - } - } - - /* - * Base de données - * - */ - if (! $error) - { - 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"]:""; - - - /* - * 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); - - if ($choix == 1) //choix 1=mysql - { - //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass; - - // Creation handler de base, verification du support et connexion - $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql'); - if ($db->error) - { - print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql'); - $error++; - } - - if (! $error) - { - 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"; - - $resql=$db->query($sql); - if ($resql) - { - dolibarr_syslog("flush privileges"); - $db->query("FLUSH Privileges;"); - - print ''; - print ''; - } - else - { - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - dolibarr_syslog("User already exists"); - print ''; - print ''; - } - else - { - dolibarr_syslog("Failed to create user"); - print ''; - print '"; - } - } - - $db->close(); - } - else - { - print ''; - print ''; - print ''; - - // Affiche aide diagnostique - print ''; - - $error++; - } - } - } - else //choix 2=postgresql - { - //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass; - - // Creation handler de base, verification du support et connexion - $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,$conf->db->name); - if ($db->error) - { - print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql'); - $error++; - } - - if (! $error) - { - if ($db->connected) - { - $nom = $dolibarr_main_db_user; - $sql = "create user \"".$nom."\" with password '".$dolibarr_main_db_pass."';"; - //print $query_str; - $resql = $db->query($sql); - if ($resql) - { - print ''; - print ''; - print ''; - } - else - { - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - dolibarr_syslog("User already exists"); - print ''; - print ''; - } - else - { - dolibarr_syslog("Failed to create user"); - print ''; - print '"; - } - } - } - else - { - print ''; - print ''; - print ''; - - // Affiche aide diagnostique - print ''; - - $error++; - } - } - } - - } // Fin si "creation utilisateur" - - - /* - * Si creation database demandée, on la crée - */ - if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on")) - { - dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name); + // Sauvegarde fichier configuration + if (! $error) + { + $fp = fopen("$conffile", "w"); + + if($fp) + { + clearstatcache(); + + fputs($fp, 'db->type,$conf->db->host,$userroot,$passroot); + /* Preparation integration SMARTY */ + fputs($fp, '$dolibarr_smarty_libs_dir="";'); + fputs($fp,"\n"); + + fputs($fp, '$dolibarr_smarty_compile="";'); + fputs($fp,"\n"); - if ($db->connected) - { - if ($db->DDLCreateDb($dolibarr_main_db_name)) - { - print ''; - print ""; - } - else - { - print ''; - print ''; - - // Affiche aide diagnostique - print ''; - - $error++; - } - $db->close(); - } - else { - print ''; - print ''; - print ''; - - // Affiche aide diagnostique - print ''; - - $error++; - } - } // Fin si "creation database" + fputs($fp, '$dolibarr_smarty_cache="";'); + fputs($fp,"\n"); + /* Fin Smarty*/ + + fputs($fp, '?>'); + fclose($fp); + + if (file_exists("$conffile")) + { + include("$conffile"); // On force rechargement. Ne pas mettre include_once ! + print ""; + } + else + { + $error++; + } + } + + if($dolibarr_main_db_type == "mysql") + { + $choix=1; + } + else + { + $choix=2; + } + + // Chargement driver acces bases + require_once($dolibarr_main_document_root."/lib/databases/".$dolibarr_main_db_type.".lib.php"); + + } - /* - * On test maintenant l'accès par le user admin dolibarr - */ - if (! $error) - { - 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; + /*************************************************************************** + * Creation des répertoires + ***************************************************************************/ - $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); + // Creation des sous-répertoires main_data_dir + if (! $error) + { + dolibarr_syslog ("Le dossier '".$main_dir."' existe"); + + // Répertoire des documents + if (! is_dir($main_data_dir)) + { + create_exdir($main_data_dir); + } + + if (! is_dir($main_data_dir)) + { + print ""; + $error++; + } + else + { + // 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/rss"; + $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++) + { + if (is_dir($dir[$i])) + { + dolibarr_syslog ("Directory '".$dir[$i]."' exists"); + } + else + { + if (create_exdir($dir[$i]) < 0) + { + print ""; + $error++; + } + else + { + dolibarr_syslog("Directory '".$dir[$i]."' created"); + } + } + } + } + } - 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. - if ($db->database_selected == 1) - { - dolibarr_syslog("la connexion au serveur par le user ".$conf->db->user." est reussie"); - print ""; + /** + * Création des Bases de données + */ + if (! $error) + { + 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"]:""; - dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie"); - print ""; - $error = 0; - } - else - { - dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est reussie"); - print ""; + /** + * 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("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué"); - print ""; + //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass; + + // Creation handler de base, verification du support et connexion + $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'mysql'); + if ($db->error) + { + print $langs->trans("ThisPHPDoesNotSupportTypeBase",'mysql'); + $error++; + } + + if (! $error) + { + if ($db->connected) + { + $result=$db->DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass); - // Affiche aide diagnostique - print ''; + if ($result > 0) + { + + print ''; + print ''; + } + else + { + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + dolibarr_syslog("User already exists"); + print ''; + print ''; + } + else + { + dolibarr_syslog("Failed to create user"); + print ''; + print '"; + } + } + + $db->close(); + } + else + { + print ''; + print ''; + print ''; + + // Affiche aide diagnostique + print ''; + + $error++; + } + } + } // Fin si "creation utilisateur" + + + /* + * Si creation database demandée, on la crée + */ + if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on")) + { + dolibarr_syslog ("Creation de la base : ".$dolibarr_main_db_name); - $error++; - } - } - else - { - dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est rate"); - print ""; + $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot); - // Affiche aide diagnostique - print ''; + if ($db->connected) + { + if ($db->DDLCreateDb($dolibarr_main_db_name)) + { + print ''; + print ""; + } + else + { + print ''; + print ''; - $error++; - } - } - } + // Affiche aide diagnostique + print ''; + + $error++; + } + $db->close(); + } + else { + print ''; + print ''; + print ''; + + // Affiche aide diagnostique + print ''; + + $error++; + } + } // Fin si "creation database" + + + /* + * On test maintenant l'accès par le user admin dolibarr + */ + if (! $error) + { + 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. + if ($db->database_selected == 1) + { + dolibarr_syslog("la connexion au serveur par le user ".$conf->db->user." est reussie"); + print ""; + + dolibarr_syslog("la connexion a la base : ".$conf->db->name.",par le user : ".$conf->db->user." est reussie"); + print ""; + + $error = 0; + } + else + { + dolibarr_syslog("la connection au serveur par le user ".$conf->db->user." est reussie"); + print ""; + + dolibarr_syslog("la connexion a la base ".$conf->db->name.",par le user ".$conf->db->user." a échoué"); + print ""; + + // Affiche aide diagnostique + print ''; + + $error++; + } + } + else + { + dolibarr_syslog("la connection 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("ConfigurationSaving")."".$langs->trans("OK")."
".$langs->trans("ErrorDirDoesNotExists",$main_data_dir); - print $langs->trans("YouMustCreateItAndAllowServerToWrite"); - print ''; - print $langs->trans("Error"); - print "
"; - print "Failed to create directory: ".$dir[$i]; - print ''; - print $langs->trans("Error"); - print "
'; - 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 '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.'".
'; - print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
'; - print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
'; - 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 '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.'".
'; - print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
'; - print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
'; - print $langs->trans("DatabaseCreation").' : '; - print $dolibarr_main_db_name; - print '".$langs->trans("OK")."
'; - print $langs->trans("DatabaseCreation").' : '; - print $dolibarr_main_db_name; - print ''.$langs->trans("Error").' '.$db->errno().'

'; - print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'
'; - print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate"); - print '
'; - print '
'; - print $langs->trans("DatabaseCreation").' : '; - print $dolibarr_main_db_name; - 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.'".
'; - print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
'; - print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
".$langs->trans("ConfigurationSaving")."".$langs->trans("OK")."
".$langs->trans("ErrorDirDoesNotExists",$main_data_dir); + print $langs->trans("YouMustCreateItAndAllowServerToWrite"); + print ''; + print $langs->trans("Error"); + print "
"; + print "Failed to create directory: ".$dir[$i]; + print ''; + print $langs->trans("Error"); + print "
"; - print $langs->trans("ServerConnection")." : "; - print $dolibarr_main_db_host; - print ""; - print $langs->trans("OK"); - print "
"; - print $langs->trans("DatabaseConnection")." : "; - print $dolibarr_main_db_name; - print ""; - print $langs->trans("OK"); - print "
"; - print $langs->trans("ServerConnection")." : "; - print $dolibarr_main_db_host; - print ""; - print $langs->trans("OK"); - print "
"; - print $langs->trans("DatabaseConnection")." : "; - print $dolibarr_main_db_name; - 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 $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
'; + 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 '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.'".
'; + print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
'; + print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; + print '
"; - print $langs->trans("ServerConnection")." : "; - print $dolibarr_main_db_host; - print ''; - print ''.$db->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 $langs->trans("ErrorGoBackAndCorrectParameters").'

'; - print '
'; + print $langs->trans("DatabaseCreation").' : '; + print $dolibarr_main_db_name; + print '".$langs->trans("OK")."
'; + print $langs->trans("DatabaseCreation").' : '; + print $dolibarr_main_db_name; + print ''.$langs->trans("Error").' '.$db->errno().'

'; + print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'
'; + print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate"); + print '
'; + print '
'; + print $langs->trans("DatabaseCreation").' : '; + print $dolibarr_main_db_name; + 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.'".
'; + print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.
'; + print $langs->trans("ErrorGoBackAndCorrectParameters").'

'; + print '
"; + print $langs->trans("ServerConnection")." : "; + print $dolibarr_main_db_host; + print ""; + print $langs->trans("OK"); + print "
"; + print $langs->trans("DatabaseConnection")." : "; + print $dolibarr_main_db_name; + print ""; + print $langs->trans("OK"); + print "
"; + print $langs->trans("ServerConnection")." : "; + print $dolibarr_main_db_host; + print ""; + print $langs->trans("OK"); + print "
"; + print $langs->trans("DatabaseConnection")." : "; + print $dolibarr_main_db_name; + 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 $langs->trans("ErrorGoBackAndCorrectParameters").'

'; + print '
"; + print $langs->trans("ServerConnection")." : "; + print $dolibarr_main_db_host; + print ''; + print ''.$db->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 $langs->trans("ErrorGoBackAndCorrectParameters").'

'; + print '
'; } diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index faf9d32f1bf..9de17af84a2 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -779,6 +779,48 @@ class DoliDb else return 1; } + + /** + \brief Crée un utilisateur + \param dolibarr_main_db_host Ip serveur + \param dolibarr_main_db_user Nom user à créer + \param dolibarr_main_db_pass Mot de passe user à créer + \return int <0 si KO, >=0 si OK + */ + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass) + { + $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');"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + if (! $resql) + { + return -1; + } + + $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');"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + if (! $resql) + { + return -1; + } + + $sql="FLUSH Privileges"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + + return 1; + } + } ?> diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index 6d00844a5f9..0b36e20465c 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -785,6 +785,46 @@ class DoliDb return 1; } + /** + \brief Crée un utilisateur + \param dolibarr_main_db_host Ip serveur + \param dolibarr_main_db_user Nom user à créer + \param dolibarr_main_db_pass Mot de passe user à créer + \return int <0 si KO, >=0 si OK + */ + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass) + { + $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');"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + if (! $resql) + { + return -1; + } + + $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');"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + if (! $resql) + { + return -1; + } + + $sql="FLUSH Privileges"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + + return 1; + } } ?> diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index a0581aacfae..a1898a30275 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -609,6 +609,27 @@ class DoliDb return $this->results; } + + /** + \brief Crée un utilisateur + \param dolibarr_main_db_host Ip serveur + \param dolibarr_main_db_user Nom user à créer + \param dolibarr_main_db_pass Mot de passe user à créer + \return int <0 si KO, >=0 si OK + */ + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass) + { + $sql = "create user \"".$dolibarr_main_db_user."\" with password '".$dolibarr_main_db_pass."'"; + + dolibarr_syslog("mysql.lib::DDLCreateUser sql=".$sql); + $resql=$this->query($sql); + if (! $resql) + { + return -1; + } + + return 1; + } } ?>