Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.security.antispam.SecurityPolicy Class Reference
Inheritance diagram for MoinMoin.security.antispam.SecurityPolicy:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.security.antispam.SecurityPolicy:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def save
def __getattr__

Public Attributes

 name
 request

Detailed Description

Extend the default security policy with antispam feature 

Definition at line 135 of file antispam.py.


Member Function Documentation

def MoinMoin.security.Permissions.__getattr__ (   self,
  attr 
) [inherited]
Shortcut to export getPermission function for all known ACL rights

if attr is one of the rights in acl_rights_valid, then return a
checking function for it. Else raise an AttributeError.

@param attr: one of ACL rights as defined in acl_rights_valid
@rtype: function
@return: checking function for that right, accepting a pagename

Definition at line 137 of file __init__.py.

00137 
00138     def __getattr__(self, attr):
00139         """ Shortcut to export getPermission function for all known ACL rights
00140 
00141         if attr is one of the rights in acl_rights_valid, then return a
00142         checking function for it. Else raise an AttributeError.
00143 
00144         @param attr: one of ACL rights as defined in acl_rights_valid
00145         @rtype: function
00146         @return: checking function for that right, accepting a pagename
00147         """
00148         request = self.request
00149         if attr not in request.cfg.acl_rights_valid:
00150             raise AttributeError, attr
00151         return lambda pagename: _check(self.request, pagename, self.name, attr)
00152 
00153 
# make an alias for the default policy

Here is the call graph for this function:

def MoinMoin.security.antispam.SecurityPolicy.save (   self,
  editor,
  newtext,
  rev,
  kw 
)
Check whether user may save a page.

`editor` is the PageEditor instance, the other arguments are
those of the `PageEditor.saveText` method.

@param editor: PageEditor instance.
@param newtext: new page text, you can enable of disable saving according
    to the content of the text, e.g. prevent link spam.
@param rev: new revision number? XXX
@param kw: XXX
@rtype: bool
@return: True if you can save or False

Reimplemented from MoinMoin.security.Permissions.

Definition at line 138 of file antispam.py.

00138 
00139     def save(self, editor, newtext, rev, **kw):
00140         BLACKLISTPAGES = ["BadContent", "LocalBadContent"]
00141         if not editor.page_name in BLACKLISTPAGES:
00142             request = editor.request
00143 
00144             # Start timing of antispam operation
00145             request.clock.start('antispam')
00146 
00147             blacklist = []
00148             latest_mtime = 0
00149             for pn in BLACKLISTPAGES:
00150                 do_update = (pn != "LocalBadContent" and
00151                              request.cfg.interwikiname != 'MoinMaster') # MoinMaster wiki shall not fetch updates from itself
00152                 blacklist_mtime, blacklist_entries = getblacklist(request, pn, do_update)
00153                 blacklist += blacklist_entries
00154                 latest_mtime = max(latest_mtime, blacklist_mtime)
00155 
00156             if blacklist:
00157                 invalid_cache = not getattr(request.cfg.cache, "antispam_blacklist", None)
00158                 if invalid_cache or request.cfg.cache.antispam_blacklist[0] < latest_mtime:
00159                     mmblcache = []
00160                     for blacklist_re in blacklist:
00161                         try:
00162                             mmblcache.append(re.compile(blacklist_re, re.I))
00163                         except re.error, err:
00164                             logging.error("Error in regex '%s': %s. Please check the pages %s." % (
00165                                           blacklist_re,
00166                                           str(err),
00167                                           ', '.join(BLACKLISTPAGES)))
00168                     request.cfg.cache.antispam_blacklist = (latest_mtime, mmblcache)
00169 
00170                 from MoinMoin.Page import Page
00171 
00172                 oldtext = ""
00173                 if rev > 0: # rev is the revision of the old page
00174                     page = Page(request, editor.page_name, rev=rev)
00175                     oldtext = page.get_raw_body()
00176 
00177                 newset = frozenset(newtext.splitlines(1))
00178                 oldset = frozenset(oldtext.splitlines(1))
00179                 difference = newset - oldset
00180                 addedtext = kw.get('comment', u'') + u''.join(difference)
00181 
00182                 for blacklist_re in request.cfg.cache.antispam_blacklist[1]:
00183                     match = blacklist_re.search(addedtext)
00184                     if match:
00185                         # Log error and raise SaveError, PageEditor should handle this.
00186                         _ = editor.request.getText
00187                         msg = _('Sorry, can not save page because "%(content)s" is not allowed in this wiki.') % {
00188                                   'content': wikiutil.escape(match.group())
00189                               }
00190                         logging.info(msg)
00191                         raise editor.SaveError(msg)
00192             request.clock.stop('antispam')
00193 
00194         # No problem to save if my base class agree
00195         return Permissions.save(self, editor, newtext, rev, **kw)
00196 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 118 of file __init__.py.

Definition at line 119 of file __init__.py.


The documentation for this class was generated from the following file: