Commit 6915fe17 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '6040-make-an-ipam-plugin' into '1.4-dev'

Resolve "make an ipam plugin"

See merge request fusiondirectory/fd-plugins!738
parents 94e06449 c9033fe3
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2009 GONICUS GmbH
Copyright (C) 2012 WILLIAME Jeremy
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-2020 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -20,7 +21,6 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class freeradiusAccount extends simplePlugin
{
protected $displayHeader = TRUE;
......@@ -29,27 +29,23 @@ class freeradiusAccount extends simplePlugin
{
return [
'plShortName' => _('Freeradius'),
'plDescription' => _('This Plugin is for Radius accounting based in FreeRadius'),
'plDescription' => _('Radius accounting based on FreeRadius'),
'plFilter' => '(objectClass=radiusprofile)',
'plIcon' => 'geticon.php?context=applications&icon=freeradius&size=48',
'plSmallIcon' => 'geticon.php?context=applications&icon=freeradius&size=16',
'plSelfModify' => TRUE,
'plPriority' => 11,
'plObjectClass' => ['radiusprofile'],
'plObjectType' => ['user'],
'plObjectType' => ['user','ipamVlan','ipamSubnet'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
];
}
/*!
* \brief The main function : information about attributes
*/
static function getAttributesInfo (): array
{
return [
// Attributes are grouped by section
'section1' => [
'section1' => [
'name' => _('Support 802.1x'),
'attrs' => [
new StringAttribute(
......@@ -57,15 +53,14 @@ class freeradiusAccount extends simplePlugin
'radiusTunnelMediumType', TRUE,
'IEEE-802'
),
new StringAttribute(
new StringAttribute(
_('Tunnel type'), _('Name of the tunnel type'),
'radiusTunnelType', TRUE,
'VLAN'
),
new StringAttribute(
_('VLAN id'), _('VLAN identifier'),
'radiusTunnelPrivateGroupId', FALSE,
''
'radiusTunnelPrivateGroupId', FALSE
),
new DateAttribute(
_('Expiration date'), _('Date of the expiration account'),
......@@ -78,74 +73,92 @@ class freeradiusAccount extends simplePlugin
'name' => _('Groups'),
'attrs' => [
new SetAttribute(
new SelectAttribute(
_('Groups'),
_('FreeRadius Group'),
'radiusGroupName',
FALSE,
[""]
new SelectAttribute(
_('Groups'), _('FreeRadius Groups'),
'radiusGroupName', FALSE
)
),
],
],
'section3' => [
'name' => _('User preferences'),
'attrs' => [
new StringAttribute(
_('Protocol'), _('Protocol'),
'radiusFramedProtocol', FALSE,
'PPP'
),
'attrs' => [
new StringAttribute(
_('Protocol'), _('Protocol'),
'radiusFramedProtocol', FALSE,
'PPP'
),
new StringAttribute(
_('IP Address'), _('IP Address'),
'radiusFramedIPAddress', FALSE,
'255.255.255.254'
),
new StringAttribute(
_('IP Netmask'), _('IP Netmask'),
'radiusFramedIPNetmask', FALSE
),
new IntAttribute(
_('Framed-MTU'), _('Framed-MTU'),
'radiusFramedMTU', FALSE,
0,
FALSE,
1500
),
new StringAttribute(
_('Compression'), _('Compression'),
'radiusFramedCompression', FALSE,
'Van-Jacobsen-TCP-IP'
),
new StringAttribute(
_('Service type'), _('Service type'),
'radiusServiceType', FALSE,
'Framed-User'
),
new IntAttribute(
_('Session Timeout'), _('Session Timeout'),
'radiusSessionTimeout', FALSE,
FALSE,
FALSE
),
new IntAttribute(
_('Idle Timeout'), _('Idle Timeout'),
'radiusIdleTimeout', FALSE,
FALSE,
FALSE,
10
),
new IntAttribute(
_('Port limit'), _('Port limit'),
'radiusPortLimit', FALSE,
0,
FALSE,
2
)
]
],
'advanced' => [
'name' => _('Advanced'),
'attrs' => [
new SetAttribute(
new StringAttribute(
_('IP Address'), _('IP Address'),
'radiusFramedIPAddress', FALSE,
'255.255.255.254'
),
_('Control attributes'), _('Control attributes using format [qualifiers.]<attribute> <operator> <value>'),
'radiusControlAttribute', FALSE
)
),
new SetAttribute(
new StringAttribute(
_('IP Netmask'), _('IP Netmask'),
'radiusFramedIPNetmask', FALSE,
''
),
new IntAttribute(
_('Framed-MTU'), _('Framed-MTU'),
'radiusFramedMTU', FALSE,
0,
FALSE,
1500
),
_('Reply attributes'), _('Reply attributes using format [qualifiers.]<attribute> <operator> <value>'),
'radiusReplyAttribute', FALSE
)
),
new SetAttribute(
new StringAttribute(
_('Compression'), _('Compression'),
'radiusFramedCompression', FALSE,
'Van-Jacobsen-TCP-IP'
),
new StringAttribute(
_('Service type'), _('Service type'),
'radiusServiceType', FALSE,
'Framed-User'
),
new IntAttribute(
_('Session Timeout'), _('Session Timeout'),
'radiusSessionTimeout', FALSE,
FALSE,
FALSE,
""
),
new IntAttribute(
_('Idle Timeout'), _('Idle Timeout'),
'radiusIdleTimeout', FALSE,
"",
FALSE,
10
),
new IntAttribute(
_('Port limit'), _('Port limit'),
'radiusPortLimit', FALSE,
0,
FALSE,
2
_('Request attributes'), _('Request attributes using format [qualifiers.]<attribute> <operator> <value>'),
'radiusRequestAttribute', FALSE
)
]
]
),
],
],
];
}
......@@ -153,13 +166,13 @@ class freeradiusAccount extends simplePlugin
* \brief Constructor of the freeradiusAccount
* It will build the select groups choices
*/
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE)
{
global $config;
parent::__construct($dn, $object, $parent, $mainTab);
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=radiusprofile)', ['cn']);
$ldap->search('(&(objectClass=radiusprofile)(cn=*))', ['cn']);
$groups = [];
while ($attrs = $ldap->fetch()) {
$groups[] = $attrs['cn'][0];
......
......@@ -28,7 +28,18 @@ class CIDRAttribute extends StringAttribute
function validate ()
{
list($ip,$bits) = explode('/', $this->getValue(), 2);
if (empty($ip) || empty($bits) || !tests::is_ip($ip) || !preg_match('/^[0-9]+$/', $bits) || ($bits > 128)) {
if (
/* Incomplete values */
empty($ip) || empty($bits) ||
/* Non-numerical suffix */
!preg_match('/^[0-9]+$/', $bits) ||
/* Mask size too big for v4 */
(($bits > 32) && tests::is_ipv4($ip)) ||
/* Not an IP */
!tests::is_ip($ip) ||
/* Mask size too big for v6 */
($bits > 128)
) {
return msgPool::invalid($this->getLabel(), $this->getValue(), $this->example);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment