From 809ca27ccd4199dd5009ff882ee841cc39146e17 Mon Sep 17 00:00:00 2001 From: loiclau Date: Wed, 11 Oct 2017 15:59:05 +0200 Subject: [PATCH 1/2] fix(clapi) fix duplicate ldap server --- .../centreon-clapi/centreonLDAP.class.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/www/class/centreon-clapi/centreonLDAP.class.php b/www/class/centreon-clapi/centreonLDAP.class.php index bd553ae8b50..8674065b543 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)", From 66dc9efaa247f90beedf34fdee3c6dab3bfe3ef1 Mon Sep 17 00:00:00 2001 From: loiclau Date: Wed, 11 Oct 2017 16:15:03 +0200 Subject: [PATCH 2/2] fix(clapi ldap) fix undefined variable --- www/class/centreon-clapi/centreonLDAP.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/class/centreon-clapi/centreonLDAP.class.php b/www/class/centreon-clapi/centreonLDAP.class.php index 8674065b543..2ce55f229ba 100644 --- a/www/class/centreon-clapi/centreonLDAP.class.php +++ b/www/class/centreon-clapi/centreonLDAP.class.php @@ -325,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(