Changeset 223:e44ed54b1001 for plugins
- Timestamp:
- 05/08/11 21:44:10 (14 years ago)
- Branch:
- default
- Children:
- 224:23ec5a339bcf, 225:411ee50a8664, 249:d0a17b7ca6e0
- Location:
- plugins/antispam
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/antispam/filters/class.dc.filter.ip.php
r3 r223 16 16 public $name = 'IP Filter'; 17 17 public $has_gui = true; 18 18 19 19 private $style_list = 'height: 200px; overflow: auto; margin-bottom: 1em; '; 20 20 private $style_p = 'margin: 1px 0 0 0; padding: 0.2em 0.5em; '; 21 21 private $style_global = 'background: #ccff99; '; 22 22 23 23 private $con; 24 24 private $table; 25 25 26 26 public function __construct($core) 27 27 { … … 30 30 $this->table = $core->prefix.'spamrule'; 31 31 } 32 32 33 33 protected function setInfo() 34 34 { 35 35 $this->description = __('IP Blacklist / Whitelist Filter'); 36 36 } 37 37 38 38 public function getStatusMessage($status,$comment_id) 39 39 { 40 40 return sprintf(__('Filtered by %1$s with rule %2$s.'),$this->guiLink(),$status); 41 41 } 42 42 43 43 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 44 44 { … … 46 46 return; 47 47 } 48 48 49 49 # White list check 50 50 if ($this->checkIP($ip,'white') !== false) { 51 51 return false; 52 52 } 53 53 54 54 # Black list check 55 55 if (($s = $this->checkIP($ip,'black')) !== false) { … … 58 58 } 59 59 } 60 60 61 61 public function gui($url) 62 62 { 63 63 global $default_tab; 64 64 $core =& $this->core; 65 65 66 66 # Set current type and tab 67 67 $ip_type = 'black'; … … 70 70 } 71 71 $default_tab = 'tab_'.$ip_type; 72 72 73 73 # Add IP to list 74 74 if (!empty($_POST['addip'])) … … 77 77 { 78 78 $global = !empty($_POST['globalip']) && $core->auth->isSuperAdmin(); 79 79 80 80 $this->addIP($ip_type,$_POST['addip'],$global); 81 81 http::redirect($url.'&added=1&ip_type='.$ip_type); … … 86 86 } 87 87 } 88 88 89 89 # Remove IP from list 90 90 if (!empty($_POST['delip']) && is_array($_POST['delip'])) … … 97 97 } 98 98 } 99 99 100 100 /* DISPLAY 101 101 ---------------------------------------------- */ 102 102 $res = ''; 103 103 104 104 if (!empty($_GET['added'])) { 105 105 $res .= '<p class="message">'.__('IP address has been successfully added.').'</p>'; … … 108 108 $res .= '<p class="message">'.__('IP addresses have been successfully removed.').'</p>'; 109 109 } 110 110 111 111 $res .= 112 112 $this->displayForms($url,'black',__('Blacklist')). 113 113 $this->displayForms($url,'white',__('Whitelist')); 114 114 115 115 return $res; 116 116 } 117 117 118 118 private function displayForms($url,$type,$title) 119 119 { 120 120 $core =& $this->core; 121 121 122 122 $res = 123 123 '<div class="multi-part" id="tab_'.$type.'" title="'.$title.'">'. 124 124 125 125 '<form action="'.html::escapeURL($url).'" method="post">'. 126 126 '<fieldset><legend>'.__('Add an IP address').'</legend><p>'. 127 127 form::hidden(array('ip_type'),$type). 128 form::field(array('addip'),18,255).' '; 129 128 '<label class="classic" for="addip_'.$type.'">'.__('Add an IP address').' '. 129 form::field(array('addip', 'addip_'.$type),18,255). 130 '</label>'; 130 131 if ($core->auth->isSuperAdmin()) { 131 $res .= '<label class="classic" >'.form::checkbox(array('globalip'),1).' '.132 $res .= '<label class="classic" for="globalip_'.$type.'">'.form::checkbox(array('globalip', 'globalip_'.$type),1).' '. 132 133 __('Global IP').'</label> '; 133 134 } 134 135 135 136 $res .= 136 137 $core->formNonce(). 137 138 '<input type="submit" value="'.__('Add').'"/></p>'. 138 139 '</fieldset></form>'; 139 140 140 141 $rs = $this->getRules($type); 141 142 142 143 if ($rs->isEmpty()) 143 144 { … … 150 151 '<fieldset><legend>' . __('IP list') . '</legend>'. 151 152 '<div style="'.$this->style_list.'">'; 152 153 153 154 while ($rs->fetch()) 154 155 { … … 157 158 $ip = $bits[1]; 158 159 $bitmask = $bits[2]; 159 160 160 161 $disabled_ip = false; 161 162 $p_style = $this->style_p; … … 164 165 $p_style .= $this->style_global; 165 166 } 166 167 167 168 $res .= 168 169 '<p style="'.$p_style.'"><label class="classic">'. 169 form::checkbox(array('delip[]'),$rs->rule_id,false,'','',$disabled_ip ).' '.170 form::checkbox(array('delip[]'),$rs->rule_id,false,'','',$disabled_ip, 'title="'.html::escapeHTML($pattern).'"').' '. 170 171 html::escapeHTML($pattern). 171 172 '</label></p>'; … … 178 179 '</p>'. 179 180 '</fieldset></form>'; 180 } 181 181 } 182 182 183 $res .= '</div>'; 183 184 184 185 return $res; 185 186 } 186 187 187 188 private function ipmask($pattern,&$ip,&$mask) 188 189 { 189 190 $bits = explode('/',$pattern); 190 191 191 192 # Set IP 192 193 $bits[0] .= str_repeat(".0", 3 - substr_count($bits[0], ".")); 193 194 $ip = ip2long($bits[0]); 194 195 195 196 if (!$ip || $ip == -1) { 196 197 throw new Exception('Invalid IP address'); 197 198 } 198 199 199 200 # Set mask 200 201 if (!isset($bits[1])) { … … 209 210 } 210 211 } 211 212 212 213 private function addIP($type,$pattern,$global) 213 214 { … … 215 216 $pattern = long2ip($ip).($mask != -1 ? '/'.long2ip($mask) : ''); 216 217 $content = $pattern.':'.$ip.':'.$mask; 217 218 218 219 $old = $this->getRuleCIDR($type,$global,$ip,$mask); 219 220 $cur = $this->con->openCursor($this->table); 220 221 221 222 if ($old->isEmpty()) 222 223 { 223 224 $id = $this->con->select('SELECT MAX(rule_id) FROM '.$this->table)->f(0) + 1; 224 225 225 226 $cur->rule_id = $id; 226 227 $cur->rule_type = (string) $type; 227 228 $cur->rule_content = (string) $content; 228 229 229 230 if ($global && $this->core->auth->isSuperAdmin()) { 230 231 $cur->blog_id = null; … … 232 233 $cur->blog_id = $this->core->blog->id; 233 234 } 234 235 235 236 $cur->insert(); 236 237 } … … 242 243 } 243 244 } 244 245 245 246 private function getRules($type='all') 246 247 { … … 251 252 "AND (blog_id = '".$this->core->blog->id."' OR blog_id IS NULL) ". 252 253 'ORDER BY blog_id ASC, rule_content ASC '; 253 254 254 255 return $this->con->select($strReq); 255 256 } 256 257 257 258 private function getRuleCIDR($type,$global,$ip,$mask) 258 259 { … … 262 263 "AND rule_content LIKE '%:".(integer) $ip.":".(integer) $mask."' ". 263 264 'AND blog_id '.($global ? 'IS NULL ' : "= '".$this->core->blog->id."' "); 264 265 265 266 return $this->con->select($strReq); 266 267 } 267 268 268 269 private function checkIP($cip,$type) 269 270 { 270 271 $core =& $this->core; 271 272 272 273 $strReq = 273 274 'SELECT DISTINCT(rule_content) '. … … 276 277 "AND (blog_id = '".$this->core->blog->id."' OR blog_id IS NULL) ". 277 278 'ORDER BY rule_content ASC '; 278 279 279 280 $rs = $this->con->select($strReq); 280 281 while ($rs->fetch()) … … 287 288 return false; 288 289 } 289 290 290 291 private function removeRule($ids) 291 292 { 292 293 $strReq = 'DELETE FROM '.$this->table.' '; 293 294 294 295 if (is_array($ids)) { 295 296 foreach ($ids as $i => $v) { … … 301 302 $strReq .= 'WHERE rule_id = '.$ids.' '; 302 303 } 303 304 304 305 if (!$this->core->auth->isSuperAdmin()) { 305 306 $strReq .= "AND blog_id = '".$this->core->blog->id."' "; 306 307 } 307 308 308 309 $this->con->execute($strReq); 309 310 } 310 311 } 311 312 ?> 313 -
plugins/antispam/filters/class.dc.filter.iplookup.php
r0 r223 16 16 public $name = 'IP Lookup'; 17 17 public $has_gui = true; 18 18 19 19 private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 20 20 21 21 public function __construct($core) 22 22 { 23 23 parent::__construct($core); 24 24 25 25 if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 26 26 $this->has_gui = false; 27 27 } 28 28 } 29 29 30 30 protected function setInfo() 31 31 { 32 32 $this->description = __('Checks sender IP address against DNSBL servers'); 33 33 } 34 34 35 35 public function getStatusMessage($status,$comment_id) 36 36 { 37 37 return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status); 38 38 } 39 39 40 40 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 41 41 { … … 43 43 return; 44 44 } 45 45 46 46 $match = array(); 47 47 48 48 $bls = $this->getServers(); 49 49 $bls = preg_split('/\s*,\s*/',$bls); 50 50 51 51 foreach ($bls as $bl) 52 52 { … … 55 55 } 56 56 } 57 57 58 58 if (!empty($match)) { 59 59 $status = substr(implode(', ',$match),0,128); … … 61 61 } 62 62 } 63 63 64 64 public function gui($url) 65 65 { 66 66 $bls = $this->getServers(); 67 67 68 68 if (isset($_POST['bls'])) 69 69 { … … 76 76 } 77 77 } 78 78 79 79 /* DISPLAY 80 80 ---------------------------------------------- */ 81 81 $res = ''; 82 82 83 83 $res .= 84 84 '<form action="'.html::escapeURL($url).'" method="post">'. 85 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>'.86 '<p>'.'<label for="bls">'.__('Add here a coma separated list of servers.').'</label>'. 87 form::textarea('bls',40,3,html::escapeHTML($bls),'maximal').'</p>'. 88 88 '<p><input type="submit" value="'.__('Save').'" />'. 89 89 $this->core->formNonce().'</p>'. 90 90 '</fieldset>'. 91 91 '</form>'; 92 92 93 93 return $res; 94 94 } 95 95 96 96 private function getServers() 97 97 { … … 102 102 return $this->default_bls; 103 103 } 104 104 105 105 return $bls; 106 106 } 107 107 108 108 private function dnsblLookup($ip,$bl) 109 109 { 110 110 $revIp = implode('.',array_reverse(explode('.',$ip))); 111 111 112 112 $host = $revIp.'.'.$bl.'.'; 113 113 if (gethostbyname($host) != $host) { 114 114 return true; 115 115 } 116 116 117 117 return false; 118 118 } 119 119 } 120 120 ?> 121 -
plugins/antispam/filters/class.dc.filter.words.php
r3 r223 16 16 public $has_gui = true; 17 17 public $name = 'Bad Words'; 18 18 19 19 private $style_list = 'height: 200px; overflow: auto; margin-bottom: 1em; '; 20 20 private $style_p = 'margin: 1px 0 0 0; padding: 0.2em 0.5em; '; 21 21 private $style_global = 'background: #ccff99; '; 22 22 23 23 private $con; 24 24 private $table; 25 25 26 26 public function __construct($core) 27 27 { … … 30 30 $this->table = $core->prefix.'spamrule'; 31 31 } 32 32 33 33 protected function setInfo() 34 34 { 35 35 $this->description = __('Words Blacklist'); 36 36 } 37 37 38 38 public function getStatusMessage($status,$comment_id) 39 39 { 40 40 return sprintf(__('Filtered by %1$s with word %2$s.'),$this->guiLink(),'<em>'.$status.'</em>'); 41 41 } 42 42 43 43 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 44 44 { 45 45 $str = $author.' '.$email.' '.$site.' '.$content; 46 46 47 47 $rs = $this->getRules(); 48 48 49 49 while ($rs->fetch()) 50 50 { 51 51 $word = $rs->rule_content; 52 52 53 53 if (substr($word,0,1) == '/' && substr($word,-1,1) == '/') { 54 54 $reg = substr(substr($word,1),0,-1); … … 57 57 $reg = '(^|\s+|>|<)'.$reg.'(>|<|\s+|\.|$)'; 58 58 } 59 59 60 60 if (preg_match('/'.$reg.'/msiu',$str)) { 61 61 $status = $word; … … 64 64 } 65 65 } 66 66 67 67 public function gui($url) 68 68 { 69 69 $core =& $this->core; 70 70 71 71 # Create list 72 72 if (!empty($_POST['createlist'])) … … 79 79 } 80 80 } 81 81 82 82 # Adding a word 83 83 if (!empty($_POST['swa'])) 84 84 { 85 85 $globalsw = !empty($_POST['globalsw']) && $core->auth->isSuperAdmin(); 86 86 87 87 try { 88 88 $this->addRule($_POST['swa'],$globalsw); … … 92 92 } 93 93 } 94 94 95 95 # Removing spamwords 96 96 if (!empty($_POST['swd']) && is_array($_POST['swd'])) … … 103 103 } 104 104 } 105 105 106 106 /* DISPLAY 107 107 ---------------------------------------------- */ 108 108 $res = ''; 109 109 110 110 if (!empty($_GET['list'])) { 111 111 $res .= '<p class="message">'.__('Words have been successfully added.').'</p>'; … … 117 117 $res .= '<p class="message">'.__('Words have been successfully removed.').'</p>'; 118 118 } 119 119 120 120 $res .= 121 121 '<form action="'.html::escapeURL($url).'" method="post">'. 122 122 '<fieldset><legend>'.__('Add a word').'</legend>'. 123 '<p> '.form::field('swa',20,128).'';124 123 '<p><label class="classic" for="swa">'.__('Add a word').' '.form::field('swa',20,128).'</label>'; 124 125 125 if ($core->auth->isSuperAdmin()) { 126 $res .= '<label class="classic" >'.form::checkbox('globalsw',1).' '.126 $res .= '<label class="classic" for="globalsw">'.form::checkbox('globalsw',1).' '. 127 127 __('Global word').'</label> '; 128 128 } 129 129 130 130 $res .= 131 131 $core->formNonce(). … … 133 133 '</fieldset>'. 134 134 '</form>'; 135 135 136 136 $rs = $this->getRules(); 137 137 if ($rs->isEmpty()) … … 145 145 '<fieldset><legend>' . __('List') . '</legend>'. 146 146 '<div style="'.$this->style_list.'">'; 147 147 148 148 while ($rs->fetch()) 149 149 { … … 154 154 $p_style .= $this->style_global; 155 155 } 156 156 157 157 $res .= 158 158 '<p style="'.$p_style.'"><label class="classic">'. 159 form::checkbox(array('swd[]'),$rs->rule_id,false,'','',$disabled_word ).' '.159 form::checkbox(array('swd[]'),$rs->rule_id,false,'','',$disabled_word, 'title="'.html::escapeHTML($rs->rule_content).'"').' '. 160 160 html::escapeHTML($rs->rule_content). 161 161 '</label></p>'; 162 162 } 163 163 164 164 $res .= 165 165 '</div>'. … … 169 169 '</fieldset></form>'; 170 170 } 171 171 172 172 if ($core->auth->isSuperAdmin()) 173 173 { … … 180 180 '</form>'; 181 181 } 182 182 183 183 return $res; 184 184 } 185 185 186 186 private function getRules() 187 187 { … … 192 192 "OR blog_id IS NULL ) ". 193 193 'ORDER BY blog_id ASC, rule_content ASC '; 194 194 195 195 return $this->con->select($strReq); 196 196 } 197 197 198 198 private function addRule($content,$general=false) 199 199 { … … 202 202 "AND rule_content = '".$this->con->escape($content)."' "; 203 203 $rs = $this->con->select($strReq); 204 204 205 205 if (!$rs->isEmpty()) { 206 206 throw new Exception(__('This word exists')); 207 207 } 208 208 209 209 $rs = $this->con->select('SELECT MAX(rule_id) FROM '.$this->table); 210 210 $id = (integer) $rs->f(0) + 1; 211 211 212 212 $cur = $this->con->openCursor($this->table); 213 213 $cur->rule_id = $id; 214 214 $cur->rule_type = 'word'; 215 215 $cur->rule_content = (string) $content; 216 216 217 217 if ($general && $this->core->auth->isSuperAdmin()) { 218 218 $cur->blog_id = null; … … 220 220 $cur->blog_id = $this->core->blog->id; 221 221 } 222 222 223 223 $cur->insert(); 224 224 } 225 225 226 226 private function removeRule($ids) 227 227 { 228 228 $strReq = 'DELETE FROM '.$this->table.' '; 229 229 230 230 if (is_array($ids)) { 231 231 foreach ($ids as &$v) { … … 237 237 $strReq .= 'WHERE rule_id = '.$ids.' '; 238 238 } 239 239 240 240 if (!$this->core->auth->isSuperAdmin()) { 241 241 $strReq .= "AND blog_id = '".$this->con->escape($this->core->blog->id)."' "; 242 242 } 243 243 244 244 $this->con->execute($strReq); 245 245 } 246 246 247 247 public function defaultWordsList() 248 248 { … … 347 347 'zolus' 348 348 ); 349 349 350 350 foreach ($words as $w) { 351 351 try { … … 356 356 } 357 357 ?> 358 -
plugins/antispam/index.php
r3 r223 28 28 throw new Exception(__('Filter does not exist.')); 29 29 } 30 30 31 31 if (!$filters[$_GET['f']]->hasGUI()) { 32 32 throw new Exception(__('Filter has no user interface.')); 33 33 } 34 34 35 35 $filter = $filters[$_GET['f']]; 36 36 $filter_gui = $filter->gui($filter->guiURL()); 37 37 } 38 38 39 39 # Remove all spam 40 40 if (!empty($_POST['delete_all'])) 41 41 { 42 42 $ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone); 43 43 44 44 dcAntispam::delAllSpam($core,$ts); 45 45 http::redirect($p_url.'&del=1'); 46 46 } 47 47 48 48 # Update filters 49 49 if (isset($_POST['filters_upd'])) … … 55 55 $i++; 56 56 } 57 57 58 58 # Enable active filters 59 59 if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) { … … 62 62 } 63 63 } 64 64 65 65 # Order filters 66 66 if (!empty($_POST['f_order']) && empty($_POST['filters_order'])) … … 74 74 $order = explode(',',trim($_POST['filters_order'],',')); 75 75 } 76 76 77 77 if (isset($order)) { 78 78 foreach ($order as $i => $f) { … … 80 80 } 81 81 } 82 82 83 83 # Set auto delete flag 84 84 if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) { … … 87 87 } 88 88 } 89 89 90 90 dcAntispam::$filters->saveFilterOpts($filters_opt); 91 91 http::redirect($p_url.'&upd=1'); … … 116 116 echo '<p><a href="'.$p_url.'">'.__('Return to filters').'</a></p>'; 117 117 printf('<h3>'.__('%s configuration').'</h3>',$filter->name); 118 118 119 119 echo $filter_gui; 120 120 } … … 125 125 $published_count = dcAntispam::countPublishedComments($core); 126 126 $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; 127 127 128 128 echo 129 129 '<form action="'.$p_url.'" method="post">'. 130 130 '<fieldset><legend>'.__('Information').'</legend>'; 131 131 132 132 if (!empty($_GET['del'])) { 133 133 echo '<p class="message">'.__('Spam comments have been successfully deleted.').'</p>'; 134 134 } 135 135 136 136 echo 137 137 '<ul class="spaminfo">'. … … 141 141 $published_count.'</li>'. 142 142 '</ul>'; 143 143 144 144 if ($spam_count > 0) 145 145 { … … 153 153 } 154 154 echo '</fieldset></form>'; 155 156 155 156 157 157 # Filters 158 158 echo 159 159 '<form action="'.$p_url.'" method="post">'. 160 160 '<fieldset><legend>'.__('Available spam filters').'</legend>'; 161 161 162 162 if (!empty($_GET['upd'])) { 163 163 echo '<p class="message">'.__('Filters configuration has been successfully saved.').'</p>'; 164 164 } 165 165 166 166 echo 167 167 '<table class="dragable">'. … … 169 169 '<th>'.__('Order').'</th>'. 170 170 '<th>'.__('Active').'</th>'. 171 '<th>'.__('Auto Del.').'</th>'. 171 '<th>'.__('Auto Del.').'</th>'. 172 172 '<th class="nowrap">'.__('Filter name').'</th>'. 173 173 '<th colspan="2">'.__('Description').'</th>'. 174 174 '</tr></thead>'. 175 175 '<tbody id="filters-list" >'; 176 176 177 177 $i = 0; 178 178 foreach ($filters as $fid => $f) … … 185 185 'title="'.__('Filter configuration').'" /></a>'; 186 186 } 187 187 188 188 echo 189 189 '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'. 190 '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i ).'</td>'.191 '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active ).'</td>'.192 '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete ).'</td>'.190 '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, '', '', false, 'title="'.__('position').'"').'</td>'. 191 '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'. 192 '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'. 193 193 '<td class="nowrap">'.$f->name.'</td>'. 194 194 '<td class="maximal">'.$f->description.'</td>'. … … 203 203 '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'. 204 204 '</fieldset></form>'; 205 206 205 206 207 207 # Syndication 208 208 if (DC_ADMIN_URL) 209 209 { 210 $ham_feed = $core->blog->url.$core->url->getBase('hamfeed').'/'.$code = dcAntispam::getUserCode($core); 210 $ham_feed = $core->blog->url.$core->url->getBase('hamfeed').'/'.$code = dcAntispam::getUserCode($core); 211 211 $spam_feed = $core->blog->url.$core->url->getBase('spamfeed').'/'.$code = dcAntispam::getUserCode($core); 212 212 213 213 echo 214 214 '<fieldset><legend>'.__('Syndication').'</legend>'. … … 224 224 </body> 225 225 </html> 226
Note: See TracChangeset
for help on using the changeset viewer.