Private GIT

Skip to content
Snippets Groups Projects
Commit edb8a117 authored by loiclau's avatar loiclau Committed by Matthieu Kermagoret
Browse files

fix(clapi) fix duplicate ldap server

parent 9ddb2fdc
Branches
Tags
No related merge requests found
...@@ -135,6 +135,18 @@ class CentreonLDAP extends CentreonObject ...@@ -135,6 +135,18 @@ class CentreonLDAP extends CentreonObject
return $ldapId; 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 * Show list of ldap configurations
* *
...@@ -235,9 +247,17 @@ class CentreonLDAP extends CentreonObject ...@@ -235,9 +247,17 @@ class CentreonLDAP extends CentreonObject
} }
list($arName, $address, $port, $ssl, $tls) = $params; list($arName, $address, $port, $ssl, $tls) = $params;
$arId = $this->getLdapId($arName); $arId = $this->getLdapId($arName);
if (is_null($arId)) { if (is_null($arId)) {
throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ' ' . $arName); 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( $this->db->query(
"INSERT INTO auth_ressource_host (auth_ressource_id, host_address, host_port, use_ssl, use_tls) "INSERT INTO auth_ressource_host (auth_ressource_id, host_address, host_port, use_ssl, use_tls)
VALUES (:arId, :address, :port, :ssl, :tls)", VALUES (:arId, :address, :port, :ssl, :tls)",
...@@ -305,7 +325,7 @@ class CentreonLDAP extends CentreonObject ...@@ -305,7 +325,7 @@ class CentreonLDAP extends CentreonObject
if (in_array(strtolower($params[1]), array('name', 'description', 'enable'))) { if (in_array(strtolower($params[1]), array('name', 'description', 'enable'))) {
if (strtolower($params[1]) == 'name') { if (strtolower($params[1]) == 'name') {
if (!$this->isUnique($params[2], $arId)) { if (!$this->isUnique($params[2], $arId)) {
throw new CentreonClapiException(self::NAMEALREADYINUSE . ' (' . $name . ')'); throw new CentreonClapiException(self::NAMEALREADYINUSE . ' (' . $params[2] . ')');
} }
} }
$this->db->query( $this->db->query(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment