mirror of
https://github.com/Yubico/yubiadmin.git
synced 2025-02-20 14:54:30 +01:00
Added priority and disable to apps.
This commit is contained in:
parent
2b4373cd43
commit
8b32cf89e9
@ -37,3 +37,4 @@ for filename in os.listdir(os.path.dirname(__file__)):
|
||||
__all__.append(module)
|
||||
if hasattr(module, 'app'):
|
||||
apps.append(module.app)
|
||||
apps.sort(key=lambda app: (app.priority, app.name))
|
||||
|
@ -26,21 +26,18 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from wtforms.fields import IntegerField
|
||||
from wtforms.validators import NumberRange, IPAddress, URL
|
||||
from yubiadmin.util.app import App
|
||||
from yubiadmin.util.config import (RegexHandler, FileConfig, php_inserter,
|
||||
parse_block, strip_comments)
|
||||
parse_block, strip_comments, strip_quotes)
|
||||
from yubiadmin.util.form import ConfigForm, FileForm, DBConfigForm, ListField
|
||||
from yubiadmin.util.system import invoke_rc_d
|
||||
|
||||
__all__ = [
|
||||
'app'
|
||||
]
|
||||
|
||||
COMMENT = re.compile(r'(?ms)(/\*.*?\*/)|(//[^$]*$)|(#[^$]*$)')
|
||||
VALUE = re.compile(r'\s*[\'"](.*)[\'"]\s*')
|
||||
|
||||
|
||||
def yk_pattern(varname, prefix='', suffix='', flags=None):
|
||||
regex = r'(?m)^(?!#)\$baseParams\[\'__YKVAL_%s__\'\]\s*=' \
|
||||
@ -60,13 +57,6 @@ def yk_handler(varname, default):
|
||||
inserter=php_inserter, default=default)
|
||||
|
||||
|
||||
def strip_quotes(value):
|
||||
match = VALUE.match(value)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return value
|
||||
|
||||
|
||||
def yk_parse_arraystring(value):
|
||||
return filter(None, [strip_quotes(x).strip() for x in strip_comments(value)
|
||||
.split(',')])
|
||||
@ -115,24 +105,8 @@ class KSMHandler(object):
|
||||
return php_inserter(content, value)
|
||||
|
||||
|
||||
def run(cmd):
|
||||
p = subprocess.Popen(['sh', '-c', cmd], stdout=subprocess.PIPE)
|
||||
return p.wait(), p.stdout.read()
|
||||
|
||||
|
||||
def invoke_rc_d(cmd):
|
||||
if run('which invoke-rd.d')[0] == 0:
|
||||
return run('invoke-rc.d ykval-queue %s' % cmd)
|
||||
else:
|
||||
return run('/etc/init.d/ykval-queue %s' % cmd)
|
||||
|
||||
|
||||
def is_daemon_running():
|
||||
return invoke_rc_d('status')[0] == 0
|
||||
|
||||
|
||||
def restart_daemon():
|
||||
invoke_rc_d('restart')
|
||||
return invoke_rc_d('ykval-queue', 'status')[0] == 0
|
||||
|
||||
|
||||
ykval_config = FileConfig(
|
||||
@ -205,7 +179,7 @@ class SyncPoolForm(ConfigForm):
|
||||
def save(self):
|
||||
super(SyncPoolForm, self).save()
|
||||
if is_daemon_running():
|
||||
restart_daemon()
|
||||
invoke_rc_d('ykval-queue', 'restart')
|
||||
|
||||
|
||||
class KSMForm(ConfigForm):
|
||||
@ -259,11 +233,11 @@ class YubikeyVal(App):
|
||||
def daemon(self, request):
|
||||
if request.params['daemon'] == 'toggle':
|
||||
if is_daemon_running():
|
||||
invoke_rc_d('stop')
|
||||
invoke_rc_d('ykval-queue', 'stop')
|
||||
else:
|
||||
invoke_rc_d('start')
|
||||
invoke_rc_d('ykval-queue', 'start')
|
||||
else:
|
||||
restart_daemon()
|
||||
invoke_rc_d('ykval-queue', 'restart')
|
||||
|
||||
return self.redirect('/%s/synchronization' % self.name)
|
||||
|
||||
|
@ -49,10 +49,8 @@ VALUES = {
|
||||
|
||||
def parse(conf, settings={}):
|
||||
for confkey, settingskey in VALUES.items():
|
||||
try:
|
||||
settings[settingskey] = conf.__getattribute__(confkey)
|
||||
except AttributeError:
|
||||
pass
|
||||
if hasattr(conf, confkey):
|
||||
settings[settingskey] = getattr(conf, confkey)
|
||||
return settings
|
||||
|
||||
|
||||
|
@ -27,33 +27,34 @@
|
||||
|
||||
from webob import exc
|
||||
from webob.dec import wsgify
|
||||
from collections import OrderedDict
|
||||
from yubiadmin.util.app import render
|
||||
from yubiadmin.apps import apps
|
||||
|
||||
|
||||
def inspect_app(app):
|
||||
cls = app.__class__
|
||||
name = cls.name
|
||||
doc = app.__doc__.strip()
|
||||
title, desc = doc.split('\n', 1)
|
||||
desc = desc.strip()
|
||||
sections = [{
|
||||
'name': section,
|
||||
'title': app.__getattribute__(section).__doc__.strip(),
|
||||
'advanced': hasattr(app.__getattribute__(section), 'advanced')
|
||||
'title': getattr(app, section).__doc__.strip(),
|
||||
'advanced': bool(getattr(getattr(app, section), 'advanced', False))
|
||||
} for section in cls.sections]
|
||||
|
||||
return {
|
||||
'name': name,
|
||||
'name': cls.name,
|
||||
'title': title,
|
||||
'description': desc,
|
||||
'sections': sections,
|
||||
'disabled': bool(getattr(app, 'disabled', False))
|
||||
}
|
||||
|
||||
|
||||
class YubiAdmin(object):
|
||||
def __init__(self):
|
||||
self.apps = {}
|
||||
self.apps = OrderedDict()
|
||||
for app in apps:
|
||||
app_data = inspect_app(app)
|
||||
self.apps[app_data['name']] = (app, app_data)
|
||||
@ -73,6 +74,7 @@ class YubiAdmin(object):
|
||||
app, module = self.apps[module_name]
|
||||
if not section_name:
|
||||
section_name = module['sections'][0]['name']
|
||||
raise exc.HTTPSeeOther(location=request.path + '/' + section_name)
|
||||
|
||||
if not hasattr(app, section_name):
|
||||
raise exc.HTTPNotFound
|
||||
@ -86,7 +88,7 @@ class YubiAdmin(object):
|
||||
module=module,
|
||||
section=section,
|
||||
title='YubiAdmin - %s - %s' % (module_name, section_name),
|
||||
page=app.__getattribute__(section_name)(request)
|
||||
page=getattr(app, section_name)(request)
|
||||
)
|
||||
|
||||
application = YubiAdmin()
|
||||
|
@ -21,6 +21,10 @@ a:hover {
|
||||
background-color: #8bc53f;
|
||||
}
|
||||
|
||||
a.disabled, a.disabled:hover {
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #9edb48;
|
||||
color: #ffffff;
|
||||
|
@ -4,18 +4,9 @@
|
||||
<div class="container">
|
||||
|
||||
<div class="row">
|
||||
<div class="span3">
|
||||
<div class="span12">
|
||||
<h1>YubiADMIN</h1>
|
||||
</div>
|
||||
<div class="span9">
|
||||
{% if alert %}
|
||||
<div class="alert alert-{{ alert.type }}">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<strong>{{ alert.title }}</strong>
|
||||
{{ alert.message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@ -23,11 +14,21 @@
|
||||
<div class="well">
|
||||
<ul class="nav nav-list">
|
||||
<li class="nav-header">Modules</li>
|
||||
{% for mod in modules %}
|
||||
{% for mod in modules if not mod.disabled %}
|
||||
<li {% if module is defined and mod.name == module.name %}class="active"{% endif %} >
|
||||
<a href="/{{ mod.name }}">{{ mod.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
{% for mod in modules if mod.disabled %}
|
||||
{% if loop.first %}
|
||||
<li class="nav-header">Not installed</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a class="disabled">{{ mod.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -63,6 +63,7 @@ def populate_forms(forms, data):
|
||||
class App(object):
|
||||
name = None
|
||||
sections = []
|
||||
priority = 50
|
||||
|
||||
def redirect(self, url):
|
||||
raise exc.HTTPSeeOther(location=url)
|
||||
|
@ -36,10 +36,16 @@ __all__ = [
|
||||
'FileConfig',
|
||||
'strip_comments',
|
||||
'php_inserter',
|
||||
'parse_block'
|
||||
'parse_block',
|
||||
'parse_value'
|
||||
]
|
||||
|
||||
PHP_BLOCKS = re.compile('(?ms)<\?php(.*?)\s*\?>')
|
||||
QUOTED_STR = re.compile(r'\s*[\'"](.*)[\'"]\s*')
|
||||
COMMENTS = re.compile(
|
||||
r'#.*?$|//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||
re.DOTALL | re.MULTILINE
|
||||
)
|
||||
|
||||
|
||||
def php_inserter(content, value):
|
||||
@ -55,11 +61,6 @@ def php_inserter(content, value):
|
||||
|
||||
|
||||
def strip_comments(text):
|
||||
COMMENTS = re.compile(
|
||||
r'#.*?$|//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||
re.DOTALL | re.MULTILINE
|
||||
)
|
||||
|
||||
def replacer(match):
|
||||
s = match.group(0)
|
||||
if s[0] in ['/', '#']:
|
||||
@ -69,6 +70,13 @@ def strip_comments(text):
|
||||
return COMMENTS.sub(replacer, text)
|
||||
|
||||
|
||||
def strip_quotes(value):
|
||||
match = QUOTED_STR.match(value)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return value
|
||||
|
||||
|
||||
def parse_block(content, opening='(', closing=')'):
|
||||
level = 0
|
||||
index = 0
|
||||
@ -83,6 +91,18 @@ def parse_block(content, opening='(', closing=')'):
|
||||
return content
|
||||
|
||||
|
||||
def parse_value(valrepr):
|
||||
try:
|
||||
return int(valrepr)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
return float(valrepr)
|
||||
except ValueError:
|
||||
pass
|
||||
return strip_quotes(valrepr)
|
||||
|
||||
|
||||
class RegexHandler(object):
|
||||
def __init__(self, pattern, writer, reader=lambda x: x.group(1),
|
||||
inserter=lambda x, y: '%s\n%s' % (x, y),
|
||||
|
Loading…
x
Reference in New Issue
Block a user