Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (63 sloc) 2.671 kB
ff20af9 @alobbs Adds the new admin
alobbs authored
1 # Cheroke Admin: RRD plug-in
2 #
3 # Authors:
4 # Alvaro Lopez Ortega <alvaro@alobbs.com>
5 #
6 # Copyright (C) 2009-2010 Alvaro Lopez Ortega
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of version 2 of the GNU General Public
10 # License as published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21 #
22
23 import CTK
24
25 from Rule import RulePlugin
26 from util import *
27
28 URL_APPLY = '/plugin/%s/apply'
29
30 def apply (extension):
31 # POST info
32 key = CTK.post.pop ('key', None)
33 vsrv_num = CTK.post.pop ('vsrv_num', None)
34 new_val = CTK.post.pop ('tmp!%s'%(extension), None)
35
36 # New
37 if new_val:
38 next_rule, next_pre = cfg_vsrv_rule_get_next ('vserver!%s'%(vsrv_num))
39
40 CTK.cfg['%s!match'%(next_pre)] = extension
41 CTK.cfg['%s!match!%s'%(next_pre, extension)] = new_val
42
43 return {'ret': 'ok', 'redirect': '/vserver/%s/rule/%s' %(vsrv_num, next_rule)}
44
45 # Modifications
46 return CTK.cfg_apply_post()
47
48
49 class PluginSimple (RulePlugin):
50 def __init__ (self, key, title, extension, note, name_desc, validation_fn=None, **kwargs):
51 RulePlugin.__init__ (self, key)
52
53 self.extension = extension
54 self.name_desc = name_desc
55
56 url_apply = URL_APPLY %(extension)
57 props = ({},{'class': 'noauto'})[key.startswith('tmp')]
58
59 table = CTK.PropsTable()
60 table.Add (title, CTK.TextCfg('%s!%s'%(key, extension), False, props), note)
61
62 submit = CTK.Submitter (url_apply)
63 submit += CTK.Hidden ('key', key)
64 submit += CTK.Hidden ('vsrv_num', kwargs.pop('vsrv_num', ''))
65 submit += table
66 self += submit
67
68 # Build validation
69 if validation_fn:
70 validation = [('tmp!%s'%(extension), validation_fn),
71 ('vserver![\d]+!rule![\d]+!match!%s'%(extension), validation_fn)]
72 else:
73 validation = []
74
75 # Public URL
e09f720 @alobbs Seeding random() once is enough.
alobbs authored
76 CTK.publish ('^%s'%(url_apply), apply, method="POST", validation=validation, extension=extension)
ff20af9 @alobbs Adds the new admin
alobbs authored
77
78 def GetName (self):
79 value = CTK.cfg.get_val ('%s!%s' %(self.key, self.extension), '')
80 return "%s %s" %(self.name_desc, value)
Something went wrong with that request. Please try again.