Dotclear

source: plugins/antispam/filters/class.dc.filter.linkslookup.php @ 913:dda0e8b497de

Revision 913:dda0e8b497de, 1.9 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

enhance links lookup anti spam filter, thanks gnieark, fixes #1152

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcFilterLinksLookup extends dcSpamFilter
15{
16     public $name = 'Links Lookup';
17     
18     private $server = 'multi.surbl.org';
19     
20     protected function setInfo()
21     {
22          $this->description = __('Checks links in comments against surbl.org');
23     }
24     
25     public function getStatusMessage($status,$comment_id)
26     {
27          return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status);
28     }
29     
30     public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
31     {
32          if (!$ip || long2ip(ip2long($ip)) != $ip) {
33               return;
34          }
35         
36          $urls = $this->getLinks($content);
37          array_unshift($urls,$site);
38         
39          foreach ($urls as $u)
40          {
41               $b = parse_url($u);
42               if (!isset($b['host']) || !$b['host']) {
43                    continue;
44               }
45
46               $domain = preg_replace('/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/','$1',$b['host']);
47               $domain_elem = explode(".",$domain);
48
49               $i = count($domain_elem) - 1;
50               $host = $domain_elem[$i];
51               do
52               {
53                    $host = $domain_elem[$i - 1].'.'.$host;
54                    $i--;
55                    if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) 
56                    {
57                         $status = substr($domain,0,128);
58                         return true;
59                    }                   
60               } while ($i > 0);
61          }
62     }
63     
64     private function getLinks($text)
65     {
66          $res = array();
67         
68          # href attribute on "a" tags
69          if (preg_match_all('/<a ([^>]+)>/ms', $text, $match, PREG_SET_ORDER))
70          {
71               for ($i = 0; $i<count($match); $i++)
72               {
73                    if (preg_match('/href="(http:\/\/[^"]+)"/ms', $match[$i][1], $matches)) {
74                         $res[] = $matches[1];
75                    }
76               }
77          }
78         
79          return $res;
80     }
81}
82?>
Note: See TracBrowser for help on using the repository browser.

Sites map