Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 1360:b4bc7f335d38

Revision 1360:b4bc7f335d38, 2.8 KB checked in by Pascal Chevrel <pascal.chevrel@…>, 12 years ago (diff)

don't return false in isSpam() otherwise it doesn't allow other spam filters to work (weird logic IMO)

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-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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcFilterIpLookup extends dcSpamFilter
15{
16     public $name = 'IP Lookup';
17     public $has_gui = true;
18
19     private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net';
20
21     public function __construct($core)
22     {
23          parent::__construct($core);
24
25          if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) {
26               $this->has_gui = false;
27          }
28     }
29
30     protected function setInfo()
31     {
32          $this->description = __('Checks sender IP address against DNSBL servers');
33     }
34
35     public function getStatusMessage($status,$comment_id)
36     {
37          return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status);
38     }
39
40     public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
41     {
42          if (!$ip || long2ip(ip2long($ip)) != $ip) {
43               return;
44          }
45
46          $bls = $this->getServers();
47          $bls = preg_split('/\s*,\s*/',$bls);
48
49          foreach ($bls as $bl) {
50               if ($this->dnsblLookup($ip,$bl)) {
51                    return true;
52               }
53          }
54     }
55
56     public function gui($url)
57     {
58          $bls = $this->getServers();
59
60          if (isset($_POST['bls']))
61          {
62               try {
63                    $this->core->blog->settings->addNamespace('antispam');
64                    $this->core->blog->settings->antispam->put('antispam_dnsbls',$_POST['bls'],'string','Antispam DNSBL servers',true,false);
65                    http::redirect($url.'&upd=1');
66               } catch (Exception $e) {
67                    $core->error->add($e->getMessage());
68               }
69          }
70
71          /* DISPLAY
72          ---------------------------------------------- */
73          $res = '';
74
75          $res .=
76          '<form action="'.html::escapeURL($url).'" method="post">'.
77          '<fieldset><legend>' . __('IP Lookup servers') . '</legend>'.
78          '<p><label for="bls">'.__('Add here a coma separated list of servers.').
79          form::textarea('bls',40,3,html::escapeHTML($bls),'maximal').
80          '</p>'.
81          '<p><input type="submit" value="'.__('Save').'" /></label></p>'.
82          $this->core->formNonce().'</p>'.
83          '</fieldset>'.
84          '</form>';
85
86          return $res;
87     }
88
89     private function getServers()
90     {
91          $bls = $this->core->blog->settings->antispam->antispam_dnsbls;
92          if ($bls === null) {
93               $this->core->blog->settings->addNamespace('antispam');
94               $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false);
95               return $this->default_bls;
96          }
97
98          return $bls;
99     }
100
101     private function dnsblLookup($ip,$bl)
102     {
103          $revIp = implode('.',array_reverse(explode('.',$ip)));
104
105          $host = $revIp.'.'.$bl.'.';
106          if (gethostbyname($host) != $host) {
107               return true;
108          }
109
110          return false;
111     }
112}
113?>
Note: See TracBrowser for help on using the repository browser.

Sites map