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

Commit

Permalink
get enabled and disabled hostgroups by acl (#12038)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-launois authored Oct 26, 2022
1 parent 303db80 commit 0c99e15
Showing 1 changed file with 76 additions and 14 deletions.
90 changes: 76 additions & 14 deletions www/class/centreonACL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ public function getServiceGroupAclConf($search = null, $broker = null, $options
$empty_exists = "";
if (!is_null($sg_empty)) {
$empty_exists = 'AND EXISTS (
SELECT * FROM servicegroup_relation
SELECT * FROM servicegroup_relation
WHERE (servicegroup_relation.servicegroup_sg_id = servicegroup.sg_id
AND servicegroup_relation.service_service_id IS NOT NULL)) ';
}
Expand Down Expand Up @@ -2293,7 +2293,7 @@ public function getHostServiceAclConf($host_id, $broker = null, $options = null)
}

/**
* Get HostGroup from ACL and configuration DB
* Get HostGroup from ACL and configuration DB (enabled only)
*/
public function getHostGroupAclConf($search = null, $broker = null, $options = null, $hg_empty = false)
{
Expand Down Expand Up @@ -2349,6 +2349,68 @@ public function getHostGroupAclConf($search = null, $broker = null, $options = n
return $hg;
}

/**
* Get HostGroup from ACL and configuration DB (enabled and disabled)
*
* @param string $search
* @param array<string,mixed> $options
* @param bool $hg_empty
* @return string[]
*/
public function getAllHostGroupAclConf($search = null, $options = null, $hg_empty = false)
{
$hg = [];

if (is_null($options)) {
$options = [
'order' => ['LOWER(hg_name)'],
'fields' => ['hg_id', 'hg_name'],
'keys' => ['hg_id'],
'keys_separator' => '',
'get_row' => 'hg_name'
];
}

$request = $this->constructRequest($options, true);

$searchCondition = "";
if ($search != "") {
$searchCondition = "AND hg_name LIKE '%" . CentreonDB::escape($search) . "%' ";
}
if ($this->admin) {
$empty_exists = "";
if ($hg_empty) {
$empty_exists = 'AND EXISTS (SELECT * FROM hostgroup_relation WHERE
(hostgroup_relation.hostgroup_hg_id = hostgroup.hg_id
AND hostgroup_relation.host_host_id IS NOT NULL)) ';
}
$request = $this->constructRequest($options, false);

$query = $request['select'] . $request['fields'] . " "
. "FROM hostgroup "
. $request['conditions']
. $searchCondition
. $empty_exists;
} else {
$groupIds = array_keys($this->accessGroups);
$request = $this->constructRequest($options, true);

$query = $request['select'] . $request['fields'] . " "
. "FROM hostgroup, acl_res_group_relations, acl_resources_hg_relations "
. "WHERE acl_res_group_relations.acl_group_id IN (" . implode(',', $groupIds) . ") "
. "AND acl_res_group_relations.acl_res_id = acl_resources_hg_relations.acl_res_id "
. "AND acl_resources_hg_relations.hg_hg_id = hostgroup.hg_id "
. $request['conditions']
. $searchCondition;
}

$query .= $request['order'] . $request['pages'];

$hg = $this->constructResult($query, $options);

return $hg;
}

/**
* @param $hg_id
* @param null $broker
Expand Down Expand Up @@ -2572,10 +2634,10 @@ public static function duplicateHostAcl($hosts = [])
*/
public static function duplicateHgAcl($hgs = array())
{
$sql = "INSERT INTO %s
$sql = "INSERT INTO %s
(hg_hg_id, acl_res_id)
(SELECT %d, acl_res_id
FROM %s
(SELECT %d, acl_res_id
FROM %s
WHERE hg_hg_id = %d)";
$tb = "acl_resources_hg_relations";
foreach ($hgs as $copyId => $originalId) {
Expand All @@ -2591,10 +2653,10 @@ public static function duplicateHgAcl($hgs = array())
*/
public static function duplicateSgAcl($sgs = array())
{
$sql = "INSERT INTO %s
$sql = "INSERT INTO %s
(sg_id, acl_res_id)
(SELECT %d, acl_res_id
FROM %s
(SELECT %d, acl_res_id
FROM %s
WHERE sg_id = %d)";
$tb = "acl_resources_sg_relations";
foreach ($sgs as $copyId => $originalId) {
Expand All @@ -2610,10 +2672,10 @@ public static function duplicateSgAcl($sgs = array())
*/
public static function duplicateHcAcl($hcs = array())
{
$sql = "INSERT INTO %s
$sql = "INSERT INTO %s
(hc_id, acl_res_id)
(SELECT %d, acl_res_id
FROM %s
(SELECT %d, acl_res_id
FROM %s
WHERE hc_id = %d)";
$tb = "acl_resources_hc_relations";
foreach ($hcs as $copyId => $originalId) {
Expand All @@ -2629,10 +2691,10 @@ public static function duplicateHcAcl($hcs = array())
*/
public static function duplicateScAcl($scs = array())
{
$sql = "INSERT INTO %s
$sql = "INSERT INTO %s
(sc_id, acl_res_id)
(SELECT %d, acl_res_id
FROM %s
(SELECT %d, acl_res_id
FROM %s
WHERE sc_id = %d)";
$tb = "acl_resources_sc_relations";
foreach ($scs as $copyId => $originalId) {
Expand Down

0 comments on commit 0c99e15

Please sign in to comment.