Commit 43fbc8a2 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(systems): mandatory IP fields can now be configured

In the systems plugin configuration you can now select which object
 should have the IP field as mandatory

issue #5705
Showing with 101 additions and 39 deletions
+101 -39
...@@ -94,7 +94,7 @@ class posixAccount extends simplePlugin ...@@ -94,7 +94,7 @@ class posixAccount extends simplePlugin
'plObjectType' => array('user'), 'plObjectType' => array('user'),
'plForeignKeys' => array( 'plForeignKeys' => array(
'gidNumber' => array( 'gidNumber' => array(
array('group','gidNumber'), array('ogroup','gidNumber'),
array('mixedGroup','gidNumber'), array('mixedGroup','gidNumber'),
), ),
'host' => array( 'host' => array(
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class componentGeneric extends simplePlugin class componentGeneric extends ipHostPlugin
{ {
var $mainTab = TRUE; var $mainTab = TRUE;
var $objectclasses = array("top", "device", "ipHost", "ieee802Device"); var $objectclasses = array('device', 'ieee802Device');
static function plInfo() static function plInfo()
{ {
...@@ -35,7 +35,7 @@ class componentGeneric extends simplePlugin ...@@ -35,7 +35,7 @@ class componentGeneric extends simplePlugin
'component' => array( 'component' => array(
'name' => _('Network device'), 'name' => _('Network device'),
'description' => _('Network device'), 'description' => _('Network device'),
'filter' => '(&(objectClass=ieee802Device)(objectClass=device)(objectClass=ipHost))', 'filter' => '(&(objectClass=ieee802Device)(objectClass=device))',
'icon' => 'geticon.php?context=devices&icon=network-device&size=16', 'icon' => 'geticon.php?context=devices&icon=network-device&size=16',
'ou' => get_ou('componentRDN'), 'ou' => get_ou('componentRDN'),
) )
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2016-2017 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*! \brief This class is made for plugins using the ipHostNumber field
*
* It adds the ipHost class if the field is filled, and removes it otherwise
* It is also used to list classes having the IP filled
*/
class ipHostPlugin extends simplePlugin
{
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
global $config;
parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['ipHostNumber']->setRequired(
in_array(get_class($this), $config->get_cfg_value('mandatoryIpClasses', array()))
);
$this->attributesAccess['ipHostNumber']->setUnique('whole', '(objectClass=ipHost)');
if (isset($this->attributesAccess['macAddress'])) {
$this->attributesAccess['macAddress']->setUnique('whole', '(objectClass=ieee802Device)');
}
}
/* Used by prepare_save and template::apply */
public function mergeObjectClasses(array $oc)
{
$objectclasses = $oc;
if (empty($this->ipHostNumber)) {
$objectclasses = array_remove_entries_ics(array('ipHost'), $objectclasses);
} else {
$objectclasses[] = 'ipHost';
}
return parent::mergeObjectClasses($objectclasses);
}
}
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class mobilePhoneGeneric extends simplePlugin class mobilePhoneGeneric extends ipHostPlugin
{ {
var $mainTab = TRUE; var $mainTab = TRUE;
...@@ -114,17 +114,5 @@ class mobilePhoneGeneric extends simplePlugin ...@@ -114,17 +114,5 @@ class mobilePhoneGeneric extends simplePlugin
), ),
); );
} }
/* Used by prepare_save and template::apply */
public function mergeObjectClasses(array $oc)
{
$objectclasses = $oc;
if (empty($this->ipHostNumber)) {
$objectclasses = array_remove_entries_ics(array('ipHost'), $objectclasses);
} else {
$objectclasses[] = 'ipHost';
}
return array_merge_unique($objectclasses, $this->objectclasses);
}
} }
?> ?>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class phoneGeneric extends simplePlugin class phoneGeneric extends ipHostPlugin
{ {
var $mainTab = TRUE; var $mainTab = TRUE;
...@@ -93,17 +93,5 @@ class phoneGeneric extends simplePlugin ...@@ -93,17 +93,5 @@ class phoneGeneric extends simplePlugin
), ),
); );
} }
/* Used by prepare_save and template::apply */
public function mergeObjectClasses(array $oc)
{
$objectclasses = $oc;
if (empty($this->ipHostNumber)) {
$objectclasses = array_remove_entries_ics(array('ipHost'), $objectclasses);
} else {
$objectclasses[] = 'ipHost';
}
return array_merge_unique($objectclasses, $this->objectclasses);
}
} }
?> ?>
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class printGeneric extends simplePlugin class printGeneric extends ipHostPlugin
{ {
var $objectclasses = array('fdPrinter', 'ipHost', 'ieee802Device'); var $objectclasses = array('fdPrinter', 'ieee802Device');
/* Return plugin information */ /* Return plugin information */
static function plInfo() static function plInfo()
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
class serverGeneric extends workstationGeneric class serverGeneric extends workstationGeneric
{ {
var $objectclasses = array('fdServer', 'ipHost', 'ieee802Device'); var $objectclasses = array('fdServer', 'ieee802Device');
static function getAttributesInfo ($word = NULL, $rdn = NULL) static function getAttributesInfo ($word = NULL, $rdn = NULL)
{ {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
class terminalGeneric extends workstationGeneric class terminalGeneric extends workstationGeneric
{ {
var $objectclasses = array('fdTerminal', 'ipHost', 'ieee802Device'); var $objectclasses = array('fdTerminal', 'ieee802Device');
/*! /*!
* \brief The main function : information about attributes * \brief The main function : information about attributes
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class workstationGeneric extends simplePlugin class workstationGeneric extends ipHostPlugin
{ {
var $mainTab = TRUE; var $mainTab = TRUE;
var $objectclasses = array('fdWorkstation', 'ipHost', 'ieee802Device'); var $objectclasses = array('fdWorkstation', 'ieee802Device');
static function plInfo() static function plInfo()
{ {
...@@ -110,8 +110,6 @@ class workstationGeneric extends simplePlugin ...@@ -110,8 +110,6 @@ class workstationGeneric extends simplePlugin
parent::__construct($dn, $object, $parent, $mainTab); parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['cn']->setUnique(TRUE); $this->attributesAccess['cn']->setUnique(TRUE);
$this->attributesAccess['ipHostNumber']->setUnique('whole', '(objectClass=ipHost)');
$this->attributesAccess['macAddress']->setUnique('whole', '(objectClass=ieee802Device)');
} }
function remove_from_parent() function remove_from_parent()
......
...@@ -22,6 +22,8 @@ class systemsPluginConfig extends simplePlugin ...@@ -22,6 +22,8 @@ class systemsPluginConfig extends simplePlugin
{ {
var $objectclasses = array('fdSystemsPluginConf'); var $objectclasses = array('fdSystemsPluginConf');
static protected $ipClasses = array();
static function plInfo() static function plInfo()
{ {
return array( return array(
...@@ -114,9 +116,35 @@ class systemsPluginConfig extends simplePlugin ...@@ -114,9 +116,35 @@ class systemsPluginConfig extends simplePlugin
), ),
TRUE /* edit enabled */ TRUE /* edit enabled */
), ),
new SetAttribute(
new SelectAttribute(
_('Mandatory IP'), _('Object types tabs for which IP field should be mandatory'),
'fdMandatoryIpClasses', FALSE
),
array('componentGeneric','printGeneric','workstationGeneric','terminalGeneric','serverGeneric')
),
) )
) )
); );
} }
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
if (empty(static::$ipClasses)) {
$plist = session::global_get('plist');
static::$ipClasses = array();
foreach ($plist->info as $cname => $info) {
if ($cname == 'all') {
continue;
}
if (is_subclass_of($cname, 'ipHostPlugin')) {
static::$ipClasses[$cname] = $info['plTitle'];
}
}
}
$this->attributesAccess['fdMandatoryIpClasses']->attribute->setChoices(array_keys(static::$ipClasses), array_values(static::$ipClasses));
}
} }
?> ?>
...@@ -77,6 +77,12 @@ attributetype ( 1.3.6.1.4.1.38414.18.11.1 NAME 'fdEncodings' ...@@ -77,6 +77,12 @@ attributetype ( 1.3.6.1.4.1.38414.18.11.1 NAME 'fdEncodings'
SUBSTR caseExactIA5SubstringsMatch SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26) SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
attributetype ( 1.3.6.1.4.1.38414.18.11.2 NAME 'fdMandatoryIpClasses'
DESC 'FusionDirectory - Classes for which IP should be mandatory'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
# Object Class # Object Class
objectclass ( 1.3.6.1.4.1.38414.18.2.1 NAME 'fdSystemsPluginConf' objectclass ( 1.3.6.1.4.1.38414.18.2.1 NAME 'fdSystemsPluginConf'
...@@ -85,7 +91,7 @@ objectclass ( 1.3.6.1.4.1.38414.18.2.1 NAME 'fdSystemsPluginConf' ...@@ -85,7 +91,7 @@ objectclass ( 1.3.6.1.4.1.38414.18.2.1 NAME 'fdSystemsPluginConf'
MUST ( cn ) MUST ( cn )
MAY ( fdSystemRDN $ fdServerRDN $ fdWorkstationRDN $ fdTerminalRDN $ MAY ( fdSystemRDN $ fdServerRDN $ fdWorkstationRDN $ fdTerminalRDN $
fdPrinterRDN $ fdComponentRDN $ fdMobilePhoneRDN $ fdEncodings $ fdPrinterRDN $ fdComponentRDN $ fdMobilePhoneRDN $ fdEncodings $
fdDeviceRDN $ fdPhoneRDN ) ) fdDeviceRDN $ fdPhoneRDN $ fdMandatoryIpClasses ) )
# asterisk-fd-conf.schema Object Class # asterisk-fd-conf.schema Object Class
......
Supports Markdown
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