Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 3.0 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

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

Sites map