root/cherokee/trunk/admin/ModuleAuth.py

Revision 2094, 1.7 kB (checked in by alo, 2 months ago)

--

Line 
1 import validations
2
3 from Form import *
4 from Table import *
5 from Module import *
6 from consts import *
7
8 DATA_VALIDATION = [
9     ('vserver!.*?!(directory|extensions|request)!.*?!auth!users', validations.is_safe_id_list)
10 ]
11
12 NOTE_METHODS = 'Allowed HTTP Authentication methods.'
13 NOTE_REALM   = 'Name associated with the protected resource.'
14 NOTE_USERS   = 'User filter. List of allowed users.'
15
16 class ModuleAuthBase (Module, FormHelper):
17     PROPERTIES = [
18         'methods',
19         'realm',
20         'users'
21     ]
22
23     def __init__ (self, cfg, prefix, name, submit):
24         FormHelper.__init__ (self, name, cfg)
25         Module.__init__ (self, name, cfg, prefix, submit)
26
27     def _op_render (self):
28         txt = ''
29
30         if len(self.METHODS) > 1:
31             methods = VALIDATOR_METHODS
32         else:
33             method = self.METHODS[0]
34             methods = filter (lambda x,m=method: x[0] == method, VALIDATOR_METHODS)
35
36         table = TableProps()
37         self.AddPropOptions_Reload (table, "Methods", "%s!methods"%(self._prefix), methods, NOTE_METHODS)
38         self.AddPropEntry   (table, "Realm",   "%s!realm"  %(self._prefix), NOTE_REALM)
39         self.AddPropEntry   (table, "Users",   "%s!users"  %(self._prefix), NOTE_USERS)
40
41         txt += "<h2>Authentication Details</h2>"
42         txt += self.Indent(table)
43         return txt
44
45     def _op_apply_changes (self, uri, post):
46         # Check Realm
47         pre = '%s!realm' % (self._prefix)
48         self.Validate_NotEmpty (post, pre, 'Realm can not be empty')
49
50         # Auto-methods
51         if len(self.METHODS) <= 1:
52             self._cfg['%s!methods'%(self._prefix)] = self.METHODS[0]
53
54         # the rest
55         self.ApplyChanges ([], post, DATA_VALIDATION)
Note: See TracBrowser for help on using the browser.