Dotclear

source: plugins/antispam/filters/class.dc.filter.iplookup.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 3.3 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

Line 
1<?php
2/**
3 * @brief antispam, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
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            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                dcPage::addSuccessNotice(__('The list of DNSBL servers has been succesfully updated.'));
68                http::redirect($url);
69            } catch (Exception $e) {
70                $core->error->add($e->getMessage());
71            }
72        }
73
74        /* DISPLAY
75        ---------------------------------------------- */
76        $res = dcPage::notices();
77
78        $res .=
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}
Note: See TracBrowser for help on using the repository browser.

Sites map