mirror of
https://github.com/Yubico/yubiadmin.git
synced 2024-11-29 10:24:11 +01:00
Added form for dbconfig-common files.
This commit is contained in:
parent
86c45089ed
commit
a2037d8c63
@ -1,9 +1,11 @@
|
|||||||
|
from yubiadmin.util import App, DBConfigForm
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'app'
|
'app'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class YubikeyKsm(object):
|
class YubikeyKsm(App):
|
||||||
"""
|
"""
|
||||||
YubiKey Key Storage Module
|
YubiKey Key Storage Module
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ class YubikeyKsm(object):
|
|||||||
"""
|
"""
|
||||||
Database Settings
|
Database Settings
|
||||||
"""
|
"""
|
||||||
return "Hello world"
|
return self.render_forms(request, [
|
||||||
|
DBConfigForm('/etc/yubico/ksm/config-db.php')])
|
||||||
|
|
||||||
app = YubikeyKsm()
|
app = YubikeyKsm()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from wtforms.fields import StringField, IntegerField, PasswordField
|
from wtforms.fields import IntegerField
|
||||||
from wtforms.validators import NumberRange, Optional
|
from wtforms.validators import NumberRange
|
||||||
from wtforms.widgets import PasswordInput
|
from yubiadmin.util import App, DBConfigForm, ConfigForm, FileConfig
|
||||||
from yubiadmin.util import App, ConfigForm, FileConfig, render
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'app'
|
'app'
|
||||||
@ -78,29 +77,6 @@ class MiscForm(ConfigForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DatabaseForm(ConfigForm):
|
|
||||||
legend = 'Database'
|
|
||||||
dbtype = StringField('DB type')
|
|
||||||
dbserver = StringField('Host')
|
|
||||||
dbport = IntegerField('Port', [Optional(), NumberRange(1, 65535)])
|
|
||||||
dbname = StringField('DB name')
|
|
||||||
dbuser = StringField('DB username')
|
|
||||||
dbpass = PasswordField('DB password',
|
|
||||||
widget=PasswordInput(hide_value=False))
|
|
||||||
|
|
||||||
config = FileConfig(
|
|
||||||
'/home/dain/yubico/yubiadmin/config-db.php',
|
|
||||||
[
|
|
||||||
('dbtype', db_read('type'), db_write('type'), 'mysql'),
|
|
||||||
('dbserver', db_read('server'), db_write('server'), 'localhost'),
|
|
||||||
('dbport', db_read('port'), db_write('port'), ''),
|
|
||||||
('dbname', db_read('name'), db_write('name'), 'ykval'),
|
|
||||||
('dbuser', db_read('user'), db_write('user'), 'ykval_verifier'),
|
|
||||||
('dbpass', db_read('pass'), db_write('pass'), ''),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class YubikeyVal(App):
|
class YubikeyVal(App):
|
||||||
"""
|
"""
|
||||||
YubiKey Validation Server
|
YubiKey Validation Server
|
||||||
@ -121,18 +97,19 @@ class YubikeyVal(App):
|
|||||||
"""
|
"""
|
||||||
Database Settings
|
Database Settings
|
||||||
"""
|
"""
|
||||||
return self.render_forms(request, [DatabaseForm()])
|
return self.render_forms(request, [
|
||||||
|
DBConfigForm('/home/dain/yubico/yubiadmin/config-db.php')])
|
||||||
|
|
||||||
def syncpool(self, request):
|
def syncpool(self, request):
|
||||||
"""
|
"""
|
||||||
Sync pool
|
Sync pool
|
||||||
"""
|
"""
|
||||||
return render('form', target=request.path)
|
return 'Not yet implemented.'
|
||||||
|
|
||||||
def ksms(self, request):
|
def ksms(self, request):
|
||||||
"""
|
"""
|
||||||
Key Store Modules
|
Key Store Modules
|
||||||
"""
|
"""
|
||||||
return render('form', target=request.path)
|
return 'Not yet implemented.'
|
||||||
|
|
||||||
app = YubikeyVal()
|
app = YubikeyVal()
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from UserDict import DictMixin
|
from UserDict import DictMixin
|
||||||
from wtforms import Form
|
from wtforms import Form, StringField, IntegerField, PasswordField
|
||||||
|
from wtforms.widgets import PasswordInput
|
||||||
|
from wtforms.validators import Optional, NumberRange
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'App',
|
'App',
|
||||||
'FileConfig',
|
'FileConfig',
|
||||||
'ConfigForm',
|
'ConfigForm',
|
||||||
|
'DBConfigForm',
|
||||||
'render',
|
'render',
|
||||||
'populate_forms',
|
'populate_forms',
|
||||||
]
|
]
|
||||||
@ -72,6 +75,9 @@ class ValueHandler(object):
|
|||||||
|
|
||||||
|
|
||||||
class FileConfig(DictMixin):
|
class FileConfig(DictMixin):
|
||||||
|
"""
|
||||||
|
Maps key-value pairs to a backing config file.
|
||||||
|
"""
|
||||||
def __init__(self, filename, params=[]):
|
def __init__(self, filename, params=[]):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.params = {}
|
self.params = {}
|
||||||
@ -107,6 +113,9 @@ class FileConfig(DictMixin):
|
|||||||
|
|
||||||
|
|
||||||
class ConfigForm(Form):
|
class ConfigForm(Form):
|
||||||
|
"""
|
||||||
|
Form that can load and save data to a config.
|
||||||
|
"""
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
@ -121,3 +130,41 @@ class ConfigForm(Form):
|
|||||||
if field.id in self.config:
|
if field.id in self.config:
|
||||||
self.config[field.id] = field.data
|
self.config[field.id] = field.data
|
||||||
self.config.commit()
|
self.config.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def db_read(varname):
|
||||||
|
return r'\$db%s=\'(.*)\';' % varname
|
||||||
|
|
||||||
|
|
||||||
|
def db_write(varname):
|
||||||
|
return lambda x: '$db%s=\'%s\';' % (varname, x)
|
||||||
|
|
||||||
|
|
||||||
|
class DBConfigForm(ConfigForm):
|
||||||
|
"""
|
||||||
|
Complete form for editing a dbconfig-common generated for PHP.
|
||||||
|
"""
|
||||||
|
legend = 'Database'
|
||||||
|
dbtype = StringField('DB type')
|
||||||
|
dbserver = StringField('Host')
|
||||||
|
dbport = IntegerField('Port', [Optional(), NumberRange(1, 65535)])
|
||||||
|
dbname = StringField('DB name')
|
||||||
|
dbuser = StringField('DB username')
|
||||||
|
dbpass = PasswordField('DB password',
|
||||||
|
widget=PasswordInput(hide_value=False))
|
||||||
|
|
||||||
|
config = FileConfig(
|
||||||
|
'/dev/null',
|
||||||
|
[
|
||||||
|
('dbtype', db_read('type'), db_write('type'), 'mysql'),
|
||||||
|
('dbserver', db_read('server'), db_write('server'), 'localhost'),
|
||||||
|
('dbport', db_read('port'), db_write('port'), ''),
|
||||||
|
('dbname', db_read('name'), db_write('name'), 'ykval'),
|
||||||
|
('dbuser', db_read('user'), db_write('user'), 'ykval_verifier'),
|
||||||
|
('dbpass', db_read('pass'), db_write('pass'), ''),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, filename, *args, **kwargs):
|
||||||
|
self.__class__.config.filename = filename
|
||||||
|
super(DBConfigForm, self).__init__(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user