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

Commit

Permalink
use correct id for acl host relation (#5896)
Browse files Browse the repository at this point in the history
fix host id for acl relation
  • Loading branch information
loiclau committed Nov 20, 2017
1 parent fb2ac05 commit 38806cc
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions www/include/configuration/configObject/host/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function testHostExistence($name = null)
$id = null;
if (isset($form)) {
$id = $form->getSubmitValue('host_id');
;
}
$DBRESULT = $pearDB->query("SELECT host_name, host_id
FROM host
Expand Down Expand Up @@ -757,7 +758,7 @@ function insertHostInDB($ret = array(), $macro_on_demand = null)

$host_id = insertHost($ret, $macro_on_demand, $server_id);
updateHostHostParent($host_id, $ret);
updateHostHostChild($host_id, $ret);
updateHostHostChild($host_id);
updateHostContactGroup($host_id, $ret);
updateHostContact($host_id, $ret);
updateHostNotifs($host_id, $ret);
Expand All @@ -766,7 +767,7 @@ function insertHostInDB($ret = array(), $macro_on_demand = null)
updateHostNotifOptionFirstNotificationDelay($host_id, $ret);
updateHostHostGroup($host_id, $ret);
updateHostHostCategory($host_id, $ret);
updateHostTemplateService($host_id, $ret);
updateHostTemplateService($host_id);
updateNagiosServerRelation($host_id, $ret);
$ret = $form->getSubmitValues();
if (isset($ret["dupSvTplAssoc"]["dupSvTplAssoc"]) && $ret["dupSvTplAssoc"]["dupSvTplAssoc"]) {
Expand Down Expand Up @@ -1043,18 +1044,25 @@ function insertHost($ret, $macro_on_demand = null, $server_id = null)
}

if (isset($ret['acl_groups']) && count($ret['acl_groups'])) {
$sql = "INSERT INTO acl_resources_host_relations (acl_res_id, host_host_id) VALUES ";
$first = true;
foreach ($ret['acl_groups'] as $groupId) {
$sql = "SELECT acl_res_id FROM acl_res_group_relations WHERE acl_group_id = " . $groupId;
$res = $pearDB->query($sql);

$query = "INSERT INTO acl_resources_host_relations (acl_res_id, host_host_id) VALUES ";
$first = true;

while ($aclRes = $res->fetchRow()) {
if (!$first) {
$query .= ", ";
} else {
$first = false;
}
$query .= "(" . $aclRes['acl_res_id'] . ", " . $pearDB->escape($host_id['MAX(host_id)']) . ")";
}

if (!$first) {
$sql .= ", ";
} else {
$first = false;
$pearDB->query($query);
}
$sql .= "(" . $pearDB->escape($groupId) . ", " . $pearDB->escape($host_id['MAX(host_id)']) . ")";
}
if (!$first) {
$pearDB->query($sql);
}
}
/*
Expand Down

0 comments on commit 38806cc

Please sign in to comment.