Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 1499:fc4bc1ece727

Revision 1499:fc4bc1ece727, 2.9 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Let fieldsets be fieldsets (work in progress): blogpref, category, blogtheme, langs, media, plugins, user actions, antispam, importexport.

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                    // Pass by reference $status to contain matching DNSBL
52                    $status = $bl;
53                    return true;
54               }
55          }
56     }
57
58     public function gui($url)
59     {
60          $bls = $this->getServers();
61
62          if (isset($_POST['bls']))
63          {
64               try {
65                    $this->core->blog->settings->addNamespace('antispam');
66                    $this->core->blog->settings->antispam->put('antispam_dnsbls',$_POST['bls'],'string','Antispam DNSBL servers',true,false);
67                    http::redirect($url.'&upd=1');
68               } catch (Exception $e) {
69                    $core->error->add($e->getMessage());
70               }
71          }
72
73          /* DISPLAY
74          ---------------------------------------------- */
75          $res = '';
76
77          $res .=
78          '<form action="'.html::escapeURL($url).'" method="post" class="fieldset">'.
79          '<h3>' . __('IP Lookup servers') . '</h3>'.
80          '<p><label for="bls">'.__('Add here a coma separated list of servers.').'</label>'.
81          form::textarea('bls',40,3,html::escapeHTML($bls),'maximal').
82          '</p>'.
83          '<p><input type="submit" value="'.__('Save').'" /></p>'.
84          $this->core->formNonce().'</p>'.
85          '</form>';
86
87          return $res;
88     }
89
90     private function getServers()
91     {
92          $bls = $this->core->blog->settings->antispam->antispam_dnsbls;
93          if ($bls === null) {
94               $this->core->blog->settings->addNamespace('antispam');
95               $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false);
96               return $this->default_bls;
97          }
98
99          return $bls;
100     }
101
102     private function dnsblLookup($ip,$bl)
103     {
104          $revIp = implode('.',array_reverse(explode('.',$ip)));
105
106          $host = $revIp.'.'.$bl.'.';
107          if (gethostbyname($host) != $host) {
108               return true;
109          }
110
111          return false;
112     }
113}
114?>
Note: See TracBrowser for help on using the repository browser.

Sites map