Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 0:54703be25dd6

Revision 0:54703be25dd6, 2.9 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

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

Sites map