# Path: yubiadmin/util/app.py
# class App(object):
#     sections = []
#     priority = 50
# 
#     @property
#     def name(self):
#         self.__class__.name = sys.modules[self.__module__].__file__ \
#             .split('/')[-1].rsplit('.', 1)[0]
#         return self.name
# 
#     def __call__(self, request):
#         section_name = request.path_info_pop()
# 
#         if not section_name:
#             return self.redirect('/%s/%s' % (self.name, self.sections[0]))
# 
#         if not hasattr(self, section_name):
#             raise exc.HTTPNotFound
# 
#         sections = [{
#             'name': section,
#             'title': (getattr(self, section).__doc__ or section.capitalize()
#                       ).strip(),
#             'active': section == section_name,
#             'advanced': bool(getattr(getattr(self, section), 'advanced',
#                                      False))
#         } for section in self.sections]
# 
#         request.environ['yubiadmin.response'].extend('content', render(
#             'app_base',
#             name=self.name,
#             sections=sections,
#             title='YubiAdmin - %s - %s' % (self.name, section_name)
#         ))
# 
#         resp = getattr(self, section_name)(request)
#         if isinstance(resp, Response):
#             return resp
#         request.environ['yubiadmin.response'].extend('page', resp)
# 
#     def redirect(self, url):
#         raise exc.HTTPSeeOther(location=url)
# 
#     def render_forms(self, request, forms, template='form',
#                      success_msg='Settings updated!', **kwargs):
#         alerts = []
#         if not request.params:
#             for form in filter(lambda x: hasattr(x, 'load'), forms):
#                 form.load()
#         else:
#             errors = False
#             for form in forms:
#                 form.process(request.params)
#                 errors = not form.validate() or errors
#             if not errors:
#                 try:
#                     if success_msg:
#                         alerts = [{'type': 'success', 'title': success_msg}]
#                     for form in filter(lambda x: hasattr(x, 'save'), forms):
#                         form.save()
#                 except Exception as e:
#                     alerts = [{'type': 'error', 'title': 'Error:',
#                                'message': str(e)}]
#             else:
#                 alerts = [{'type': 'error', 'title': 'Invalid data!'}]
# 
#         return render(template, target=request.path, fieldsets=forms,
#                       alerts=alerts, **kwargs)
# 
# Path: yubiadmin/util/form.py
# class DBConfigForm(ConfigForm):
#     """
#     Complete form for editing a dbconfig-common generated for PHP.
#     """
#     legend = 'Database'
#     description = 'Settings for connecting to the database.'
#     dbtype = TextField('Database type')
#     dbserver = TextField('Host')
#     dbport = IntegerField('Port', [Optional(), NumberRange(1, 65535)])
#     dbname = TextField('Database name')
#     dbuser = TextField('Username')
#     dbpass = PasswordField('Password',
#                            widget=PasswordInput(hide_value=False))
# 
#     def db_handler(self, varname, default):
#         pattern = r'\$%s=\'(.*)\';' % varname
#         writer = lambda x: '$%s=\'%s\';' % (varname, x)
#         return RegexHandler(pattern, writer, inserter=php_inserter,
#                             default=default)
# 
#     def __init__(self, filename, *args, **kwargs):
#         if not self.config:
#             self.config = FileConfig(
#                 filename,
#                 [
#                     ('dbtype', self.db_handler(
#                         'dbtype', kwargs.pop('dbtype', 'mysql'))),
#                     ('dbserver', self.db_handler(
#                         'dbserver', kwargs.pop('dbserver', 'localhost'))),
#                     ('dbport', self.db_handler(
#                         'dbport', kwargs.pop('dbport', ''))),
#                     ('dbname', self.db_handler(
#                         'dbname', kwargs.pop('dbname', ''))),
#                     ('dbuser', self.db_handler(
#                         'dbuser', kwargs.pop('dbuser', ''))),
#                     ('dbpass', self.db_handler(
#                         'dbpass', kwargs.pop('dbpass', ''))),
#                 ]
#             )
# 
#         super(DBConfigForm, self).__init__(*args, **kwargs)


import os
from yubiadmin.util.app import App
from yubiadmin.util.form import DBConfigForm
#   Redistribution and use in source and binary forms, with or
#   without modification, are permitted provided that the following
#   conditions are met:
#
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


__all__ = [
    'app'
]



# Path: yubiadmin/util/app.py
# class App(object):
#     sections = []
#     priority = 50
# 
#     @property
#     def name(self):
#         self.__class__.name = sys.modules[self.__module__].__file__ \
#             .split('/')[-1].rsplit('.', 1)[0]
#         return self.name
# 
#     def __call__(self, request):
#         section_name = request.path_info_pop()
# 
#         if not section_name:
#             return self.redirect('/%s/%s' % (self.name, self.sections[0]))
# 
#         if not hasattr(self, section_name):
#             raise exc.HTTPNotFound
# 
#         sections = [{
#             'name': section,
#             'title': (getattr(self, section).__doc__ or section.capitalize()
#                       ).strip(),
#             'active': section == section_name,
#             'advanced': bool(getattr(getattr(self, section), 'advanced',
#                                      False))
#         } for section in self.sections]
# 
#         request.environ['yubiadmin.response'].extend('content', render(
#             'app_base',
#             name=self.name,
#             sections=sections,
#             title='YubiAdmin - %s - %s' % (self.name, section_name)
#         ))
# 
#         resp = getattr(self, section_name)(request)
#         if isinstance(resp, Response):
#             return resp
#         request.environ['yubiadmin.response'].extend('page', resp)
# 
#     def redirect(self, url):
#         raise exc.HTTPSeeOther(location=url)
# 
#     def render_forms(self, request, forms, template='form',
#                      success_msg='Settings updated!', **kwargs):
#         alerts = []
#         if not request.params:
#             for form in filter(lambda x: hasattr(x, 'load'), forms):
#                 form.load()
#         else:
#             errors = False
#             for form in forms:
#                 form.process(request.params)
#                 errors = not form.validate() or errors
#             if not errors:
#                 try:
#                     if success_msg:
#                         alerts = [{'type': 'success', 'title': success_msg}]
#                     for form in filter(lambda x: hasattr(x, 'save'), forms):
#                         form.save()
#                 except Exception as e:
#                     alerts = [{'type': 'error', 'title': 'Error:',
#                                'message': str(e)}]
#             else:
#                 alerts = [{'type': 'error', 'title': 'Invalid data!'}]
# 
#         return render(template, target=request.path, fieldsets=forms,
#                       alerts=alerts, **kwargs)
# 
# Path: yubiadmin/util/form.py
# class DBConfigForm(ConfigForm):
#     """
#     Complete form for editing a dbconfig-common generated for PHP.
#     """
#     legend = 'Database'
#     description = 'Settings for connecting to the database.'
#     dbtype = TextField('Database type')
#     dbserver = TextField('Host')
#     dbport = IntegerField('Port', [Optional(), NumberRange(1, 65535)])
#     dbname = TextField('Database name')
#     dbuser = TextField('Username')
#     dbpass = PasswordField('Password',
#                            widget=PasswordInput(hide_value=False))
# 
#     def db_handler(self, varname, default):
#         pattern = r'\$%s=\'(.*)\';' % varname
#         writer = lambda x: '$%s=\'%s\';' % (varname, x)
#         return RegexHandler(pattern, writer, inserter=php_inserter,
#                             default=default)
# 
#     def __init__(self, filename, *args, **kwargs):
#         if not self.config:
#             self.config = FileConfig(
#                 filename,
#                 [
#                     ('dbtype', self.db_handler(
#                         'dbtype', kwargs.pop('dbtype', 'mysql'))),
#                     ('dbserver', self.db_handler(
#                         'dbserver', kwargs.pop('dbserver', 'localhost'))),
#                     ('dbport', self.db_handler(
#                         'dbport', kwargs.pop('dbport', ''))),
#                     ('dbname', self.db_handler(
#                         'dbname', kwargs.pop('dbname', ''))),
#                     ('dbuser', self.db_handler(
#                         'dbuser', kwargs.pop('dbuser', ''))),
#                     ('dbpass', self.db_handler(
#                         'dbpass', kwargs.pop('dbpass', ''))),
#                 ]
#             )
# 
#         super(DBConfigForm, self).__init__(*args, **kwargs)


# Path: yubiadmin/apps/ksm.py
import os
from yubiadmin.util.app import App
from yubiadmin.util.form import DBConfigForm

#   Redistribution and use in source and binary forms, with or
#   without modification, are permitted provided that the following
#   conditions are met:
#
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


__all__ = [
    'app'
]



class YubikeyKsm(App):