Attachment 'usage.py'
Download 1 # Add to moin config
2
3 # Security policy
4 # Tested only with moin 1.1
5 try:
6 import cPickle as pickle
7 except ImportError:
8 import pickle
9 from blacklist import blacklist
10 from MoinMoin import security
11
12
13 class SecurityPolicy(security.Default):
14 def __init__(self, user):
15 security.Default.__init__(self, user)
16 self.loadBlacklist()
17
18 def edit(self, pagename, **kw):
19 """ Extend the default edit permissions """
20
21 # blacklist only non users
22 if not self.user.valid and hasattr(self, 'blacklist'):
23 # Needed for moin 1.1 compatibility
24 if not hasattr(self.user._request, 'remote_addr'):
25 import os
26 self.user._request.remote_addr = os.environ.get('REMOTE_ADDR', '')
27 # Blacklist
28 if self.user._request.remote_addr in self.blacklist:
29 return 0
30
31 # Use standard permissions
32 return security.Default.edit(self, pagename, **kw)
33
34 def loadBlacklist(self):
35 """ Load data from file or wiki page """
36 import sys
37 blacklistFile = 'blacklist.cache'
38 try:
39 self.blacklist = pickle.load(file(blacklistFile))
40 except (IOError, OSError, pickle.UnpicklingError), why:
41 # Read the data from a text file, or better from
42 # a wiki page.
43 sys.stderr.write('load blacklist failed %s:' % str(why))
44 text = file('blacklist.txt').read()
45 self.blacklist = blacklist.BlackList(text)
46 try:
47 pickle.dump(self.blacklist, file(blacklistFile, 'w'))
48 except (IOError, pickle.PicklingError), why:
49 sys.stderr.write('cache blacklist failed: %s' % str(why))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.