Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(clapi) fix duplicate ldap server #5769

Merged
merged 2 commits into from
Oct 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion www/class/centreon-clapi/centreonLDAP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ public function getLdapId($name)
return $ldapId;
}

/**
* @param $id
* @return mixed
*/
public function getLdapServers($id)
{
$query = "SELECT host_address, host_port FROM auth_ressource_host WHERE auth_ressource_id = ?";
$res = $this->db->query($query, array($id));
$row = $res->fetchAll();
return $row;
}

/**
* Show list of ldap configurations
*
Expand Down Expand Up @@ -235,9 +247,17 @@ public function addserver($parameters)
}
list($arName, $address, $port, $ssl, $tls) = $params;
$arId = $this->getLdapId($arName);

if (is_null($arId)) {
throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ' ' . $arName);
}

$serverList = $this->getLdapServers($arId);
$newServer = array('host_address' => $address, 'host_port' => $port);
if (in_array($newServer, $serverList)) {
throw new CentreonClapiException(self::OBJECTALREADYEXISTS . ' ' . $address);
}

$this->db->query(
"INSERT INTO auth_ressource_host (auth_ressource_id, host_address, host_port, use_ssl, use_tls)
VALUES (:arId, :address, :port, :ssl, :tls)",
Expand Down Expand Up @@ -305,7 +325,7 @@ public function setparam($parameters)
if (in_array(strtolower($params[1]), array('name', 'description', 'enable'))) {
if (strtolower($params[1]) == 'name') {
if (!$this->isUnique($params[2], $arId)) {
throw new CentreonClapiException(self::NAMEALREADYINUSE . ' (' . $name . ')');
throw new CentreonClapiException(self::NAMEALREADYINUSE . ' (' . $params[2] . ')');
}
}
$this->db->query(
Expand Down