Ticket #8406: Extlinks-with-whitelist.diff
| File Extlinks-with-whitelist.diff, 1.5 KB (added by Sven, 3 years ago) |
|---|
-
tracspamfilter/filters/extlinks.py
13 13 14 14 import re 15 15 16 from trac.config import IntOption16 from trac.config import ListOption, IntOption 17 17 from trac.core import * 18 18 from tracspamfilter.api import IFilterStrategy 19 19 from tracspamfilter.model import LogEntry … … 33 33 """The maximum number of external links allowed in a submission until 34 34 that submission gets negative karma.""") 35 35 36 allowed_domains = ListOption('spam-filter', 'extlinks_allowed_domains', 37 'example.com, example.org', doc= 38 """List of domains that should be allowed in external links""") 39 36 40 _URL_RE = re.compile('https?://([^/]+)/?', re.IGNORECASE) 37 41 38 42 # IFilterStrategy methods 39 43 40 44 def test(self, req, author, content): 41 45 num_ext = 0 46 allowed = self.allowed_domains 47 allowed.append(req.get_header('Host')) 48 42 49 for host in self._URL_RE.findall(content): 43 if host != req.get_header('Host'): 50 if host not in allowed: 51 self.env.log.debug('"%s" is not in extlink_allowed_domains' % host) 44 52 num_ext += 1 53 else: 54 self.env.log.debug('"%s" is whitelisted.' % host) 45 55 46 56 if num_ext > self.max_links: 47 57 return -abs(self.karma_points) * num_ext / self.max_links, \
