From ccdbc270a4d0e98d88c1d7a29e8cb3c5f260bcef Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Tue, 23 Jan 2007 22:20:15 +0000 Subject: [PATCH] #603: Show QoS informations -> new page "admin/mx/broken" to register the MXs to which mail can't be delivered -> show information to users who has no valid redirection or who has a redirection which use a 'broken mx' -> add 'broken mx' stats on 'stats/coupures' git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1390 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 3 +++ include/emails.inc.php | 58 +++++++++++++++++++++++++++++++++++++++--- include/xorg.misc.inc.php | 11 ++++++++ include/xorg/session.inc.php | 1 + modules/admin.php | 10 ++++++++ modules/stats.php | 6 ++++- templates/admin/index.tpl | 2 ++ templates/events/index.tpl | 23 +++++++++++++++++ templates/stats/coupure.tpl | 21 ++++++++++++++- upgrade/0.9.13/06_mx_watch.sql | 8 ++++++ 10 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 upgrade/0.9.13/06_mx_watch.sql diff --git a/ChangeLog b/ChangeLog index b6bdb99..6716bca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,9 @@ Bug/Wish: * Register: - #277: Improve ergonomy. -FRU + * Stats: + - #603: Add informations on mail delivery -FRU + * Xnet: - #570: Fix geoloc skin. -FRU - #589: Can attach a file when sending an email -FRU diff --git a/include/emails.inc.php b/include/emails.inc.php index 1e01343..f954b23 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -235,6 +235,7 @@ class Redirect unset($this->emails[$i]); } } + check_redirect($this); return SUCCESS; } @@ -263,6 +264,7 @@ class Redirect // security stuff check_email($email, "Ajout d'une adresse surveillée aux redirections de " . $this->uid); + check_redirect($this); return SUCCESS; } @@ -279,9 +281,11 @@ class Redirect } $this->emails[$i]->rewrite($emails_rewrite[$mail->email], $this->uid); } + check_redirect($this); } - function modify_one_email($email, $activate) { + function modify_one_email($email, $activate) + { $allinactive = true; $thisone = false; foreach ($this->emails as $i=>$mail) { @@ -293,10 +297,12 @@ class Redirect if ($thisone === false) { return ERROR_INVALID_EMAIL; } - if ($allinactive || $activate) + if ($allinactive || $activate) { $this->emails[$thisone]->activate($this->uid); - else + } else { $this->emails[$thisone]->deactivate($this->uid); + } + check_redirect($this); if ($allinactive && !$activate) { return ERROR_INACTIVE_REDIRECTION; } else { @@ -308,11 +314,55 @@ class Redirect foreach ($this->emails as $i=>$mail) { if ($mail->email == $email) { $this->emails[$i]->rewrite($redirect, $this->uid); - return; + check_redirect($this); + return; } } } // }}} + // {{{ function get_broken_mx() + + function get_broken_mx() + { + $res = XDB::iterRow("SELECT host, text + FROM mx_watch + WHERE state != 'ok'"); + if (!$res->total()) { + return array(); + } + $mxs = array(); + while (list($host, $text) = $res->next()) { + $host = preg_quote($host, '/'); + $host = str_replace('\*', '.*', $host); + $host = str_replace('\?', '.', $host); + $mxs[] = array('host' => "/^$host\\.?$/", 'text' => $text); + } + $mails = array(); + foreach ($this->emails as &$mail) { + if ($mail->active) { + list(,$domain) = explode('@', $mail->email); + getmxrr($domain, $lcl_mxs); + if (empty($lcl_mxs)) { + $lcl_mxs = array($domain); + } + $broken = false; + foreach ($mxs as &$mx) { + foreach ($lcl_mxs as $lcl) { + if (preg_match($mx['host'], $lcl)) { + $broken = $mx['text']; + break; + } + } + if ($broken) { + $mails[] = array('mail' => $mail->email, 'text' => $broken); + } + } + } + } + return $mails; + } + + // }}} } // }}} diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index 5473e7e..18722fc 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -139,6 +139,17 @@ function check_email($email, $message) return false; } +function check_redirect($red = null) +{ + require_once 'emails.inc.php'; + if (is_null($red)) { + $red = new Redirect(S::v('uid')); + } + $_SESSION['no_redirect'] = !$red->other_active(''); + $_SESSION['mx_failures'] = $red->get_broken_mx(); + +} + function send_warning_mail($title) { $mailer = new PlMailer(); diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index 71fe324..515a8fe 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -262,6 +262,7 @@ function start_connexion ($uid, $identified) } } set_skin(); + check_redirect(); return true; } diff --git a/modules/admin.php b/modules/admin.php index 54ef3b1..a635f00 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -36,6 +36,7 @@ class AdminModule extends PLModule 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), + 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'), 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), @@ -842,6 +843,15 @@ class AdminModule extends PLModule $table_editor->describe('email','email',true); $table_editor->apply($page, $action, $id); } + function handler_mx_broken(&$page, $action = 'list', $id = null) { + $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants'); + $page->assign('title', 'MX Défaillant'); + $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); + $table_editor->describe('host', 'Masque', true); + $table_editor->describe('state', 'Niveau', true); + $table_editor->describe('text', 'Description du problème', false); + $table_editor->apply($page, $action, $id); + } function handler_logger_actions(&$page, $action = 'list', $id = null) { $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); $page->assign('title', 'Gestion des actions de logger'); diff --git a/modules/stats.php b/modules/stats.php index 5dff251..c6f12e7 100644 --- a/modules/stats.php +++ b/modules/stats.php @@ -281,7 +281,7 @@ EOF2; $cp = $res->fetchOneAssoc(); } - if($cp) { + if(@$cp) { $cp['lg_services'] = serv_to_str($cp['services']); $page->assign_by_ref('cp',$cp); } else { @@ -289,6 +289,10 @@ EOF2; $sql = "SELECT id, debut, resume, services FROM coupures where debut > '$beginning_date' order by debut desc"; $page->assign('coupures', XDB::iterator($sql)); + $res = XDB::iterator("SELECT host, text + FROM mx_watch + WHERE state != 'ok'"); + $page->assign('mxs', $res); } } } diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index 95e26e2..5ce73d1 100644 --- a/templates/admin/index.tpl +++ b/templates/admin/index.tpl @@ -75,6 +75,8 @@ Infos dynamiques :   Coupures   |   + MX défaillants +   |   Astuces diff --git a/templates/events/index.tpl b/templates/events/index.tpl index 58628f1..a0222d9 100644 --- a/templates/events/index.tpl +++ b/templates/events/index.tpl @@ -35,11 +35,34 @@ Bienvenue {$smarty.session.prenom} {/if} +{if $smarty.session.host}
Ta connexion précédente date du {$smarty.session.lastlogin|date_format:"%x, %X"} depuis la machine {$smarty.session.host}
+{/if} + +{if $smarty.session.no_redirect} +

+ Tu n'as plus de redirection valide ce qui rend ton adresse Polytechnique.org + inutilisable. Rend-toi au plus vite sur la page de + gestion des emails pour corriger ce problème. +

+{/if} + +{if $smarty.session.mx_failures|@count} +
+ {icon name=error}Des problèmes sont actuellement recontrés sur tes redirections suivantes + {foreach from=$smarty.session.mx_failures item=mail} +
+ {$mail.mail} +
{$mail.text}
+
+{/foreach} +
+{/if} + {if $fiche_incitation}

La dernière mise à jour de ta diff --git a/templates/stats/coupure.tpl b/templates/stats/coupure.tpl index 96c02f2..d8025be 100644 --- a/templates/stats/coupure.tpl +++ b/templates/stats/coupure.tpl @@ -20,6 +20,8 @@ {* *} {**************************************************************************} +

Coupures de Polytechnique.org

+ {if $cp} @@ -73,7 +75,7 @@ {iterate item=cp from=$coupures} - + {/iterate}
services affectés
{$cp.debut|date_format} @@ -92,6 +94,23 @@
+ +

Problèmes avec les autres fournisseurs de services

+ +

+ La liste ci-dessous indique quels sont les fournisseurs de mails vers lesquels nous avons + actuellement des problèmes de tranmission. +

+ + + + {iterate from=$mxs item=mx} + + + + {/iterate} +
Liste des disfonctionnements
{$mx.host}
{$mx.text}
+ {/if} {* vim:set et sw=2 sts=2 sws=2: *} diff --git a/upgrade/0.9.13/06_mx_watch.sql b/upgrade/0.9.13/06_mx_watch.sql new file mode 100644 index 0000000..8799cc4 --- /dev/null +++ b/upgrade/0.9.13/06_mx_watch.sql @@ -0,0 +1,8 @@ +CREATE TABLE `mx_watch` ( + `host` VARCHAR(64) NOT NULL, + `state` ENUM('ok', 'warning', 'broken') DEFAULT 'ok', + `text` MEDIUMTEXT NOT NULL, + PRIMARY KEY(`host`) +); + +# vim:set syntax=mysql: -- 2.1.4