Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/antispam/filters/class.dc.filter.iplookup.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcFilterIpLookup extends dcSpamFilter 
    1515{ 
    16      public $name = 'IP Lookup'; 
    17      public $has_gui = true; 
    18      public $help = 'iplookup-filter'; 
     16    public $name    = 'IP Lookup'; 
     17    public $has_gui = true; 
     18    public $help    = 'iplookup-filter'; 
    1919 
    20      private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 
     20    private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 
    2121 
    22      public function __construct($core) 
    23      { 
    24           parent::__construct($core); 
     22    public function __construct($core) 
     23    { 
     24        parent::__construct($core); 
    2525 
    26           if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 
    27                $this->has_gui = false; 
    28           } 
    29      } 
     26        if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 
     27            $this->has_gui = false; 
     28        } 
     29    } 
    3030 
    31      protected function setInfo() 
    32      { 
    33           $this->description = __('Checks sender IP address against DNSBL servers'); 
    34      } 
     31    protected function setInfo() 
     32    { 
     33        $this->description = __('Checks sender IP address against DNSBL servers'); 
     34    } 
    3535 
    36      public function getStatusMessage($status,$comment_id) 
    37      { 
    38           return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status); 
    39      } 
     36    public function getStatusMessage($status, $comment_id) 
     37    { 
     38        return sprintf(__('Filtered by %1$s with server %2$s.'), $this->guiLink(), $status); 
     39    } 
    4040 
    41      public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 
    42      { 
    43           if (!$ip || long2ip(ip2long($ip)) != $ip) { 
    44                return; 
    45           } 
     41    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) 
     42    { 
     43        if (!$ip || long2ip(ip2long($ip)) != $ip) { 
     44            return; 
     45        } 
    4646 
    47           $bls = $this->getServers(); 
    48           $bls = preg_split('/\s*,\s*/',$bls); 
     47        $bls = $this->getServers(); 
     48        $bls = preg_split('/\s*,\s*/', $bls); 
    4949 
    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      } 
     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    } 
    5858 
    59      public function gui($url) 
    60      { 
    61           $bls = $this->getServers(); 
     59    public function gui($url) 
     60    { 
     61        $bls = $this->getServers(); 
    6262 
    63           if (isset($_POST['bls'])) 
    64           { 
    65                try { 
    66                     $this->core->blog->settings->addNamespace('antispam'); 
    67                     $this->core->blog->settings->antispam->put('antispam_dnsbls',$_POST['bls'],'string','Antispam DNSBL servers',true,false); 
    68                     dcPage::addSuccessNotice(__('The list of DNSBL servers has been succesfully updated.')); 
    69                     http::redirect($url); 
    70                } catch (Exception $e) { 
    71                     $core->error->add($e->getMessage()); 
    72                } 
    73           } 
     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        } 
    7473 
    75           /* DISPLAY 
    76           ---------------------------------------------- */ 
    77           $res = dcPage::notices(); 
     74        /* DISPLAY 
     75        ---------------------------------------------- */ 
     76        $res = dcPage::notices(); 
    7877 
    79           $res .= 
    80           '<form action="'.html::escapeURL($url).'" method="post" class="fieldset">'. 
    81           '<h3>' . __('IP Lookup servers') . '</h3>'. 
    82           '<p><label for="bls">'.__('Add here a coma separated list of servers.').'</label>'. 
    83           form::textarea('bls',40,3,html::escapeHTML($bls),'maximal'). 
    84           '</p>'. 
    85           '<p><input type="submit" value="'.__('Save').'" />'. 
    86           $this->core->formNonce().'</p>'. 
    87           '</form>'; 
     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>'; 
    8887 
    89           return $res; 
    90      } 
     88        return $res; 
     89    } 
    9190 
    92      private function getServers() 
    93      { 
    94           $bls = $this->core->blog->settings->antispam->antispam_dnsbls; 
    95           if ($bls === null) { 
    96                $this->core->blog->settings->addNamespace('antispam'); 
    97                $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false); 
    98                return $this->default_bls; 
    99           } 
     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        } 
    10099 
    101           return $bls; 
    102      } 
     100        return $bls; 
     101    } 
    103102 
    104      private function dnsblLookup($ip,$bl) 
    105      { 
    106           $revIp = implode('.',array_reverse(explode('.',$ip))); 
     103    private function dnsblLookup($ip, $bl) 
     104    { 
     105        $revIp = implode('.', array_reverse(explode('.', $ip))); 
    107106 
    108           $host = $revIp.'.'.$bl.'.'; 
    109           if (gethostbyname($host) != $host) { 
    110                return true; 
    111           } 
     107        $host = $revIp . '.' . $bl . '.'; 
     108        if (gethostbyname($host) != $host) { 
     109            return true; 
     110        } 
    112111 
    113           return false; 
    114      } 
     112        return false; 
     113    } 
    115114} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map