Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 2121:9725f2bf0081

Revision 2121:9725f2bf0081, 2.9 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Antispam, ipfilter : Balisage corrigé, lien de retour fait. Reste à ajouter un message de confirmation de bon enregistrement des modifs. Addresses #1494

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          '<p><a href="plugin.php?p=antispam" class="back">'.__('Back to filters list').'</a></p>'.
79          '<form action="'.html::escapeURL($url).'" method="post" class="fieldset">'.
80          '<h3>' . __('IP Lookup servers') . '</h3>'.
81          '<p><label for="bls">'.__('Add here a coma separated list of servers.').'</label>'.
82          form::textarea('bls',40,3,html::escapeHTML($bls),'maximal').
83          '</p>'.
84          '<p><input type="submit" value="'.__('Save').'" />'.
85          $this->core->formNonce().'</p>'.
86          '</form>';
87
88          return $res;
89     }
90
91     private function getServers()
92     {
93          $bls = $this->core->blog->settings->antispam->antispam_dnsbls;
94          if ($bls === null) {
95               $this->core->blog->settings->addNamespace('antispam');
96               $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false);
97               return $this->default_bls;
98          }
99
100          return $bls;
101     }
102
103     private function dnsblLookup($ip,$bl)
104     {
105          $revIp = implode('.',array_reverse(explode('.',$ip)));
106
107          $host = $revIp.'.'.$bl.'.';
108          if (gethostbyname($host) != $host) {
109               return true;
110          }
111
112          return false;
113     }
114}
115?>
Note: See TracBrowser for help on using the repository browser.

Sites map