1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/emailpoubelle_ynh.git synced 2024-09-03 18:26:29 +02:00

Re-organisation

This commit is contained in:
David 2013-11-18 14:02:48 +01:00
parent f05d5714a3
commit 0bde314d6c
31 changed files with 488 additions and 218 deletions

5
.gitignore vendored
View file

@ -1,2 +1,5 @@
/postfix
/data
virtual
virtual.db
checkupdate
test*

View file

@ -32,3 +32,8 @@ Configurer Postfix :
/usr/sbin/postmap /www/emailPoubelle/postfix/virtual
chown www-data /www/emailPoubelle/postfix/virtual
chown www-data /www/emailPoubelle/postfix/virtual.db
Ajouter dans le fichier /etc/alias le devnull
echo "devnull: /dev/null" >> /etc/aliases
newaliases

78
bin/migrate-0.3-1.0.php Normal file
View file

@ -0,0 +1,78 @@
#!/usr/bin/php
<?php
include('./conf.php');
// Connect DB
try {
if (preg_match('/^sqlite/', DB)) {
$dbco = new PDO(DB);
} else {
$dbco = new PDO(DB, DBUSER, DBPASS);
}
$dbco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch ( PDOException $e ) {
die('Connexion à la base '.$e->getMessage());
}
// postmap command
function UpdateVirtualDB() {
global $dbco;
try {
$selectcmd = $dbco->prepare("SELECT alias, email
FROM ".DBTABLEPREFIX."alias
WHERE status = 5
ORDER BY id ASC");
$selectcmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
$file_content=null;
while($alias_db = $selectcmd->fetch()) {
$file_content .= $alias_db['alias'].' '.$alias_db['email']."\n";
}
$alias_file=fopen(FICHIERALIAS,'w');
fputs($alias_file, $file_content);
fclose($alias_file);
exec(BIN_POSTMAP.' '.FICHIERALIAS,$output,$return);
}
// add new alias
function AjouterAlias($status, $alias,$email, $life, $comment) {
global $dbco;
$dateCreat=date('Y-m-d H:i:s', 0);
$dateExpir=NULL;
try {
$insertcmd = $dbco->prepare("INSERT INTO ".DBTABLEPREFIX."alias (status, alias, email, dateCreat, dateExpir, comment)
VALUES (:status, :alias, :email, :dateCreat, :dateExpir, :comment)");
$insertcmd->bindParam('status', $status, PDO::PARAM_INT);
$insertcmd->bindParam('alias', $alias, PDO::PARAM_STR);
$insertcmd->bindParam('email', $email, PDO::PARAM_STR);
$insertcmd->bindParam('dateCreat', $dateCreat, PDO::PARAM_STR);
$insertcmd->bindParam('dateExpir', $dateExpir, PDO::PARAM_STR);
$insertcmd->bindParam('comment', $comment, PDO::PARAM_STR);
$insertcmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
return $dbco->lastInsertId();
}
$handle = fopen(FICHIERALIAS, 'r');
while (!feof($handle)) {
$buffer = fgets($handle);
if ($buffer) {
$bufferExplode = explode(' ', $buffer);
if (!preg_match('/^(#|$|;)/', $buffer)) {
echo $bufferExplode[0].' -> '.$bufferExplode[1]."\n";
AjouterAlias(5, trim($bufferExplode[0]), trim($bufferExplode[1]), null, null);
}
}
}
fclose($handle);
UpdateVirtualDB();
?>

View file

@ -7,6 +7,15 @@
// Home : http://poubelle.zici.fr
//-----------------------------------------------------------
// writable for script
define('DATA', '../var');
// include directory
define('INC', '../lib');
// include function
include_once(INC.'/ep_function.php');
include_once(INC.'/ep_admin.php');
define('DEBUG', true);
// Domain email (separe with ;)
@ -26,8 +35,7 @@ define('DBUSER', 'c1_demo');
define('DBPASS', 'sqdf2csd4rvn45548');
define('DBTABLEPREFIX', 'ep_');
// writable for script
define('DATA', './data');
// Fichier d'alias postfix
define('FICHIERALIAS', DATA.'/virtual');
@ -48,12 +56,13 @@ define('URLREWRITE_FIN', false);
define('EMAILTAGSUJET', '[EmailPoubelle]');
// From de l'email
define('EMAILFROM', '"NO REPLAY emailPoubelle" <emailpoubelle@exemple.com>');
define('EMAILEND', 'emailPoubelle.zici.fr');
// Alisas interdit : (regex ligne par ligne) - commenter pour désactiver
define('ALIASDENY', './aliasdeny.txt');
define('ALIASDENY', DATA.'/aliasdeny.txt');
// Blackliste d'email : (regex ligne par ligne) - commenter pour désactiver
define('BLACKLIST', './blacklist.txt');
define('BLACKLIST', DATA.'/blacklist.txt');
// Depend pear Net/DNS2
define('CHECKMX', false);
@ -64,6 +73,11 @@ if (CHECKMX) {
define('NS2', '8.8.8.8');
}
define('CHECKUPDATE', true);
// check update :
// enable : in seconds
// disable : false
define('CHECKUPDATE', 300);
?>

View file

@ -10,18 +10,21 @@
// Depend : Postifx (postmap command) php-pdo
//-----------------------------------------------------------
include_once('./conf.php');
define('VERSION', '1.0');
// @todo
// form ergonomie
// sqlite
// disable time
//////////////////
// Init & check
//////////////////
define('VERSION', '1.0');
if (DEBUG) {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
echo '<div class="highlight-2">Debug activé</div>';
print_r($_REQUEST);
echo '<div class="highlight-2">Debug activé <br />'.print_r($_REQUEST).'</div>';
}
if (defined(DOMAIN)) {
@ -73,198 +76,55 @@ $create = $dbco->query("CREATE TABLE IF NOT EXISTS ".DBTABLEPREFIX."alias (
die();
}
//////////////////
// Function
//////////////////
// Verification des emails
function VerifMXemail($email) {
if (CHECKMX) {
$domaine=explode('@', $email);
$r = new Net_DNS2_Resolver(array('nameservers' => array(NS1, NS2)));
try {
$result = $r->query($domaine[1], 'MX');
} catch(Net_DNS2_Exception $e) {
return false;
}
if ($result->answer) {
return true;
} else {
return false;
}
} else {
return true;
}
}
// postmap command
function UpdateVirtualDB() {
// @todo : créer le ficheir à partir de la base
//echo exec(BIN_POSTMAP.' '.FICHIERALIAS,$output,$return);
}
// add new alias
function AjouterAlias($status, $alias,$email, $life, $comment) {
global $dbco;
$dateCreat=date('Y-m-d H:i:s');
if ($life == 0) {
$dateExpir=NULL;
} else {
$dateExpir=date('Y-m-d H:i:s', time()+$life);
}
$insertcmd = $dbco->prepare("INSERT INTO ".DBTABLEPREFIX."alias (status, alias, email, dateCreat, dateExpir, comment)
VALUES ($status, '$alias', '$email', '$dateCreat', '$dateExpir', '$comment')");
$insertcmd->execute();
if (!$insertcmd) {
echo '<div class="highlight-1">Erreur pendant l\'ajout dans la base. Merci de contacter l\'administrateur ';
if (DEBUG) {
print_r($dbco->errorInfo());
}
echo '</div>';
} else {
return $dbco->lastInsertId();
}
// @todo : a faire
UpdateVirtualDB();
}
// delete new alias
function SupprimerAlias($alias,$email) {
// @todo : a faire
UpdateVirtualDB();
}
// update alias status
function UpdateStatusAlias($id, $alias_full, $status) {
global $dbco;
try {
$updatecmd = $dbco->prepare("UPDATE ".DBTABLEPREFIX."alias SET status = $status WHERE id = $id AND alias = '$alias_full'");
$updatecmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
UpdateVirtualDB();
}
// parse file for blacklist and aliasdeny
function parseFileRegex($file, $chaine) {
$return=false;
$handle = fopen($file, 'r');
while (!feof($handle)) {
$buffer = fgets($handle);
$buffer = str_replace("\n", "", $buffer);
if ($buffer) {
if (!preg_match('/^(#|$|;)/', $buffer) && preg_match($buffer, $chaine)) {
$return=true;
break;
}
}
}
fclose($handle);
return $return;
}
// Check blacklistemail
function BlacklistEmail($email) {
if (defined('BLACKLIST')) {
return parseFileRegex(BLACKLIST, $email);
} else {
return false;
}
}
// check aliasdeny
function AliasDeny($alias) {
if (defined('ALIASDENY')) {
return parseFileRegex(ALIASDENY, $alias);
} else {
return false;
}
}
//// A FAIRE :
// list alias
function ListeAlias($email) {
// @todo : a faire
return ($alias);
}
function SendEmail($recipient, $sujet, $message) {
$header = 'From: '.EMAILFROM.'\n';
$header.= 'MIME-Version: 1.0\n';
if (preg_match('#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#', $recipient)) {
$header = str_replace('\n', '\r\n', $header);
$message = str_replace('\n', '\r\n', $header);
}
mail($recipient,EMAILTAGSUJET.' '.$sujet,$message,$header);
}
function urlGen($act,$id,$alias_full) {
$idUrl=base64_encode($id.';'.$alias_full);
if (URLREWRITE_DEBUT && URLREWRITE_FIN) {
return URLREWRITE_DEBUT.$idUrl.URLREWRITE_FIN;
} else {
return URLPAGE."?act=".$act."&value=".$idUrl;
}
}
//////////////////
// Admin function
//////////////////
function CheckUpdate() {
//$doc = file_get_contents('http://poubelle.zici.fr/ep_checkupdate');
//echo $doc;
}
//////////////////
// Start program
//////////////////
// Valid email process
if (isset($_GET['act']) && $_GET['act'] == 'validemail' && isset($_GET['value'])) {
$idUrl = explode(';', base64_decode($_GET['value']));
echo $dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE id = '".$idUrl[0]."' AND status = 0")->fetchColumn();
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE id = '".$idUrl[0]."' AND status = 0")->fetchColumn() != 0) {
UpdateStatusAlias($idUrl[0], $idUrl[1], 5);
echo '<div class="highlight-3">Votre email poubelle <b>'.$idUrl[1].'</b> est maintenant actif</div>';
} else {
echo '<div class="highlight-1">Erreur : ID introuvable ou déjà validé</div>';
}
} elseif (isset($_GET['dis'])) {
// @todo fa faire
} elseif (isset($_GET['del'])) {
// @todo fa faire
// list email process
} elseif (isset($_GET['list'])) {
$email=strtolower($_REQUEST['email']);
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
// get process act
$action = isset($_GET['act']) ? $_GET['act'] : '';
switch ($action) {
case "validemail" :
$get_value = urlUnGen($_GET['value']);
echo $dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE id = '".$get_value['id']."' AND status = 0")->fetchColumn();
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE id = '".$get_value['id']."' AND status = 0")->fetchColumn() != 0) {
UpdateStatusAlias($get_value['id'], $get_value['alias_full'], 5);
echo '<div class="highlight-3">Votre email poubelle <b>'.$get_value['alias_full'].'</b> est maintenant actif</div>';
} else {
echo '<div class="highlight-1">Erreur : ID introuvable ou déjà validé</div>';
}
break;
case "disable" :
$get_value = urlUnGen($_GET['value']);
DisableAlias($get_value['id'], $get_value['alias_full'], null);
break;
case "enable" :
$get_value = urlUnGen($_GET['value']);
EnableAlias($get_value['id'], $get_value['alias_full'], null);
break;
case "delete" :
$get_value = urlUnGen($_GET['value']);
DeleteAlias($get_value['id'], $get_value['alias_full']);
break;
}
// Form
if (isset($_POST['list'])) {
$email=strtolower($_POST['email']);
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo '<div class="highlight-1">Erreur : Adresse email incorrect</div>';
} else if (! VerifMXemail($email)) {
echo '<div class="highlight-1">Erreur : Adresse email incorrect (2)</div>';
} else if (!preg_match('#\n[a-z0-9]+@'.DOMAIN.' '.$email.'#', file_get_contents(FICHIERALIAS))) {
echo '<div class="highlight-1">Vous n\'avez encore aucun alias d\'actif</div>';
} else {
$header = 'From: '.EMAIL_FROM.'\n';
$header.= 'MIME-Version: 1.0\n';
$message= 'Liste de vos redirections poubelles : \n';
foreach (ListeAlias($email) as $alias) {
$message.=' * '.$alias.'\n';
}
$message.= 'Pour supprimer un email poubelle vous pouvez vous rendre sur le lien ci-dessou : \n';
$message.= "\t * ".URLPAGE.'\n';
SendEmail($email,'Liste des alias',$message);
echo '<div class="highlight-3">Un email vous a été adressé avec la liste de vos emails poubelles actifs.</div>';
}
// Form
} elseif (isset($_POST['email']) && isset($_POST['alias'])) {
} else if (ListeAlias($email)) {
echo '<div class="highlight-3">Un email vient de vous être envoyé</div>';
} else {
echo '<div class="highlight-1">Erreur : aucun email actif connu</div>';
}
} else if (isset($_POST['email']) && isset($_POST['alias'])) {
$alias=strtolower($_POST['alias']);
$email=strtolower($_POST['email']);
$domain=$_POST['domain'];
$life=$_POST['life'];
$comment=$_POST['comment'];
$alias_full=$alias.'@'.$domain;
// Check form
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo '<div class="highlight-1">Erreur : Adresse email incorrect</div>';
@ -276,53 +136,54 @@ if (isset($_GET['act']) && $_GET['act'] == 'validemail' && isset($_GET['value'])
echo '<div class="highlight-1">Erreur : ce domain n\'est pas pris en charge</div>';
} else if (AliasDeny($alias)) {
echo '<div class="highlight-1">Erreur : email poubelle interdit</div>';
} else if (BlacklistEmail($email)) {
echo '<div class="highlight-1">Erreur : vous avez été blacklisté sur ce service</div>';
} else if (BlacklistEmail($email)) {
echo '<div class="highlight-1">Erreur : vous avez été blacklisté sur ce service</div>';
// add
} elseif (isset($_POST['add'])) {
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE alias = '".$alias.'@'.$domain."'")->fetchColumn() != 0) {
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE alias = '".$alias_full."'")->fetchColumn() != 0) {
echo '<div class="highlight-1">Erreur : cet email poubelle est déjà utilisé</div>';
} else {
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE email = '".$email."' AND status = 5")->fetchColumn() != 0) {
AjouterAlias(5, $alias.'@'.$domain, $email, $life, $comment);
echo '<div class="highlight-3">Votre email poubelle <b>'.$alias.'@'.$domain.' > '.$email.'</b> est maintenant actif</div>';
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE email = '".$email."' AND status > 0")->fetchColumn() != 0) {
AjouterAlias(5, $alias_full, $email, $life, $comment);
echo '<div class="highlight-3">Votre email poubelle <b>'.$alias_full.' > '.$email.'</b> est maintenant actif</div>';
} else {
$lastId=AjouterAlias(0, $alias.'@'.$domain, $email, $life, $comment);
$lastId=AjouterAlias(0, $alias_full, $email, $life, $comment);
$message= "Confirmation de la création de votre redirection email poubelle : ";
$message= $alias.'@'.$domain.' => '.$email."\n";
$message= $alias_full.' => '.$email."\n";
$message= "Cliquer sur le lien ci-dessous pour confirmer : \n";
$message.= "\t * ".urlGen('validemail',$lastId,$alias.'@'.$domain)."\n";
$message.= "Pour suspendre temporairement cet email poubelle vous pouvez vous rendre sur le lien ci-dessou : \n";
$message.= "\t * ".urlGen('dis',$lastId,$alias.'@'.$domain)."\n";
$message.= "\t * ".urlGen('validemail',$lastId,$alias_full)."\n";
$message.= "Pour supprimer cet email poubelle vous pouvez vous rendre sur le lien ci-dessou : \n";
$message.= "\t * ".urlGen('del',$lastId,$alias.'@'.$domain)."\n";
$message.= "\t * ".urlGen('del',$lastId,$alias_full)."\n";
$message.= "\n";
$message.= "Après confirmation, vous pourez suspendre temporairement cet email poubelle vous pouvez vous rendre sur le lien ci-dessou : \n";
$message.= "\t * ".urlGen('disable',$lastId,$alias_full)."\n";
SendEmail($email,'Confirmation alias '.$alias,$message);
echo '<div class="highlight-2">Votre email ('.$email.') nous étant inconnu, une confirmation vous a été envoyé par email.</div>';
}
}
// delete
} else if (isset($_POST['del'])) {
if ($id = $dbco->query("SELECT id FROM ".DBTABLEPREFIX."alias WHERE email = '".$email."' AND alias = '".$alias.'@'.$domain."'")->fetchColumn()) {
if ($id = $dbco->query("SELECT id FROM ".DBTABLEPREFIX."alias WHERE email = '".$email."' AND alias = '".$alias_full."'")->fetchColumn()) {
$message= "Confirmation de la création de votre redirection email poubelle : ";
$message= $alias.'@'.$domain.' => '.$email."\n";
$message= $alias_full.' => '.$email."\n";
$message= "Cliquer sur le lien ci-dessous pour confirmer la suppression : \n";
$message.= "\t * ".urlGen('del',$id,$alias.'@'.$domain)."\n\n";
$message.= "\t * ".urlGen('del',$id,$alias_full)."\n\n";
$message.= "Sinon pour suspendre temporairement cet email poubelle vous pouvez vous rendre sur le lien ci-dessou : \n";
$message.= "\t * ".urlGen('dis',$id,$alias.'@'.$domain)."\n";
$message.= "\t * ".urlGen('disable',$id,$alias_full)."\n";
SendEmail($email,'Suppression de l\'alias '.$alias,$message);
echo '<div class="highlight-2">Un email de confirmation vient de vous être envoyé.</div>';
} else {
echo '<div class="highlight-1">Erreur : impossible de trouver cet email poubelle</div>';
}
// disable
} else if (isset($_POST['dis'])) {
// @todo a faire
if ($return=DisableAlias($alias.'@'.$domain,$email)) {
echo '<div class="highlight-3">Votre email poubelle <b>'.$alias.'@'.$domain.'</b> est maintenant suspendu !</div>';
} else {
echo '<div class="highlight-1">Erreur : '.$return.'</div>';
}
} else if (isset($_POST['disable'])) {
DisableAlias(null, $alias_full, $email);
// enable
} else if (isset($_POST['enable'])) {
EnableAlias(null, $alias_full, $email);
}
// memory email
if (isset($_POST['memory'])) {
setcookie ("email", $email, time() + 31536000);
} else if (isset($_COOKIE['email'])) {
@ -376,10 +237,12 @@ $dbco = null;
</div>
<div id="form-submit">
<input class="button" type="submit" id="button-add" name="add" value="Activer" /> -
<input class="button" type="submit" id="button-dis" name="dis" value="Susprendre" /> -
<input class="button" type="submit" id="button-disable" name="disable" value="Susprendre" /> -
<input class="button" type="submit" id="button-enable" name="enable" value="Reprendre" /> -
<input class="button" type="submit" id="button-del" name="del" value="Supprimer" />
</div>
</form>
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
@ -393,7 +256,7 @@ $dbco = null;
document.getElementById('input-domain').disabled = false;
document.getElementById('button-list').disabled = false;
document.getElementById('button-add').disabled = false;
document.getElementById('button-dis').disabled = false;
document.getElementById('button-disable').disabled = false;
document.getElementById('button-del').disabled = false;
document.getElementById('input-life').disabled = false;
document.getElementById('form-comment').style.display = "block" ;
@ -405,7 +268,7 @@ $dbco = null;
document.getElementById('input-life').disabled = false;
document.getElementById('form-comment').style.display = "display" ;
document.getElementById('button-add').disabled = true;
document.getElementById('button-dis').disabled = true;
document.getElementById('button-disable').disabled = true;
document.getElementById('button-del').disabled = true;
document.getElementById('input-life').disabled = true;
document.getElementById('form-comment').style.display = "none" ;
@ -415,7 +278,7 @@ $dbco = null;
document.getElementById('input-domain').disabled = true;
document.getElementById('button-list').disabled = true;
document.getElementById('button-add').disabled = true;
document.getElementById('button-dis').disabled = true;
document.getElementById('button-disable').disabled = true;
document.getElementById('button-del').disabled = true;
document.getElementById('input-life').disabled = true;
document.getElementById('form-comment').style.display = "none" ;
@ -425,3 +288,5 @@ $dbco = null;
</script>
<p>Version <?= VERSION ?> - Créé par David Mercereau sous licence GNU GPL v3</p>
<p>Télécharger et utiliser ce script sur le site du projet <a target="_blank" href="http://forge.zici.fr/p/emailpoubelle-php/">emailPoubelle.php</a></p>
<?php echo '<p>Upgrade note : '.CheckUpdate().'</p>'; ?>

2
lib/ep_admin.php Normal file
View file

@ -0,0 +1,2 @@
<?php
?>

302
lib/ep_function.php Normal file
View file

@ -0,0 +1,302 @@
<?php
//////////////////
// Function
//////////////////
// Verification des emails
function VerifMXemail($email) {
if (CHECKMX) {
$domaine=explode('@', $email);
$r = new Net_DNS2_Resolver(array('nameservers' => array(NS1, NS2)));
try {
$result = $r->query($domaine[1], 'MX');
} catch(Net_DNS2_Exception $e) {
return false;
}
if ($result->answer) {
return true;
} else {
return false;
}
} else {
return true;
}
}
// postmap command
function UpdateVirtualDB() {
global $dbco;
try {
$selectcmd = $dbco->prepare("SELECT status, alias, email
FROM ".DBTABLEPREFIX."alias
WHERE status > 0
ORDER BY id ASC");
$selectcmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
$file_content=null;
while($alias_db = $selectcmd->fetch()) {
if ($alias_db['status'] == 5) {
$file_content .= $alias_db['alias'].' '.$alias_db['email']."\n";
} else if ($alias_db['status'] == 3) {
$file_content .= $alias_db['alias']." devnull\n";
}
}
$alias_file=fopen(FICHIERALIAS,'w');
fputs($alias_file, $file_content);
fclose($alias_file);
exec(BIN_POSTMAP.' '.FICHIERALIAS,$output,$return);
}
// add new alias
function AjouterAlias($status, $alias,$email, $life, $comment) {
global $dbco;
$dateCreat=date('Y-m-d H:i:s');
if ($life == 0) {
$dateExpir=NULL;
} else {
$dateExpir=date('Y-m-d H:i:s', time()+$life);
}
try {
$insertcmd = $dbco->prepare("INSERT INTO ".DBTABLEPREFIX."alias (status, alias, email, dateCreat, dateExpir, comment)
VALUES (:status, :alias, :email, :dateCreat, :dateExpir, :comment)");
$insertcmd->bindParam('status', $status, PDO::PARAM_INT);
$insertcmd->bindParam('alias', $alias, PDO::PARAM_STR);
$insertcmd->bindParam('email', $email, PDO::PARAM_STR);
$insertcmd->bindParam('dateCreat', $dateCreat, PDO::PARAM_STR);
$insertcmd->bindParam('dateExpir', $dateExpir, PDO::PARAM_STR);
$insertcmd->bindParam('comment', $comment, PDO::PARAM_STR);
$insertcmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
UpdateVirtualDB();
return $dbco->lastInsertId();
}
// delete alias
function DeleteAlias($id, $alias_full) {
global $dbco;
if ($dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE alias = '".$alias_full."' AND id = ".$id)->fetchColumn() != 0) {
try {
$deletecmd = $dbco->prepare("DELETE FROM ".DBTABLEPREFIX."alias WHERE id = :id AND alias = :alias_full");
$deletecmd->bindParam('id', $id, PDO::PARAM_INT);
$deletecmd->bindParam('alias_full', $alias_full, PDO::PARAM_STR);
$deletecmd->execute();
echo '<div class="highlight-3">l\'email <b>'.$alias_full.'</b> a bien été supprimé</div>';
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
} else {
echo '<div class="highlight-1">Erreur : email poubelle inconnu</div>';
}
UpdateVirtualDB();
}
// enable alias
function EnableAlias($id, $alias_full, $email) {
global $dbco;
if ($id == null) {
$selectcmd = $dbco->prepare("SELECT id,status FROM ".DBTABLEPREFIX."alias WHERE email = :email AND alias = :alias_full");
$selectcmd->bindParam('email', $email, PDO::PARAM_STR);
} else {
$selectcmd = $dbco->prepare("SELECT id,status FROM ".DBTABLEPREFIX."alias WHERE id = :id AND alias = :alias_full");
$selectcmd->bindParam('id', $id, PDO::PARAM_INT);
}
$selectcmd->bindParam('alias_full', $alias_full, PDO::PARAM_STR);
$selectcmd->execute();
$alias_fetch = $selectcmd->fetch();
if (! $alias_fetch) {
echo '<div class="highlight-1">Erreur : impossible de trouver cet email poubelle</div>';
} else if ($alias_fetch['status'] == 3) {
UpdateStatusAlias($alias_fetch['id'], $alias_full, 5);
echo '<div class="highlight-3">La réception sur <b>'.$alias_full.'</b> est de nouveau active.</div>';
} else if ($alias_fetch['status'] == 5) {
echo '<div class="highlight-2">La réception sur <b>'.$alias_full.'</b> est déjà active.</div>';
} else if ($alias_fetch['status'] == 0) {
echo '<div class="highlight-1">La réception sur <b>'.$alias_full.'</b n\'à pas été confirmé par email.</div>';
} else {
echo '<div class="highlight-1">Erreur : status inconnu</div>';
}
UpdateVirtualDB();
}
// disable alias
function DisableAlias($id, $alias_full, $email) {
global $dbco;
if ($id == null) {
$selectcmd = $dbco->prepare("SELECT id,status FROM ".DBTABLEPREFIX."alias WHERE email = :email AND alias = :alias_full");
$selectcmd->bindParam('email', $email, PDO::PARAM_STR);
} else {
$selectcmd = $dbco->prepare("SELECT id,status FROM ".DBTABLEPREFIX."alias WHERE id = :id AND alias = :alias_full");
$selectcmd->bindParam('id', $id, PDO::PARAM_INT);
}
$selectcmd->bindParam('alias_full', $alias_full, PDO::PARAM_STR);
$selectcmd->execute();
$alias_fetch = $selectcmd->fetch();
if (! $alias_fetch) {
echo '<div class="highlight-1">Erreur : impossible de trouver cet email poubelle</div>';
} else if ($alias_fetch['status'] == 5) {
UpdateStatusAlias($alias_fetch['id'], $alias_full, 3);
echo '<div class="highlight-3">La réception sur <b>'.$alias_full.'</b> est maintenant suspendu.</div>';
} else if ($alias_fetch['status'] == 3) {
echo '<div class="highlight-2">La réception sur <b>'.$alias_full.'</b> est déjà suspendu.</div>';
} else if ($alias_fetch['status'] == 0) {
echo '<div class="highlight-1">La réception sur <b>'.$alias_full.'</b> ne peut être suspendu car elle n\'a pas encore été activé.</div>';
} else {
echo '<div class="highlight-1">Erreur : status inconnu</div>';
}
UpdateVirtualDB();
}
// update alias status
function UpdateStatusAlias($id, $alias_full, $status) {
global $dbco;
try {
$updatecmd = $dbco->prepare("UPDATE ".DBTABLEPREFIX."alias SET status = $status WHERE id = :id AND alias = :alias_full");
$updatecmd->bindParam('id', $id, PDO::PARAM_INT);
$updatecmd->bindParam('alias_full', $alias_full, PDO::PARAM_STR);
$updatecmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
UpdateVirtualDB();
}
// parse file for blacklist and aliasdeny
function parseFileRegex($file, $chaine) {
$return=false;
$handle = fopen($file, 'r');
while (!feof($handle)) {
$buffer = fgets($handle);
$buffer = str_replace("\n", "", $buffer);
if ($buffer) {
if (!preg_match('/^(#|$|;)/', $buffer) && preg_match($buffer, $chaine)) {
$return=true;
break;
}
}
}
fclose($handle);
return $return;
}
// check blacklistemail
function BlacklistEmail($email) {
if (defined('BLACKLIST')) {
return parseFileRegex(BLACKLIST, $email);
} else {
return false;
}
}
// check aliasdeny
function AliasDeny($alias) {
if (defined('ALIASDENY')) {
return parseFileRegex(ALIASDENY, $alias);
} else {
return false;
}
}
// list alias
function ListeAlias($email) {
global $dbco;
try {
$selectcmd = $dbco->prepare("SELECT id, status, alias, dateCreat, dateExpir, comment
FROM ".DBTABLEPREFIX."alias
WHERE email = :email AND status > 0
ORDER BY status DESC");
$selectcmd->bindParam('email', $email, PDO::PARAM_STR);
$selectcmd->execute();
} catch ( PDOException $e ) {
echo "DB error : ", $e->getMessage();
die();
}
$nb_alias=0;
$nb_alias_disable=0;
$message= "## Liste de vos redirections poubelles active : \n\n";
while($alias_db = $selectcmd->fetch()) {
if ($alias_db['status'] == 3 && $nb_alias != 0) {
$message.= "## Liste de vos redirections poubelles désactivé : \n\n";
}
$message.=" * ".$alias_db['alias']." Créé le ".$alias_db['dateCreat'];
if ($alias_db['dateExpir']) {
$message.=" et expire le ".$alias_db['dateExpir'];
}
$message.="\n";
if ($alias_db['comment']) {
$message.="\tCommentaire : ".$alias_db['comment']."\n";
}
if ($alias_db['status'] == 5) {
$message.="\tDésactiver : ".urlGen('disable',$alias_db['id'],$alias_db['alias'])."\n";
$nb_alias++;
} else {
$message.="\tActiver : ".urlGen('enable',$alias_db['id'],$alias_db['alias'])."\n";
$nb_alias++;
}
$message.="\tSupprimer : ".urlGen('delete',$alias_db['id'],$alias_db['alias'])."\n\n";
}
$nb_alias_total = $nb_alias + $nb_alias_disable;
SendEmail($email,'Liste de vos '.$nb_alias_total.' redirection(s) poubelle(s)',$message);
if ($nb_alias_total == 0) {
return false;
} else {
return true;
}
}
function SendEmail($recipient, $sujet, $message) {
$header = "From: ".EMAILFROM."\n";
$header.= "MIME-Version: 1.0\n";
if (preg_match('#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#', $recipient)) {
$header = str_replace("\n", "\r\n", $header);
$message = str_replace("\n", "\r\n", $header);
}
$message="Bonjour,\n\n".$message."\n\n".
mail($recipient,EMAILTAGSUJET.' '.$sujet,$message,$header);
}
function urlGen($act,$id,$alias_full) {
$idUrl=base64_encode($id.';'.$alias_full);
if (URLREWRITE_DEBUT && URLREWRITE_FIN) {
return URLREWRITE_DEBUT.$idUrl.URLREWRITE_FIN;
} else {
return URLPAGE."?act=".$act."&value=".$idUrl;
}
}
function urlUnGen($get_value) {
$explode_get_value = explode(';', base64_decode($get_value));
$return['id']=$explode_get_value[0];
$return['alias_full']=$explode_get_value[1];
return $return;
}
//////////////////
// Admin function
//////////////////
function CheckUpdate() {
if (CHECKUPDATE) {
if (! is_file(DATA.'/checkupdate') || filemtime(DATA.'/checkupdate') + CHECKUPDATE < time()) {
$ep_get_version = @file_get_contents('http://poubelle.zici.fr/ep_checkupdate');
$ep_version_file=fopen(DATA.'/checkupdate','w');
fputs($ep_version_file, $ep_get_version);
fclose($ep_version_file);
if (DEBUG) { echo 'ep_checkupdate_downloaded : '.file_get_contents(DATA.'/checkupdate').'\n'; }
}
$file_current_version = trim(file_get_contents(DATA.'/checkupdate'));
if ($file_current_version != '' && $file_current_version != VERSION) {
return 'Votre version est en '.VERSION.' alors que la version en cours est en '.$file_current_version;
} else {
return false;
}
}
}
?>

View file

@ -24,7 +24,8 @@
<p>Générer des emails poubelle sans contrainte de durée de vie. </p>
<?php
// Intégration dans votre site :
include('emailPoubelle.php');
include('../conf.php');
include('../emailPoubelle.php');
?>
<h3>Let the Show Begin - Pre and Code</h3>
<p>This is how it looks if you use <code>pre</code> and <code>code</code> together, for example to highlight and nicely markup a piece of code:</p>

View file

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View file

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View file

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

View file

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

View file

Before

Width:  |  Height:  |  Size: 183 B

After

Width:  |  Height:  |  Size: 183 B

View file

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 136 B

View file

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

View file

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

View file

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 67 KiB

View file

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

View file

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

View file

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View file

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB