From 9e2a6a32494b965216ec6c4a07dc37a7a15fc365 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Wed, 4 Nov 2009 00:36:26 +0100 Subject: [PATCH] Simplifies blacklist verification (Closes #992). --- ChangeLog | 1 + configs/platal.ini | 3 ++ include/newsletter.inc.php | 85 ++++++++++++++++++++++++++++++++++++------- modules/newsletter.php | 50 ++++++++++++++++++------- templates/newsletter/edit.tpl | 29 +++++++++++++++ 5 files changed, 140 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57e13d5..8c8636a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,7 @@ Bug/Wish: * Newsletter: - #986: Improves the nl edition page -JAC - #991: Adds the text of the article in the mail when refused -JAC + - #992: Simplifies blacklist verification -JAC * Profile: - #983: Fixes issue with the professional email publicity -JAC diff --git a/configs/platal.ini b/configs/platal.ini index c6980ec..946bbf0 100644 --- a/configs/platal.ini +++ b/configs/platal.ini @@ -43,6 +43,9 @@ domain2 = "" alias_dom = "" alias_dom2 = "" +blacklist_check_url = "" +blacklist_host_resolution_limit = + [MailStorage] imap_active = 0 googleapps_active = 0 diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index c58844e..b03b419 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -26,8 +26,8 @@ require_once("massmailer.inc.php"); class NewsLetter extends MassMailer { public $_date; - public $_cats = Array(); - public $_arts = Array(); + public $_cats = array(); + public $_arts = array(); function __construct($id = null) { @@ -50,12 +50,12 @@ class NewsLetter extends MassMailer } $nl = $res->fetchOneAssoc(); - $this->_id = $nl['id']; - $this->_shortname = $nl['short_name']; - $this->_date = $nl['date']; - $this->_title = $nl['titre']; + $this->_id = $nl['id']; + $this->_shortname = $nl['short_name']; + $this->_date = $nl['date']; + $this->_title = $nl['titre']; $this->_title_mail = $nl['titre_mail']; - $this->_head = $nl['head']; + $this->_head = $nl['head']; $res = XDB::iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); while (list($cid, $title) = $res->next()) { @@ -92,19 +92,21 @@ class NewsLetter extends MassMailer public function saveArticle(&$a) { - if ($a->_aid>=0) { - XDB::execute('REPLACE INTO newsletter_art (id,aid,cid,pos,title,body,append) - VALUES ({?},{?},{?},{?},{?},{?},{?})', + if ($a->_aid >= 0) { + XDB::execute('REPLACE INTO newsletter_art (id, aid, cid, pos, title, body, append) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', $this->_id, $a->_aid, $a->_cid, $a->_pos, $a->_title, $a->_body, $a->_append); - $this->_arts['a'.$a->_aid] = $a; + $this->_arts['a' . $a->_aid] = $a; } else { XDB::execute('INSERT INTO newsletter_art - SELECT {?},MAX(aid)+1,{?},'.($a->_pos ? intval($a->_pos) : 'MAX(pos)+1').',{?},{?},{?} + SELECT {?}, MAX(aid)+1, {?}, ' + . ($a->_pos ? intval($a->_pos) : 'MAX(pos)+1') + . ', {?}, {?}, {?} FROM newsletter_art AS a - WHERE a.id={?}', + WHERE a.id = {?}', $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id); - $this->_arts['a'.$a->_aid] = $a; + $this->_arts['a' . $a->_aid] = $a; } } @@ -281,6 +283,61 @@ class NLArticle } // }}} + // {{{ function parseUrlsFromArticle() + + private function parseUrlsFromArticle() + { + $email_regex = '([a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+)'; + $url_regex = '((https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+)'; + $regex = '{' . $email_regex . '|' . $url_regex . '}i'; + + $matches = array(); + $body_matches = array(); + if (preg_match_all($regex, $this->body(), $body_matches)) { + $matches = array_merge($matches, $body_matches[0]); + } + + $append_matches = array(); + if (preg_match_all($regex, $this->append(), $append_matches)) { + $matches = array_merge($matches, $append_matches[0]); + } + + return $matches; + } + + // }}} + // {{{ function getLinkIps() + + public function getLinkIps(&$gethostbyname_count) + { + $matches = $this->parseUrlsFromArticle(); + $article_ips = array(); + + if (!empty($matches)) { + global $globals; + + foreach ($matches as $match) { + $host = parse_url($match, PHP_URL_HOST); + if ($host == '') { + list(, $host) = explode('@', $match); + } + + if ($gethostbyname_count < $globals->mail->blacklist_host_resolution_limit) { + break; + } + + if ($host != $globals->mail->alias_dom && $host != $globals->mail->alias_dom2 + && $host != $globals->mail->domain && $host != $globals->mail->domain2) { + $article_ips = array_merge($article_ips, array(gethostbyname($host) => $host)); + ++$gethostbyname_count; + } + } + } + + return $article_ips; + } + + // }}} } // }}} diff --git a/modules/newsletter.php b/modules/newsletter.php index 8d0c4c6..75ab2e9 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -118,10 +118,10 @@ class NewsletterModule extends PLModule function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { $page->changeTpl('newsletter/edit.tpl'); $page->addCssLink('nl.css'); - $page->setTitle('Administration - Newsletter : Edition'); - require_once("newsletter.inc.php"); + $page->setTitle('Administration - Newsletter : Édition'); + require_once 'newsletter.inc.php'; - $nl = new NewsLetter($nid); + $nl = new NewsLetter($nid); if($action == 'delete') { $nl->delArticle($aid); @@ -129,38 +129,60 @@ class NewsletterModule extends PLModule } if($aid == 'update') { - $nl->_title = Post::v('title'); - $nl->_title_mail= Post::v('title_mail'); - $nl->_date = Post::v('date'); - $nl->_head = Post::v('head'); - $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; + $nl->_title = Post::v('title'); + $nl->_title_mail = Post::v('title_mail'); + $nl->_date = Post::v('date'); + $nl->_head = Post::v('head'); + $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { $nl->save(); } else { - $page->trigError('Le nom de la NL n\'est pas valide'); + $page->trigError("Le nom de la NL n'est pas valide."); pl_redirect('admin/newsletter/edit/' . $nl->_id); } } if(Post::v('save')) { $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), - $aid, Post::v('cid'), Post::v('pos')); + $aid, Post::v('cid'), Post::v('pos')); $nl->saveArticle($art); pl_redirect("admin/newsletter/edit/$nid"); } - if($action == 'edit' && $aid != 'update') { + if ($action == 'edit' && $aid != 'update') { $eaid = $aid; if(Post::has('title')) { $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), - $eaid, Post::v('cid'), Post::v('pos')); + $eaid, Post::v('cid'), Post::v('pos')); } else { - $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); + $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); } $page->assign('art', $art); } - $page->assign_by_ref('nl',$nl); + if ($aid == 'blacklist_check') { + $ips_to_check = array(); + $gethostbyname_count = 0; + + foreach ($nl->_arts as $key => $articles) { + foreach ($articles as $article) { + $article_ips = $article->getLinkIps($gethostbyname_count); + if (!empty($article_ips)) { + $ips_to_check[$article->title()] = $article_ips; + } + } + } + + $page->assign('ips_to_check', $ips_to_check); + if ($gethostbyname_count >= $globals->mail->blacklist_host_resolution_limit) { + $page-trigError("Toutes les url et adresses emails de la lettre" + . " n'ont pas été prises en compte car la" + . " limite du nombre de résolutions DNS" + . " autorisée a été atteinte."); + } + } + + $page->assign_by_ref('nl', $nl); } function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { diff --git a/templates/newsletter/edit.tpl b/templates/newsletter/edit.tpl index 61fc55a..5fd721e 100644 --- a/templates/newsletter/edit.tpl +++ b/templates/newsletter/edit.tpl @@ -134,6 +134,35 @@ {/foreach} +
+ +
+ + + + + {if $ips_to_check|@count > 0} + {foreach from=$ips_to_check item=ip_list key=title} + {foreach from=$ip_list item=domain key=ip} + + + + + {assign var=title value=''} + {/foreach} + {/foreach} + {else} + + + + {/if} +
+ Vérifier les url et adresses emails sur Spamhaus +
{$title}{$domain}
+ +
+
+ {else}

-- 2.1.4