Commit 3d5967dd authored by AssanDiomande's avatar AssanDiomande
Browse files

fixed ldap configuration ID issue

parent abfc5e81
<?php
/*
* Copyright 2005-2021 CENTREON
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
namespace CentreonClapi;
require_once "centreonObject.class.php";
require_once "centreonUtils.class.php";
require_once "centreonTimePeriod.class.php";
require_once "Centreon/Object/Contact/Contact.php";
require_once "Centreon/Object/Command/Command.php";
require_once "Centreon/Object/Relation/Contact/Command/Host.php";
require_once "Centreon/Object/Relation/Contact/Command/Service.php";
require_once "centreonLDAP.class.php";
/**
* Class representating relation between a contact and his LDAP configuration
*/
class CentreonLDAPContactRelation extends CentreonObject
{
private const ORDER_NAME = 0;
private const LDAP_PARAMETER_NAME = "ar_name";
/**
* @var int
*/
protected $register;
public static $aDepends = [
'CONTACT',
'LDAP'
];
/**
* Constructor
* @param \Pimple\Container $dependencyInjector
* @return void
*/
public function __construct(\Pimple\Container $dependencyInjector)
{
parent::__construct($dependencyInjector);
$this->ldap = new CentreonLdap($dependencyInjector);
$this->contact = new \Centreon_Object_Contact($dependencyInjector);
$this->action = "LDAPCONTACT";
$this->register = 1;
$this->activateField = 'contact_activate';
}
/**
* @param string $parameters
* @throws CentreonClapiException
*/
public function initUpdateParameters(string $parameters): void
{
$params = explode($this->delim, $parameters);
if (count($params) < self::NB_UPDATE_PARAMS) {
throw new CentreonClapiException(self::MISSINGPARAMETER);
}
$params[self::ORDER_NAME] = str_replace(" ", "_", $params[self::ORDER_NAME]);
}
/**
* Export data
*
* @param string|null $filterName
* @return bool
*/
public function export($filterName = null): bool
{
if (!$this->canBeExported($filterName)) {
return false;
}
$labelField = $this->contact->getUniqueLabelField();
$filters = ["contact_register" => $this->register];
if (!is_null($filterName)) {
$filters[$labelField] = $filterName;
}
$contacts = $this->contact->getList(
"*",
-1,
0,
$labelField,
'ASC',
$filters,
"AND"
);
foreach ($contacts as $contact) {
foreach ($contact as $parameter => $value) {
if (!empty($value) && !in_array($parameter, $this->exportExcludedParams) && $parameter === "ar_id") {
$value = $this->ldap->getObjectName($value);
$value = CentreonUtils::convertLineBreak($value);
echo $this->action . $this->delim
. "setparam" . $this->delim
. $contact[$this->contact->getUniqueLabelField()] . $this->delim
. self::LDAP_PARAMETER_NAME . $this->delim
. $value . "\n";
}
}
}
return true;
}
}
......@@ -78,7 +78,7 @@ class CentreonAPI
private $dependencyInjector;
private $relationObject;
private $objectTable;
private $aExport = array();
private $aExport = [];
public function __construct(
$user,
......@@ -121,7 +121,7 @@ class CentreonAPI
$this->object = "";
}
$this->objectTable = array();
$this->objectTable = [];
/**
* Centreon DB Connexion
......@@ -130,185 +130,190 @@ class CentreonAPI
$this->DBC = $this->dependencyInjector["realtime_db"];
$this->dateStart = time();
$this->relationObject = array();
$this->relationObject["CMD"] = array(
$this->relationObject = [];
$this->relationObject["CMD"] = [
'module' => 'core',
'class' => 'Command',
'export' => true
);
$this->relationObject["HOST"] = array(
];
$this->relationObject["HOST"] = [
'module' => 'core',
'class' => 'Host',
'libs' => array(
'libs' => [
'centreonService.class.php',
'centreonHostGroup.class.php',
'centreonContact.class.php',
'centreonContactGroup.class.php'
),
],
'export' => true
);
$this->relationObject["SERVICE"] = array(
];
$this->relationObject["SERVICE"] = [
'module' => 'core',
'class' => 'Service',
'libs' => array(
'libs' => [
'centreonHost.class.php'
),
],
'export' => true
);
$this->relationObject["HGSERVICE"] = array(
];
$this->relationObject["HGSERVICE"] = [
'module' => 'core',
'class' => 'HostGroupService',
'export' => true
);
$this->relationObject["VENDOR"] = array(
];
$this->relationObject["VENDOR"] = [
'module' => 'core',
'class' => 'Manufacturer',
'export' => true
);
$this->relationObject["TRAP"] = array(
];
$this->relationObject["TRAP"] = [
'module' => 'core',
'class' => 'Trap',
'export' => true
);
$this->relationObject["HG"] = array(
];
$this->relationObject["HG"] = [
'module' => 'core',
'class' => 'HostGroup',
'export' => true
);
$this->relationObject["HC"] = array(
];
$this->relationObject["HC"] = [
'module' => 'core',
'class' => 'HostCategory',
'export' => true
);
$this->relationObject["SG"] = array(
];
$this->relationObject["SG"] = [
'module' => 'core',
'class' => 'ServiceGroup',
'export' => true
);
$this->relationObject["SC"] = array(
];
$this->relationObject["SC"] = [
'module' => 'core',
'class' => 'ServiceCategory',
'export' => true
);
$this->relationObject["CONTACT"] = array(
];
$this->relationObject["CONTACT"] = [
'module' => 'core',
'class' => 'Contact',
'libs' => array(
'libs' => [
'centreonCommand.class.php'
),
],
'export' => true
);
$this->relationObject["LDAP"] = array(
];
$this->relationObject["LDAPCONTACT"] = [
'module' => 'core',
'class' => 'LDAPContactRelation',
'export' => true
];
$this->relationObject["LDAP"] = [
'module' => 'core',
'class' => 'LDAP',
'export' => true
);
$this->relationObject["CONTACTTPL"] = array(
];
$this->relationObject["CONTACTTPL"] = [
'module' => 'core',
'class' => 'ContactTemplate',
'export' => true
);
$this->relationObject["CG"] = array(
];
$this->relationObject["CG"] = [
'module' => 'core',
'class' => 'ContactGroup',
'export' => true
);
];
/* Dependencies */
$this->relationObject["DEP"] = array(
$this->relationObject["DEP"] = [
'module' => 'core',
'class' => 'Dependency',
'export' => true
);
];
/* Downtimes */
$this->relationObject["DOWNTIME"] = array(
$this->relationObject["DOWNTIME"] = [
'module' => 'core',
'class' => 'Downtime',
'export' => true
);
];
/* RtDowntimes */
$this->relationObject["RTDOWNTIME"] = array(
$this->relationObject["RTDOWNTIME"] = [
'module' => 'core',
'class' => 'RtDowntime',
'export' => false
);
];
/* RtAcknowledgement */
$this->relationObject["RTACKNOWLEDGEMENT"] = array(
$this->relationObject["RTACKNOWLEDGEMENT"] = [
'module' => 'core',
'class' => 'RtAcknowledgement',
'export' => false
);
];
/* Templates */
$this->relationObject["HTPL"] = array(
$this->relationObject["HTPL"] = [
'module' => 'core',
'class' => 'HostTemplate',
'export' => true
);
$this->relationObject["STPL"] = array(
];
$this->relationObject["STPL"] = [
'module' => 'core',
'class' => 'ServiceTemplate',
'export' => true
);
$this->relationObject["TP"] = array(
];
$this->relationObject["TP"] = [
'module' => 'core',
'class' => 'TimePeriod',
'export' => true
);
$this->relationObject["INSTANCE"] = array(
];
$this->relationObject["INSTANCE"] = [
'module' => 'core',
'class' => 'Instance',
'export' => true
);
$this->relationObject["ENGINECFG"] = array(
];
$this->relationObject["ENGINECFG"] = [
'module' => 'core',
'class' => 'EngineCfg',
'export' => true
);
$this->relationObject["CENTBROKERCFG"] = array(
];
$this->relationObject["CENTBROKERCFG"] = [
'module' => 'core',
'class' => 'CentbrokerCfg',
'export' => true
);
$this->relationObject["RESOURCECFG"] = array(
];
$this->relationObject["RESOURCECFG"] = [
'module' => 'core',
'class' => 'ResourceCfg',
'export' => true
);
$this->relationObject["ACL"] = array(
];
$this->relationObject["ACL"] = [
'module' => 'core',
'class' => 'ACL',
'export' => false
);
$this->relationObject["ACLGROUP"] = array(
];
$this->relationObject["ACLGROUP"] = [
'module' => 'core',
'class' => 'ACLGroup',
'export' => true
);
$this->relationObject["ACLACTION"] = array(
];
$this->relationObject["ACLACTION"] = [
'module' => 'core',
'class' => 'ACLAction',
'export' => true
);
$this->relationObject["ACLMENU"] = array(
];
$this->relationObject["ACLMENU"] = [
'module' => 'core',
'class' => 'ACLMenu',
'export' => true
);
$this->relationObject["ACLRESOURCE"] = array(
];
$this->relationObject["ACLRESOURCE"] = [
'module' => 'core',
'class' => 'ACLResource',
'export' => true
);
$this->relationObject["SETTINGS"] = array(
];
$this->relationObject["SETTINGS"] = [
'module' => 'core',
'class' => 'Settings',
'export' => false
);
];
/* Get objects from modules */
$objectsPath = array();
$objectsPath = [];
$DBRESULT = $this->DB->query("SELECT name FROM modules_informations");
while ($row = $DBRESULT->fetch()) {
......@@ -332,12 +337,12 @@ class CentreonAPI
explode('-', $finalNamespace)
)
);
$this->relationObject[strtoupper($matches[2])] = array(
$this->relationObject[strtoupper($matches[2])] = [
'module' => $matches[1],
'namespace' => $finalNamespace,
'class' => $matches[2],
'export' => true
);
];
}
}
}
......@@ -406,7 +411,8 @@ class CentreonAPI
protected function requireLibs($object)
{
if ($object != "") {
if (isset($this->relationObject[$object]['class'])
if (
isset($this->relationObject[$object]['class'])
&& isset($this->relationObject[$object]['module'])
&& !class_exists("\CentreonClapi\Centreon" . $this->relationObject[$object]['class'])
) {
......@@ -421,14 +427,16 @@ class CentreonAPI
}
}
if (isset($this->relationObject[$object]['libs'])
if (
isset($this->relationObject[$object]['libs'])
&& !array_walk($this->relationObject[$object]['libs'], 'class_exists')
) {
array_walk($this->relationObject[$object]['libs'], 'require_once');
}
} else {
foreach ($this->relationObject as $sSynonyme => $oObjet) {
if (isset($oObjet['class'])
if (
isset($oObjet['class'])
&& isset($oObjet['module'])
&& !class_exists("\CentreonClapi\Centreon" . $oObjet['class'])
) {
......@@ -924,7 +932,8 @@ class CentreonAPI
private function iniObject($objname)
{
$className = '';
if (isset($this->relationObject[$objname]['namespace'])
if (
isset($this->relationObject[$objname]['namespace'])
&& $this->relationObject[$objname]['namespace']
) {
$className .= '\\' . $this->relationObject[$objname]['namespace'];
......@@ -1114,9 +1123,11 @@ class CentreonAPI
$aObject = $this->relationObject;
while ($oObjet = array_slice($aObject, -1, 1, true)) {
$key = key($oObjet);
if (isset($oObjet[$key]['class'])
if (
isset($oObjet[$key]['class'])
&& $oObjet[$key]['export'] === true
&& !in_array($key, $this->aExport)) {
&& !in_array($key, $this->aExport)
) {
$objName = '';
if (isset($oObjet[$key]['namespace'])) {
$objName = '\\' . $oObjet[$key]['namespace'];
......
......@@ -133,7 +133,7 @@ class CentreonContact extends CentreonObject
'contact_activate' => '1',
'contact_register' => '1'
);
$this->insertParams = array(
$this->insertParams = [
'contact_name',
'contact_alias',
'contact_email',
......@@ -142,12 +142,13 @@ class CentreonContact extends CentreonObject
'contact_oreon',
'contact_lang',
'contact_auth_type'
);
];
$this->exportExcludedParams = array_merge(
$this->insertParams,
array(
$this->object->getPrimaryKey(),
"contact_register"
"contact_register",
"ar_id"
)
);
$this->action = "CONTACT";
......@@ -400,7 +401,13 @@ class CentreonContact extends CentreonObject
if (
!in_array(
$params[1],
['reach_api', 'reach_api_rt', 'default_page', 'ar_id', 'show_deprecated_pages']
[
'reach_api',
'reach_api_rt',
'default_page',
'show_deprecated_pages',
'enable_one_click_export'
]
)
) {
$params[1] = "contact_" . $params[1];
......
......@@ -479,7 +479,9 @@ class CentreonLDAP extends CentreonObject
if ($configuration['ari_name'] === 'ldap_default_cg') {
$contactGroupObj = new \Centreon_Object_Contact_Group($this->dependencyInjector);
$contactGroupName = $contactGroupObj->getParameters($configuration['ari_value'], 'cg_name');
$configuration['ari_value'] = $contactGroupName['cg_name'];
$configuration['ari_value'] = !empty($contactGroupName['cg_name'])
? $contactGroupName['cg_name']
: null;
}
echo $this->action . $this->delim . "SETPARAM" . $this->delim
. $ldap['ar_name'] . $this->delim
......
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