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

Commit

Permalink
fix(clapi): Implode method that escape potential delimiter char in va…
Browse files Browse the repository at this point in the history
…lues (#11451)

Apply this new method to escape on export (used in all export methods on each objects).

Refs: #11451
Signed-off-by: Grégory Marigot <[email protected]>
  • Loading branch information
proxyconcept committed Aug 1, 2022
1 parent b5d2e22 commit 100f933
Show file tree
Hide file tree
Showing 24 changed files with 577 additions and 468 deletions.
13 changes: 7 additions & 6 deletions www/class/centreon-clapi/CentreonLDAPContactRelation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public function export($filterName = null): bool
foreach ($contact as $parameter => $value) {
if (!empty($value) && !in_array($parameter, $this->exportExcludedParams) && $parameter === "ar_id") {
$value = $this->ldap->getObjectName($value);
$value = CentreonUtils::convertLineBreak($value);
echo $this->action . $this->delim
. "setparam" . $this->delim
. $contact[$this->contact->getUniqueLabelField()] . $this->delim
. self::LDAP_PARAMETER_NAME . $this->delim
. $value . "\n";
echo $this->implodeDelimEscaped(array(
$this->action,
"setparam",
$contact[$this->contact->getUniqueLabelField()],
self::LDAP_PARAMETER_NAME,
CentreonUtils::convertLineBreak($value)
)) . "\n";
}
}
}
Expand Down
37 changes: 20 additions & 17 deletions www/class/centreon-clapi/centreonACLAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,24 @@ public function export($filterName = null)
$filters
);

$exportLine = '';
foreach ($aclActionRuleList as $aclActionRule) {
$exportLine .= $this->action . $this->delim . 'ADD' . $this->delim
. $aclActionRule['acl_action_name'] . $this->delim
. $aclActionRule['acl_action_description'] . $this->delim . "\n";

$exportLine .= $this->action . $this->delim . 'SETPARAM' . $this->delim
. $aclActionRule['acl_action_name'] . $this->delim;

$exportLine .= 'activate' . $this->delim . $aclActionRule['acl_action_activate'] . $this->delim . "\n";

$exportLine .= $this->exportGrantActions(
echo $this->implodeDelimEscaped(array(
$this->action,
'ADD',
$aclActionRule['acl_action_name'],
$aclActionRule['acl_action_description']
)) . "\n";
echo $this->implodeDelimEscaped(array(
$this->action,
'SETPARAM',
$aclActionRule['acl_action_name'],
'activate',
$aclActionRule['acl_action_activate']
)) . "\n";
echo $this->exportGrantActions(
$aclActionRule['acl_action_id'],
$aclActionRule['acl_action_name']
);

echo $exportLine;
$exportLine = '';
}
}

Expand All @@ -343,9 +343,12 @@ private function exportGrantActions($aclActionRuleId, $aclActionName)
$aclActionList = $stmt->fetchAll();

foreach ($aclActionList as $aclAction) {
$grantActions .= $this->action . $this->delim . 'GRANT' . $this->delim .
$aclActionName . $this->delim .
$aclAction['acl_action_name'] . $this->delim . "\n";
$grantActions .= $this->implodeDelimEscaped(array(
$this->action,
'GRANT',
$aclActionName,
$aclAction['acl_action_name']
)) . "\n";
}

return $grantActions;
Expand Down
40 changes: 23 additions & 17 deletions www/class/centreon-clapi/centreonACLGroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,24 @@ public function export($filterName = null)
$filters
);

$exportLine = '';
foreach ($aclGroupList as $aclGroup) {
$exportLine .= $this->action . $this->delim . "ADD" . $this->delim
. $aclGroup['acl_group_name'] . $this->delim
. $aclGroup['acl_group_alias'] . $this->delim . "\n";

$exportLine .= $this->action . $this->delim . "SETPARAM" . $this->delim
. $aclGroup['acl_group_name'] . $this->delim
. 'activate' . $this->delim
. $aclGroup['acl_group_activate'] . $this->delim . "\n";

$exportLine .= $this->exportLinkedObjects($aclGroup['acl_group_id'], $aclGroup['acl_group_name']);

echo $exportLine;
$exportLine = '';
echo $this->implodeDelimEscaped(array(
$this->action,
"ADD",
$aclGroup['acl_group_name'],
$aclGroup['acl_group_alias']
)) . "\n";
echo $this->implodeDelimEscaped(array(
$this->action,
"SETPARAM",
$aclGroup['acl_group_name'],
'activate',
$aclGroup['acl_group_activate']
)) . "\n";
echo $this->exportLinkedObjects(
$aclGroup['acl_group_id'],
$aclGroup['acl_group_name']
);
}
}

Expand Down Expand Up @@ -336,9 +339,12 @@ private function exportLinkedObjects($aclGroupId, $aclGroupName)
),
);

$linkedObjectsSetter = $this->action . $this->delim . 'SET%s' . $this->delim .
$aclGroupName . $this->delim .
'%s' . $this->delim . "\n";
$linkedObjectsSetter = $this->implodeDelimEscaped(array(
$this->action,
'SET%s',
$aclGroupName,
'%s'
)) . "\n";

$linkedObjectsStr = '';

Expand Down
41 changes: 22 additions & 19 deletions www/class/centreon-clapi/centreonACLMenu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,26 @@ public function export($filterName = null)
$filters
);

$exportLine = '';
foreach ($aclMenuList as $aclMenu) {
$exportLine .= $this->action . $this->delim . "ADD" . $this->delim
. $aclMenu['acl_topo_name'] . $this->delim
. $aclMenu['acl_topo_alias'] . $this->delim . "\n";

$exportLine .= $this->action . $this->delim .
"SETPARAM" . $this->delim .
$aclMenu['acl_topo_name'] . $this->delim;
echo $this->implodeDelimEscaped(array(
$this->action,
"ADD",
$aclMenu['acl_topo_name'],
$aclMenu['acl_topo_alias']
)) . "\n";

$setTab = array(
$this->action,
"SETPARAM",
$aclMenu['acl_topo_name'],
);
if (!empty($aclMenu['acl_comments'])) {
$exportLine .= 'comment' . $this->delim . $aclMenu['acl_comments'] . $this->delim;
$setTab = array_merge($setTab, array('comment', $aclMenu['acl_comments']));
}
$setTab = array_merge($setTab, array('activate', $aclMenu['acl_topo_activate']));
echo $this->implodeDelimEscaped($setTab) . "\n";

$exportLine .= 'activate' . $this->delim . $aclMenu['acl_topo_activate'] . $this->delim . "\n";
$exportLine .= $this->grantMenu($aclMenu['acl_topo_id'], $aclMenu['acl_topo_name']);

echo $exportLine;
$exportLine = '';
echo $this->grantMenu($aclMenu['acl_topo_id'], $aclMenu['acl_topo_name']);
}
}

Expand All @@ -438,11 +439,13 @@ private function grantMenu($aclTopoId, $aclTopoName)
{
$grantedMenu = '';

$grantedMenuTpl = $this->action . $this->delim .
'%s' . $this->delim .
$aclTopoName . $this->delim .
'%s' . $this->delim .
'%s' . $this->delim . "\n";
$grantedMenuTpl = $this->implodeDelimEscaped(array(
$this->action,
'%s',
$aclTopoName,
'%s',
'%s'
)) . "\n";

$grantedPossibilities = array(
'1' => 'GRANTRW',
Expand Down
40 changes: 22 additions & 18 deletions www/class/centreon-clapi/centreonACLResource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,25 +454,26 @@ public function export($filterName = null)
$filters
);

$exportLine = '';
foreach ($aclResourceList as $aclResource) {
$exportLine .= $this->action . $this->delim . "ADD" . $this->delim
. $aclResource['acl_res_name'] . $this->delim
. $aclResource['acl_res_alias'] . $this->delim . "\n";

$exportLine .= $this->action . $this->delim . "SETPARAM" . $this->delim
. $aclResource['acl_res_name'] . $this->delim;

echo $this->implodeDelimEscaped(array(
$this->action,
"ADD",
$aclResource['acl_res_name'],
$aclResource['acl_res_alias']
)) . "\n";

$setTab = array(
$this->action,
"SETPARAM",
$aclResource['acl_res_name']
);
if (!empty($aclResource['acl_res_comment'])) {
$exportLine .= 'comment' . $this->delim . $aclResource['acl_res_comment'] . $this->delim;
$setTab = array_merge($setTab, array('comment', $aclResource['acl_res_comment']));
}
$setTab = array_merge($setTab, array('activate', $aclResource['acl_res_activate']));
echo $this->implodeDelimEscaped($setTab) . "\n";

$exportLine .= 'activate' . $this->delim . $aclResource['acl_res_activate'] . $this->delim . "\n";

$exportLine .= $this->exportGrantResources($aclResource);

echo $exportLine;
$exportLine = '';
echo $this->exportGrantResources($aclResource);
}
}

Expand Down Expand Up @@ -742,9 +743,12 @@ private function exportGrantObject($grantedResourceItems, $grantCommand, $aclRes
$grantObject = '';

// Template for object export command
$grantedCommandTpl = $this->action . $this->delim . $grantCommand . $this->delim .
$aclResName . $this->delim .
'%s' . $this->delim . "\n";
$grantedCommandTpl = $this->implodeDelimEscaped(array(
$this->action,
$grantCommand,
$aclResName,
'%s'
)) . "\n";

$grantedObjectList = '';
if (is_array($grantedResourceItems)) { // Non wildcard mode
Expand Down
Loading

0 comments on commit 100f933

Please sign in to comment.