From: x2003bruneau Date: Tue, 10 Apr 2007 21:15:52 +0000 (+0000) Subject: Can disable email redirection X-Git-Tag: xorg/0.9.14~108 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=441c2451a618423c3ce326af2598714b68e40631;p=platal.git Can disable email redirection Can reset the error level of an email include/emails.inc.php | 151 ++++++++++++++++++++++++--------------- modules/admin.php | 147 ++++++++++++++++++++----------------- templates/admin/utilisateurs.tpl | 46 ++++++++++- templates/admin/wiki.tpl | 2 4 files changed, 212 insertions(+), 134 deletions(-) git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1681 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/include/emails.inc.php b/include/emails.inc.php index 106b6a1..d167af1 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -21,15 +21,12 @@ require_once("xorg.misc.inc.php"); -// {{{ defines - define("SUCCESS", 1); define("ERROR_INACTIVE_REDIRECTION", 2); define("ERROR_INVALID_EMAIL", 3); define("ERROR_LOOP_EMAIL", 4); -// }}} -// {{{ function fix_bestalias() +// function fix_bestalias() {{{1 function fix_bestalias($uid) { @@ -44,8 +41,7 @@ function fix_bestalias($uid) LIMIT 1", $uid); } -// }}} -// {{{ function valide_email() +// function valide_email() {{{1 function valide_email($str) { @@ -62,18 +58,16 @@ function valide_email($str) return $ident . '@' . $dom; } -// }}} -// {{{ class Bogo +// class Bogo {{{1 class Bogo { - // {{{ properties + // properties {{{2 private $state; private $_states = Array('let_spams', 'tag_spams', 'tag_and_drop_spams', 'drop_spams'); - // }}} - // {{{ constructor + // constructor {{{2 public function __construct($uid) { @@ -90,8 +84,7 @@ class Bogo } } - // }}} - // {{{ function change() + // public function change() {{{2 public function change($uid, $state) { @@ -100,44 +93,40 @@ class Bogo $this->state, $uid); } - // }}} - // {{{ function level() + // pubic function level() {{{2 public function level() { return array_search($this->state, $this->_states); } - - // }}} } -// }}} -// {{{ class Email +// class Email {{{1 class Email { - // {{{ properties + // properties {{{2 public $email; public $active; public $broken; + public $disabled; public $rewrite; public $panne; public $last; public $panne_level; - // }}} - // {{{ constructor + // constructor {{{2 public function __construct($row) { list($this->email, $flags, $this->rewrite, $this->panne, $this->last, $this->panne_level) = $row; - $this->active = ($flags == 'active'); - $this->broken = ($flags == 'panne'); + $this->active = ($flags == 'active'); + $this->broken = ($flags == 'panne'); + $this->disabled = ($flags == 'disable'); } - // }}} - // {{{ function activate() + // public function activate() {{{2 public function activate($uid) { @@ -152,8 +141,7 @@ class Email } } - // }}} - // {{{ function deactivate() + // public function deactivate() {{{2 public function deactivate($uid) { @@ -165,8 +153,7 @@ class Email } } - // }}} - // {{{ function rewrite() + // public function rewrite() {{{2 public function rewrite($rew, $uid) { @@ -181,15 +168,28 @@ class Email return; } - // }}} + // function cleanErrors() {{{2 + + public function cleanErrors($uid) + { + if (!S::has_perms()) { + return false; + } + $this->panne = 0; + $this->panne_level = 0; + $this->last = 0; + return XDB::execute("UPDATE emails + SET panne_level = 0, panne = 0, last = 0 + WHERE uid = {?} AND email = {?}", + $uid, $this->email); + } } -// }}} -// {{{ class Redirect +// class Redirect {{{1 class Redirect { - // {{{ properties + // properties {{{2 private $flag_active = 'active'; private $uid; @@ -197,8 +197,7 @@ class Redirect public $emails; public $bogo; - // }}} - // {{{ function Redirect() + // constructor {{{2 public function __construct($_uid) { @@ -213,8 +212,7 @@ class Redirect $this->bogo = new Bogo($_uid); } - // }}} - // {{{ function other_active() + // public function other_active() {{{2 public function other_active($email) { @@ -226,8 +224,7 @@ class Redirect return false; } - // }}} - // {{{ function delete_email() + // public function delete_email() {{{2 public function delete_email($email) { @@ -245,8 +242,7 @@ class Redirect return SUCCESS; } - // }}} - // {{{ function add_email() + // public function add_email() {{{2 public function add_email($email) { @@ -274,22 +270,23 @@ class Redirect return SUCCESS; } - // }}} - // {{{ function modify_email() + // public function modify_email() {{{2 public function modify_email($emails_actifs, $emails_rewrite) { - foreach ($this->emails as $i=>$mail) { - if (in_array($mail->email,$emails_actifs)) { - $this->emails[$i]->activate($this->uid); + foreach ($this->emails as &$mail) { + if (in_array($mail->email, $emails_actifs)) { + $mail->activate($this->uid); } else { - $this->emails[$i]->deactivate($this->uid); + $mail->deactivate($this->uid); } - $this->emails[$i]->rewrite($emails_rewrite[$mail->email], $this->uid); + $mail->rewrite($emails_rewrite[$mail->email], $this->uid); } check_redirect($this); } + // public function modify_one_email() {{{2 + public function modify_one_email($email, $activate) { $allinactive = true; @@ -316,18 +313,62 @@ class Redirect } } + // public function modify_one_email_redirect() {{{2 + public function modify_one_email_redirect($email, $redirect) { - foreach ($this->emails as $i=>$mail) { + foreach ($this->emails as &$mail) { if ($mail->email == $email) { - $this->emails[$i]->rewrite($redirect, $this->uid); + $mail->rewrite($redirect, $this->uid); check_redirect($this); return; } } } - // }}} - // {{{ function get_broken_mx() + + // function cleanErrors() {{{2 + + public function cleanErrors($email) + { + foreach ($this->emails as &$mail) { + if ($mail->email == $email) { + return $mail->cleanErrors($this->uid); + } + } + return false; + } + + // function disable() {{{2 + + public function disable() + { + XDB::execute("UPDATE emails + SET flags = 'disable' + WHERE flags = 'active' AND uid = {?}", $this->uid); + foreach ($this->emails as &$mail) { + if ($mail->active) { + $mail->disabled = true; + $mail->active = false; + } + } + } + + // function enable() {{{2 + + public function enable() + { + XDB::execute("UPDATE emails + SET flags = 'active' + WHERE flags = 'disable' AND uid = {?}", $this->uid); + foreach ($this->emails as &$mail) { + if ($mail->disabled) { + $mail->active = true; + $mail->disabled = false; + } + } + } + + // function get_broken_mx() {{{2 public function get_broken_mx() { @@ -362,11 +403,7 @@ class Redirect } return $mails; } - - // }}} } -// }}} - // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/modules/admin.php b/modules/admin.php index 392d523..c2ed5e8 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -45,7 +45,7 @@ class AdminModule extends PLModule 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), - 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), + 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), ); } @@ -440,16 +440,27 @@ class AdminModule extends PLModule $page->trig($val." a été supprimé"); } break; - case "activate_fwd": - if (!empty($val)) { - $redirect->modify_one_email($val, true); - } - break; - case "deactivate_fwd": - if (!empty($val)) { - $redirect->modify_one_email($val, false); - } - break; + case "activate_fwd": + if (!empty($val)) { + $redirect->modify_one_email($val, true); + } + break; + case "deactivate_fwd": + if (!empty($val)) { + $redirect->modify_one_email($val, false); + } + break; + case "disable_fwd": + $redirect->disable(); + break; + case "enable_fwd": + $redirect->enable(); + break; + case "clean_fwd": + if (!empty($val)) { + $redirect->cleanErrors($val); + } + break; case "add_alias": XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", $mr['user_id'], Env::v('email')); @@ -467,45 +478,45 @@ class AdminModule extends PLModule // Editer un profil case "u_edit": - require_once('secure_hash.inc.php'); - $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); - $naiss = Env::v('naissanceN'); - $deces = Env::v('decesN'); - $perms = Env::v('permsN'); - $prenm = Env::v('prenomN'); - $nom = Env::v('nomN'); - $promo = Env::i('promoN'); - $sexe = Env::v('sexeN'); - $comm = trim(Env::v('commentN')); - $watch = Env::v('watchN'); - $flags = ''; - if ($sexe) { - $flags = 'femme'; - } - if ($watch) { - if ($flags) { - $flags .= ','; + require_once('secure_hash.inc.php'); + $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); + $naiss = Env::v('naissanceN'); + $deces = Env::v('decesN'); + $perms = Env::v('permsN'); + $prenm = Env::v('prenomN'); + $nom = Env::v('nomN'); + $promo = Env::i('promoN'); + $sexe = Env::v('sexeN'); + $comm = trim(Env::v('commentN')); + $watch = Env::v('watchN'); + $flags = ''; + if ($sexe) { + $flags = 'femme'; + } + if ($watch) { + if ($flags) { + $flags .= ','; + } + $flags .= 'watch'; } - $flags .= 'watch'; - } - if ($watch && !$comm) { - $page->trig("Il est nécessaire de mettre un commentaire pour surveiller un compte"); - break; - } + if ($watch && !$comm) { + $page->trig("Il est nécessaire de mettre un commentaire pour surveiller un compte"); + break; + } - $query = "UPDATE auth_user_md5 SET - naissance = '$naiss', - deces = '$deces', - password = '$pass_encrypted', - perms = '$perms', - prenom = '".addslashes($prenm)."', - nom = '".addslashes($nom)."', - flags = '$flags', - promo = $promo, - comment = '".addslashes($comm)."' - WHERE user_id = '{$mr['user_id']}'"; - if (XDB::execute($query)) { + $query = "UPDATE auth_user_md5 SET + naissance = '$naiss', + deces = '$deces', + password = '$pass_encrypted', + perms = '$perms', + prenom = '".addslashes($prenm)."', + nom = '".addslashes($nom)."', + flags = '$flags', + promo = $promo, + comment = '".addslashes($comm)."' + WHERE user_id = '{$mr['user_id']}'"; + if (XDB::execute($query)) { user_reindex($mr['user_id']); $mailer = new PlMailer("admin/mail_intervention.tpl"); @@ -551,13 +562,11 @@ class AdminModule extends PLModule $page->assign('lastlogin', $lastlogin); $page->assign('host', $host); - $res = XDB::query("SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING(vid) - WHERE type = 'user' AND redirect LIKE '" . $login . "@%'"); - if ($res->numRows()) { - $page->assign('virtual', $res->fetchOneCell()); - } + $res = XDB::iterator("SELECT alias + FROM virtual + INNER JOIN virtual_redirect USING(vid) + WHERE type = 'user' AND redirect LIKE '" . $login . "@%'"); + $page->assign('virtuals', $res); $page->assign('aliases', XDB::iterator( "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire @@ -793,7 +802,7 @@ class AdminModule extends PLModule { $page->changeTpl('admin/valider.tpl'); $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); - $page->addCssLink('nl.css'); + $page->addCssLink('nl.css'); $page->addJsLink('ajax.js'); require_once("validations.inc.php"); @@ -1069,20 +1078,20 @@ class AdminModule extends PLModule } function handler_icons(&$page) - { - $page->changeTpl('admin/icons.tpl'); - $dh = opendir('../htdocs/images/icons'); - if (!$dh) { - $page->trig('Dossier des icones introuvables.'); - } - $icons = array(); - while (($file = readdir($dh)) !== false) { - if (strlen($file) > 4 && substr($file,-4) == '.gif') { - array_push($icons, substr($file, 0, -4)); - } - } - sort($icons); - $page->assign('icons', $icons); + { + $page->changeTpl('admin/icons.tpl'); + $dh = opendir('../htdocs/images/icons'); + if (!$dh) { + $page->trig('Dossier des icones introuvables.'); + } + $icons = array(); + while (($file = readdir($dh)) !== false) { + if (strlen($file) > 4 && substr($file,-4) == '.gif') { + array_push($icons, substr($file, 0, -4)); + } + } + sort($icons); + $page->assign('icons', $icons); } } diff --git a/templates/admin/utilisateurs.tpl b/templates/admin/utilisateurs.tpl index b577e38..58d91af 100644 --- a/templates/admin/utilisateurs.tpl +++ b/templates/admin/utilisateurs.tpl @@ -105,6 +105,10 @@ function act_fwd(fwd, activate) { document.forms.fwds.deactivate_fwd.value = fwd; document.forms.fwds.submit(); } +function clean_fwd(fwd) { + document.forms.fwds.clean_fwd.value = fwd; + document.forms.fwds.submit(); +} // ]]> {/literal} @@ -285,13 +289,13 @@ Pour ceci changer ses permissions en 'disabled'. {/if} {/iterate} - {if $virtual} + {iterate from=$virtuals item=virtual} - {$virtual} + {$virtual.alias} - {/if} + {/iterate} @@ -316,14 +320,27 @@ Pour ceci changer ses permissions en 'disabled'. Redirections + {assign var=actives value=false} + {assign var=disabled value=false} {foreach item=mail from=$emails} {cycle assign=class values="impair,pair"} + {if $mail->active} + {assign var=actives value=true} + {elseif $mail->disabled} + {assign var=disabled value=true} + {/if} - {if $mail->active}active{/if} + {if $mail->active}active{elseif $mail->disabled}suspendue{/if} - {if $mail->active}des{elseif $mail->broken}ré{/if}activer + + {if !$mail->disabled} + + {if $mail->active}des{elseif $mail->broken}ré{/if}activer + + {/if} + {if $mail->broken}{/if} @@ -336,15 +353,19 @@ Pour ceci changer ses permissions en 'disabled'. {if $mail->panne && $mail->panne neq "0000-00-00"} - + {icon name=error title="Panne"} Panne de {$mail->email} le {$mail->panne|date_format} {if $mail->panne neq $mail->last}confirmée le {$mail->last|date_format}{/if} + + effacer les pannes + {/if} {/foreach} - + {cycle assign=class values="impair,pair"} + Ajouter un email @@ -354,11 +375,22 @@ Pour ceci changer ses permissions en 'disabled'. + + + + {if $actives} + + {/if} + {if $disabled} + + {/if} + + diff --git a/templates/admin/wiki.tpl b/templates/admin/wiki.tpl index 441ed04..4204495 100644 --- a/templates/admin/wiki.tpl +++ b/templates/admin/wiki.tpl @@ -68,7 +68,7 @@ {/literal}

- {icon name=magnifier"} Voir les changements récents + {icon name=magnifier} Voir les changements récents

diff --git a/upgrade/0.9.14/09_emails.sql b/upgrade/0.9.14/09_emails.sql new file mode 100644 index 0000000..b30624a --- /dev/null +++ b/upgrade/0.9.14/09_emails.sql @@ -0,0 +1,3 @@ +alter table emails change column flags flags enum('active','filter','panne','disable') not null default 'active'; + +# vim:set syntax=mysql: