Files
keliopanel-v1/0.7.1/daemon/GestionMysql.php
2016-02-21 01:33:05 +01:00

154 lines
4.6 KiB
PHP
Executable File

<?php
/*
Copyright (C) 2007 Mercier Benjamin
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
{ERREUR 1] => La base de données pour l'utilisateur n'a pu être créée.
[ERREUR 2] => L'utilisateur pour la base de données n'a pu être créée.
[ERREUR 3] => Les droits n'ont pu être mis sur l'utilisateur.
[ERREUR 4] => La base de données n'a pu être mis a jour sur le panel.
[ERREUR 5] => La base de données pour l'utilisateur n'a pu être supprimé.
[ERREUR 6] => L'utilisateur pour la base de données n'a pu être supprimé.
[ERREUR 7] => La base de données n'a pu etre supprimé sur le panel.
*/
// Inclusion du core
require ('/var/www/daemon/system/core.php');
/* -------- */
/* Création */
/* -------- */
$ListBdd = $ConnexionPanel->Select("*", "basededonnee", "Status='1'", "", "", "", "");
if ( $ListBdd != FALSE )
{
$CountBdd = count ($ListBdd);
echo "\nBase(s) de données en attente de création : ".$CountBdd."\n";
if ( !empty($ServeurMySql) )
{
for ($i=0; $i < $CountBdd; $i++)
{
$DetecteServeur = $ConnexionPanel->Select ("*", "utilisateur", "Utilisateur='".$ListBdd[$i]["Utilisateur"]."'", "", "", "", "");
if ( $DetecteServeur[0]["ServeurMysql"] == $ServeurMySql )
{
echo "Base de ".$ListBdd[$i]["Utilisateur"]." : ".$ListBdd[$i]["Nom"];
$CreationBdd = $ConnexionLocale->Query ('CREATE DATABASE '.$ListBdd[$i]["Nom"]);
if ( $CreationBdd != FALSE )
{
$CreationUser = $ConnexionLocale->Query("CREATE USER '".$ListBdd[$i]["Nom"]."'@'%' IDENTIFIED BY '".$ListBdd[$i]["Password"]."'");
if ( $CreationUser != FALSE )
{
$AttribueDroit = $ConnexionLocale->Query ("GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX , ALTER , CREATE TEMPORARY TABLES , CREATE VIEW , SHOW VIEW , CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON `".$ListBdd[$i]["Nom"]."`.* TO'".$ListBdd[$i]["Nom"]."'@'%'");
if ( $AttribueDroit != FALSE )
{
$MajPanel = $ConnexionPanel->Update ("basededonnee", "Status", "2", "Nom='".$ListBdd[$i]["Nom"]."'");
if ( $MajPanel != FALSE )
{
echo "\t\t\t[OK]\n";
}
else
{
echo "\t\t\t[ERREUR 4]\n";
}
}
else
{
echo "\t\t\t[ERREUR 3]\n";
}
}
else
{
echo "\t\t\t[ERREUR 2]\n";
}
}
else
{
echo "\t\t\t[ERREUR 1]\n";
}
}
}
}
else
{
echo "Erreur : Aucun serveur MySql n'est définit\n";
}
}
else
{
echo "Aucune base de données n'est en attente de création\n";
}
/* ----------- */
/* Suppression */
/* ----------- */
$ListBdd = $ConnexionPanel->Select("*", "basededonnee", "Status='3'", "", "", "", "");
if ( $ListBdd != FALSE )
{
$CountBdd = count ($ListBdd);
echo "\nBase(s) de données en attente de suppréssion : ".$CountBdd."\n";
if ( !empty($ServeurMySql) )
{
for ($i=0; $i < $CountBdd; $i++)
{
$DetecteServeur = $ConnexionPanel->Select ("*", "utilisateur", "Utilisateur='".$ListBdd[$i]["Utilisateur"]."'", "", "", "", "");
if ( $DetecteServeur[0]["ServeurMysql"] == $ServeurMySql )
{
echo "Base de ".$ListBdd[$i]["Utilisateur"]." : ".$ListBdd[$i]["Nom"];
$SuppressionBdd = $ConnexionLocale->Query('DROP DATABASE '.$ListBdd[$i]["Nom"]);
if ( $SuppressionBdd != FALSE )
{
$SuppressionUser = $ConnexionLocale->Query("DROP USER ".$ListBdd[$i]["Nom"]."@'%'");
if ( $SuppressionUser != FALSE )
{
$MajPanel = $ConnexionPanel->Delete ('basededonnee', 'Nom="'.$ListBdd[$i]["Nom"].'"');
if ( $MajPanel != FALSE )
{
echo "\t\t\t[OK]\n";
}
else
{
echo "\t\t\t[ERREUR 7]\n";
}
}
else
{
echo "\t\t\t[ERREUR 6]\n";
}
}
else
{
echo "\t\t\t[ERREUR 5]\n";
}
}
}
}
else
{
echo "Erreur : Aucun serveur MySql n'est définit\n";
}
}
else
{
echo "Aucune base de données n'est en attente de suppréssion\n";
}
?>