Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 536:535dd04130aa

Revision 536:535dd04130aa, 2.9 KB checked in by kozlika, 13 years ago (diff)

Accessibility: fieldset aren't used if not necessary.
Create a class="fieldset" for presentation needs.

  • Property exe set to *
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-2011 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><label for="bls">'.__('Add here a coma separated list of servers.').
87          form::textarea('bls',40,3,html::escapeHTML($bls),'maximal').
88          '</p>'.
89          '<p><input type="submit" value="'.__('Save').'" /></label></p>'.
90          $this->core->formNonce().'</p>'.
91          '</fieldset>'.
92          '</form>';
93
94          return $res;
95     }
96
97     private function getServers()
98     {
99          $bls = $this->core->blog->settings->antispam->antispam_dnsbls;
100          if ($bls === null) {
101               $this->core->blog->settings->addNamespace('antispam');
102               $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false);
103               return $this->default_bls;
104          }
105
106          return $bls;
107     }
108
109     private function dnsblLookup($ip,$bl)
110     {
111          $revIp = implode('.',array_reverse(explode('.',$ip)));
112
113          $host = $revIp.'.'.$bl.'.';
114          if (gethostbyname($host) != $host) {
115               return true;
116          }
117
118          return false;
119     }
120}
121?>
Note: See TracBrowser for help on using the repository browser.

Sites map