net/freeradius: Add AVPairs (#1619)

This commit is contained in:
Michael
2020-01-01 15:32:40 +01:00
committed by Franco Fichtner
parent 884e7c2196
commit fabfb1685a
9 changed files with 211 additions and 6 deletions
@@ -0,0 +1,64 @@
<?php
/**
* Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
*
* 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 ``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
* AUTHOR 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.
*
*/
namespace OPNsense\Freeradius\Api;
use \OPNsense\Base\ApiMutableModelControllerBase;
class AvpairController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'avpair';
protected static $internalModelClass = '\OPNsense\Freeradius\Avpair';
public function searchAvpairAction()
{
return $this->searchBase('avpairs.avpair', array("enabled", "name", "operator", "value"));
}
public function getAvpairAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('avpair', 'avpairs.avpair', $uuid);
}
public function addAvpairAction()
{
return $this->addBase('avpair', 'avpairs.avpair');
}
public function delAvpairAction($uuid)
{
return $this->delBase('avpairs.avpair', $uuid);
}
public function setAvpairAction($uuid)
{
return $this->setBase('avpair', 'avpairs.avpair', $uuid);
}
public function toggleAvpairAction($uuid)
{
return $this->toggleBase('avpairs.avpair', $uuid);
}
}
@@ -33,6 +33,7 @@ class UserController extends \OPNsense\Base\IndexController
public function indexAction()
{
$this->view->formDialogEditFreeRADIUSUser = $this->getForm("dialogEditFreeRADIUSUser");
$this->view->formDialogEditFreeRADIUSAvpair = $this->getForm("dialogEditFreeRADIUSAvpair");
$this->view->pick('OPNsense/Freeradius/user');
}
}
@@ -0,0 +1,26 @@
<form>
<field>
<id>avpair.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>This will enable or disable the AVPair.</help>
</field>
<field>
<id>avpair.name</id>
<label>Name</label>
<type>text</type>
<help>Set the name for this AVPair</help>
</field>
<field>
<id>avpair.operator</id>
<label>Operator</label>
<type>text</type>
<help>Usual operators here are = or +=</help>
</field>
<field>
<id>avpair.value</id>
<label>Value</label>
<type>text</type>
<help>Set the value for this AVPair.</help>
</field>
</form>
@@ -130,4 +130,11 @@
<advanced>true</advanced>
<help>Set the Service-Type attributes for this user.</help>
</field>
<field>
<id>user.linkedAVPair</id>
<label>AVPair</label>
<type>select_multiple</type>
<allownew>true</allownew>
<help>Select the configured AVPairs for this user.</help>
</field>
</form>
@@ -0,0 +1,31 @@
<?php
/*
Copyright (C) 2019 Michael Muenz <m.muenz@gmail.com>
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 ``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
AUTHOR 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.
*/
namespace OPNsense\Freeradius;
use OPNsense\Base\BaseModel;
class Avpair extends BaseModel
{
}
@@ -0,0 +1,25 @@
<model>
<mount>//OPNsense/freeradius/avpair</mount>
<description>FreeRADIUS AVPair configuration</description>
<version>1.0.0</version>
<items>
<avpairs>
<avpair type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<name type="TextField">
<Required>Y</Required>
</name>
<operator type="TextField">
<Required>Y</Required>
<mask>/^([\-\+\~\=]){1,2}$/</mask>
</operator>
<value type="TextField">
<Required>Y</Required>
</value>
</avpair>
</avpairs>
</items>
</model>
@@ -101,6 +101,17 @@
<Option19 value="19">19</Option19>
</OptionValues>
</servicetype>
<linkedAVPair type="ModelRelationField">
<Model>
<template>
<source>OPNsense.Freeradius.Avpair</source>
<items>avpairs.avpair</items>
<display>name</display>
</template>
</Model>
<Multiple>Y</Multiple>
<Required>N</Required>
</linkedAVPair>
</user>
</users>
</items>
@@ -1,7 +1,7 @@
{#
OPNsense® is Copyright © 2014 2017 by Deciso B.V.
Copyright (C) 2017 Michael Muenz <m.muenz@gmail.com>
Copyright (C) 2017 - 2019 Michael Muenz <m.muenz@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@@ -32,10 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
$( document ).ready(function() {
updateServiceControlUI('freeradius');
/*************************************************************************************************************
* link grid actions
*************************************************************************************************************/
$("#grid-users").UIBootgrid(
{ 'search':'/api/freeradius/user/searchUser',
'get':'/api/freeradius/user/getUser/',
@@ -46,6 +42,16 @@ POSSIBILITY OF SUCH DAMAGE.
}
);
$("#grid-avpairs").UIBootgrid(
{ 'search':'/api/freeradius/avpair/searchAvpair',
'get':'/api/freeradius/avpair/getAvpair/',
'set':'/api/freeradius/avpair/setAvpair/',
'add':'/api/freeradius/avpair/addAvpair/',
'del':'/api/freeradius/avpair/delAvpair/',
'toggle':'/api/freeradius/avpair/toggleAvpair/'
}
);
/*************************************************************************************************************
* Commands
*************************************************************************************************************/
@@ -103,10 +109,10 @@ POSSIBILITY OF SUCH DAMAGE.
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#users">{{ lang._('Users') }}</a></li>
<li><a data-toggle="tab" href="#avpairs">{{ lang._('AVPair') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="users" class="tab-pane fade in active">
<!-- tab page "users" -->
<table id="grid-users" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="dialogEditFreeRADIUSUser">
<thead>
<tr>
@@ -133,6 +139,31 @@ POSSIBILITY OF SUCH DAMAGE.
</tfoot>
</table>
</div>
<div id="avpairs" class="tab-pane fade in">
<table id="grid-avpairs" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="dialogEditFreeRADIUSAvpair">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
<th data-column-id="operator" data-type="string" data-visible="false">{{ lang._('Operator') }}</th>
<th data-column-id="value" data-type="string" data-visible="true">{{ lang._('Value') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="reconfigureAct" type="button"><b>{{ lang._('Apply') }}</b> <i id="reconfigureAct_progress" class=""></i></button>
@@ -141,3 +172,4 @@ POSSIBILITY OF SUCH DAMAGE.
</div>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditFreeRADIUSUser,'id':'dialogEditFreeRADIUSUser','label':lang._('Edit User')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditFreeRADIUSAvpair,'id':'dialogEditFreeRADIUSAvpair','label':lang._('Edit AVPair')])}}
@@ -60,6 +60,14 @@
{% if user_list.mikrotik_vlan_id_type is defined %}
Mikrotik-Wireless-VLANID-Type = {{ user_list.mikrotik_vlan_id_type }},
{% endif %}
{% endif %}
{% if user_list.linkedAVPair|default("") != "" %}
{% for avlist in user_list.linkedAVPair.split(",") %}
{% set avlistdetail = helpers.getUUID(avlist) %}
{% if avlistdetail != {} and avlistdetail.enabled == '1' %}
{{ avlistdetail.name }} {{ avlistdetail.operator }} {{ avlistdetail.value }},
{% endif %}
{% endfor %}
{% endif %}
Framed-Protocol = PPP