New: Ajout methode DDLCreateUser
This commit is contained in:
parent
7d8fafe48d
commit
7920f6186e
@ -163,10 +163,9 @@ if ($_POST["action"] == "set")
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
|
||||||
* Creation des répertoires
|
* Creation des répertoires
|
||||||
*
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
// Creation des sous-répertoires main_data_dir
|
// Creation des sous-répertoires main_data_dir
|
||||||
@ -229,9 +228,8 @@ if ($_POST["action"] == "set")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Base de données
|
* Création des Bases de données
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -248,15 +246,13 @@ if ($_POST["action"] == "set")
|
|||||||
$passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
|
$passroot=isset($_POST["db_pass_root"])?$_POST["db_pass_root"]:"";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 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")
|
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;
|
//print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->pass;
|
||||||
|
|
||||||
// Creation handler de base, verification du support et connexion
|
// Creation handler de base, verification du support et connexion
|
||||||
@ -271,27 +267,10 @@ if ($_POST["action"] == "set")
|
|||||||
{
|
{
|
||||||
if ($db->connected)
|
if ($db->connected)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO user ";
|
$result=$db->DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass);
|
||||||
$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<br>\n";
|
if ($result > 0)
|
||||||
|
|
||||||
$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<br>\n";
|
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
{
|
||||||
dolibarr_syslog("flush privileges");
|
|
||||||
$db->query("FLUSH Privileges;");
|
|
||||||
|
|
||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
print $langs->trans("UserCreation").' : ';
|
print $langs->trans("UserCreation").' : ';
|
||||||
@ -343,80 +322,6 @@ if ($_POST["action"] == "set")
|
|||||||
$error++;
|
$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 '<tr><td>';
|
|
||||||
print $langs->trans("UserCreation").' : ';
|
|
||||||
print $dolibarr_main_db_user;
|
|
||||||
print '</td>';
|
|
||||||
print '<td>'.$langs->trans("OK").'</td>';
|
|
||||||
print '</tr>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
|
||||||
{
|
|
||||||
dolibarr_syslog("User already exists");
|
|
||||||
print '<tr><td>';
|
|
||||||
print $langs->trans("UserCreation").' : ';
|
|
||||||
print $dolibarr_main_db_user;
|
|
||||||
print '</td>';
|
|
||||||
print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog("Failed to create user");
|
|
||||||
print '<tr><td>';
|
|
||||||
print $langs->trans("UserCreation").' : ';
|
|
||||||
print $dolibarr_main_db_user;
|
|
||||||
print '</td>';
|
|
||||||
print '<td>'.$langs->trans("Error").' '.$db->error()."</td></tr>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<tr><td>';
|
|
||||||
print $langs->trans("UserCreation").' : ';
|
|
||||||
print $dolibarr_main_db_user;
|
|
||||||
print '</td>';
|
|
||||||
print '<td>'.$langs->trans("Error").'</td>';
|
|
||||||
print '</tr>';
|
|
||||||
|
|
||||||
// Affiche aide diagnostique
|
|
||||||
print '<tr><td colspan="2"><br>';
|
|
||||||
print 'Vous avez demandé la création du login Dolibarr "<b>'.$dolibarr_main_db_user.'</b>", mais pour cela, ';
|
|
||||||
print 'Dolibarr doit se connecter sur le serveur "<b>'.$dolibarr_main_db_host.'</b>" via le super utilisateur "<b>'.$userroot.'</b>".<br>';
|
|
||||||
print 'La connexion ayant échoué, les paramètres du serveur ou du super utilisateur sont peut-etre incorrects.<br>';
|
|
||||||
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
|
|
||||||
print '</td></tr>';
|
|
||||||
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Fin si "creation utilisateur"
|
} // Fin si "creation utilisateur"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -779,6 +779,48 @@ class DoliDb
|
|||||||
else
|
else
|
||||||
return 1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -785,6 +785,46 @@ class DoliDb
|
|||||||
return 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -609,6 +609,27 @@ class DoliDb
|
|||||||
return $this->results;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user