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

Commit

Permalink
fix(clapi) fix duplicate ldap server
Browse files Browse the repository at this point in the history
  • Loading branch information
loiclau authored and ganoze committed Oct 12, 2017
1 parent 9ddb2fd commit edb8a11
Showing 1 changed file with 21 additions and 1 deletion.
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

0 comments on commit edb8a11

Please sign in to comment.