From: x2000habouzit Date: Wed, 3 Nov 2004 15:55:22 +0000 (+0000) Subject: new bogo policy X-Git-Tag: xorg/old~1081 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=5a8f906a0c46f5e40ecf957d4961d5ded7676821;p=platal.git new bogo policy --- diff --git a/htdocs/antispam.php b/htdocs/antispam.php index c598e75..ba1159d 100644 --- a/htdocs/antispam.php +++ b/htdocs/antispam.php @@ -18,50 +18,20 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: antispam.php,v 1.9 2004-09-04 20:14:30 x2000habouzit Exp $ + $Id: antispam.php,v 1.10 2004-11-03 15:55:22 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); new_skinned_page('antispam.tpl', AUTH_MDP); +require("email.classes.inc.php"); -if (isset($_REQUEST['filtre']) and isset($_REQUEST['statut_filtre'])) { - - $new_filter = intval($_REQUEST['statut_filtre']); - - $res = $globals->db->query("SELECT COUNT(*) FROM emails WHERE uid={$_SESSION['uid']} AND find_in_set('filter', flags)"); - list($was_filter) = mysql_fetch_row($res); - mysql_free_result($res); - - if ($new_filter == 0 && $was_filter) { - $globals->db->query("DELETE FROM emails WHERE uid = {$_SESSION['uid']} AND find_in_set('filter', flags)"); - } +$bogo = new Bogo($_SESSION['uid']); - if ($new_filter != 0) { - $pipe = $new_filter == 2 ? 'drop_spams' : 'tag_spams'; - if($was_filter) { - $globals->db->query("UPDATE emails - SET email = '\"|maildrop /var/mail/.maildrop_filters/$pipe {$_SESSION['uid']}\"' - WHERE uid = {$_SESSION['uid']} AND flags = 'filter'"); - } else { - $globals->db->query("INSERT INTO emails - SET uid = {$_SESSION['uid']}, - email = '\"|maildrop /var/mail/.maildrop_filters/$pipe {$_SESSION['uid']}\"', - flags = 'filter'"); - } - } -} - -$result = $globals->db->query("SELECT email LIKE '%drop_spams%' - FROM emails - WHERE uid = {$_SESSION['uid']} AND find_in_set('filter', flags)"); -if(mysql_num_rows($result)) { - list($n) = mysql_fetch_row($result); - $page->assign('filtre',intval($n)+1); -} else { - $page->assign('filtre',0); +if (isset($_REQUEST['filtre']) and isset($_REQUEST['statut_filtre'])) { + $bogo->change($_SESSION['uid'], intval($_REQUEST['statut_filtre'])); } -mysql_free_result($result); +$page->assign('filtre',$bogo->level()); $page->run(); ?> diff --git a/htdocs/inscription/step4.php b/htdocs/inscription/step4.php index d89709b..879465e 100644 --- a/htdocs/inscription/step4.php +++ b/htdocs/inscription/step4.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: step4.php,v 1.6 2004-10-31 18:03:00 x2000chevalier Exp $ + $Id: step4.php,v 1.7 2004-11-03 15:55:23 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -85,14 +85,10 @@ if (!empty($_REQUEST['ref'])) { $logger = new DiogenesCoreLogger($uid); $logger->log("inscription",$email); - /****************** insertion de l'email dans la table emails ***/ + /****************** insertion de l'email dans la table emails + bogofilter ***/ require("email.classes.inc.php"); $redirect = new Redirect($uid); $redirect->add_email($email); - $globals->db->query("INSERT INTO emails - SET uid = $uid, - email = '\"|maildrop /var/mail/.maildrop_filters/tag_spams $uid\"', - flags = 'filter'"); /****************** ajout des formations ****************/ if (($appli_id1>0)&&($appli_type1)) $globals->db->query("insert into applis_ins set uid=$uid,aid=$appli_id1,type='$appli_type1',ordre=0"); diff --git a/include/email.classes.inc.php b/include/email.classes.inc.php index c6b994d..4872243 100644 --- a/include/email.classes.inc.php +++ b/include/email.classes.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: email.classes.inc.php,v 1.7 2004-09-06 09:59:00 x2000habouzit Exp $ + $Id: email.classes.inc.php,v 1.8 2004-11-03 15:55:23 x2000habouzit Exp $ ***************************************************************************/ require_once("xorg.misc.inc.php"); @@ -43,6 +43,32 @@ function check_mtic($email) { return false; } +class Bogo { + var $state; + var $_states = Array('let_spams', 'tag_spams', 'drop_spams'); + + function Bogo($uid) { + global $globals; + $res = $globals->db->query("SELECT email FROM emails WHERE uid = $uid AND find_in_set('filter', flags)"); + if(mysql_num_rows($res)) { + list($this->state) = mysql_fetch_row($res); + mysql_free_result($res); + } else { + $this->state = 'tag_spams'; + $res = $globals->db->query("INSERT INTO emails (uid,email,rewrite,panne,flags) + VALUES ($uid,'{$this->state}','','0000-00-00','filter')"); + } + } + + function change($uid, $state) { + global $globals; + $this->state = is_int($state) ? $this->_states[$state] : $state; + $globals->db->query("UPDATE emails SET email='{$this->state}' WHERE uid='$uid' AND find_in_set('filter', flags)"); + } + + function level() { return array_search($this->state, $this->_states); } +} + class Email { var $email; var $active; @@ -90,6 +116,7 @@ class Email { class Redirect { var $flag_active = 'active'; var $emails; + var $bogo; var $uid; function Redirect($_uid) { @@ -102,6 +129,7 @@ class Redirect { while ($row = mysql_fetch_row($result)) { $this->emails[] = new Email($row); } + $this->bogo = new Bogo($_uid); } function other_active($email) { @@ -163,4 +191,5 @@ class Redirect { } } } + ?>