Skip to content
Newer
Older
100644 111 lines (91 sloc) 4.02 KB
ff20af9 @alobbs Adds the new admin
alobbs authored Apr 18, 2010
1 # -*- coding: utf-8 -*-
2 #
3 # Cherokee-admin
4 #
5 # Authors:
6 # Alvaro Lopez Ortega <alvaro@alobbs.com>
7 #
8 # Copyright (C) 2010 Alvaro Lopez Ortega
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of version 2 of the GNU General Public
12 # License as published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23 #
24
25 import CTK
26 import Auth
27 import validations
28
29 URL_APPLY = '/plugin/authlist/apply'
30 HELPS = [('modules_validators_authlist', _("Fixed list"))]
31
32 NOTE_EMPTY = N_("At least one user/password pair should be configured.")
33
34
35 def commit():
36 new_user = CTK.post.pop('tmp!new_user')
37 new_pass = CTK.post.pop('tmp!new_pass')
38 key = CTK.post.pop('key')
39
40 # New
41 if new_user:
42 next = CTK.cfg.get_next_entry_prefix (key)
43 CTK.cfg['%s!user'%(next)] = new_user
44 CTK.cfg['%s!password'%(next)] = new_pass
45 return CTK.cfg_reply_ajax_ok()
46
47 # Modification
48 return CTK.cfg_apply_post()
49
50
51 class Plugin_authlist (Auth.PluginAuth):
52 class Content (CTK.Container):
53 def __init__ (self, refresh, key):
54 CTK.Container.__init__ (self)
55
56 keys = CTK.cfg.keys ('%s!list'%(key))
57 keys.sort(lambda x,y: cmp(int(x), int(y)))
58
59 if keys:
60 self += CTK.RawHTML ("<h3>%s</h3>" % (_('Authentication list')))
72d6c0f @ionmx Style for auth list
ionmx authored May 9, 2010
61 table = CTK.Table({'id': 'authlist-table'})
ff20af9 @alobbs Adds the new admin
alobbs authored Apr 18, 2010
62 table.set_header (1)
72d6c0f @ionmx Style for auth list
ionmx authored May 9, 2010
63 table += [CTK.RawHTML(x) for x in (_('User'), _('Password'),'')]
ff20af9 @alobbs Adds the new admin
alobbs authored Apr 18, 2010
64 for c in keys:
65 pre = '%s!list!%s'%(key, c)
66 user = CTK.RawHTML (CTK.cfg.get_val('%s!user' %(pre)))
67 passwd = CTK.RawHTML (CTK.cfg.get_val('%s!password' %(pre)))
68 remove = None
69 if len(keys) >= 2:
70 remove = CTK.ImageStock('del')
71 remove.bind('click', CTK.JS.Ajax (URL_APPLY,
72 data = {pre: ''},
73 complete = refresh.JS_to_refresh()))
74 table += [user, passwd, remove]
75 self += CTK.Indenter (table)
76 else:
77 self += CTK.Indenter (CTK.Notice ('information', CTK.RawHTML(_(NOTE_EMPTY))))
78
79 def __init__ (self, key, **kwargs):
80 Auth.PluginAuth.__init__ (self, key, **kwargs)
81 self.AddCommon (supported_methods=('basic','digest'))
82
83 # List
84 refresh = CTK.Refreshable ({'id': 'authlist'})
85 refresh.register (lambda: self.Content(refresh, key).Render())
86
87 self += CTK.RawHTML ("<h2>%s</h2>" % (_('Fixed Authentication List')))
88 self += refresh
89
90 # New
91 new_user = CTK.TextField({'name': 'tmp!new_user', 'class': 'noauto'})
92 new_pass = CTK.TextField({'name': 'tmp!new_pass', 'class': 'noauto'})
93 new_add = CTK.SubmitterButton (_('Add'))
94
95 table = CTK.Table()
96 table.set_header(1)
97 table += [CTK.RawHTML(x) for x in (_('User'), _('Password'))]
98 table += [new_user, new_pass, new_add]
99
100 submit = CTK.Submitter (URL_APPLY)
101 submit += CTK.Hidden ('key', '%s!list'%(key))
102 submit += table
103 submit.bind ('submit_success', refresh.JS_to_refresh() + new_user.JS_to_clean() + new_pass.JS_to_clean())
104
105 self += CTK.RawHTML ("<h3>%s</h3>" % (_('Add New Pair')))
106 self += CTK.Indenter (submit)
107
108 # Publish
109 VALS = [("%s!passwdfile"%(self.key), validations.is_local_file_exists)]
110 CTK.publish ('^%s'%(URL_APPLY), commit, validation=VALS, method="POST")
Something went wrong with that request. Please try again.