1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Antispam, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 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 ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class 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 | if ($i == 0) { |
---|
51 | // "domain" is 1 word long, don't check it |
---|
52 | return false; |
---|
53 | } |
---|
54 | $host = $domain_elem[$i]; |
---|
55 | do |
---|
56 | { |
---|
57 | $host = $domain_elem[$i - 1].'.'.$host; |
---|
58 | $i--; |
---|
59 | if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) |
---|
60 | { |
---|
61 | $status = substr($domain,0,128); |
---|
62 | return true; |
---|
63 | } |
---|
64 | } while ($i > 0); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | private function getLinks($text) |
---|
69 | { |
---|
70 | // href attribute on "a" tags is second match |
---|
71 | preg_match_all('|<a.*?href="(http.*?)"|', $text, $parts); |
---|
72 | |
---|
73 | return $parts[1]; |
---|
74 | } |
---|
75 | } |
---|
76 | ?> |
---|