Changeset 2566:9bf417837888 for plugins/antispam
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- Location:
- plugins/antispam
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/antispam/_admin.php
r2330 r2566 96 96 '</div>'; 97 97 } 98 98 99 99 public static function adminBeforeBlogSettingsUpdate($settings) 100 100 { … … 103 103 } 104 104 } 105 ?> -
plugins/antispam/_define.php
r1179 r2566 22 22 ) 23 23 ); 24 ?> -
plugins/antispam/_install.php
r1179 r2566 26 26 ->rule_type ('varchar', 16, false, "'word'") 27 27 ->rule_content ('varchar', 128, false) 28 28 29 29 ->primary('pk_spamrule','rule_id') 30 30 ; … … 54 54 $core->setVersion('antispam',$version); 55 55 return true; 56 ?> -
plugins/antispam/_public.php
r1179 r2566 15 15 $core->addBehavior('publicBeforeTrackbackCreate',array('dcAntispam','isSpam')); 16 16 $core->addBehavior('publicBeforeDocument',array('dcAntispam','purgeOldSpam')); 17 ?> -
plugins/antispam/filters/class.dc.filter.ip.php
r2322 r2566 321 321 } 322 322 } 323 ?> -
plugins/antispam/filters/class.dc.filter.iplookup.php
r2322 r2566 114 114 } 115 115 } 116 ?> -
plugins/antispam/filters/class.dc.filter.linkslookup.php
r1366 r2566 15 15 { 16 16 public $name = 'Links Lookup'; 17 17 18 18 private $server = 'multi.surbl.org'; 19 19 20 20 protected function setInfo() 21 21 { 22 22 $this->description = __('Checks links in comments against surbl.org'); 23 23 } 24 24 25 25 public function getStatusMessage($status,$comment_id) 26 26 { 27 27 return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status); 28 28 } 29 29 30 30 public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 31 31 { … … 33 33 return; 34 34 } 35 35 36 36 $urls = $this->getLinks($content); 37 37 array_unshift($urls,$site); 38 38 39 39 foreach ($urls as $u) 40 40 { … … 53 53 $host = $domain_elem[$i - 1].'.'.$host; 54 54 $i--; 55 if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) 55 if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) 56 56 { 57 57 $status = substr($domain,0,128); 58 58 return true; 59 } 59 } 60 60 } while ($i > 0); 61 61 } 62 62 } 63 63 64 64 private function getLinks($text) 65 65 { … … 70 70 } 71 71 } 72 ?> -
plugins/antispam/filters/class.dc.filter.words.php
r2322 r2566 362 362 } 363 363 } 364 ?> -
plugins/antispam/inc/class.dc.spamfilter.php
r2322 r2566 20 20 public $auto_delete = false; 21 21 public $help = null; 22 22 23 23 protected $has_gui = false; 24 24 protected $gui_url = null; 25 25 26 26 protected $core; 27 27 28 28 /** 29 29 Object constructor 30 30 31 31 @param core <b>dcCore</b> Dotclear core object 32 32 */ … … 35 35 $this->core =& $core; 36 36 $this->setInfo(); 37 37 38 38 if (!$this->name) { 39 39 $this->name = get_class($this); 40 40 } 41 41 42 42 $this->gui_url = 'plugin.php?p=antispam&f='.get_class($this); 43 43 } 44 44 45 45 /** 46 46 This method is called by the constructor and allows you to change some … … 51 51 $this->description = __('No description'); 52 52 } 53 53 54 54 /** 55 55 This method should return if a comment is a spam or not. If it returns true 56 56 or false, execution of next filters will be stoped. If should return nothing 57 57 to let next filters apply. 58 58 59 59 Your filter should also fill $status variable with its own information if 60 60 comment is a spam. 61 61 62 62 @param type <b>string</b> Comment type (comment or trackback) 63 63 @param author <b>string</b> Comment author … … 73 73 { 74 74 } 75 75 76 76 /** 77 77 This method is called when a non-spam (ham) comment becomes spam or when a 78 78 spam becomes a ham. 79 79 80 80 @param type <b>string</b> Comment type (comment or trackback) 81 81 @param filter <b>string</b> Filter name … … 92 92 { 93 93 } 94 94 95 95 /** 96 96 This method returns filter status message. You can overload this method to 97 97 return a custom message. Message is shown in comment details and in 98 98 comments list. 99 99 100 100 @param status <b>string</b> Filter status. 101 101 @param comment_id <b>record</b> Comment record … … 106 106 return sprintf(__('Filtered by %1$s (%2$s)'),$this->guiLink(),$status); 107 107 } 108 108 109 109 /** 110 110 This method is called when you enter filter configuration. Your class should 111 111 have $has_gui property set to "true" to enable GUI. 112 112 113 113 In this method you should put everything related to filter configuration. 114 114 $url variable is the URL of GUI <i>unescaped</i>. 115 115 116 116 @param url <b>string</b> GUI URL. 117 117 */ … … 119 119 { 120 120 } 121 121 122 122 public function hasGUI() 123 123 { … … 125 125 return false; 126 126 } 127 127 128 128 if (!$this->has_gui) { 129 129 return false; 130 130 } 131 131 132 132 return true; 133 133 } 134 134 135 135 public function guiURL() 136 136 { … … 138 138 return false; 139 139 } 140 140 141 141 return $this->gui_url; 142 142 } 143 143 144 144 /** 145 145 Returns a link to filter GUI if exists or only filter name if has_gui 146 146 property is false. 147 147 148 148 @return <b>string</b> 149 149 */ … … 156 156 $link = '%1$s'; 157 157 } 158 158 159 159 return sprintf($link,$this->name,$url); 160 160 } … … 164 164 } 165 165 } 166 ?> -
plugins/antispam/inc/class.dc.spamfilters.php
r1179 r2566 17 17 private $filters_opt = array(); 18 18 private $core; 19 19 20 20 public function __construct($core) 21 21 { 22 22 $this->core =& $core; 23 23 } 24 24 25 25 public function init($filters) 26 26 { … … 30 30 continue; 31 31 } 32 32 33 33 $r = new ReflectionClass($f); 34 34 $p = $r->getParentClass(); 35 35 36 36 if (!$p || $p->name != 'dcSpamFilter') { 37 37 continue; 38 38 } 39 39 40 40 $this->filters[$f] = new $f($this->core); 41 41 } 42 42 43 43 $this->setFilterOpts(); 44 44 if (!empty($this->filters_opt)) { … … 46 46 } 47 47 } 48 48 49 49 public function getFilters() 50 50 { 51 51 return $this->filters; 52 52 } 53 53 54 54 public function isSpam($cur) 55 55 { … … 59 59 continue; 60 60 } 61 61 62 62 $type = $cur->comment_trackback ? 'trackback' : 'comment'; 63 63 $author = $cur->comment_author; … … 67 67 $content = $cur->comment_content; 68 68 $post_id = $cur->post_id; 69 69 70 70 $is_spam = $f->isSpam($type,$author,$email,$site,$ip,$content,$post_id,$status); 71 71 72 72 if ($is_spam === true) { 73 73 if ($f->auto_delete) { … … 83 83 } 84 84 } 85 85 86 86 return false; 87 87 } 88 88 89 89 public function trainFilters($rs,$status,$filter_name) 90 90 { … … 94 94 continue; 95 95 } 96 96 97 97 $type = $rs->comment_trackback ? 'trackback' : 'comment'; 98 98 $author = $rs->comment_author; … … 101 101 $ip = $rs->comment_ip; 102 102 $content = $rs->comment_content; 103 103 104 104 $f->trainFilter($status,$filter_name,$type,$author,$email,$site,$ip,$content,$rs); 105 105 } 106 106 } 107 107 108 108 public function statusMessage($rs,$filter_name) 109 109 { 110 110 $f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null; 111 111 112 112 if ($f === null) 113 113 { … … 117 117 { 118 118 $status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null; 119 119 120 120 return $f->getStatusMessage($status,$rs->comment_id); 121 121 } 122 122 } 123 123 124 124 public function saveFilterOpts($opts,$global=false) 125 125 { … … 130 130 $this->core->blog->settings->antispam->put('antispam_filters',serialize($opts),'string','Antispam Filters',true,$global); 131 131 } 132 132 133 133 private function setFilterOpts() 134 134 { … … 136 136 $this->filters_opt = @unserialize($this->core->blog->settings->antispam->antispam_filters); 137 137 } 138 138 139 139 # Create default options if needed 140 140 if (!is_array($this->filters_opt)) { … … 142 142 $this->filters_opt = array(); 143 143 } 144 144 145 145 foreach ($this->filters_opt as $k => $o) 146 146 { 147 if (isset($this->filters[$k]) && is_array($o)) { 147 if (isset($this->filters[$k]) && is_array($o)) { 148 148 $this->filters[$k]->active = isset($o[0])?$o[0]:false; 149 149 $this->filters[$k]->order = isset($o[1])?$o[1]:0; … … 152 152 } 153 153 } 154 154 155 155 private function orderCallBack($a,$b) 156 156 { … … 158 158 return 0; 159 159 } 160 160 161 161 return $a->order > $b->order ? 1 : -1; 162 162 } 163 163 } 164 ?> -
plugins/antispam/inc/lib.dc.antispam.php
r1478 r2566 15 15 { 16 16 public static $filters; 17 17 18 18 public static function initFilters() 19 19 { 20 20 global $core; 21 21 22 22 if (!isset($core->spamfilters)) { 23 23 return; 24 24 } 25 25 26 26 self::$filters = new dcSpamFilters($core); 27 27 self::$filters->init($core->spamfilters); 28 28 } 29 29 30 30 public static function isSpam($cur) 31 31 { … … 33 33 self::$filters->isSpam($cur); 34 34 } 35 35 36 36 public static function trainFilters($blog,$cur,$rs) 37 37 { … … 41 41 $status = 'spam'; 42 42 } 43 43 44 44 # From spam to ham 45 45 if ($rs->comment_status == -2 && $cur->comment_status == 1) { 46 46 $status = 'ham'; 47 47 } 48 48 49 49 # the status of this comment has changed 50 50 if ($status) 51 51 { 52 52 $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 53 53 54 54 self::initFilters(); 55 55 self::$filters->trainFilters($rs,$status,$filter_name); 56 56 } 57 57 } 58 58 59 59 public static function statusMessage($rs) 60 60 { … … 62 62 { 63 63 $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 64 64 65 65 self::initFilters(); 66 66 67 67 return 68 68 '<p><strong>'.__('This comment is a spam:').'</strong> '. … … 70 70 } 71 71 } 72 72 73 73 public static function dashboardIcon($core, $icons) 74 74 { … … 78 78 } 79 79 } 80 80 81 81 public static function dashboardIconTitle($core) 82 82 { … … 88 88 } 89 89 } 90 90 91 91 public static function countSpam($core) 92 92 { 93 93 return $core->blog->getComments(array('comment_status'=>-2),true)->f(0); 94 94 } 95 95 96 96 public static function countPublishedComments($core) 97 97 { 98 98 return $core->blog->getComments(array('comment_status'=>1),true)->f(0); 99 99 } 100 100 101 101 public static function delAllSpam($core, $beforeDate = null) 102 102 { … … 110 110 $strReq .= 'AND comment_dt < \''.$beforeDate.'\' '; 111 111 } 112 112 113 113 $rs = $core->con->select($strReq); 114 114 $r = array(); … … 116 116 $r[] = (integer) $rs->comment_id; 117 117 } 118 118 119 119 if (empty($r)) { 120 120 return; 121 121 } 122 122 123 123 $strReq = 124 124 'DELETE FROM '.$core->prefix.'comment '. 125 125 'WHERE comment_id '.$core->con->in($r).' '; 126 126 127 127 $core->con->execute($strReq); 128 128 } 129 129 130 130 public static function getUserCode($core) 131 131 { … … 135 135 return bin2hex($code); 136 136 } 137 137 138 138 public static function checkUserCode($core,$code) 139 139 { 140 140 $code = pack('H*',$code); 141 141 142 142 $user_id = trim(@pack('a32',substr($code,0,32))); 143 143 $pwd = @unpack('H40hex',substr($code,32,40)); 144 144 145 145 if ($user_id === false || $pwd === false) { 146 146 return false; 147 147 } 148 148 149 149 $pwd = $pwd['hex']; 150 150 151 151 $strReq = 'SELECT user_id, user_pwd '. 152 152 'FROM '.$core->prefix.'user '. 153 153 "WHERE user_id = '".$core->con->escape($user_id)."' "; 154 154 155 155 $rs = $core->con->select($strReq); 156 156 157 157 if ($rs->isEmpty()) { 158 158 return false; 159 159 } 160 160 161 161 if (crypt::hmac(DC_MASTER_KEY,$rs->user_pwd) != $pwd) { 162 162 return false; 163 163 } 164 164 165 165 $permissions = $core->getBlogPermissions($core->blog->id); 166 166 167 167 if ( empty($permissions[$rs->user_id]) ) { 168 168 return false; 169 169 } 170 170 171 171 return $rs->user_id; 172 172 } 173 173 174 174 public static function purgeOldSpam($core) 175 175 { … … 177 177 $defaultModerationTTL = '7'; 178 178 $init = false; 179 179 180 180 // settings 181 181 $core->blog->settings->addNamespace('antispam'); 182 182 183 183 $dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge; 184 184 if ($dateLastPurge === null) { … … 192 192 $moderationTTL = $defaultModerationTTL; 193 193 } 194 194 195 195 if ($moderationTTL < 0) { 196 196 // disabled 197 197 return; 198 198 } 199 199 200 200 // we call the purge every day 201 201 if ((time()-$dateLastPurge) > (86400)) { … … 203 203 if (!$init) { 204 204 $core->blog->settings->antispam->put('antispam_date_last_purge',time(),null,null,true,false); 205 } 205 } 206 206 $date = date('Y-m-d H:i:s', time() - $moderationTTL*86400); 207 207 dcAntispam::delAllSpam($core, $date); … … 209 209 } 210 210 } 211 ?> -
plugins/antispam/inc/lib.dc.antispam.url.php
r1179 r2566 18 18 self::genFeed('ham',$args); 19 19 } 20 20 21 21 public static function spamFeed($args) 22 22 { 23 23 self::genFeed('spam',$args); 24 24 } 25 25 26 26 private static function genFeed($type,$args) 27 27 { 28 28 global $core; 29 29 $user_id = dcAntispam::checkUserCode($core,$args); 30 30 31 31 if ($user_id === false) { 32 32 self::p404(); 33 33 return; 34 34 } 35 35 36 36 $core->auth->checkUser($user_id,null,null); 37 37 38 38 header('Content-Type: application/xml; charset=UTF-8'); 39 39 40 40 $title = $core->blog->name.' - '.__('Spam moderation'). ' - '; 41 41 $params = array(); … … 49 49 $params['sql'] = ' AND comment_status IN (1,-1) '; 50 50 } 51 51 52 52 echo 53 53 '<?xml version="1.0" encoding="utf-8"?>'."\n". … … 59 59 '<link>'.(DC_ADMIN_URL ? DC_ADMIN_URL.'comments.php'.$end_url : 'about:blank').'</link>'."\n". 60 60 '<description></description>'."\n"; 61 61 62 62 $rs = $core->blog->getComments($params); 63 63 $maxitems = 20; 64 $nbitems = 0; 65 64 $nbitems = 0; 65 66 66 while ($rs->fetch() && ($nbitems < $maxitems)) 67 67 { … … 74 74 } 75 75 $id = $rs->getFeedID(); 76 76 77 77 $content = '<p>IP: '.$rs->comment_ip; 78 78 79 79 if (trim($rs->comment_site)) { 80 80 $content .= '<br />URL: <a href="'.$rs->comment_site.'">'.$rs->comment_site.'</a>'; … … 82 82 $content .= "</p><hr />\n"; 83 83 $content .= $rs->comment_content; 84 84 85 85 echo 86 86 '<item>'."\n". 87 ' <title>'.html::escapeHTML($title).'</title>'."\n". 87 ' <title>'.html::escapeHTML($title).'</title>'."\n". 88 88 ' <link>'.$uri.'</link>'."\n". 89 89 ' <guid>'.$id.'</guid>'."\n". 90 90 ' <pubDate>'.$rs->getRFC822Date().'</pubDate>'."\n". 91 91 ' <dc:creator>'.html::escapeHTML($author).'</dc:creator>'."\n". 92 ' <description>'.html::escapeHTML($content).'</description>'."\n". 92 ' <description>'.html::escapeHTML($content).'</description>'."\n". 93 93 '</item>'; 94 94 } 95 96 echo "</channel>\n</rss>"; 95 96 echo "</channel>\n</rss>"; 97 97 } 98 98 } 99 ?>
Note: See TracChangeset
for help on using the changeset viewer.