From edb8a1177a0230e63c48710f4c74393c086ddb96 Mon Sep 17 00:00:00 2001 From: loiclau Date: Thu, 12 Oct 2017 10:01:34 +0200 Subject: [PATCH] fix(clapi) fix duplicate ldap server --- .../centreon-clapi/centreonLDAP.class.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/www/class/centreon-clapi/centreonLDAP.class.php b/www/class/centreon-clapi/centreonLDAP.class.php index bd553ae8b50..2ce55f229ba 100644 --- a/www/class/centreon-clapi/centreonLDAP.class.php +++ b/www/class/centreon-clapi/centreonLDAP.class.php @@ -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 * @@ -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)", @@ -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(