Legend:
- Unmodified
- Added
- Removed
-
plugins/antispam/filters/class.dc.filter.iplookup.php
r2566 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcFilterIpLookup extends dcSpamFilter 15 15 { 16 public $name= 'IP Lookup';17 18 public $help= 'iplookup-filter';16 public $name = 'IP Lookup'; 17 public $has_gui = true; 18 public $help = 'iplookup-filter'; 19 19 20 20 private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 21 21 22 23 24 22 public function __construct($core) 23 { 24 parent::__construct($core); 25 25 26 27 28 29 26 if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 27 $this->has_gui = false; 28 } 29 } 30 30 31 32 33 34 31 protected function setInfo() 32 { 33 $this->description = __('Checks sender IP address against DNSBL servers'); 34 } 35 35 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 } 40 40 41 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)42 43 44 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 } 46 46 47 48 $bls = preg_split('/\s*,\s*/',$bls);47 $bls = $this->getServers(); 48 $bls = preg_split('/\s*,\s*/', $bls); 49 49 50 51 if ($this->dnsblLookup($ip,$bl)) {52 53 54 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 } 58 58 59 60 61 59 public function gui($url) 60 { 61 $bls = $this->getServers(); 62 62 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 } 74 73 75 76 77 74 /* DISPLAY 75 ---------------------------------------------- */ 76 $res = dcPage::notices(); 78 77 79 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 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>'; 88 87 89 90 88 return $res; 89 } 91 90 92 93 94 95 96 97 $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false);98 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 } 100 99 101 102 100 return $bls; 101 } 103 102 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))); 107 106 108 $host = $revIp.'.'.$bl.'.';109 110 111 107 $host = $revIp . '.' . $bl . '.'; 108 if (gethostbyname($host) != $host) { 109 return true; 110 } 112 111 113 114 112 return false; 113 } 115 114 }
Note: See TracChangeset
for help on using the changeset viewer.