332 lines
9.8 KiB
PHP
Executable File
332 lines
9.8 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] => Erreur lors de la sélection du type dans la BDD
|
|
[ERREUR 2] => Erreur lors de l'ajout d'un compte dans la BDD
|
|
[ERREUR 3] => Erreur lors de la mise à jour du statut du compte dans la BDD
|
|
[ERREUR 4] => Erreur lors de l'ajout d'un alias dans la BDD
|
|
[ERREUR 5] => Erreur lors de la mise à jour du statut du compte dans la BDD
|
|
[ERREUR 6] => Erreur lors de la suppression du domaine email dans la BDD
|
|
[ERREUR 7] => Erreur lors de la sélection du type dans la BDD
|
|
[ERREUR 8] => Erreur lors de la suppression du compte email dans la BDD
|
|
[ERREUR 9] => Erreur lors de la suppression du dossier complet du domaine email
|
|
[ERREUR 10] => Erreur lors de la suppression de l'entrée compte dans la BDD
|
|
[ERREUR 11] => Erreur lors de la suppression du domaine email dans la BDD
|
|
[ERREUR 12] => Erreur lors de la suppression de l'alias email dans la BDD
|
|
[ERREUR 13] => Erreur lors de la suppression de l'entrée alias dans la BDD
|
|
[ERREUR 14] => Le MX ne correspond pas.
|
|
[ERREUR 15] => Erreur lors de la sélection du type dans la BDD.
|
|
[ERREUR 16] => Erreur lors de l'ajout du domaine email dans la BDD.
|
|
*/
|
|
|
|
// Annulation de la connexion MySql locale :
|
|
$ConnexionLocale = "non";
|
|
|
|
// Inclusion du core
|
|
require ('/var/www/daemon/system/core.php');
|
|
|
|
/* -------- */
|
|
/* Création */
|
|
/* -------- */
|
|
$ListMail = $ConnexionPanel->Select ("*", "email", "Status='1'", "", "", "", "");
|
|
if ( $ListMail != FALSE )
|
|
{
|
|
$CountMail = count ($ListMail);
|
|
echo "\nCompte(s) ou alias en attente de création : ".$CountMail."\n";
|
|
|
|
for ($i=0; $i < $CountMail; $i++)
|
|
{
|
|
if ( $ListMail[$i]["Type"] == "alias" )
|
|
{
|
|
echo "Alias de ".$ListMail[$i]["Utilisateur"]." : ".$ListMail[$i]["Nom"];
|
|
}
|
|
elseif ( $ListMail[$i]["Type"] == "compte" )
|
|
{
|
|
echo "Compte de ".$ListMail[$i]["Utilisateur"]." : ".$ListMail[$i]["Nom"];
|
|
}
|
|
|
|
$Email = explode ('@', $ListMail[$i]["Nom"]);
|
|
$Domaine = $Email[1];
|
|
$VerifMX = getmxrr($Domaine, $Mxhost, $MxWeight);
|
|
if ( $VerifMX != FALSE )
|
|
{
|
|
$u=0;
|
|
foreach ($Mxhost as $key => $value)
|
|
{
|
|
$ServeurMail[$value] = $MxWeight[$u];
|
|
$u++;
|
|
}
|
|
asort($ServeurMail);
|
|
|
|
if ( (current(array_keys($ServeurMail)) == "mail.kelio.org") or (gethostbyname(current(array_keys($ServeurMail))) == gethostbyname("mail.kelio.org")) )
|
|
{
|
|
|
|
//vérification du domaine dans la bdd
|
|
$VerifMailDomain = $ConnexionPanel->Count("*", "email", "Nom LIKE '%@".$Domaine."' AND Status='2'");
|
|
if ( $VerifMailDomain <= 0 ) { $VerifMailDomain = FALSE; } else { $VerifMailDomain = TRUE; }
|
|
|
|
if ( $ListMail[$i]["Type"] == "alias" )
|
|
{
|
|
$Champs = "source, destination";
|
|
$Valeurs = "'".$ListMail[$i]["Nom"]."', '".$ListMail[$i]["Pointage"]."'";
|
|
|
|
$InsertMail = $ConnexionSystem->Insert($Champs, $Valeurs, "alias");
|
|
if ( $InsertMail != FALSE )
|
|
{
|
|
|
|
//si il n'y a pas de domaine
|
|
if ( $VerifMailDomain == FALSE )
|
|
{
|
|
//on l'ajoute
|
|
$InsertMailDomain = $ConnexionSystem->Insert("domain", "'".$Domaine."'", "domain");
|
|
if ( $InsertMailDomain != FALSE )
|
|
{
|
|
$MajPanel = $ConnexionPanel->Update ("email", "Status", "2", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 5]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 16]\n";
|
|
}
|
|
}
|
|
// sinon on met à jour le panel
|
|
else
|
|
{
|
|
$MajPanel = $ConnexionPanel->Update ("email", "Status", "2", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 5]\n";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 4]\n";
|
|
}
|
|
}
|
|
elseif ( $ListMail[$i]["Type"] == "compte" )
|
|
{
|
|
$Champs = "email, password";
|
|
$Valeurs = "'".$ListMail[$i]["Nom"]."', ENCRYPT('".$ListMail[$i]["Password"]."')";
|
|
|
|
$InsertMail = $ConnexionSystem->Insert($Champs, $Valeurs, "mailbox");
|
|
if ( $InsertMail != FALSE )
|
|
{
|
|
if ( $VerifMailDomain == FALSE )
|
|
{
|
|
$InsertMailDomain = $ConnexionSystem->Insert("domain", "'".$Domaine."'", "domain");
|
|
if ( $InsertMailDomain != FALSE )
|
|
{
|
|
$MajPanel = $ConnexionPanel->Update("email", "Status", "2", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
$mail = "robot@kelio.org";
|
|
mail ($ListMail[$i]['Nom'], 'Kelio.org - Création de votre compte email','Ce message confirme que votre adresse email '.$ListMail[$i]['Nom'].' a bien été créée.', 'FROM: '.$mail);
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 3]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 16]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$MajPanel = $ConnexionPanel->Update("email", "Status", "2", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
$mail = "robot@kelio.org";
|
|
mail ($ListMail[$i]['Nom'], 'Kelio.org - Création de votre compte email','Ce message confirme que votre adresse email '.$ListMail[$i]['Nom'].' a bien été créée.', 'FROM: '.$mail);
|
|
echo "\t\t\t[OK]\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 "\t\t\t[ERREUR 14]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 15]\n";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "Aucun compte ou alias en attente de création\n";
|
|
}
|
|
|
|
/* ----------- */
|
|
/* Suppression */
|
|
/* ----------- */
|
|
$ListMail = $ConnexionPanel->Select ("*", "email", "Status='3'", "", "", "", "");
|
|
if ( $ListMail != FALSE )
|
|
{
|
|
$CountMail = count ($ListMail);
|
|
echo "\nCompte(s) ou alias en attente de suppression : ".$CountMail."\n";
|
|
|
|
for ($i=0; $i < $CountMail; $i++)
|
|
{
|
|
$Email = explode ('@', $ListMail[$i]["Nom"]);
|
|
$Domaine = $Email[1];
|
|
$Nom = $Email[0];
|
|
//vérifier si l'utilisateur n'a pas plusieurs adresses déjà existantes sur le même domaine!
|
|
$VerifDomGeneral = $ConnexionPanel->Count("*", "email", "Nom LIKE '%@".$Domaine."'") - 1;
|
|
$VerifDomCompte = $ConnexionPanel->Count("*", "email", "Nom LIKE '%@".$Domaine."' AND Type='compte'") - 1;
|
|
|
|
if ( $VerifDomGeneral <= 0 ) { $VerifDomGeneral = FALSE; } else { $VerifDomGeneral = TRUE; }
|
|
if ( $VerifDomCompte <= 0 ) { $VerifDomCompte = FALSE; } else { $VerifDomCompte = TRUE; }
|
|
|
|
|
|
if ( $ListMail[$i]["Type"] == "alias" )
|
|
{
|
|
echo "Alias de ".$ListMail[$i]["Utilisateur"]." : ".$ListMail[$i]["Nom"];
|
|
|
|
$DeleteMail = $ConnexionSystem->Delete ("alias", "source='".$ListMail[$i]["Nom"]."'");
|
|
if ( $DeleteMail != FALSE )
|
|
{
|
|
$MajPanel = $ConnexionPanel->Delete ("email", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE AND $VerifDomGeneral == FALSE )
|
|
{
|
|
$SuppressionMailDomain = $ConnexionSystem->Delete ("domain", "domain='".$Domaine."'"); // Verifier si cette req != FALSE
|
|
if ( $SuppressionMailDomain != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 11]\n";
|
|
}
|
|
}
|
|
elseif ( $MajPanel != FALSE AND $VerifDomGeneral != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 13]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 12]\n";
|
|
}
|
|
}
|
|
|
|
elseif ($ListMail[$i]["Type"] == "compte")
|
|
{
|
|
echo "Compte de ".$ListMail[$i]["Utilisateur"]." : ".$ListMail[$i]["Nom"];
|
|
|
|
$DeleteMail = $ConnexionSystem->Delete ("mailbox", "email='".$ListMail[$i]["Nom"]."'");
|
|
if ( $DeleteMail != FALSE )
|
|
{
|
|
shell_exec("rm -Rf /var/www/mail/".$Domaine."/".$Nom);
|
|
$dossier = "/var/www/mail/".$Domaine."/";
|
|
|
|
if ( $VerifDomCompte != FALSE ) // Il reste encore des comptes
|
|
{
|
|
$MajPanel = $ConnexionPanel->Delete ("email", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 10]\n";
|
|
}
|
|
}
|
|
else // Il ne reste plus de comptes
|
|
{
|
|
|
|
$DeleteAll = shell_exec("rm -Rf /var/www/mail/".$Domaine);
|
|
|
|
$MajPanel = $ConnexionPanel->Delete ("email", "Nom='".$ListMail[$i]["Nom"]."'");
|
|
if ( $MajPanel != FALSE )
|
|
{
|
|
if ( $VerifDomGeneral == FALSE ) // Il n'y a plus d'alias
|
|
{
|
|
$SuppressionMailDomain = $ConnexionSystem->Delete ("domain", "domain='".$Domaine."'");
|
|
if ( $SuppressionMailDomain != FALSE )
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 11]\n";
|
|
}
|
|
}// Il reste des alias
|
|
else
|
|
{
|
|
echo "\t\t\t[OK]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 10]\n";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 8]\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "\t\t\t[ERREUR 7]\n";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "Aucun compte n'est en attente de suppression\n";
|
|
}
|
|
|
|
?>
|