diff --git a/src/Centreon/Domain/Monitoring/CommandLineTrait.php b/src/Centreon/Domain/Monitoring/CommandLineTrait.php index 7de470a386a..0e076abb00a 100644 --- a/src/Centreon/Domain/Monitoring/CommandLineTrait.php +++ b/src/Centreon/Domain/Monitoring/CommandLineTrait.php @@ -43,6 +43,9 @@ private function buildCommandLineFromConfiguration( array $macros, string $replacementValue ): string { + // if the command line contains $$ after a macro (so $$$), delete one of them to match with + // the command executed by centreon-engine + $configurationCommand = str_replace('$$$', '$$', $configurationCommand); $macroPasswordNames = []; foreach ($macros as $macro) { if ($macro->isPassword()) { diff --git a/src/Centreon/Domain/Repository/TopologyRepository.php b/src/Centreon/Domain/Repository/TopologyRepository.php index dc682d3acb3..64506d925f7 100644 --- a/src/Centreon/Domain/Repository/TopologyRepository.php +++ b/src/Centreon/Domain/Repository/TopologyRepository.php @@ -105,14 +105,15 @@ public function getReactTopologiesPerUserWithAcl($user) if ($DBRESULT->rowCount()) { $topology = array(); $tmp_topo_page = array(); + $statement = $this->db->prepare("SELECT topology_topology_id, acl_topology_relations.access_right " + . "FROM acl_topology_relations, acl_topology " + . "WHERE acl_topology.acl_topo_activate = '1' " + . "AND acl_topology.acl_topo_id = acl_topology_relations.acl_topo_id " + . "AND acl_topology_relations.acl_topo_id = :acl_topo_id "); while ($topo_group = $DBRESULT->fetchRow()) { - $query2 = "SELECT topology_topology_id, acl_topology_relations.access_right " - . "FROM acl_topology_relations, acl_topology " - . "WHERE acl_topology.acl_topo_activate = '1' " - . "AND acl_topology.acl_topo_id = acl_topology_relations.acl_topo_id " - . "AND acl_topology_relations.acl_topo_id = '" . $topo_group["acl_topology_id"] . "' "; - $DBRESULT2 = $this->db->query($query2); - while ($topo_page = $DBRESULT2->fetchRow()) { + $statement->bindValue(':acl_topo_id', $topo_group["acl_topology_id"], \PDO::PARAM_INT); + $statement->execute(); + while ($topo_page = $statement->fetch(\PDO::FETCH_ASSOC)) { $topology[] = (int)$topo_page["topology_topology_id"]; if (!isset($tmp_topo_page[$topo_page['topology_topology_id']])) { $tmp_topo_page[$topo_page["topology_topology_id"]] = $topo_page["access_right"]; @@ -127,7 +128,7 @@ public function getReactTopologiesPerUserWithAcl($user) } } } - $DBRESULT2->closeCursor(); + $statement->closeCursor(); } $DBRESULT->closeCursor(); diff --git a/src/Centreon/Tests/Domain/Repository/TopologyRepositoryTest.php b/src/Centreon/Tests/Domain/Repository/TopologyRepositoryTest.php index 9a13235a202..1c986ef6f0f 100644 --- a/src/Centreon/Tests/Domain/Repository/TopologyRepositoryTest.php +++ b/src/Centreon/Tests/Domain/Repository/TopologyRepositoryTest.php @@ -52,7 +52,7 @@ protected function setUp(): void . "FROM acl_topology_relations, acl_topology " . "WHERE acl_topology.acl_topo_activate = '1' " . "AND acl_topology.acl_topo_id = acl_topology_relations.acl_topo_id " - . "AND acl_topology_relations.acl_topo_id = '1' ", + . "AND acl_topology_relations.acl_topo_id = :acl_topo_id ", 'data' => [ [ 'topology_topology_id' => 1, diff --git a/src/Core/Application/RealTime/UseCase/FindHost/FindHost.php b/src/Core/Application/RealTime/UseCase/FindHost/FindHost.php index d4cbe47c9ad..98c26a326b9 100644 --- a/src/Core/Application/RealTime/UseCase/FindHost/FindHost.php +++ b/src/Core/Application/RealTime/UseCase/FindHost/FindHost.php @@ -102,6 +102,14 @@ public function __invoke(int $hostId, FindHostPresenterInterface $presenter): vo $host->addHostgroup($hostgroup); } + $acknowledgement = $host->isAcknowledged() === true + ? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostId($hostId) + : null; + + $downtimes = $host->isInDowntime() === true + ? $this->downtimeRepository->findOnGoingDowntimesByHostId($hostId) + : []; + /** * Obfuscate the passwords in Host commandLine * @todo Re-write this code when monitoring repository will be migrated to new architecture @@ -111,8 +119,8 @@ public function __invoke(int $hostId, FindHostPresenterInterface $presenter): vo $presenter->present( $this->createResponse( $host, - $this->downtimeRepository->findOnGoingDowntimesByHostId($hostId), - $this->acknowledgementRepository->findOnGoingAcknowledgementByHostId($hostId) + $downtimes, + $acknowledgement ) ); } diff --git a/src/Core/Application/RealTime/UseCase/FindMetaService/FindMetaService.php b/src/Core/Application/RealTime/UseCase/FindMetaService/FindMetaService.php index 1eaa1d48f3c..46de2824fcc 100644 --- a/src/Core/Application/RealTime/UseCase/FindMetaService/FindMetaService.php +++ b/src/Core/Application/RealTime/UseCase/FindMetaService/FindMetaService.php @@ -120,12 +120,20 @@ public function __invoke( $hostId = $metaService->getHostId(); $serviceId = $metaService->getServiceId(); + $acknowledgement = $metaService->isAcknowledged() === true + ? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId) + : null; + + $downtimes = $metaService->isInDowntime() === true + ? $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId) + : []; + $presenter->present( $this->createResponse( $metaService, $metaServiceConfiguration, - $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId), - $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId) + $downtimes, + $acknowledgement ) ); } diff --git a/src/Core/Application/RealTime/UseCase/FindService/FindService.php b/src/Core/Application/RealTime/UseCase/FindService/FindService.php index 5b04dd2f1c3..42ca2a163f5 100644 --- a/src/Core/Application/RealTime/UseCase/FindService/FindService.php +++ b/src/Core/Application/RealTime/UseCase/FindService/FindService.php @@ -141,11 +141,20 @@ public function __invoke( */ $service->setCommandLine($this->obfuscatePasswordInServiceCommandLine($service)); + + $acknowledgement = $service->isAcknowledged() === true + ? $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId) + : null; + + $downtimes = $service->isInDowntime() === true + ? $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId) + : []; + $presenter->present( $this->createResponse( $service, - $this->downtimeRepository->findOnGoingDowntimesByHostIdAndServiceId($hostId, $serviceId), - $this->acknowledgementRepository->findOnGoingAcknowledgementByHostIdAndServiceId($hostId, $serviceId), + $downtimes, + $acknowledgement, $host ) ); diff --git a/src/EventSubscriber/WebSSOEventSubscriber.php b/src/EventSubscriber/WebSSOEventSubscriber.php index 84735d2aacb..e47b7355844 100644 --- a/src/EventSubscriber/WebSSOEventSubscriber.php +++ b/src/EventSubscriber/WebSSOEventSubscriber.php @@ -252,7 +252,7 @@ private function createSession(Contact $user, Request $request): void 'contact_autologin_key' => '', 'contact_admin' => $user->isAdmin() ? '1' : '0', 'default_page' => $user->getDefaultPage(), - 'contact_location' => $user->getLocale(), + 'contact_location' => (string) $user->getTimezoneId(), 'show_deprecated_pages' => $user->isUsingDeprecatedPages(), 'reach_api' => $user->hasAccessToApiConfiguration() ? 1 : 0, 'reach_api_rt' => $user->hasAccessToApiRealTime() ? 1 : 0, diff --git a/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostTest.php b/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostTest.php index 4bce35405a7..01c3e14ccc9 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostTest.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostTest.php @@ -201,7 +201,9 @@ public function testFindHostAsAdmin(): void /** * @var Host */ - $host = HostTest::createHostModel(); + $host = (HostTest::createHostModel()) + ->setIsAcknowledged(true) + ->setIsInDowntime(true); $this->repository ->expects($this->once()) @@ -308,7 +310,9 @@ public function testFindHostAsNonAdmin(): void /** * @var Host */ - $host = HostTest::createHostModel(); + $host = (HostTest::createHostModel()) + ->setIsAcknowledged(true) + ->setIsInDowntime(true); $this->repository ->expects($this->once()) diff --git a/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServiceTest.php b/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServiceTest.php index 0cff38c15b2..67e292d37d5 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServiceTest.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServiceTest.php @@ -257,7 +257,9 @@ public function testMetaServiceFound(): void ->setAdmin(false); $metaServiceConfiguration = MetaServiceConfigurationTest::createMetaServiceModel(); - $metaService = MetaServiceTest::createMetaServiceModel(); + $metaService = (MetaServiceTest::createMetaServiceModel()) + ->setIsAcknowledged(true) + ->setIsInDowntime(true); $downtimes[] = (new Downtime(1, 1, 10)) ->setCancelled(false); diff --git a/tests/php/Core/Application/RealTime/UseCase/FindService/FindServiceTest.php b/tests/php/Core/Application/RealTime/UseCase/FindService/FindServiceTest.php index a7a51824231..431511e1b4a 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindService/FindServiceTest.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindService/FindServiceTest.php @@ -301,7 +301,10 @@ public function testFindServiceAsAdmin(): void /** * @var Service */ - $service = ServiceTest::createServiceModel(); + $service = (ServiceTest::createServiceModel()) + ->setIsAcknowledged(true) + ->setIsInDowntime(true); + $servicegroup = new Servicegroup(1, 'ALL'); $this->hostRepository @@ -420,7 +423,10 @@ public function testFindServiceAsNonAdmin(): void ); $host = HostTest::createHostModel(); - $service = ServiceTest::createServiceModel(); + $service = (ServiceTest::createServiceModel()) + ->setIsAcknowledged(true) + ->setIsInDowntime(true); + $servicegroup = new Servicegroup(1, 'ALL'); $this->hostRepository diff --git a/www/class/centreonDB.class.php b/www/class/centreonDB.class.php index 7661578361f..d8195b79703 100644 --- a/www/class/centreonDB.class.php +++ b/www/class/centreonDB.class.php @@ -289,7 +289,7 @@ public static function escape($str, $htmlSpecialChars = false) /** * Query * - * @return PDOStatement|null + * @return CentreonDBStatement|false * @param string $queryString * @param mixed $parameters * @param mixed $parametersArgs diff --git a/www/include/configuration/configObject/host/DB-Func.php b/www/include/configuration/configObject/host/DB-Func.php index ded9185e1ab..ebd46a93851 100644 --- a/www/include/configuration/configObject/host/DB-Func.php +++ b/www/include/configuration/configObject/host/DB-Func.php @@ -1349,6 +1349,13 @@ function updateHost($host_id = null, $from_MC = false, $cfg = null) $ret = $cfg; } + if (!isset($ret["contact_additive_inheritance"])) { + $ret["contact_additive_inheritance"] = "0"; + } + if (!isset($ret["cg_additive_inheritance"])) { + $ret["cg_additive_inheritance"] = "0"; + } + isset($ret["nagios_server_id"]) ? $server_id = $ret["nagios_server_id"] : $server_id = $form->getSubmitValue("nagios_server_id"); @@ -2620,8 +2627,8 @@ function sanitizeFormHostParameters(array $ret): array $inputValue = filter_var($inputValue, FILTER_SANITIZE_STRING); $bindParams[':' . $inputName] = [ \PDO::PARAM_STR => ($inputValue === '' || $inputValue === false) - ? null - : $inputValue + ? null + : $inputValue ]; } break; @@ -2661,38 +2668,34 @@ function sanitizeFormHostParameters(array $ret): array $inputValue = filter_var(implode(",", array_keys($inputValue)), FILTER_SANITIZE_STRING); $bindParams[':host_notification_options'] = [ \PDO::PARAM_STR => ($inputValue === '' || $inputValue === false) - ? null - : $inputValue + ? null + : $inputValue ]; } break; case 'contact_additive_inheritance': case 'cg_additive_inheritance': - $bindParams[':' . $inputName] = [ - \PDO::PARAM_INT => (isset($ret[$inputName]) ? 1 : 0) - ]; + $bindParams[':' . $inputName] = [\PDO::PARAM_INT => $inputValue]; break; case 'mc_contact_additive_inheritance': case 'mc_cg_additive_inheritance': - $bindParams[':' . str_replace('mc_', '', $inputName)] = [ - \PDO::PARAM_INT => (isset($ret[$inputName]) ? 1 : 0) - ]; + if (in_array($inputValue[$inputName], ['0', '1'])) { + $bindParams[':' . str_replace('mc_', '', $inputName)] = [ + \PDO::PARAM_INT => $inputValue[$inputName] + ]; + } break; case 'host_stalOpts': if (!empty($inputValue)) { $inputValue = filter_var(implode(",", array_keys($inputValue)), FILTER_SANITIZE_STRING); $bindParams[':host_stalking_options'] = [ - \PDO::PARAM_STR => ($inputValue === '' || $inputValue === false) - ? null - : $inputValue + \PDO::PARAM_STR => ($inputValue === '' || $inputValue === false) ? null : $inputValue ]; } break; case 'host_register': $bindParams[':' . $inputName] = [ - \PDO::PARAM_STR => in_array($inputValue, ['0', '1', '2', '3']) - ? $inputValue - : null + \PDO::PARAM_STR => in_array($inputValue, ['0', '1', '2', '3']) ? $inputValue : null ]; break; case 'host_activate': diff --git a/www/include/monitoring/objectDetails/serviceDetails.php b/www/include/monitoring/objectDetails/serviceDetails.php index cf71401d922..e0ac888e93c 100644 --- a/www/include/monitoring/objectDetails/serviceDetails.php +++ b/www/include/monitoring/objectDetails/serviceDetails.php @@ -621,18 +621,17 @@ $status .= "&value[" . $key . "]=" . $value; } - $optionsURL = "host_name=" . urlencode($host_name) . "&service_description=" . urlencode($svc_description); - - $query = "SELECT id FROM `index_data`, `metrics` WHERE host_name = '" . $pearDBO->escape($host_name) . - "' AND service_description = '" . $pearDBO->escape($svc_description) . "' AND id = index_id LIMIT 1"; - $DBRES = $pearDBO->query($query); + $query = "SELECT id FROM `index_data`, `metrics` WHERE host_name = :host_name" . + " AND service_description = :svc_description AND id = index_id LIMIT 1"; + $statement = $pearDBO->prepare($query); + $statement->bindValue(':host_name', $host_name, \PDO::PARAM_STR); + $statement->bindValue(':svc_description', $svc_description, \PDO::PARAM_STR); + $statement->execute(); $index_data = 0; - if ($DBRES->rowCount()) { - $row = $DBRES->fetchRow(); + if ($statement->rowCount()) { + $row = $statement->fetchRow(); $index_data = $row['id']; } - $optionsURL2 = "index=" . $index_data; - /* * Assign translations */ @@ -875,9 +874,7 @@ $tpl->assign("sv_ext_action_url_lang", _("Action URL")); $tpl->assign("sv_ext_action_url", CentreonUtils::escapeSecure($actionurl)); $tpl->assign("sv_ext_icon_image_alt", getMyServiceExtendedInfoField($service_id, "esi_icon_image_alt")); - $tpl->assign("options", $optionsURL); $tpl->assign("index_data", $index_data); - $tpl->assign("options2", CentreonUtils::escapeSecure($optionsURL2)); /** * Build the service detail URI that will be used in the diff --git a/www/install/insertBaseConf.sql b/www/install/insertBaseConf.sql index 02dd52d742e..64c58364d05 100644 --- a/www/install/insertBaseConf.sql +++ b/www/install/insertBaseConf.sql @@ -2,7 +2,7 @@ -- Insert version -- -INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '22.04.5'); +INSERT INTO `informations` (`key` ,`value`) VALUES ('version', '22.04.6'); -- -- Contenu de la table `contact`