mirror of
https://github.com/Yubico/yubiadmin.git
synced 2025-02-21 17:54:17 +01:00
Added freerad app with radtest.
This commit is contained in:
parent
8f9fd30a7c
commit
d3a499a554
@ -239,9 +239,6 @@ class CreateUserForm(Form):
|
|||||||
super(CreateUserForm, self).__init__(**kwargs)
|
super(CreateUserForm, self).__init__(**kwargs)
|
||||||
self.auth = auth
|
self.auth = auth
|
||||||
|
|
||||||
def load(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
self.auth.create_user(self.username.data, self.password.data)
|
self.auth.create_user(self.username.data, self.password.data)
|
||||||
self.auth.commit()
|
self.auth.commit()
|
||||||
|
90
yubiadmin/apps/freerad.py
Normal file
90
yubiadmin/apps/freerad.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
# Copyright (c) 2013 Yubico AB
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from yubiadmin.util.app import App, render
|
||||||
|
from yubiadmin.util.system import run
|
||||||
|
from wtforms import Form
|
||||||
|
from wtforms.fields import TextField, PasswordField
|
||||||
|
import os
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'app'
|
||||||
|
]
|
||||||
|
|
||||||
|
CLIENTS_CONFIG_FILE = '/etc/freeradius/clients.conf'
|
||||||
|
|
||||||
|
|
||||||
|
class RadTestForm(Form):
|
||||||
|
legend = 'RADIUS test'
|
||||||
|
username = TextField('Username')
|
||||||
|
password = PasswordField('Password')
|
||||||
|
|
||||||
|
|
||||||
|
class FreeRadius(App):
|
||||||
|
"""
|
||||||
|
FreeRADIUS
|
||||||
|
|
||||||
|
RADIUS Server
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = 'freerad'
|
||||||
|
sections = ['general', 'clients']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def disabled(self):
|
||||||
|
return not os.path.isdir('/etc/freeradius')
|
||||||
|
|
||||||
|
def general(self, request):
|
||||||
|
"""
|
||||||
|
General
|
||||||
|
"""
|
||||||
|
alerts = []
|
||||||
|
if 'username' in request.params:
|
||||||
|
username = request.params['username']
|
||||||
|
password = request.params.get('password', '')
|
||||||
|
cmd = 'radtest %s %s localhost 0 testing123' % (username, password)
|
||||||
|
status, output = run(cmd)
|
||||||
|
alert = {'title': cmd, 'message': '<pre>%s</pre>' % output}
|
||||||
|
if status == 0:
|
||||||
|
alert['type'] = 'success'
|
||||||
|
elif status == 1:
|
||||||
|
alert['type'] = 'warn'
|
||||||
|
else:
|
||||||
|
alert['type'] = 'error'
|
||||||
|
alert['message'] = 'There was an error running the command. ' \
|
||||||
|
'Exit code: %d' % status
|
||||||
|
alerts.append(alert)
|
||||||
|
|
||||||
|
return render('freerad/general', form=RadTestForm(), alerts=alerts)
|
||||||
|
|
||||||
|
def clients(self, request):
|
||||||
|
"""
|
||||||
|
RADIUS clients
|
||||||
|
"""
|
||||||
|
return ''
|
||||||
|
|
||||||
|
app = FreeRadius()
|
@ -38,7 +38,7 @@ def inspect_app(app):
|
|||||||
desc = desc.strip()
|
desc = desc.strip()
|
||||||
sections = [{
|
sections = [{
|
||||||
'name': section,
|
'name': section,
|
||||||
'title': getattr(app, section).__doc__.strip(),
|
'title': (getattr(app, section).__doc__ or section).strip(),
|
||||||
'advanced': bool(getattr(getattr(app, section), 'advanced', False))
|
'advanced': bool(getattr(getattr(app, section), 'advanced', False))
|
||||||
} for section in app.sections]
|
} for section in app.sections]
|
||||||
|
|
||||||
|
@ -31,6 +31,10 @@ caption {
|
|||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.message {
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #8bc53f;
|
color: #8bc53f;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<div class="alert alert-{{ alert.type }}">
|
<div class="alert alert-{{ alert.type }}">
|
||||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
<strong>{{ alert.title }}</strong>
|
<strong>{{ alert.title }}</strong>
|
||||||
{{ alert.message }}
|
<span class="message">{{ alert.message }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
7
yubiadmin/templates/freerad/general.html
Normal file
7
yubiadmin/templates/freerad/general.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{% from 'form.html' import form_fieldset %}
|
||||||
|
|
||||||
|
<form action="/freerad/general" method="post">
|
||||||
|
{{ form_fieldset(form) }}
|
||||||
|
<input type="submit" class="btn" value="Test" />
|
||||||
|
</form>
|
||||||
|
|
@ -70,7 +70,7 @@ def render(tmpl, **kwargs):
|
|||||||
|
|
||||||
def populate_forms(forms, data):
|
def populate_forms(forms, data):
|
||||||
if not data:
|
if not data:
|
||||||
for form in forms:
|
for form in filter(lambda x: hasattr(x, 'load'), forms):
|
||||||
form.load()
|
form.load()
|
||||||
else:
|
else:
|
||||||
errors = False
|
errors = False
|
||||||
@ -78,7 +78,7 @@ def populate_forms(forms, data):
|
|||||||
form.process(data)
|
form.process(data)
|
||||||
errors = not form.validate() or errors
|
errors = not form.validate() or errors
|
||||||
if not errors:
|
if not errors:
|
||||||
for form in forms:
|
for form in filter(lambda x: hasattr(x, 'save'), forms):
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class App(object):
|
|||||||
success_msg='Settings updated!', **kwargs):
|
success_msg='Settings updated!', **kwargs):
|
||||||
alerts = []
|
alerts = []
|
||||||
if not request.params:
|
if not request.params:
|
||||||
for form in forms:
|
for form in filter(lambda x: hasattr(x, 'load'), forms):
|
||||||
form.load()
|
form.load()
|
||||||
else:
|
else:
|
||||||
errors = False
|
errors = False
|
||||||
@ -105,7 +105,7 @@ class App(object):
|
|||||||
try:
|
try:
|
||||||
if success_msg:
|
if success_msg:
|
||||||
alerts = [{'type': 'success', 'title': success_msg}]
|
alerts = [{'type': 'success', 'title': success_msg}]
|
||||||
for form in forms:
|
for form in filter(lambda x: hasattr(x, 'save'), forms):
|
||||||
form.save()
|
form.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
alerts = [{'type': 'error', 'title': 'Error:',
|
alerts = [{'type': 'error', 'title': 'Error:',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user