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

[SNYK] : MON-14671-sanitize-and-bind-update-22-04-0-beta-1-queries #11656

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions www/install/php/Update-22.04.0-beta.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,26 +528,34 @@ function migrateBrokerConfigOutputsToUnifiedSql(CentreonDB $pearDB): void
throw new \Exception("Cannot find max config group id in cfg_centreonbroker_info table");
}
$nextConfigGroupId = (int) $maxConfigGroupId['max_config_group_id'] + 1;

$blockIdsQueryBinds = [];
foreach ($blockIds as $key => $value) {
$blockIdsQueryBinds[':block_id_' . $key] = $value;
}
$blockIdBinds = implode(',', array_keys($blockIdsQueryBinds));
// Find config group ids of outputs to replace
$dbResult = $pearDB->query(
"SELECT config_group_id FROM cfg_centreonbroker_info
WHERE config_id = $configId AND config_key = 'blockId'
AND config_value IN ('" . implode('\', \'', $blockIds) . "')"
);
$configGroupIds = $dbResult->fetchAll(\PDO::FETCH_COLUMN, 0);
$grpIdStatement = $pearDB->prepare("SELECT config_group_id FROM cfg_centreonbroker_info
WHERE config_id = :configId AND config_key = 'blockId'
AND config_value IN ($blockIdBinds)");
$grpIdStatement->bindValue(':configId', (int) $configId, PDO::PARAM_INT);
foreach ($blockIdsQueryBinds as $key => $value) {
$grpIdStatement->bindValue($key, (int) $value, PDO::PARAM_INT);
}
$grpIdStatement->execute();
$configGroupIds = $grpIdStatement->fetchAll(\PDO::FETCH_COLUMN, 0);
if (empty($configGroupIds)) {
throw new \Exception("Cannot find config group ids in cfg_centreonbroker_info table");
}

// Build unified sql output config from outputs to replace
$unifiedSqlOutput = [];
$statement = $pearDB->prepare("SELECT * FROM cfg_centreonbroker_info
WHERE config_id = :configId AND config_group = 'output' AND config_group_id = :configGroupId");
foreach ($configGroupIds as $configGroupId) {
$dbResult = $pearDB->query(
"SELECT * FROM cfg_centreonbroker_info
WHERE config_id = $configId AND config_group = 'output' AND config_group_id = $configGroupId"
);
while ($row = $dbResult->fetch()) {
$statement->bindValue(':configId', (int) $configId, PDO::PARAM_INT);
$statement->bindValue(':configGroupId', (int) $configGroupId, PDO::PARAM_INT);
$statement->execute();
while ($row = $statement->fetch()) {
$unifiedSqlOutput[$row['config_key']] = array_merge($unifiedSqlOutput[$row['config_key']] ?? [], $row);
$unifiedSqlOutput[$row['config_key']]['config_group_id'] = $nextConfigGroupId;
}
Expand Down