repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.15.php | centreon/www/install/php/Update-21.10.15.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.10.16.php | centreon/www/install/php/Update-20.10.16.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.10.15.php | centreon/www/install/php/Update-22.10.15.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.04.17.php | centreon/www/install/php/Update-20.04.17.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.20.php | centreon/www/install/php/Update-2.8.20.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
// Set default poller with localhost if it is not set
if (isset($pearDB)) {
$res = $pearDB->query('SELECT `name` FROM `nagios_server` WHERE `is_default` = 1');
if ($res->rowCount() == 0) {
$res = $pearDB->query("UPDATE `nagios_server` SET `is_default` = 1 WHERE `localhost` = '1'");
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.17.php | centreon/www/install/php/Update-2.8.17.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.17.php | centreon/www/install/php/Update-21.10.17.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.04.11.php | centreon/www/install/php/Update-20.04.11.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
include_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 20.04.11 : ';
/**
* Queries needing exception management and rollback if failing
*/
try {
// engine postpone
if ($pearDB->isColumnExist('cfg_nagios', 'postpone_notification_to_timeperiod')) {
// An update is required
$errorMessage = 'Impossible to drop postpone_notification_to_timeperiod from fg_nagios';
$pearDB->query('ALTER TABLE `cfg_nagios` DROP COLUMN `postpone_notification_to_timeperiod`');
}
$errorMessage = '';
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.04.0-rc.1.php | centreon/www/install/php/Update-20.04.0-rc.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.2.php | centreon/www/install/php/Update-21.10.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
include_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.10.2: ';
/**
* Query with transaction
*/
try {
$errorMessage = 'Impossible to add "contact_js_effects" column to "contact" table';
if (! $pearDB->isColumnExist('contact', 'contact_js_effects')) {
$pearDB->query(
"ALTER TABLE `contact`
ADD COLUMN `contact_js_effects` enum('0','1') DEFAULT '0'
AFTER `contact_comment`"
);
}
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-19.04.4.php | centreon/www/install/php/Update-19.04.4.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
include_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
/**
* LDAP auto or manual synchronization feature
*/
try {
$pearDB->query('SET SESSION innodb_strict_mode=OFF');
// Adding two columns to check last user's LDAP sync timestamp
if (! $pearDB->isColumnExist('contact', 'contact_ldap_last_sync')) {
// $pearDB = "centreon"
// $pearDBO = "realtime"
$pearDB->query(
'ALTER TABLE `contact` ADD COLUMN `contact_ldap_last_sync` INT(11) NOT NULL DEFAULT 0'
);
}
if (! $pearDB->isColumnExist('contact', 'contact_ldap_required_sync')) {
$pearDB->query(
"ALTER TABLE `contact` ADD COLUMN `contact_ldap_required_sync` enum('0','1') NOT NULL DEFAULT '0'"
);
}
// Adding a column to check last specific LDAP sync timestamp
$needToUpdateValues = false;
if (! $pearDB->isColumnExist('auth_ressource', 'ar_sync_base_date')) {
$pearDB->query(
'ALTER TABLE `auth_ressource` ADD COLUMN `ar_sync_base_date` INT(11) DEFAULT 0'
);
$needToUpdateValues = true;
}
} catch (PDOException $e) {
$centreonLog->insertLog(
2,
"UPGRADE : 19.04.4 Unable to add LDAP new feature's tables in the database"
);
} finally {
$pearDB->query('SET SESSION innodb_strict_mode=ON');
}
// Initializing reference synchronization time for all LDAP configurations */
if ($needToUpdateValues) {
try {
$stmt = $pearDB->prepare(
'UPDATE `auth_ressource` SET `ar_sync_base_date` = :minusTime'
);
$stmt->bindValue(':minusTime', time(), PDO::PARAM_INT);
$stmt->execute();
} catch (PDOException $e) {
$centreonLog->insertLog(
2,
'UPGRADE : 19.04.4 Unable to initialize LDAP reference date'
);
}
// Adding to each LDAP configuration two new fields
try {
// field to enable the automatic sync at login
$addSyncStateField = $pearDB->prepare(
"INSERT IGNORE INTO auth_ressource_info
(`ar_id`, `ari_name`, `ari_value`)
VALUES (:arId, 'ldap_auto_sync', '1')"
);
// interval between two sync at login
$addSyncIntervalField = $pearDB->prepare(
"INSERT IGNORE INTO auth_ressource_info
(`ar_id`, `ari_name`, `ari_value`)
VALUES (:arId, 'ldap_sync_interval', '1')"
);
$pearDB->beginTransaction();
$stmt = $pearDB->query('SELECT DISTINCT(ar_id) FROM auth_ressource');
while ($row = $stmt->fetch()) {
$addSyncIntervalField->bindValue(':arId', $row['ar_id'], PDO::PARAM_INT);
$addSyncIntervalField->execute();
$addSyncStateField->bindValue(':arId', $row['ar_id'], PDO::PARAM_INT);
$addSyncStateField->execute();
}
$pearDB->commit();
} catch (PDOException $e) {
$centreonLog->insertLog(
1, // ldap.log
'UPGRADE PROCESS : Error - Please open your LDAP configuration and save manually each LDAP form'
);
$centreonLog->insertLog(
2, // sql-error.log
'UPGRADE : 19.04.4 Unable to add LDAP new fields'
);
$pearDB->rollBack();
}
}
// update topology of poller wizard to display breadcrumb
$pearDB->query(
'UPDATE topology
SET topology_parent = 60901,
topology_page = 60959,
topology_group = 1,
topology_show = "0"
WHERE topology_url LIKE "/poller-wizard/%"'
);
try {
// Add trap regexp matching
if (! $pearDB->isColumnExist('traps', 'traps_mode')) {
$pearDB->query('SET SESSION innodb_strict_mode=OFF');
$pearDB->query(
"ALTER TABLE `traps` ADD COLUMN `traps_mode` enum('0','1') DEFAULT '0' AFTER `traps_oid`"
);
}
} catch (PDOException $e) {
$centreonLog->insertLog(
2,
'UPGRADE : 19.04.4 Unable to modify regexp matching in the database'
);
} finally {
$pearDB->query('SET SESSION innodb_strict_mode=ON');
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.10.7.php | centreon/www/install/php/Update-20.10.7.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.10.php | centreon/www/install/php/Update-21.10.10.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.10.10: ';
$errorMessage = '';
try {
if ($pearDB->isColumnExist('remote_servers', 'server_id') === 0) {
$errorMessage = "Unable to add 'server_id' column to remote_servers table";
$pearDB->query(
'ALTER TABLE remote_servers
ADD COLUMN `server_id` int(11) NOT NULL'
);
migrateRemoteServerRelations($pearDB);
$errorMessage = 'Unable to add foreign key constraint of remote_servers.server_id';
$pearDB->query(
'ALTER TABLE remote_servers
ADD CONSTRAINT `remote_server_nagios_server_ibfk_1`
FOREIGN KEY(`server_id`) REFERENCES `nagios_server` (`id`)
ON DELETE CASCADE'
);
}
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
/**
* Manage relations between remote servers and nagios servers
*
* @param CentreonDB $pearDB
*/
function migrateRemoteServerRelations(CentreonDB $pearDB): void
{
$processedIps = [];
$selectServerStatement = $pearDB->prepare(
'SELECT id FROM nagios_server WHERE ns_ip_address = :ip_address'
);
$deleteRemoteStatement = $pearDB->prepare(
'DELETE FROM remote_servers WHERE id = :id'
);
$updateRemoteStatement = $pearDB->prepare(
'UPDATE remote_servers SET server_id = :server_id WHERE id = :id'
);
$result = $pearDB->query(
'SELECT id, ip FROM remote_servers'
);
while ($remote = $result->fetch()) {
$remoteIp = $remote['ip'];
$remoteId = $remote['id'];
if (in_array($remoteIp, $processedIps)) {
$deleteRemoteStatement->bindValue(':id', $remoteId, PDO::PARAM_INT);
$deleteRemoteStatement->execute();
}
$processedIps[] = $remoteIp;
$selectServerStatement->bindValue(':ip_address', $remoteIp, PDO::PARAM_STR);
$selectServerStatement->execute();
if ($server = $selectServerStatement->fetch()) {
$updateRemoteStatement->bindValue(':server_id', $server['id'], PDO::PARAM_INT);
$updateRemoteStatement->bindValue(':id', $remoteId, PDO::PARAM_INT);
$updateRemoteStatement->execute();
} else {
$deleteRemoteStatement->bindValue(':id', $remoteId, PDO::PARAM_INT);
$deleteRemoteStatement->execute();
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-25.05.1.php | centreon/www/install/php/Update-25.05.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.04.16.php | centreon/www/install/php/Update-22.04.16.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-18.10.1.php | centreon/www/install/php/Update-18.10.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.04.7.php | centreon/www/install/php/Update-20.04.7.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.04.0-beta.2.php | centreon/www/install/php/Update-22.04.0-beta.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 22.04.0-beta.2: ';
$errorMessage = '';
try {
// Centengine logger v2
if (
$pearDB->isColumnExist('cfg_nagios', 'log_archive_path') === 1
&& $pearDB->isColumnExist('cfg_nagios', 'log_rotation_method') === 1
&& $pearDB->isColumnExist('cfg_nagios', 'daemon_dumps_core') === 1
) {
$errorMessage = 'Unable to remove log_archive_path,log_rotation_method,daemon_dumps_core from cfg_nagios table';
$pearDB->query(
'ALTER TABLE `cfg_nagios`
DROP COLUMN `log_archive_path`,
DROP COLUMN `log_rotation_method`,
DROP COLUMN `daemon_dumps_core`'
);
}
if ($pearDB->isColumnExist('cfg_nagios', 'logger_version') !== 1) {
$errorMessage = 'Unable to add logger_version to cfg_nagios table';
$pearDB->query(
"ALTER TABLE `cfg_nagios`
ADD COLUMN `logger_version` enum('log_v2_enabled', 'log_legacy_enabled') DEFAULT 'log_v2_enabled'"
);
}
// Add contact_theme column to contact table
if ($pearDB->isColumnExist('contact', 'contact_theme') !== 1) {
$errorMessage = "Unable to add column 'contact_theme' to table 'contact'";
$pearDB->query(
'ALTER TABLE `contact` ADD COLUMN '
. "`contact_theme` enum('light','dark') DEFAULT 'light' AFTER `contact_js_effects`"
);
}
if ($pearDB->isColumnExist('cfg_centreonbroker', 'bbdo_version') !== 1) {
$errorMessage = "Unable to add 'bbdo_version' column to 'cfg_centreonbroker' table";
$pearDB->query('ALTER TABLE `cfg_centreonbroker` ADD `bbdo_version` VARCHAR(50) DEFAULT "3.0.0"');
}
$errorMessage = 'Unable to update logger_version from cfg_nagios table';
$pearDB->query(
"UPDATE `cfg_nagios` set logger_version = 'log_legacy_enabled'"
);
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.10.6.php | centreon/www/install/php/Update-22.10.6.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 22.10.6: ';
$errorMessage = '';
try {
// Transactional queries
$pearDB->beginTransaction();
// check if entry ldap_connection_timeout exist
$query = $pearDB->query("SELECT * FROM auth_ressource_info WHERE ari_name = 'ldap_connection_timeout'");
$ldapResult = $query->fetchAll(PDO::FETCH_ASSOC);
// insert entry ldap_connection_timeout with default value
if (! $ldapResult) {
$errorMessage = 'Unable to add default LDAP connection timeout';
$pearDB->query(
"INSERT INTO auth_ressource_info (ar_id, ari_name, ari_value)
(SELECT ar_id, 'ldap_connection_timeout', '' FROM auth_ressource)"
);
}
$pearDB->commit();
} catch (Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-19.10.0-beta.2.php | centreon/www/install/php/Update-19.10.0-beta.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.04.3.php | centreon/www/install/php/Update-21.04.3.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.12.php | centreon/www/install/php/Update-21.10.12.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-23.10.2.php | centreon/www/install/php/Update-23.10.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 23.10.2: ';
$errorMessage = '';
$createNotificationContactgroupRelationTable = function (CentreonDB $pearDB) use (&$errorMessage): void {
$errorMessage = 'Unable to create table: notification_contactgroup_relation';
$pearDB->query(
<<<'SQL'
CREATE TABLE IF NOT EXISTS `notification_contactgroup_relation` (
`notification_id` INT UNSIGNED NOT NULL,
`contactgroup_id` INT NOT NULL,
UNIQUE KEY `notification_contactgroup_relation_unique_index` (`notification_id`,`contactgroup_id`),
CONSTRAINT `notification_contactgroup_relation_notification_id`
FOREIGN KEY (`notification_id`)
REFERENCES `notification` (`id`) ON DELETE CASCADE,
CONSTRAINT `notification_contactgroup_relation_contactgroup_id`
FOREIGN KEY (`contactgroup_id`)
REFERENCES `contactgroup` (`cg_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SQL
);
};
try {
$createNotificationContactgroupRelationTable($pearDB);
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-25.09.0.php | centreon/www/install/php/Update-25.09.0.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
use Core\Common\Domain\TrimmedString;
use Core\Security\Token\Domain\Model\NewJwtToken;
require_once __DIR__ . '/../../../bootstrap.php';
/**
* This file contains changes to be included in the next version.
* The actual version number should be added in the variable $version.
*/
$version = '25.09.0';
$errorMessage = '';
/**
* Add Column Encryption ready for poller configuration
*/
$addIsEncryptionReadyColumn = function () use ($pearDB, $pearDBO, &$errorMessage): void {
if ($pearDB->isColumnExist('nagios_server', 'is_encryption_ready') !== 1) {
$errorMessage = "Unable to add 'is_encryption_ready' column to 'nagios_server' table";
$pearDB->query("ALTER TABLE `nagios_server` ADD COLUMN `is_encryption_ready` enum('0', '1') NOT NULL DEFAULT '1'");
}
if ($pearDBO->isColumnExist('instances', 'is_encryption_ready') !== 1) {
$errorMessage = "Unable to add 'is_encryption_ready' column to 'instances' table";
$pearDBO->query("ALTER TABLE `instances` ADD COLUMN `is_encryption_ready` enum('0', '1') NOT NULL DEFAULT '0'");
}
};
/**
* Set encryption ready to false by default for all existing pollers to ensure retrocompatibility
*/
$setEncryptionReadyToFalseByDefaultOnNagiosServer = function () use ($pearDB, &$errorMessage): void {
$errorMessage = "Unable to update 'is_encryption_ready' column on 'nagios_server' table";
$pearDB->executeQuery(
<<<'SQL'
UPDATE nagios_server SET `is_encryption_ready` = '0' WHERE `localhost` = '0'
SQL
);
};
/**
* Add column `show_deprecated_custom_views` to contact table.
* @var CentreonDB $pearDB
*/
$addDeprecateCustomViewsToContact = function () use (&$errorMessage, &$pearDB): void {
$errorMessage = 'Unable to add column show_deprecated_custom_views to contact table';
if (! $pearDB->isColumnExist('contact', 'show_deprecated_custom_views')) {
$pearDB->executeStatement(
<<<'SQL'
ALTER TABLE contact ADD COLUMN show_deprecated_custom_views ENUM('0','1') DEFAULT '0'
SQL
);
}
};
/**
* Switch Topology Order between Dashboards and Custom Views.
*/
$updateDashboardAndCustomViewsTopology = function () use (&$errorMessage, &$pearDB): void {
$errorMessage = 'Unable to update topology of Custom Views';
$pearDB->update(
<<<'SQL'
UPDATE topology SET topology_order = 2, is_deprecated ="1" WHERE topology_name = "Custom Views"
SQL
);
$errorMessage = 'Unable to update topology of Dashboards';
$pearDB->update(
<<<'SQL'
UPDATE topology SET topology_order = 1 WHERE topology_name = "Dashboards"
SQL
);
};
/**
* Set encryption ready to false by default for all existing pollers to ensure retrocompatibility
*/
$setEncryptionReadyToFalseByDefaultOnInstances = function () use ($pearDB, $pearDBO, &$errorMessage): void {
$errorMessage = "Unable to update 'is_encryption_ready' column on 'nagios_server' table";
/** @var CentreonDB $pearDB */
$instanceIds = $pearDB->fetchFirstColumn(
<<<'SQL'
SELECT `id` FROM nagios_server WHERE `localhost` = '0';
SQL
);
if ($instanceIds === []) {
return;
}
$instanceIdsAsString = implode(',', $instanceIds);
$statement = $pearDBO->prepare(
<<<SQL
UPDATE instances SET `is_encryption_ready` = '0' WHERE `instance_id` IN ({$instanceIdsAsString});
SQL
);
$statement->execute();
};
/**
* Set Show Deprecated Custom Views to true by default is there is existing custom views.
*/
$updateContactsShowDeprecatedCustomViews = function () use (&$errorMessage, &$pearDB): void {
$errorMessage = 'Unable to retrieve custom views';
$configuredCustomViews = $pearDB->fetchFirstColumn(
<<<'SQL'
SELECT 1 FROM custom_views LIMIT 1
SQL
);
if ((bool) $configuredCustomViews === true) {
$pearDB->update(
<<<'SQL'
UPDATE contact SET show_deprecated_custom_views = '1'
SQL
);
}
};
$updateCfgParameters = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Unable to update cfg_nagios table';
$pearDB->update(
<<<'SQL'
UPDATE cfg_nagios
SET enable_flap_detection = '1',
host_down_disable_service_checks = '1'
WHERE enable_flap_detection != '1'
OR host_down_disable_service_checks != '1'
SQL
);
};
/** -------------------------------------------- BBDO cfg update -------------------------------------------- */
$bbdoDefaultUpdate = function () use ($pearDB, &$errorMessage): void {
if ($pearDB->isColumnExist('cfg_centreonbroker', 'bbdo_version') !== 1) {
$errorMessage = "Unable to update 'bbdo_version' column to 'cfg_centreonbroker' table";
$pearDB->executeStatement('ALTER TABLE `cfg_centreonbroker` MODIFY `bbdo_version` VARCHAR(50) DEFAULT "3.1.0"');
}
};
$bbdoCfgUpdate = function () use ($pearDB, &$errorMessage): void {
$errorMessage = "Unable to update 'bbdo_version' version in 'cfg_centreonbroker' table";
$pearDB->update('UPDATE `cfg_centreonbroker` SET `bbdo_version` = "3.1.0"');
};
$addResourceStatusSearchModeOption = function () use ($pearDB, &$errorMessage): void {
$errorMessage = "Unable to retrieve 'resource_status_search_mode' option from options table";
$optionExists = $pearDB->fetchFirstColumn("SELECT 1 FROM options WHERE `key` = 'resource_status_search_mode'");
$errorMessage = "Unable to insert option 'resource_status_search_mode' option into table options";
if ((bool) $optionExists === false) {
$pearDB->insert("INSERT INTO `options` (`key`, `value`) VALUES ('resource_status_search_mode', 1)");
}
};
/** ------------------------------------------ Services as contacts ------------------------------------------ */
$addServiceFlagToContacts = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Unable to update contact table';
if (! $pearDB->isColumnExist('contact', 'is_service_account')) {
$pearDB->executeStatement(
<<<'SQL'
ALTER TABLE `contact`
ADD COLUMN `is_service_account` boolean DEFAULT 0 COMMENT 'Indicates if the contact is a service account (ex: centreon-gorgone)'
SQL
);
}
};
// @var mixed $pearDB
$flagContactsAsServiceAccount = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Unable to update contact table';
$pearDB->executeStatement(
<<<'SQL'
UPDATE `contact`
SET `is_service_account` = 1
WHERE `contact_name` IN ('centreon-gorgone', 'CBIS', 'centreon-map')
SQL
);
};
$alterContactPagerSize = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Unable to alter contact_pager column size in contact table';
if ($pearDB->isColumnExist('contact', 'contact_pager')) {
$pearDB->executeStatement(
<<<'SQL'
ALTER TABLE `contact`
MODIFY COLUMN `contact_pager` VARCHAR(300)
SQL
);
}
};
/** ------------------------------------------ ACL Media ------------------------------------------ */
/**
* @var CentreonDB $pearDB
*/
$addImageFolderResourceAccessRelationTable = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Failed to create relation table acl_resources_image_folder_relations';
$pearDB->executeStatement(
<<<'SQL'
CREATE TABLE IF NOT EXISTS `acl_resources_image_folder_relations` (
`dir_id` int(11) DEFAULT NULL COMMENT 'Unique identifier of the image folder',
`acl_res_id` int(11) DEFAULT NULL COMMENT 'Unique identifier of the ACL resource',
KEY `dir_id` (`dir_id`),
KEY `acl_res_id` (`acl_res_id`),
CONSTRAINT `acl_resources_image_folder_relations_ibfk_1` FOREIGN KEY (`dir_id`) REFERENCES `view_img_dir` (`dir_id`) ON DELETE CASCADE,
CONSTRAINT `acl_resources_image_folder_relations_ibfk_2` FOREIGN KEY (`acl_res_id`) REFERENCES `acl_resources` (`acl_res_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Relation table between ACL resources and image folders';
SQL
);
};
/**
* @var CentreonDB $pearDB
*/
$addAllImageFoldersColumn = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Failed to add column all_image_folders to acl_resources table';
if (! $pearDB->isColumnExist('acl_resources', 'all_image_folders')) {
$pearDB->executeStatement(
<<<'SQL'
ALTER TABLE acl_resources ADD COLUMN `all_image_folders` TINYINT NOT NULL DEFAULT '0' AFTER `all_servicegroups`
SQL
);
}
};
/** ------------------------------------------ Agent Configuration ------------------------------------------ */
/*
* Generate a token based on the first found admin contact to update old agent_configurations
*
* @return array{token_name: string, creator_id: int}
*/
$generateToken = function () use ($pearDB): array {
$admin = $pearDB->fetchAssociative(
<<<'SQL'
SELECT contact_id, contact_name
FROM contact
WHERE contact_admin = '1'
LIMIT 1
SQL
);
// Reuse an existing cma-default token if available for this creator
$existing = $pearDB->fetchAssociative(
<<<'SQL'
SELECT token_name, creator_id
FROM jwt_tokens
WHERE token_name = :token_name AND creator_id = :creator_id
LIMIT 1
SQL,
QueryParameters::create([
QueryParameter::string(':token_name', 'cma-default'),
QueryParameter::int(':creator_id', (int) $admin['contact_id']),
])
);
if (! empty($existing)) {
return ['name' => 'cma-default', 'creator_id' => (int) $admin['contact_id']];
}
$token = new NewJwtToken(
name: new TrimmedString('cma-default'),
creatorId: (int) $admin['contact_id'],
creatorName: new TrimmedString((string) $admin['contact_name']),
expirationDate: null
);
$pearDB->executeStatement(
<<<'SQL'
INSERT INTO `jwt_tokens` (token_string,token_name,creator_id,creator_name,encoding_key,is_revoked,creation_date,expiration_date)
VALUES (:token_string,:token_name,:creator_id,:creator_name,:encoding_key,:is_revoked,:creation_date,:expiration_date)
SQL,
QueryParameters::create([
QueryParameter::string(':token_string', (string) $token->getToken()),
QueryParameter::string(':token_name', (string) $token->getName()),
QueryParameter::int(':creator_id', (int) $token->getCreatorId()),
QueryParameter::string(':creator_name', (string) $token->getCreatorName()),
QueryParameter::string(':encoding_key', (string) $token->getEncodingKey()),
QueryParameter::bool(':is_revoked', false),
QueryParameter::int(':creation_date', $token->getCreationDate()->getTimestamp()),
QueryParameter::null(':expiration_date'),
])
);
return ['name' => 'cma-default', 'creator_id' => (int) $admin['contact_id']];
};
/**
* Align inconsistent Agent Configuration with the new schema:
* - Add a `tokens` key for each configuration in non reverse
* - Add a `token` key for each configuration in reverse
* - Add a `id` key for each hosts in each in reverse configuration
* - host id is based on the first ID found for this address.
* - As many hosts could have the same address, users should validate that the picken host is the good one.
*/
$alignCMAAgentConfigurationWithNewSchema = function () use ($pearDB, &$errorMessage, $generateToken): void {
$errorMessage = 'Unable to align agent configuration with new schema';
$agentConfigurations = $pearDB->fetchAllAssociative(
<<<'SQL'
SELECT * FROM `agent_configuration`
WHERE `type` = 'centreon-agent'
SQL
);
if ($agentConfigurations === []) {
return;
}
$tokenInformation = $generateToken();
foreach ($agentConfigurations as $agentConfiguration) {
$configuration = json_decode(
json: $agentConfiguration['configuration'],
associative: true,
flags: JSON_THROW_ON_ERROR
);
if ($configuration['is_reverse']) {
// `tokens` should be an empty array for reverse connection
if (! array_key_exists('tokens', $configuration)) {
$configuration['tokens'] = [];
}
if (! isset($configuration['hosts']) || ! is_array($configuration['hosts'])) {
$configuration['hosts'] = [];
}
foreach ($configuration['hosts'] as &$host) {
if (! array_key_exists('token', $host)) {
$host['token'] = $tokenInformation;
}
if (! array_key_exists('id', $host)) {
$hostId = $pearDB->fetchOne(
<<<'SQL'
SELECT host_id
FROM host
WHERE host_address = :hostAddress
LIMIT 1
SQL,
QueryParameters::create([QueryParameter::string(':hostAddress', $host['address'])])
);
$host['id'] = $hostId;
}
}
} else {
// `hosts` should be an empty array for not reverse connection
if (! array_key_exists('hosts', $configuration)) {
$configuration['hosts'] = [];
}
if (! array_key_exists('tokens', $configuration)) {
$configuration['tokens'] = [$tokenInformation];
}
}
$pearDB->update(
<<<'SQL'
UPDATE agent_configuration
SET configuration = :configuration
WHERE id = :id
SQL,
QueryParameters::create([
QueryParameter::string(':configuration', json_encode($configuration, JSON_THROW_ON_ERROR)),
QueryParameter::int(':id', $agentConfiguration['id']),
])
);
}
};
$updateOnPremiseACLs = function () use ($pearDB, &$errorMessage): void {
$errorMessage = 'Failed to set all_image_folders to 1 for existing acl resource accesses';
$pearDB->update(
<<<'SQL'
UPDATE acl_resources SET all_image_folders = '1' WHERE cloud_specific = '0'
SQL
);
};
try {
$addIsEncryptionReadyColumn();
// DDL statements for configuration database
$addImageFolderResourceAccessRelationTable();
$addAllImageFoldersColumn();
$alterContactPagerSize();
$addDeprecateCustomViewsToContact();
$bbdoDefaultUpdate();
$addServiceFlagToContacts();
if (! $pearDB->inTransaction()) {
$pearDB->beginTransaction();
}
if (! $pearDBO->inTransaction()) {
$pearDBO->beginTransaction();
}
$setEncryptionReadyToFalseByDefaultOnNagiosServer();
$setEncryptionReadyToFalseByDefaultOnInstances();
$alignCMAAgentConfigurationWithNewSchema();
$updateDashboardAndCustomViewsTopology();
$updateContactsShowDeprecatedCustomViews();
$updateCfgParameters();
$bbdoCfgUpdate();
$addResourceStatusSearchModeOption();
$flagContactsAsServiceAccount();
$updateOnPremiseACLs();
$pearDB->commit();
$pearDBO->commit();
} catch (Throwable $exception) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: " . $errorMessage,
exception: $exception
);
try {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
if ($pearDBO->inTransaction()) {
$pearDBO->rollBack();
}
} catch (PDOException $rollbackException) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: error while rolling back the upgrade operation for : {$errorMessage}",
exception: $rollbackException
);
throw new Exception(
"UPGRADE - {$version}: error while rolling back the upgrade operation for : {$errorMessage}",
(int) $rollbackException->getCode(),
$rollbackException
);
}
throw new Exception("UPGRADE - {$version}: " . $errorMessage, (int) $exception->getCode(), $exception);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-23.04.9.php | centreon/www/install/php/Update-23.04.9.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.5.php | centreon/www/install/php/Update-21.10.5.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-23.04.6.php | centreon/www/install/php/Update-23.04.6.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 23.04.6: ';
$errorMessage = '';
$alterMetricsTable = function (CentreonDB $pearDBO): void {
$pearDBO->query(
<<<'SQL'
ALTER TABLE `metrics`
MODIFY COLUMN `metric_name` VARCHAR(1021) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL
SQL
);
};
try {
$errorMessage = 'Impossible to alter metrics table';
$alterMetricsTable($pearDBO);
} catch (Exception $e) {
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.10.15.php | centreon/www/install/php/Update-20.10.15.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-25.11.0.php | centreon/www/install/php/Update-25.11.0.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\ConnectionInterface;
use Adaptation\Database\Connection\Exception\ConnectionException;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
require_once __DIR__ . '/../../../bootstrap.php';
$version = '25.11.0';
$errorMessage = '';
/**
* @var ConnectionInterface $pearDB
* @var ConnectionInterface $pearDBO
*/
// -------------------------------------- AgentConfiguration updates --------------------------------------
/**
* Align preexisting Agent Configuration with the new schema:
* - Add is_poller_initiated bool
* - Add is_agent_initiated bool
* - Remove is_reverse bool
*/
$alignCMAAgentConfigurationWithNewSchema = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Unable to align agent configuration with new schema';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: aligning agent configuration with new schema"
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: retrieving agent configurations from database..."
);
$agentConfigurations = $pearDB->fetchAllAssociative(
<<<'SQL'
SELECT * FROM `agent_configuration`
WHERE `type` = 'centreon-agent'
SQL
);
if ($agentConfigurations === []) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: no agent configurations found, skipping"
);
return;
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: found " . count($agentConfigurations) . ' agent configurations, updating...'
);
foreach ($agentConfigurations as $agentConfiguration) {
$configuration = json_decode(
json: $agentConfiguration['configuration'],
associative: true,
flags: JSON_THROW_ON_ERROR
);
$configuration['agent_initiated'] = false;
$configuration['poller_initiated'] = false;
if ($configuration['is_reverse']) {
$configuration['poller_initiated'] = true;
unset($configuration['is_reverse']);
} else {
$configuration['agent_initiated'] = true;
unset($configuration['is_reverse']);
}
$pearDB->update(
<<<'SQL'
UPDATE agent_configuration
SET configuration = :configuration
WHERE id = :id
SQL,
QueryParameters::create([
QueryParameter::string(':configuration', json_encode($configuration, JSON_THROW_ON_ERROR)),
QueryParameter::int(':id', $agentConfiguration['id']),
])
);
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: agent configurations aligned successfully"
);
};
$cleanGlobalMacrosName = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Failed to clean global macros name';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: cleaning global macros name"
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: retrieving invalid macros from database..."
);
$invalidMacros = $pearDB->fetchAllAssociative(
<<<'SQL'
SELECT resource_id, resource_name FROM cfg_resource
WHERE resource_name NOT LIKE '\$%' OR resource_name NOT LIKE '%\$'
SQL
);
if ($invalidMacros === []) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: no invalid macros found, skipping"
);
return;
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: found " . count($invalidMacros) . ' invalid macros, updating...'
);
foreach ($invalidMacros as $macro) {
$newName = $macro['resource_name'];
if (str_starts_with($newName, '$') === false) {
$newName = '$' . $newName;
}
if (str_ends_with($newName, '$') === false) {
$newName .= '$';
}
$pearDB->update(
<<<'SQL'
UPDATE cfg_resource
SET resource_name = :resource_name
WHERE resource_id = :id
SQL,
QueryParameters::create([
QueryParameter::string(':resource_name', $newName),
QueryParameter::int(':id', (int) $macro['resource_id']),
])
);
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: global macros name cleaned successfully"
);
};
$fixTypoInStandardMacroName = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Failed to fix typo in standard macro name';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: fixing typo in standard macro name..."
);
$nbUpdate = $pearDB->update(
<<<'SQL'
UPDATE nagios_macro SET macro_name = '$TOTALHOSTSUNREACHABLEUNHANDLED$' WHERE macro_id = 65
SQL
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: {$nbUpdate} typo in standard macro name fixed successfully"
);
};
/**
* Update SAML provider configuration:
* - If requested_authn_context exists, set requested_authn_context_comparison to its value and requested_authn_context to true
* - If requested_authn_context does not exist, set requested_authn_context_comparison to 'exact' and requested_authn_context to false
*/
$updateSamlProviderConfiguration = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Unable to retrieve SAML provider configuration';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: updating SAML provider configuration"
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: retrieving SAML provider configuration from database..."
);
$samlConfiguration = $pearDB->fetchAssociative(
<<<'SQL'
SELECT * FROM `provider_configuration`
WHERE `type` = 'saml'
SQL
);
if (! $samlConfiguration || ! isset($samlConfiguration['custom_configuration'])) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: no SAML provider configuration found, skipping"
);
return;
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: SAML provider configuration found, checking for requested_authn_context"
);
$customConfiguration = json_decode($samlConfiguration['custom_configuration'], true, JSON_THROW_ON_ERROR);
if (isset($customConfiguration['requested_authn_context'])) {
$customConfiguration['requested_authn_context_comparison'] = $customConfiguration['requested_authn_context'];
$customConfiguration['requested_authn_context'] = true;
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: requested_authn_context found, requested_authn_context_comparison takes the value of requested_authn_context, and requested_authn_context is set to true"
);
} else {
$customConfiguration['requested_authn_context_comparison'] = 'exact';
$customConfiguration['requested_authn_context'] = false;
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: requested_authn_context not found, setting requested_authn_context to false and requested_authn_context_comparison to 'exact'"
);
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: updating SAML provider configuration in database..."
);
$query = <<<'SQL'
UPDATE `provider_configuration`
SET `custom_configuration` = :custom_configuration
WHERE `type` = 'saml'
SQL;
$queryParameters = QueryParameters::create(
[QueryParameter::string('custom_configuration', json_encode($customConfiguration, JSON_THROW_ON_ERROR))]
);
$pearDB->update($query, $queryParameters);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: SAML provider configuration updated successfully"
);
};
/** -------------------------------------- Broker configuration -------------------------------------- */
$fixBrokerConfigTypo = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Failed to fix typo in broker configuration';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: fixing typo in broker configuration..."
);
$nbUpdate = $pearDB->executeStatement(
<<<'SQL'
UPDATE cfg_centreonbroker_info SET config_key = 'negotiation' WHERE config_key = 'negociation'
SQL
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: {$nbUpdate} typo in broker configuration fixed successfully"
);
};
/** -------------------------------------- Engine Configuration updates -------------------------------------- */
$addOpentelemetryLogLevelColumn = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = 'Failed to add log_level_otl column to cfg_nagios_logger table';
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: adding log_level_otl column to cfg_nagios_logger table..."
);
if (! $pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'cfg_nagios_logger',
'log_level_otl'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: log_level_otl column does not exist, adding it..."
);
$pearDB->executeStatement(
<<<'SQL'
ALTER TABLE `cfg_nagios_logger`
ADD COLUMN `log_level_otl` enum('trace', 'debug', 'info', 'warning', 'err', 'critical', 'off') DEFAULT 'err'
SQL
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: log_level_otl column added successfully"
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: log_level_otl column already exists, skipping"
);
}
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: log_level_otl column already exists, skipping"
);
};
/** -------------------------------------------- BBDO cfg update -------------------------------------------- */
$bbdoDefaultUpdate = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = "Unable to update 'bbdo_version' column to 'cfg_centreonbroker' table";
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: updating 'bbdo_version' column to 'cfg_centreonbroker' table"
);
if ($pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'cfg_centreonbroker',
'bbdo_version'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: 'bbdo_version' column exists, modifying it..."
);
$pearDB->executeStatement('ALTER TABLE `cfg_centreonbroker` MODIFY `bbdo_version` VARCHAR(50) DEFAULT "3.0.1"');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: 'bbdo_version' column modified successfully"
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: 'bbdo_version' column does not exist, skipping"
);
}
};
$bbdoCfgUpdate = function () use ($pearDB, &$errorMessage, $version): void {
$errorMessage = "Unable to update 'bbdo_version' version in 'cfg_centreonbroker' table";
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: updating 'bbdo_version' version in 'cfg_centreonbroker' table"
);
$pearDB->executeStatement('UPDATE `cfg_centreonbroker` SET `bbdo_version` = "3.0.1"');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: 'bbdo_version' version updated successfully"
);
};
// -------------------------------------------- Password encryption --------------------------------------------
$addIsEncryptionReadyAsBooleanColumn = function () use ($pearDB, $pearDBO, &$errorMessage, $version): void {
$errorMessage = "Unable to update 'is_encryption_ready' column to boolean type";
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: updating 'is_encryption_ready' column to boolean type"
);
if (
$pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'nagios_server',
'is_encryption_ready'
)
&& ! $pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'nagios_server',
'is_encryption_ready_old'
)
) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Renaming column 'is_encryption_ready' on 'nagios_server' table",
);
$pearDB->executeStatement('ALTER TABLE `nagios_server` RENAME COLUMN `is_encryption_ready` TO `is_encryption_ready_old`');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready' renamed successfully on 'nagios_server' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready' already renamed on 'nagios_server' table, skipping",
);
}
if (! $pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'nagios_server',
'is_encryption_ready'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Adding column 'is_encryption_ready' of type boolean on 'nagios_server' table",
);
$pearDB->executeStatement('ALTER TABLE `nagios_server` ADD COLUMN `is_encryption_ready` BOOLEAN NOT NULL DEFAULT 1');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready' added successfully on 'nagios_server' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready' already exists on 'nagios_server' table, skipping",
);
}
if ($pearDB->columnExists(
$pearDB->getConnectionConfig()->getDatabaseNameConfiguration(),
'nagios_server',
'is_encryption_ready_old'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Moving 'is_encryption_ready' value of existing pollers on 'nagios_server' table",
);
$pearDB->executeStatement(
<<<'SQL'
UPDATE nagios_server ns
SET ns.is_encryption_ready = 0
WHERE ns.is_encryption_ready_old = '0'
SQL
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] 'is_encryption_ready' values moved successfully on 'nagios_server' table",
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Dropping column 'is_encryption_ready_old' on 'nagios_server' table",
);
$pearDB->executeStatement('ALTER TABLE `nagios_server` DROP COLUMN `is_encryption_ready_old`');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready_old' dropped successfully on 'nagios_server' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Configuration] Column 'is_encryption_ready_old' does not exist on 'nagios_server' table, skipping",
);
}
if (
$pearDBO->columnExists(
$pearDBO->getConnectionConfig()->getDatabaseNameRealTime(),
'instances',
'is_encryption_ready'
)
&& ! $pearDBO->columnExists(
$pearDBO->getConnectionConfig()->getDatabaseNameRealTime(),
'instances',
'is_encryption_ready_old'
)
) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Moving 'is_encryption_ready' value of existing pollers on 'instances' table",
);
$pearDBO->executeStatement('ALTER TABLE `instances` RENAME COLUMN `is_encryption_ready` TO `is_encryption_ready_old`');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready' renamed successfully on 'instances' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready' already renamed on 'instances' table, skipping",
);
}
if (! $pearDBO->columnExists(
$pearDBO->getConnectionConfig()->getDatabaseNameRealTime(),
'instances',
'is_encryption_ready'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Adding column 'is_encryption_ready' of type boolean on 'instances' table",
);
$pearDBO->executeStatement('ALTER TABLE `instances` ADD COLUMN `is_encryption_ready` BOOLEAN NOT NULL DEFAULT 0');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready' added successfully on 'instances' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready' already exists on 'instances' table, skipping",
);
}
if ($pearDBO->columnExists(
$pearDBO->getConnectionConfig()->getDatabaseNameRealTime(),
'instances',
'is_encryption_ready_old'
)) {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Moving 'is_encryption_ready' value of existing pollers on 'instances' table",
);
$pearDBO->executeStatement(
<<<'SQL'
UPDATE instances ins
SET ins.is_encryption_ready = 1
WHERE ins.is_encryption_ready_old = '1'
SQL
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] 'is_encryption_ready' values moved successfully on 'instances' table",
);
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Dropping column 'is_encryption_ready_old' on 'instances' table",
);
$pearDBO->executeStatement('ALTER TABLE `instances` DROP COLUMN `is_encryption_ready_old`');
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready_old' dropped successfully on 'instances' table",
);
} else {
CentreonLog::create()->info(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: [DB Realtime] Column 'is_encryption_ready_old' does not exist on 'instances' table, skipping",
);
}
};
try {
// DDL statements for real time database
// TODO add your function calls to update the real time database structure here
// DDL statements for configuration database
$bbdoDefaultUpdate();
$addOpentelemetryLogLevelColumn();
$addIsEncryptionReadyAsBooleanColumn();
// Transactional queries for configuration database
if (! $pearDB->isTransactionActive()) {
$pearDB->startTransaction();
}
// TODO add your function calls to update the configuration database data here
$alignCMAAgentConfigurationWithNewSchema();
$cleanGlobalMacrosName();
$fixTypoInStandardMacroName();
$fixBrokerConfigTypo();
$bbdoCfgUpdate();
$updateSamlProviderConfiguration();
$pearDB->commitTransaction();
} catch (Throwable $throwable) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: " . $errorMessage,
exception: $throwable
);
try {
if ($pearDB->isTransactionActive()) {
$pearDB->rollBackTransaction();
}
} catch (ConnectionException $rollbackException) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_UPGRADE,
message: "UPGRADE - {$version}: error while rolling back the upgrade operation for : {$errorMessage}",
exception: $rollbackException
);
throw new RuntimeException(
message: "UPGRADE - {$version}: error while rolling back the upgrade operation for : {$errorMessage}",
previous: $rollbackException
);
}
throw new RuntimeException(
message: "UPGRADE - {$version}: " . $errorMessage,
previous: $throwable
);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.13.php | centreon/www/install/php/Update-21.10.13.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.04.6.php | centreon/www/install/php/Update-21.04.6.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
include_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.04.6:';
/**
* Query with transaction
*/
try {
$pearDB->beginTransaction();
// Purge all session.
$errorMessage = 'Impossible to purge the table session';
$pearDB->query('DELETE FROM `session`');
$errorMessage = 'Impossible to purge the table ws_token';
$pearDB->query('DELETE FROM `ws_token`');
$pearDB->commit();
$constraintStatement = $pearDB->query(
"SELECT COUNT(*) as count FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='session_ibfk_1'"
);
if (($constraint = $constraintStatement->fetch()) && (int) $constraint['count'] === 0) {
$errorMessage = 'Impossible to add Delete Cascade constraint on the table session';
$pearDB->query(
'ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`user_id`) '
. 'REFERENCES `contact` (`contact_id`) ON DELETE CASCADE'
);
}
$errorMessage = "Impossible to drop column 'contact_platform_data_sending' from 'contact' table";
if ($pearDB->isColumnExist('contact', 'contact_platform_data_sending')) {
$pearDB->query('ALTER TABLE `contact` DROP COLUMN `contact_platform_data_sending`');
}
} catch (Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.04.16.php | centreon/www/install/php/Update-21.04.16.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.23.php | centreon/www/install/php/Update-2.8.23.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.1.php | centreon/www/install/php/Update-21.10.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-25.03.1.php | centreon/www/install/php/Update-25.03.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.10.2.php | centreon/www/install/php/Update-22.10.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 22.10.2: ';
$errorMessage = '';
/**
* Update illegal_object_name_chars + illegal_macro_output_chars fields from cf_nagios table.
* The aim is to decode entities from them.
*
* @param CentreonDB $pearDB
*/
$decodeIllegalCharactersNagios = function (CentreonDB $pearDB): void {
$configs = $pearDB->query(
<<<'SQL'
SELECT
nagios_id,
illegal_object_name_chars,
illegal_macro_output_chars
FROM
`cfg_nagios`
SQL
)->fetchAll(PDO::FETCH_ASSOC);
$statement = $pearDB->prepare(
<<<'SQL'
UPDATE
`cfg_nagios`
SET
illegal_object_name_chars = :illegal_object_name_chars,
illegal_macro_output_chars = :illegal_macro_output_chars
WHERE
nagios_id = :nagios_id
SQL
);
foreach ($configs as $config) {
$modified = $config;
$modified['illegal_object_name_chars'] = html_entity_decode($config['illegal_object_name_chars']);
$modified['illegal_macro_output_chars'] = html_entity_decode($config['illegal_macro_output_chars']);
if ($config === $modified) {
// no need to update, we skip a useless query
continue;
}
$statement->bindValue(':illegal_object_name_chars', $modified['illegal_object_name_chars'], PDO::PARAM_STR);
$statement->bindValue(':illegal_macro_output_chars', $modified['illegal_macro_output_chars'], PDO::PARAM_STR);
$statement->bindValue(':nagios_id', $modified['nagios_id'], PDO::PARAM_INT);
$statement->execute();
}
};
try {
if ($pearDB->isColumnExist('cfg_centreonbroker', 'event_queues_total_size') === 0) {
$errorMessage = 'Impossible to update cfg_centreonbroker table';
$pearDB->query(
'ALTER TABLE `cfg_centreonbroker`
ADD COLUMN `event_queues_total_size` INT(11) DEFAULT NULL
AFTER `event_queue_max_size`'
);
}
$errorMessage = 'Impossible to delete color picker topology_js entries';
$pearDB->query(
"DELETE FROM `topology_JS`
WHERE `PathName_js` = './include/common/javascript/color_picker_mb.js'"
);
// Transactional queries
$pearDB->beginTransaction();
$errorMessage = 'Unable to update illegal characters fields from engine configuration of pollers';
$decodeIllegalCharactersNagios($pearDB);
$pearDB->commit();
} catch (Exception $e) {
if ($pearDB->inTransaction()) {
$pearDB->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.0.php | centreon/www/install/php/Update-21.10.0.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.26.php | centreon/www/install/php/Update-2.8.26.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.10.0.php | centreon/www/install/php/Update-22.10.0.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.14.php | centreon/www/install/php/Update-2.8.14.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.04.17.php | centreon/www/install/php/Update-21.04.17.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-20.04.0-rc.2.php | centreon/www/install/php/Update-20.04.0-rc.2.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-22.10.7.php | centreon/www/install/php/Update-22.10.7.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.24.php | centreon/www/install/php/Update-2.8.24.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
// Create tempory table to delete duplicate entries
$query = 'CREATE TABLE `centreon_acl_new` ( '
. '`group_id` int(11) NOT NULL, '
. '`host_id` int(11) NOT NULL, '
. '`service_id` int(11) DEFAULT NULL, '
. 'UNIQUE KEY (`group_id`,`host_id`,`service_id`), '
. 'KEY `index1` (`host_id`,`service_id`,`group_id`) '
. ') ENGINE=InnoDB DEFAULT CHARSET=utf8 ';
$pearDBO->query($query);
/**
* Checking if centAcl.php is running and waiting 2min for it to stop before locking cron_operation table
*/
$query = "SELECT running FROM cron_operation WHERE `name` = 'centAcl.php'";
$i = 0;
while ($i < 120) {
$i++;
$result = $pearDB->query($query);
while ($row = $result->fetchRow()) {
if ($row['running'] == '1') {
sleep(1);
} else {
break 2;
}
}
}
/**
* Lock centAcl cron during upgrade
*/
$query = "UPDATE cron_operation SET running = '1' WHERE `name` = 'centAcl.php'";
$pearDB->query($query);
/**
* Copy data from old table to new table with duplicate entries deletion
*/
$query = 'INSERT INTO centreon_acl_new (group_id, host_id, service_id) '
. 'SELECT group_id, host_id, service_id FROM centreon_acl '
. 'GROUP BY group_id, host_id, service_id';
$pearDBO->query($query);
/**
* Drop old table with duplicate entries
*/
$query = 'DROP TABLE centreon_acl';
$pearDBO->query($query);
/**
* Rename temporary table to stable table
*/
$query = 'ALTER TABLE centreon_acl_new RENAME TO centreon_acl';
$pearDBO->query($query);
/**
* Unlock centAcl cron during upgrade
*/
$query = "UPDATE cron_operation SET running = '0' WHERE `name` = 'centAcl.php'";
$pearDB->query($query);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.04.19.php | centreon/www/install/php/Update-21.04.19.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.15.php | centreon/www/install/php/Update-2.8.15.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (isset($pearDB)) {
$res = $pearDB->query(
"SHOW INDEXES FROM `traps_group` WHERE key_name = 'PRIMARY'"
);
if ($res->numRows() <= 0) {
$pearDB->query(
'ALTER TABLE `traps_group_relation` '
. 'DROP FOREIGN KEY `traps_group_relation_ibfk_2`'
);
$pearDB->query(
'ALTER TABLE `traps_group` '
. ' CHANGE COLUMN `traps_group_id` '
. ' `traps_group_id` INT NOT NULL AUTO_INCREMENT'
);
$pearDB->query(
'ALTER TABLE `traps_group` ADD PRIMARY KEY (`traps_group_id`)'
);
$pearDB->query(
'ALTER TABLE `traps_group` '
. ' DROP KEY `traps_group_id`'
);
$pearDB->query(
'ALTER TABLE `traps_group_relation` '
. 'ADD CONSTRAINT `traps_group_relation_ibfk_2` '
. 'FOREIGN KEY (`traps_group_id`) REFERENCES `traps_group` (`traps_group_id`) ON DELETE CASCADE'
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-2.8.1.php | centreon/www/install/php/Update-2.8.1.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
// Update comments unique key
if (isset($pearDBO)) {
$query = 'SHOW INDEX FROM comments '
. 'WHERE column_name = "host_id" '
. 'AND Key_name = "host_id" ';
$res = $pearDBO->query($query);
if (! $res->rowCount()) {
$pearDBO->query('ALTER TABLE comments ADD KEY host_id(host_id)');
}
$query = 'ALTER TABLE `comments` '
. 'DROP KEY `entry_time`, '
. 'ADD UNIQUE KEY `entry_time` (`entry_time`,`host_id`,`service_id`, `instance_id`, `internal_id`) ';
$pearDBO->query($query);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/php/Update-21.10.11.php | centreon/www/install/php/Update-21.10.11.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../class/centreonLog.class.php';
$centreonLog = new CentreonLog();
// error specific content
$versionOfTheUpgrade = 'UPGRADE - 21.10.11: ';
$errorMessage = '';
try {
$errorMessage = "Impossible to update 'hosts' table";
if (! str_contains(strtolower($pearDBO->getColumnType('hosts', 'notification_number')), 'bigint')) {
$pearDBO->beginTransaction();
$pearDBO->query('UPDATE `hosts` SET `notification_number`= 0 WHERE `notification_number`< 0');
$pearDBO->query('ALTER TABLE `hosts` MODIFY `notification_number` BIGINT(20) UNSIGNED DEFAULT NULL');
}
$errorMessage = "Impossible to update 'services' table";
if (! str_contains(strtolower($pearDBO->getColumnType('services', 'notification_number')), 'bigint')) {
$pearDBO->beginTransaction();
$pearDBO->query('UPDATE `services` SET `notification_number`= 0 WHERE `notification_number`< 0');
$pearDBO->query('ALTER TABLE `services` MODIFY `notification_number` BIGINT(20) UNSIGNED DEFAULT NULL');
}
} catch (Exception $e) {
if ($pearDBO->inTransaction()) {
$pearDBO->rollBack();
}
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage
. ' - Code : ' . (int) $e->getCode()
. ' - Error : ' . $e->getMessage()
. ' - Trace : ' . $e->getTraceAsString()
);
throw new Exception($versionOfTheUpgrade . $errorMessage, (int) $e->getCode(), $e);
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/step.php | centreon/www/install/steps/step.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../bootstrap.php';
$installFactory = new CentreonLegacy\Core\Install\Factory($dependencyInjector);
$information = $installFactory->newInformation();
$parameters = filter_input_array(INPUT_GET);
$action = $parameters['action'] ?? 'stepContent';
switch ($action) {
case 'stepContent':
echo $information->getStepContent();
break;
case 'nextStep':
echo $information->nextStepContent();
break;
case 'previousStep':
echo $information->previousStepContent();
break;
case 'vaultStep':
echo $information->vaultStepContent();
break;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/functions.php | centreon/www/install/steps/functions.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../class/centreonAuth.class.php';
use Centreon\Domain\VersionHelper;
use Symfony\Component\Yaml\Yaml;
/**
* Checks if line is sql comment
*
* @param string $str
* @return bool
*/
function isSqlComment($str)
{
return (bool) (str_starts_with(trim($str), '--'));
}
/**
* Get template
*
* @param string $dir directory of templates
* @return Smarty
*/
function getTemplate($dir)
{
$libDir = __DIR__ . '/../../../GPL_LIB';
$template = new SmartyBC();
$template->setTemplateDir($dir);
$template->setCompileDir($libDir . '/SmartyCache/compile');
$template->setConfigDir($libDir . '/SmartyCache/config');
$template->setCacheDir($libDir . '/SmartyCache/cache');
$template->addPluginsDir($libDir . '/smarty-plugins');
$template->loadPlugin('smarty_function_eval');
$template->setForceCompile(true);
$template->setAutoLiteral(false);
return $template;
}
/**
* Connect to database with user root
*
* @return mixed
*/
function myConnect()
{
$user = 'root';
if (! empty($_SESSION['root_user'])) {
$user = $_SESSION['root_user'];
}
$pass = '';
if (! empty($_SESSION['root_password'])) {
$pass = $_SESSION['root_password'];
}
$host = 'localhost';
if (isset($_SESSION['ADDRESS']) && $_SESSION['ADDRESS']) {
$host = $_SESSION['ADDRESS'];
}
$port = '3306';
if (isset($_SESSION['DB_PORT']) && $_SESSION['DB_PORT']) {
$port = $_SESSION['DB_PORT'];
}
return new PDO('mysql:host=' . $host . ';port=' . $port, $user, $pass);
}
/**
* Replace macros
*
* @param string $query
* @param mixed $macros
* @return string
*/
function replaceInstallationMacros($query, $macros = [])
{
while (preg_match('/@([a-zA-Z0-9_]+)@/', $query, $matches)) {
$macroValue = '';
if ($matches[1] == 'MAILER') {
$macroValue = '-MAILER-';
} elseif (isset($macros[$matches[1]])) {
$macroValue = $macros[$matches[1]];
} elseif (isset($_SESSION[$matches[1]])) {
$macroValue = $_SESSION[$matches[1]];
}
$query = preg_replace('/@' . $matches[1] . '@/', $macroValue, $query);
}
$query = str_replace('-MAILER-', '@MAILER@', $query);
return $query;
}
/**
* Split queries
*
* @param string $file
* @param string $delimiter
* @param CentreonDB $connector
* @param string $tmpFile | $tmpFile will store the number of executed queries sql script
* @param mixed $macros
* @return string | returns "0" if everything is ok, or returns error message
*/
function splitQueries($file, $delimiter = ';', $connector = null, $tmpFile = '', $macros = [])
{
if (is_null($connector)) {
$connector = myConnect();
}
set_time_limit(0);
$count = 0;
$start = 0;
$fileName = basename($file);
if ($tmpFile != '' && is_file($tmpFile)) {
$start = file_get_contents($tmpFile);
}
if (is_file($file) === true) {
$file = fopen($file, 'r');
if (is_resource($file) === true) {
$query = [];
$line = 0;
while (feof($file) === false) {
$line++;
$currentLine = fgets($file);
if (isSqlComment($currentLine) == false) {
$query[] = $currentLine;
}
if (preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1) {
$query = trim(implode('', $query));
$query = replaceInstallationMacros($query, $macros);
$count++;
if ($count > $start) {
try {
$result = $connector->query($query);
if (! $result) {
throw new Exception('Cannot execute query : ' . $query);
}
} catch (Exception $e) {
return "{$fileName} Line {$line}:" . $e->getMessage();
}
while (ob_get_level() > 0) {
ob_end_flush();
}
flush();
if ($tmpFile != '') {
file_put_contents($tmpFile, $count);
}
}
}
if (is_string($query) === true) {
$query = [];
}
}
fclose($file);
return '0';
}
}
return _('File not found');
}
/**
* Exit process
*
* @param string $id | name of the process
* @param int $result | 0 = ok, 1 = nok
* @param string $msg | error message
*/
function exitProcess($id, $result, $msg)
{
$msg = str_replace('"', '\"', $msg);
$msg = str_replace('\\', '\\\\', $msg);
echo '{
"id" : "' . $id . '",
"result" : "' . $result . '",
"msg" : "' . $msg . '"
}';
exit;
}
/**
* Exit upgrade process
*
* @param int $result | 0 = ok, 1 = nok
* @param string $current
* @param string $next
* @param string $msg | error message
* @return void
*/
function exitUpgradeProcess($result, $current, $next, $msg)
{
$msg = str_replace('"', '\"', $msg);
$msg = str_replace('\\', '\\\\', $msg);
echo '{
"result" : "' . $result . '",
"current" : "' . $current . '",
"next" : "' . $next . '",
"msg" : "' . $msg . '"
}';
exit;
}
/**
* Get param lines from file
*
* @param string $varPath
* @param string $objectType
* @return array
*/
function getParamLines($varPath, $objectType)
{
$contents = '';
if ($handle = opendir($varPath)) {
while (false !== ($object = readdir($handle))) {
if ($object == $objectType) {
$contents = file_get_contents($varPath . '/' . $object);
}
}
closedir($handle);
}
return explode("\n", $contents);
}
/**
* Set session variables
*
* @param array $conf_centreon
* @return void
*/
function setSessionVariables($conf_centreon)
{
$_SESSION['INSTALL_DIR_CENTREON'] = $conf_centreon['centreon_dir'];
$_SESSION['CENTREON_ETC'] = $conf_centreon['centreon_etc'];
$_SESSION['BIN_MAIL'] = $conf_centreon['mail'];
$_SESSION['BIN_RRDTOOL'] = $conf_centreon['rrdtool_dir'];
$_SESSION['MONITORINGENGINE_USER'] = $conf_centreon['monitoring_user'];
$_SESSION['MONITORINGENGINE_GROUP'] = $conf_centreon['monitoring_group'];
$_SESSION['MONITORINGENGINE_ETC'] = $conf_centreon['monitoring_etc'];
$_SESSION['MONITORINGENGINE_PLUGIN'] = $conf_centreon['plugin_dir'];
$_SESSION['CENTREON_LOG'] = $conf_centreon['centreon_log'];
$_SESSION['CENTREON_RRD_DIR'] = $conf_centreon['centreon_dir_rrd'];
$_SESSION['MONITORING_BINARY'] = $conf_centreon['monitoring_binary'];
$_SESSION['CENTREON_VARLIB'] = $conf_centreon['centreon_varlib'];
$_SESSION['MONITORING_VAR_LOG'] = $conf_centreon['monitoring_varlog'];
$_SESSION['CENTREON_ENGINE_CONNECTORS'] = $conf_centreon['centreon_engine_connectors'];
$_SESSION['CENTREON_ENGINE_LIB'] = $conf_centreon['centreon_engine_lib'];
$_SESSION['CENTREONPLUGINS'] = $conf_centreon['centreon_plugins'];
}
function getDatabaseVariable($db, $variable)
{
$query = "SHOW VARIABLES LIKE '" . $variable . "'";
$result = $db->query($query);
$value = null;
while ($row = $result->fetch()) {
$value = $row['Value'];
}
$result->closeCursor();
return $value;
}
/**
* Get gorgone api credentials from configuration file
*
* @param string $gorgoneEtcPath
* @return array{
* GORGONE_USER: string
* GORGONE_PASSWORD: string
* }
*/
function getGorgoneApiCredentialMacros(string $gorgoneEtcPath): array
{
$macros = [
'GORGONE_USER' => 'centreon-gorgone',
'GORGONE_PASSWORD' => '',
];
$apiConfigurationFile = $gorgoneEtcPath . '/config.d/31-centreon-api.yaml';
if (file_exists($apiConfigurationFile)) {
$configuration = Yaml::parseFile($apiConfigurationFile);
if (isset($configuration['gorgone']['tpapi'][0]['username'])) {
$macros['GORGONE_USER'] = $configuration['gorgone']['tpapi'][0]['username'];
}
if (isset($configuration['gorgone']['tpapi'][0]['password'])) {
$macros['GORGONE_PASSWORD'] = password_hash(
$configuration['gorgone']['tpapi'][0]['password'],
CentreonAuth::PASSWORD_HASH_ALGORITHM
);
}
}
return $macros;
}
/**
* Check PHP version and throws exception if prerequisite is not respected
*
* @param PDO $db
* @throws Exception
*/
function checkPhpPrerequisite(): void
{
$currentPhpMajorVersion = VersionHelper::regularizeDepthVersion(PHP_VERSION, 1);
if (! VersionHelper::compare($currentPhpMajorVersion, _CENTREON_PHP_VERSION_, VersionHelper::EQUAL)) {
throw new Exception(
sprintf(
_('Please install PHP version %s instead of %s.'),
_CENTREON_PHP_VERSION_,
PHP_VERSION,
),
);
}
}
/**
* Check MariaDB version and throws exception if prerequisite is not respected
*
* @param PDO $db
* @throws Exception
*/
function checkMariaDBPrerequisite(PDO $db): void
{
$currentMariaDBVersion = getMariaDBVersion($db);
if ($currentMariaDBVersion !== null) {
$currentMariaDBMajorVersion = VersionHelper::regularizeDepthVersion($currentMariaDBVersion, 1);
if (VersionHelper::compare($currentMariaDBMajorVersion, _CENTREON_MARIA_DB_MIN_VERSION_, VersionHelper::LT)) {
throw new Exception(
sprintf(
_('Please install MariaDB version %s instead of %s.'),
_CENTREON_MARIA_DB_MIN_VERSION_,
$currentMariaDBVersion,
),
);
}
}
}
/**
* Get MariaDB version
* Returns nulls if not found or if MySQL is installed
*
* @return string|null
*/
function getMariaDBVersion(PDO $db): ?string
{
$version = null;
$dbmsName = null;
$statement = $db->query("SHOW VARIABLES WHERE Variable_name IN ('version', 'version_comment')");
while ($row = $statement->fetch()) {
if ($row['Variable_name'] === 'version') {
$version = $row['Value'];
} elseif ($row['Variable_name'] === 'version_comment') {
$dbmsName = $row['Value'];
}
}
if (str_contains($dbmsName, 'MariaDB') && $version !== null) {
return $version;
}
return null;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/index.php | centreon/www/install/steps/index.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
$installFactory = new CentreonLegacy\Core\Install\Factory($dependencyInjector);
$information = $installFactory->newInformation();
$step = $information->getStep();
require_once __DIR__ . '/functions.php';
$template = getTemplate(__DIR__ . '/templates');
$template->assign('step', $step);
$template->display('install.tpl');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/installConfigurationDb.php | centreon/www/install/steps/process/installConfigurationDb.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once '../functions.php';
$return = ['id' => 'dbconf', 'result' => 1, 'msg' => ''];
$step = new CentreonLegacy\Core\Install\Step\Step6($dependencyInjector);
$parameters = $step->getDatabaseConfiguration();
try {
$db = new PDO(
'mysql:host=' . $parameters['address'] . ';port=' . $parameters['port'],
$parameters['root_user'],
$parameters['root_password']
);
} catch (PDOException $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
// Check if MySQL innodb_file_perf_table is enabled
$innodb_file_per_table = getDatabaseVariable($db, 'innodb_file_per_table');
if (is_null($innodb_file_per_table) || strtolower($innodb_file_per_table) == 'off') {
$return['msg']
= _('Add innodb_file_per_table=1 in my.cnf file under the [mysqld] section and restart MySQL Server.');
echo json_encode($return);
exit;
}
// Check if MySQL open_files_limit parameter is higher than 32000
$open_files_limit = getDatabaseVariable($db, 'open_files_limit');
if (is_null($open_files_limit)) {
$open_files_limit = 0;
}
if ($open_files_limit < 32000) {
$return['msg'] = 'Add LimitNOFILE=32000 value in the service file '
. '/etc/systemd/system/<database_service_name>.service.d/centreon.conf '
. '(replace <database_service_name> by mysql, mysqld or mariadb depending on the systemd service name) '
. 'and reload systemd : systemctl daemon-reload';
echo json_encode($return);
exit;
}
try {
// Check if configuration database exists
$statementShowDatabase = $db->prepare('SHOW DATABASES LIKE :dbConfiguration');
$statementShowDatabase->bindValue(':dbConfiguration', $parameters['db_configuration'], PDO::PARAM_STR);
$statementShowDatabase->execute();
// If it doesn't exist, create it
if ($result = $statementShowDatabase->fetch(PDO::FETCH_ASSOC) === false) {
$db->exec('CREATE DATABASE `' . $parameters['db_configuration'] . '`');
// Create table
$db->exec('use `' . $parameters['db_configuration'] . '`');
$result = splitQueries('../../createTables.sql', ';', $db, '../../tmp/createTables');
if ($result != '0') {
$return['msg'] = $result;
echo json_encode($return);
exit;
}
} else {
// If it exist, check if database is empty (no tables)
$statement = $db->prepare(
'SELECT COUNT(*) as tables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :dbConfiguration'
);
$statement->bindValue(':dbConfiguration', $parameters['db_configuration'], PDO::PARAM_STR);
$statement->execute();
// If it is not empty, throw an error
if (($resultCount = $statement->fetch(PDO::FETCH_ASSOC)) && (int) $resultCount['tables'] > 0) {
throw new Exception(
sprintf('Your \'%s\' database is not empty, please remove all your tables or drop your database '
. 'then click on refresh to retry', $parameters['db_configuration'])
);
}
}
// Create table
$db->exec('use `' . $parameters['db_configuration'] . '`');
$result = splitQueries('../../createTables.sql', ';', $db, '../../tmp/createTables');
if ($result != '0') {
$return['msg'] = $result;
echo json_encode($return);
exit;
}
} catch (Exception $e) {
if (! is_file('../../tmp/createTables')) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
}
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/getFeatureFlags.php | centreon/www/install/steps/process/getFeatureFlags.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
require_once __DIR__ . '/../../../../bootstrap.php';
use Core\Common\Infrastructure\FeatureFlags;
use Symfony\Component\Dotenv\Dotenv;
(new Dotenv())->bootEnv('/usr/share/centreon/.env');
$isCloudPlatform = false;
if (array_key_exists('IS_CLOUD_PLATFORM', $_ENV) && $_ENV['IS_CLOUD_PLATFORM']) {
$isCloudPlatform = true;
}
$featuresFileContent = file_get_contents(__DIR__ . '/../../../../config/features.json');
$featureFlagManager = new FeatureFlags($isCloudPlatform, $featuresFileContent);
echo json_encode($featureFlagManager->getAll());
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step3.php | centreon/www/install/steps/process/process_step3.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
$step = new CentreonLegacy\Core\Install\Step\Step3($dependencyInjector);
$parametersConfiguration = $step->getEngineParameters();
$err = ['required' => [], 'directory_not_found' => [], 'file_not_found' => []];
$parameters = filter_input_array(INPUT_POST);
foreach ($parameters as $name => $value) {
if (trim($value) == '' && $parametersConfiguration[$name]['required'] == 1) {
$err['required'][] = $name;
} elseif (trim($value) != '' && $parametersConfiguration[$name]['type'] == 0) { // is directory
if (! is_dir($value)) {
$err['directory_not_found'][] = $name;
}
} elseif (trim($value) != '' && $parametersConfiguration[$name]['type'] == 1) { // is file
if (! is_file($value)) {
$err['file_not_found'][] = $name;
}
}
}
if ($err['file_not_found'] === [] && $err['file_not_found'] === [] && $err['file_not_found'] === []) {
$step->setEngineConfiguration($parameters);
}
echo json_encode($err);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step9.php | centreon/www/install/steps/process/process_step9.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../../../include/common/vault-functions.php';
use App\Kernel;
use Core\Common\Application\Repository\WriteVaultRepositoryInterface;
use Core\Common\Infrastructure\FeatureFlags;
use Core\Installation\Infrastructure\InstallationHelper;
use Symfony\Component\Dotenv\Dotenv;
$step = new CentreonLegacy\Core\Install\Step\Step9($dependencyInjector);
$version = $step->getVersion();
$parameters = filter_input_array(INPUT_POST);
if ((int) $parameters['send_statistics'] == 1) {
$query = "INSERT INTO options (`key`, `value`) VALUES ('send_statistics', '1')";
} else {
$query = "INSERT INTO options (`key`, `value`) VALUES ('send_statistics', '0')";
}
$db = $dependencyInjector['configuration_db'];
$db->query("DELETE FROM options WHERE `key` = 'send_statistics'");
$db->query($query);
$message = '';
try {
// Handle the migration of the database credentials to Vault.
(new Dotenv())->bootEnv('/usr/share/centreon/.env');
$isCloudPlatform = false;
if (array_key_exists('IS_CLOUD_PLATFORM', $_ENV) && $_ENV['IS_CLOUD_PLATFORM']) {
$isCloudPlatform = true;
}
$featuresFileContent = file_get_contents(__DIR__ . '/../../../../config/features.json');
$featureFlagManager = new FeatureFlags($isCloudPlatform, $featuresFileContent);
$isVaultFeatureEnable = $featureFlagManager->isEnabled('vault');
$kernel = Kernel::createForWeb();
if ($isVaultFeatureEnable && file_exists(_CENTREON_VARLIB_ . '/vault/vault.json')) {
$writeVaultRepository = $kernel->getContainer()->get(WriteVaultRepositoryInterface::class);
$writeVaultRepository->setCustomPath('database');
$databaseVaultPaths = migrateDatabaseCredentialsToVault($writeVaultRepository);
if ($databaseVaultPaths !== []) {
updateConfigFilesWithVaultPath($databaseVaultPaths);
}
if ($featureFlagManager->isEnabled('vault_gorgone')) {
$gorgoneVaultPaths = migrateGorgoneCredentialsToVault($writeVaultRepository);
if ($gorgoneVaultPaths !== []) {
updateGorgoneApiFile($gorgoneVaultPaths);
}
}
}
/** @var InstallationHelper $installationHelper */
$installationHelper = $kernel->getContainer()->get(InstallationHelper::class);
$installationHelper->writeEngineContextFile();
$backupDir = _CENTREON_VARLIB_ . '/installs/'
. '/install-' . $version . '-' . date('Ymd_His');
$installDir = realpath(__DIR__ . '/../..');
$dependencyInjector['filesystem']->mirror($installDir, $backupDir);
$dependencyInjector['filesystem']->remove($installDir);
if ($dependencyInjector['filesystem']->exists($installDir)) {
throw new Exception(
'Cannot move directory from ' . $installDir . ' to ' . $backupDir
. ', please move it manually.'
);
}
$dependencyInjector['filesystem']->remove($backupDir . '/tmp/admin.json');
$dependencyInjector['filesystem']->remove($backupDir . '/tmp/database.json');
$result = true;
} catch (Throwable $e) {
$result = false;
$message = $e->getMessage();
}
echo json_encode(['result' => $result, 'message' => $message]);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/createEngineContextConfiguration.php | centreon/www/install/steps/process/createEngineContextConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
use App\Kernel;
use Core\Engine\Application\Repository\EngineRepositoryInterface;
use Core\Installation\Infrastructure\InstallationHelper;
set_time_limit(0);
require __DIR__ . '/../../../../vendor/autoload.php';
$return = [];
$kernel = Kernel::createForWeb();
/** @var InstallationHelper $installationHelper */
$installationHelper = $kernel->getContainer()->get(InstallationHelper::class);
/** @var EngineRepositoryInterface $engineRepository */
$engineRepository = $kernel->getContainer()->get(EngineRepositoryInterface::class);
try {
// This file should not be touched if it has content.
if ($engineRepository->engineSecretsHasContent() === false) {
$installationHelper->writeEngineContextFile();
}
$return['result'] = 0;
$return['msg'] = 'OK';
} catch (Throwable $ex) {
$return['result'] = 1;
$return['msg'] = $ex->getMessage();
}
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/installStorageDb.php | centreon/www/install/steps/process/installStorageDb.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once '../functions.php';
$return = ['id' => 'dbstorage', 'result' => 1, 'msg' => ''];
$factory = new CentreonLegacy\Core\Utils\Factory($dependencyInjector);
$utils = $factory->newUtils();
$step = new CentreonLegacy\Core\Install\Step\Step6($dependencyInjector);
$parameters = $step->getDatabaseConfiguration();
try {
$db = new PDO(
'mysql:host=' . $parameters['address'] . ';port=' . $parameters['port'],
$parameters['root_user'],
$parameters['root_password']
);
} catch (PDOException $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
try {
// Check if realtime database exists
$statementShowDatabase = $db->prepare('SHOW DATABASES LIKE :dbStorage');
$statementShowDatabase->bindValue(':dbStorage', $parameters['db_storage'], PDO::PARAM_STR);
$statementShowDatabase->execute();
// If it doesn't exist, create it
if ($result = $statementShowDatabase->fetch(PDO::FETCH_ASSOC) === false) {
$db->exec('CREATE DATABASE `' . $parameters['db_storage'] . '`');
} else {
// If it exist, check if database is empty (no tables)
$statement = $db->prepare(
'SELECT COUNT(*) as tables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :dbStorage'
);
$statement->bindValue(':dbStorage', $parameters['db_storage'], PDO::PARAM_STR);
$statement->execute();
if (($resultCount = $statement->fetch(PDO::FETCH_ASSOC)) && (int) $resultCount['tables'] > 0) {
throw new Exception(
sprintf('Your database \'%s\' is not empty, please remove all your tables or drop your database '
. 'then click on refresh to retry', $parameters['db_storage'])
);
}
}
$macros = array_merge(
$step->getBaseConfiguration(),
$step->getDatabaseConfiguration(),
$step->getAdminConfiguration(),
$step->getEngineConfiguration(),
$step->getBrokerConfiguration()
);
$result = $db->query('use `' . $parameters['db_storage'] . '`');
if (! $result) {
throw new Exception('Cannot access to "' . $parameters['db_storage'] . '" database');
}
$result = splitQueries(
'../../createTablesCentstorage.sql',
';',
$db,
'../../tmp/createTablesCentstorage',
$macros
);
if ($result != '0') {
$return['msg'] = $result;
echo json_encode($return);
exit;
}
$result = splitQueries(
'../../installBroker.sql',
';',
$db,
'../../tmp/installBroker',
$macros
);
if ($result != '0') {
$return['msg'] = $result;
echo json_encode($return);
exit;
}
} catch (Exception $e) {
if (! is_file('../../tmp/createTablesCentstorage')) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
}
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/generationCache.php | centreon/www/install/steps/process/generationCache.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
set_time_limit(0);
require __DIR__ . '/../../../../vendor/autoload.php';
function extractErrorMessage(BufferedOutput $output): ?string
{
$rawMessage = $output->fetch();
$messages = explode("\n", $rawMessage);
$filteredMessages = [];
foreach ($messages as $rawMessage) {
if (! empty(trim($rawMessage))) {
$filteredMessages[] = $rawMessage;
}
}
if ($filteredMessages !== []) {
if (str_starts_with(strtolower($filteredMessages[0]), 'in')) {
array_shift($filteredMessages);
}
return implode('<br/>', $filteredMessages);
}
return null;
}
$return = ['id' => 'generationCache', 'result' => 0, 'msg' => 'OK'];
try {
if (! class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}
require __DIR__ . '/../../../../config/bootstrap.php';
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->setAutoExit(false);
$consoleOutput = new BufferedOutput();
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_QUIET | OutputInterface::OUTPUT_RAW);
$input = new ArgvInput(['', 'cache:clear']);
$code = $application->run($input, $consoleOutput);
if (! is_null($message = extractErrorMessage($consoleOutput))) {
throw new Exception($message);
}
} catch (Exception $e) {
$return['result'] = 1;
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
echo json_encode($return);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/createDbUser.php | centreon/www/install/steps/process/createDbUser.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once '../functions.php';
$return = [
'id' => 'createuser',
'result' => 1,
'msg' => '',
];
$step = new CentreonLegacy\Core\Install\Step\Step6($dependencyInjector);
$parameters = $step->getDatabaseConfiguration();
try {
$link = new PDO(
'mysql:host=' . $parameters['address'] . ';port=' . $parameters['port'],
$parameters['root_user'],
$parameters['root_password']
);
} catch (PDOException $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
$host = 'localhost';
// if database server is not on localhost...
if ($parameters['address'] != '127.0.0.1' && $parameters['address'] != 'localhost') {
$getIpQuery = $link->prepare(
'SELECT host FROM information_schema.processlist WHERE ID = connection_id()'
);
$getIpQuery->execute();
// The result example (172.17.0.1:38216), use the explode function to remove port
$host = explode(':', $getIpQuery->fetchAll(PDO::FETCH_COLUMN)[0])[0];
}
$queryValues = [
':dbUser' => $parameters['db_user'],
':host' => $host,
':dbPass' => $parameters['db_password'],
];
// Set defined privileges for the user.
$mandatoryPrivileges = [
'SELECT',
'UPDATE',
'DELETE',
'INSERT',
'CREATE',
'DROP',
'INDEX',
'ALTER',
'LOCK TABLES',
'CREATE TEMPORARY TABLES',
'EVENT',
'CREATE VIEW',
'SHOW VIEW',
'REFERENCES',
'TRIGGER',
];
$privilegesQuery = implode(', ', $mandatoryPrivileges);
$query = 'GRANT ' . $privilegesQuery . " ON `%s`.* TO '" . $parameters['db_user'] . "'@'" . $host . "'";
$flushQuery = 'FLUSH PRIVILEGES';
try {
$findUserStatement = $link->prepare('SELECT * FROM mysql.user WHERE User = :dbUser AND Host = :host');
$findUserStatement->bindValue(':dbUser', $queryValues[':dbUser'], PDO::PARAM_STR);
$findUserStatement->bindValue(':host', $queryValues[':host'], PDO::PARAM_STR);
$findUserStatement->execute();
// If user doesn't exist, create it
if ($result = $findUserStatement->fetch(PDO::FETCH_ASSOC) === false) {
// creating the user - mandatory for MySQL DB
$prepareCreate = $link->prepare('CREATE USER :dbUser@:host IDENTIFIED BY :dbPass');
foreach ($queryValues as $key => $value) {
$prepareCreate->bindValue($key, $value, PDO::PARAM_STR);
}
// creating the user
$prepareCreate->execute();
// granting privileges
$link->exec(sprintf($query, $parameters['db_configuration']));
$link->exec(sprintf($query, $parameters['db_storage']));
// enabling the new parameters
$link->exec($flushQuery);
} else {
// If he exists check the right
$privilegesStatement = $link->prepare('SHOW GRANTS FOR :dbUser@:host');
$privilegesStatement->bindValue(':dbUser', $queryValues[':dbUser'], PDO::PARAM_STR);
$privilegesStatement->bindValue(':host', $queryValues[':host'], PDO::PARAM_STR);
$privilegesStatement->execute();
// If rights are found
$foundPrivilegesForCentreonDatabase = false;
$foundPrivilegesForCentreonStorageDatabase = false;
while ($result = $privilegesStatement->fetch(PDO::FETCH_ASSOC)) {
foreach ($result as $grant) {
// Format Grant result to get privileges list, and concerned database.
if (preg_match('/^GRANT\s(?!USAGE)(.+)\sON\s?(.+)\.\*/', $grant, $matches)) {
// Check if privileges has been found for global (*) or centreon databases.
switch ($matches[2]) {
case '`' . $parameters['db_configuration'] . '`':
$foundPrivilegesForCentreonDatabase = true;
break;
case '`' . $parameters['db_storage'] . '`':
$foundPrivilegesForCentreonStorageDatabase = true;
break;
case '*':
$foundPrivilegesForCentreonStorageDatabase = true;
$foundPrivilegesForCentreonDatabase = true;
break;
}
$resultPrivileges = explode(', ', $matches[1]);
// Check that user has sufficient privileges to perform all needed actions.
$missingPrivileges = [];
if ($resultPrivileges[0] !== 'ALL PRIVILEGES') {
foreach ($mandatoryPrivileges as $mandatoryPrivilege) {
if (! in_array($mandatoryPrivilege, $resultPrivileges)) {
$missingPrivileges[] = $mandatoryPrivilege;
}
}
if ($missingPrivileges !== []) {
throw new Exception(
sprintf(
'Missing privileges %s on user %s',
implode(', ', $missingPrivileges),
$queryValues[':dbUser']
)
);
}
}
}
}
}
if ($foundPrivilegesForCentreonDatabase === false || $foundPrivilegesForCentreonStorageDatabase === false) {
throw new Exception(
sprintf(
'No privileges for \'%s\' or \'%s\' databases for \'%s\' user has been found, '
. 'please check your MySQL configuration',
$parameters['db_configuration'],
$parameters['db_storage'],
$queryValues[':dbUser']
)
);
}
}
} catch (Exception $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step4.php | centreon/www/install/steps/process/process_step4.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
$step = new CentreonLegacy\Core\Install\Step\Step4($dependencyInjector);
$parametersConfiguration = $step->getBrokerParameters();
$err = ['required' => [], 'directory_not_found' => [], 'file_not_found' => []];
$parameters = filter_input_array(INPUT_POST);
foreach ($parameters as $name => $value) {
if (trim($value) == '' && $parametersConfiguration[$name]['required'] == 1) {
$err['required'][] = $name;
} elseif (trim($value) != '' && $parametersConfiguration[$name]['type'] == 0) { // is directory
if (! is_dir($value)) {
$err['directory_not_found'][] = $name;
}
} elseif (trim($value) != '' && $parametersConfiguration[$name]['type'] == 1) { // is file
if (! is_file($value)) {
$err['file_not_found'][] = $name;
}
}
}
if ($err['file_not_found'] === [] && $err['file_not_found'] === [] && $err['file_not_found'] === []) {
$step->setBrokerConfiguration($parameters);
}
echo json_encode($err);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step_vault.php | centreon/www/install/steps/process/process_step_vault.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../../install.conf.php';
$requiredParameters = [
'address',
'port',
'root_path',
'role_id',
'secret_id',
];
$err = [
'required' => [],
'connection_error' => '',
];
$parameters = filter_input_array(INPUT_POST);
foreach (array_keys($parameters) as $fieldName) {
if (in_array($fieldName, $requiredParameters) && trim($value) === '') {
$err['required'][] = $name;
}
}
try {
$url = $parameters['address'] . ':' . $parameters['port'] . '/v1/auth/approle/login';
$url = sprintf('%s://%s', 'https', $url);
$body = [
'role_id' => $parameters['role_id'],
'secret_id' => $parameters['secret_id'],
];
$httpClient = new Symfony\Component\HttpClient\CurlHttpClient();
$loginResponse = $httpClient->request('POST', $url, ['json' => $body]);
$content = json_decode($loginResponse->getContent(), true);
if (! isset($content['auth']['client_token'])) {
throw new Exception('Unable to authenticate to Vault');
}
/**
* @var Security\Interfaces\EncryptionInterface $encryption
*/
$encryption = new Security\Encryption();
(new Symfony\Component\Dotenv\Dotenv())->bootEnv('/usr/share/centreon/.env');
$encryption->setFirstKey($_ENV['APP_SECRET']);
$writeVaultConfigurationRepository
= new Core\Security\Vault\Infrastructure\Repository\FsWriteVaultConfigurationRepository(
$conf_centreon['centreon_varlib'] . '/vault/vault.json',
new Symfony\Component\Filesystem\Filesystem()
);
$vaultConfiguration = new Core\Security\Vault\Domain\Model\NewVaultConfiguration(
$encryption,
$parameters['address'],
(int) $parameters['port'],
$parameters['root_path'],
$parameters['role_id'],
$parameters['secret_id']
);
$writeVaultConfigurationRepository->create($vaultConfiguration);
} catch (Symfony\Component\HttpClient\Exception\TransportException $e) {
$err['connection_error'] = $e->getMessage();
} catch (Throwable $e) {
$err['connection_error'] = 'Unable to create vault configuration';
}
if ($err['required'] === [] && trim($err['connection_error']) == '') {
$step = new CentreonLegacy\Core\Install\Step\Step6Vault($dependencyInjector);
$step->setVaultConfiguration($parameters);
}
echo json_encode($err);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/insertBaseConf.php | centreon/www/install/steps/process/insertBaseConf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once '../functions.php';
use CentreonModule\ServiceProvider;
$return = ['id' => 'baseconf', 'result' => 1, 'msg' => ''];
$factory = new CentreonLegacy\Core\Utils\Factory($dependencyInjector);
$utils = $factory->newUtils();
$step = new CentreonLegacy\Core\Install\Step\Step6($dependencyInjector);
$parameters = $step->getDatabaseConfiguration();
try {
$link = new PDO(
'mysql:host=' . $parameters['address'] . ';port=' . $parameters['port'],
$parameters['root_user'],
$parameters['root_password']
);
} catch (PDOException $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
/**
* Create tables
*/
try {
$result = $link->query('use `' . $parameters['db_configuration'] . '`');
if (! $result) {
throw new Exception('Cannot access to "' . $parameters['db_configuration'] . '" database');
}
$macros = array_merge(
$step->getBaseConfiguration(),
$step->getDatabaseConfiguration(),
$step->getAdminConfiguration(),
$step->getEngineConfiguration(),
$step->getBrokerConfiguration(),
getGorgoneApiCredentialMacros(_CENTREON_ETC_ . '/../centreon-gorgone'),
);
$utils->executeSqlFile(__DIR__ . '/../../insertMacros.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../insertCommands.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../insertTimeperiods.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../var/baseconf/centreon-engine.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../var/baseconf/centreon-broker.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../insertTopology.sql', $macros);
$utils->executeSqlFile(__DIR__ . '/../../insertBaseConf.sql', $macros);
/**
* @var CentreonModuleService
*/
$moduleService = Centreon\LegacyContainer::getInstance()[ServiceProvider::CENTREON_MODULE];
$widgets = $moduleService->getList(null, false, null, ['widget']);
foreach ($widgets['widget'] as $widget) {
if ($widget->isInternal()) {
$moduleService->install($widget->getId(), 'widget');
}
}
} catch (Exception $e) {
$return['msg'] = $e->getMessage();
echo json_encode($return);
exit;
}
$hostName = gethostname() ?: null;
// Insert Central to 'platform_topology' table, as first server and parent of all others.
$centralServerQuery = $link->query("SELECT `id`, `name` FROM nagios_server WHERE localhost = '1'");
if ($row = $centralServerQuery->fetch()) {
$stmt = $link->prepare("
INSERT INTO `platform_topology` (
`address`,
`hostname`,
`name`,
`type`,
`parent_id`,
`server_id`,
`pending`
) VALUES (
:centralAddress,
:hostname,
:name,
'central',
NULL,
:id,
'0'
)
");
$stmt->bindValue(':centralAddress', $_SERVER['SERVER_ADDR'], PDO::PARAM_STR);
$stmt->bindValue(':hostname', $hostName, PDO::PARAM_STR);
$stmt->bindValue(':name', $row['name'], PDO::PARAM_STR);
$stmt->bindValue(':id', (int) $row['id'], PDO::PARAM_INT);
$stmt->execute();
}
// Manage timezone
$timezone = date_default_timezone_get();
$statement = $link->prepare('SELECT timezone_id FROM timezone WHERE timezone_name= :timezone_name');
$statement->bindValue(':timezone_name', $timezone, PDO::PARAM_STR);
if (! $statement->execute()) {
$return['msg'] = _('Cannot get timezone information');
echo json_encode($return);
exit;
}
if ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$timezoneId = $row['timezone_id'];
} else {
$timezoneId = '334'; // Europe/London timezone
}
$statement = $link->prepare("INSERT INTO `options` (`key`, `value`) VALUES ('gmt', :value)");
$statement->bindValue(':value', $timezoneId, PDO::PARAM_STR);
$statement->execute();
// Generate random key for this instance and set it to be not central and not remote
$informationsTableInsert = "INSERT INTO `informations` (`key`,`value`) VALUES
('isRemote', 'no'),
('isCentral', 'yes')";
$link->exec($informationsTableInsert);
splitQueries('../../insertACL.sql', ';', $link, '../../tmp/insertACL');
// Get Centreon version
$res = $link->query("SELECT `value` FROM informations WHERE `key` = 'version'");
if (! $res) {
$return['msg'] = _('Cannot get Centreon version');
echo json_encode($return);
exit;
}
$row = $res->fetch();
$step->setVersion($row['value']);
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step6.php | centreon/www/install/steps/process/process_step6.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../functions.php';
require __DIR__ . '/../../../include/common/common-Func.php';
use CentreonLegacy\Core\Install\Step\Step6;
define('SQL_ERROR_CODE_ACCESS_DENIED', 1698);
$requiredParameters = [
'db_configuration',
'db_storage',
'db_user',
'db_password',
'db_password_confirm',
];
$err = [
'required' => [],
'password' => true,
'connection' => '',
'use_vault' => false,
'vault_error' => '',
];
$parameters = filter_input_array(INPUT_POST);
foreach ($parameters as $name => $value) {
if (in_array($name, $requiredParameters) && trim($value) == '') {
$err['required'][] = $name;
}
}
if (array_key_exists('use_vault', $parameters)) {
$err['use_vault'] = true;
}
if (! in_array('db_password', $err['required']) && ! in_array('db_password_confirm', $err['required'])
&& $parameters['db_password'] != $parameters['db_password_confirm']
) {
$err['password'] = false;
}
try {
if ($parameters['address'] == '') {
$parameters['address'] = 'localhost';
}
if ($parameters['port'] == '') {
$parameters['port'] = '3306';
}
if ($parameters['root_user'] == '') {
$parameters['root_user'] = 'root';
}
$link = new PDO(
'mysql:host=' . $parameters['address'] . ';port=' . $parameters['port'],
$parameters['root_user'],
$parameters['root_password']
);
checkMariaDBPrerequisite($link);
$link = null;
} catch (Exception $e) {
if ($e instanceof PDOException && (int) $e->getCode() === SQL_ERROR_CODE_ACCESS_DENIED) {
$err['connection']
= 'Please check the root database username and password. '
. 'If the problem persists, check that you have properly '
. '<a target="_blank" href="https://docs.centreon.com/docs/installation'
. '/installation-of-a-central-server/using-packages/#secure-the-database">secured your DBMS</a>';
} else {
$err['connection'] = $e->getMessage();
}
}
if ($err['required'] === [] && $err['password'] && trim($err['connection']) == '') {
$step = new Step6($dependencyInjector);
$step->setDatabaseConfiguration($parameters);
}
echo json_encode($err);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/partitionTables.php | centreon/www/install/steps/process/partitionTables.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once '../functions.php';
require_once '../../../../config/centreon.config.php';
require_once '../../../class/centreonDB.class.php';
require_once '../../../class/centreon-partition/partEngine.class.php';
require_once '../../../class/centreon-partition/config.class.php';
require_once '../../../class/centreon-partition/mysqlTable.class.php';
require_once '../../../class/centreon-partition/options.class.php';
$return = ['id' => 'dbpartitioning', 'result' => 1, 'msg' => ''];
// Create partitioned tables
$database = new CentreonDB('centstorage');
$centreonDb = new CentreonDB('centreon');
$partEngine = new PartEngine();
if (! $partEngine->isCompatible($database)) {
$return['msg'] = '[' . date(DATE_RFC822) . '] '
. "CRITICAL: MySQL server is not compatible with partitionning. MySQL version must be greater or equal to 5.1\n";
echo json_encode($return);
exit;
}
$tables = ['data_bin', 'logs', 'log_archive_host', 'log_archive_service'];
try {
foreach ($tables as $table) {
$config = new Config(
$database,
_CENTREON_PATH_ . '/config/partition.d/partitioning-' . $table . '.xml',
$centreonDb
);
$mysqlTable = $config->getTable($table);
// past partitions do not need to be created
// it optimizes the time for partition process
$partEngine->createParts($mysqlTable, $database, false);
}
} catch (Exception $e) {
$return['msg'] = preg_replace('/\n/', '', $e->getMessage());
echo json_encode($return);
exit;
}
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/configFileSetup.php | centreon/www/install/steps/process/configFileSetup.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../../functions.php';
$return = [
'id' => 'configfile',
'result' => 1,
'msg' => '',
];
$step = new CentreonLegacy\Core\Install\Step\Step6($dependencyInjector);
$parameters = $step->getDatabaseConfiguration();
$configuration = $step->getBaseConfiguration();
$engine = $step->getEngineConfiguration();
$gorgonePassword = generatePassword();
$host = $parameters['address'] ?: 'localhost';
// escape double quotes and backslashes
$needle = ['\\', '"'];
$escape = ['\\\\', '\"'];
$password = str_replace($needle, $escape, $parameters['db_password']);
$macroReplacements = [
'--ADDRESS--' => $host,
'--DBUSER--' => $parameters['db_user'],
'--DBPASS--' => $password,
'--CONFDB--' => $parameters['db_configuration'],
'--STORAGEDB--' => $parameters['db_storage'],
'--CENTREONDIR--' => $configuration['centreon_dir'],
'--CENTREON_CACHEDIR--' => $configuration['centreon_cachedir'],
'--DBPORT--' => $parameters['port'],
'--INSTANCEMODE--' => 'central',
'--CENTREON_VARLIB--' => $configuration['centreon_varlib'],
// specific additional mandatory parameters used by Gorgone.d in a full ZMQ mode
'--CENTREON_SPOOL--' => '/var/spool/centreon',
'--HTTPSERVERADDRESS--' => '0.0.0.0',
'--HTTPSERVERPORT--' => '8085',
'--SSLMODE--' => 'false',
'--CENTREON_TRAPDIR--' => '/etc/snmp/centreon_traps',
'--GORGONE_VARLIB--' => '/var/lib/centreon-gorgone',
'--ENGINE_COMMAND--' => $engine['monitoring_var_lib'] . '/rw/centengine.cmd',
'@GORGONE_USER@' => 'centreon-gorgone',
'@GORGONE_PASSWORD@' => $gorgonePassword,
];
$centreonEtcPath = rtrim($configuration['centreon_etc'], '/');
/**
* centreon.conf.php
*/
$centreonConfFile = $centreonEtcPath . '/centreon.conf.php';
$contents = file_get_contents('../../var/configFileTemplate');
$contents = str_replace(array_keys($macroReplacements), array_values($macroReplacements), $contents);
file_put_contents($centreonConfFile, $contents);
chmod($centreonConfFile, 0640);
/**
* conf.pm
*/
$centreonConfPmFile = $centreonEtcPath . '/conf.pm';
$contents = file_get_contents('../../var/configFilePmTemplate');
$contents = str_replace(array_keys($macroReplacements), array_values($macroReplacements), $contents);
file_put_contents($centreonConfPmFile, $contents);
/**
* Database configuration file
*/
$gorgoneDatabaseFile = $centreonEtcPath . '/config.d/10-database.yaml';
$contents = file_get_contents('../../var/databaseTemplate.yaml');
$contents = str_replace(array_keys($macroReplacements), array_values($macroReplacements), $contents);
$oldMask = umask(0137);
file_put_contents($gorgoneDatabaseFile, $contents);
umask($oldMask);
/**
* Gorgone API configuration file
*/
$apiConfigurationFile = $centreonEtcPath . '/../centreon-gorgone/config.d/31-centreon-api.yaml';
if (file_exists($apiConfigurationFile) && is_writable($apiConfigurationFile)) {
file_put_contents(
$apiConfigurationFile,
str_replace(
array_keys($macroReplacements),
array_values($macroReplacements),
file_get_contents($apiConfigurationFile)
),
);
}
/**
* Gorgone daemon configuration file for a central
*/
$gorgoneCoreFileForCentral = $centreonEtcPath . '/../centreon-gorgone/config.d/40-gorgoned.yaml';
if (is_writable(dirname($gorgoneCoreFileForCentral))) {
$contents = file_get_contents('../../var/gorgone/gorgoneCentralTemplate.yaml');
$contents = str_replace(array_keys($macroReplacements), array_values($macroReplacements), $contents);
file_put_contents($gorgoneCoreFileForCentral, $contents);
}
$return['result'] = 0;
echo json_encode($return);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step8.php | centreon/www/install/steps/process/process_step8.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
$result = [];
$parameters = filter_input_array(INPUT_POST);
if (isset($parameters['modules'])) {
$utilsFactory = new CentreonLegacy\Core\Utils\Factory($dependencyInjector);
$utils = $utilsFactory->newUtils();
$moduleFactory = new CentreonLegacy\Core\Module\Factory($dependencyInjector, $utils);
foreach ($parameters['modules'] as $module) {
/* If the selected module is already installed (as dependency for example)
* then we can skip the installation process
*/
if (
isset($result['modules'][$module]['install'])
&& $result['modules'][$module]['install'] === true
) {
continue;
}
/* retrieving the module's information stored in the conf.php
* configuration file
*/
$information = $moduleFactory->newInformation();
$moduleInformation = $information->getConfiguration($module);
/* if the selected module has dependencies defined in its configuration file
* then we need to install them before installing the selected module to
* ensure its correct installation
*/
if (isset($moduleInformation['dependencies'])) {
foreach ($moduleInformation['dependencies'] as $dependency) {
// If the dependency is already installed skip install
if (
isset($result['modules'][$dependency]['install'])
&& $result['modules'][$dependency]['install'] === true
) {
continue;
}
$installer = $moduleFactory->newInstaller($dependency);
$id = $installer->install();
$install = $id ? true : false;
$result['modules'][$dependency] = [
'module' => $dependency,
'install' => $install,
];
}
}
// installing the selected module
$installer = $moduleFactory->newInstaller($module);
$id = $installer->install();
$install = $id ? true : false;
$result['modules'][$module] = [
'module' => $module,
'install' => $install,
];
}
}
if (isset($parameters['widgets'])) {
$utilsFactory = new CentreonLegacy\Core\Utils\Factory($dependencyInjector);
$utils = $utilsFactory->newUtils();
$widgetFactory = new CentreonLegacy\Core\Widget\Factory($dependencyInjector, $utils);
foreach ($parameters['widgets'] as $widget) {
$installer = $widgetFactory->newInstaller($widget);
$id = $installer->install();
$install = ($id) ? true : false;
$result['widgets'][$widget] = ['widget' => $widget, 'install' => $install];
}
}
echo json_encode($result);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/steps/process/process_step5.php | centreon/www/install/steps/process/process_step5.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
session_start();
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../../../class/centreonAuth.class.php';
$err = ['required' => [], 'email' => true, 'password' => true, 'password_security_policy' => true];
$emailRegexp = "/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?"
. "(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/";
$parameters = filter_input_array(INPUT_POST);
foreach ($parameters as $name => $value) {
if (trim($value) == '') {
$err['required'][] = $name;
}
}
if (! in_array('email', $err['required']) && ! preg_match($emailRegexp, $parameters['email'])) {
$err['email'] = false;
}
if (
! in_array('admin_password', $err['required'])
&& ! in_array('confirm_password', $err['required'])
&& $parameters['admin_password'] !== $parameters['confirm_password']
) {
$err['password'] = false;
}
if (
! preg_match(
'/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$/',
$parameters['admin_password']
)
) {
$err['password_security_policy'] = false;
} else {
$parameters['admin_password'] = password_hash(
$parameters['admin_password'],
CentreonAuth::PASSWORD_HASH_ALGORITHM
);
}
if ($err['required'] === [] && $err['password'] && $err['email'] && $err['password_security_policy']) {
$step = new CentreonLegacy\Core\Install\Step\Step5($dependencyInjector);
$step->setAdminConfiguration($parameters);
}
echo json_encode($err);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/sql/centstorage/index.php | centreon/www/install/sql/centstorage/index.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/www/install/sql/centreon/index.php | centreon/www/install/sql/centreon/index.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/.php-cs-fixer.conf.php | centreon-dsm/.php-cs-fixer.conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
return [
'legacy' => [
'files' => [
'.php-cs-fixer.conf.php',
'.php-cs-fixer.diff.php',
'.php-cs-fixer.legacy.php',
'rector.conf.php',
'rector.diff.php',
'rector.legacy.php',
],
'directories' => [
'www',
],
'skip' => [],
],
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/.php-cs-fixer.diff.php | centreon-dsm/.php-cs-fixer.diff.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use Tools\PhpCsFixer\Command\RunCsFixerOnDiffCommand;
use Tools\PhpCsFixer\Command\RunCsFixerOnDiffCommandHandler;
require_once __DIR__ . '/../php-tools/vendor/autoload.php';
$pathsConfig = require_once __DIR__ . '/.php-cs-fixer.conf.php';
$args = $_SERVER['argv'] ?? [];
$runCsFixerOnDiffCommand = new RunCsFixerOnDiffCommand(
moduleName: 'centreon-dsm',
sections: ['legacy'],
pathsConfig: $pathsConfig,
args: $args
);
$runCsFixerOnDiffCommandHandler = new RunCsFixerOnDiffCommandHandler();
$runCsFixerOnDiffCommandHandler->run($runCsFixerOnDiffCommand);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/.php-cs-fixer.legacy.php | centreon-dsm/.php-cs-fixer.legacy.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use PhpCsFixer\Finder;
$config = require_once __DIR__ . '/../php-tools/php-cs-fixer/config/base.unstrict.php';
$pathsConfig = require_once __DIR__ . '/.php-cs-fixer.conf.php';
$finder = Finder::create()
->in($pathsConfig['legacy']['directories'])
->append($pathsConfig['legacy']['files'])
->notPath($pathsConfig['legacy']['skip']);
return $config
->setFinder($finder)
->setCacheFile('.php-cs-fixer.legacy.cache');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/rector.diff.php | centreon-dsm/rector.diff.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use Tools\Rector\Command\RunRectorOnDiffCommand;
use Tools\Rector\Command\RunRectorOnDiffCommandHandler;
require_once __DIR__ . '/../php-tools/vendor/autoload.php';
$pathsConfig = require_once __DIR__ . '/rector.conf.php';
$args = $_SERVER['argv'] ?? [];
$runRectorOnDiffCommand = new RunRectorOnDiffCommand(
moduleName: 'centreon-dsm',
sections: ['legacy'],
pathsConfig: $pathsConfig,
args: $args
);
$runRectorOnDiffCommandHandler = new RunRectorOnDiffCommandHandler();
$runRectorOnDiffCommandHandler->run($runRectorOnDiffCommand);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/rector.legacy.php | centreon-dsm/rector.legacy.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
$rectorConfig = require_once __DIR__ . '/../php-tools/rector/config/base.unstrict.php';
$pathsConfig = require_once __DIR__ . '/rector.conf.php';
return $rectorConfig
->withCache(__DIR__ . '/var/cache/rector.legacy')
->withPaths($pathsConfig['legacy']['paths'])
->withSkip($pathsConfig['legacy']['skip']);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/rector.conf.php | centreon-dsm/rector.conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
return [
'legacy' => [
'paths' => [
// directories
'www',
// files
'.php-cs-fixer.conf.php',
'.php-cs-fixer.diff.php',
'.php-cs-fixer.legacy.php',
'rector.conf.php',
'rector.diff.php',
'rector.legacy.php',
],
'skip' => [],
],
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/conf.php | centreon-dsm/www/modules/centreon-dsm/conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
// Be Careful with internal_name, it's case sensitive (with directory module name)
$module_conf['centreon-dsm']['name'] = 'centreon-dsm';
$module_conf['centreon-dsm']['rname'] = 'Dynamic Services Management';
$module_conf['centreon-dsm']['mod_release'] = '26.01.0';
$module_conf['centreon-dsm']['infos'] = 'Centreon Dynamic Service Management (Centreon-DSM) is a module to manage '
. 'alarms with an event logs system. With DSM, Centreon can receive events such as SNMP traps resulting from the '
. 'detection of a problem and assign events dynamically to a slot defined in Centreon, like a tray events.
A resource has a set number of “slots” (containers) on which alerts will be assigned (stored). While this event has '
. 'not been taken into account by a human action, it will remain visible in the interface Centreon. When event is '
. 'acknowledged manually or by a recovery event, the slot becomes available for new events.
The goal of this module is to overhead the basic trap management system of Centreon. The basic function run '
. 'with a single service and alarm crashed by successive alarms.
';
$module_conf['centreon-dsm']['is_removeable'] = '1';
$module_conf['centreon-dsm']['author'] = 'Centreon';
$module_conf['centreon-dsm']['stability'] = 'stable';
$module_conf['centreon-dsm']['last_update'] = '2025-11-18';
$module_conf['centreon-dsm']['images'] = [
'images/dsm_snmp_events_tray.png',
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/core/configuration/services/slots.php | centreon-dsm/www/modules/centreon-dsm/core/configuration/services/slots.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (! isset($oreon)) {
exit();
}
$cG = $_GET['pool_id'] ?? null;
$cP = $_POST['pool_id'] ?? null;
$slot_id = $cG ?? $cP;
$slot_id = $slot_id !== null ? (int) $slot_id : null;
$cG = $_GET['select'] ?? null;
$cP = $_POST['select'] ?? null;
$select = $cG ?? $cP;
$cG = $_GET['dupNbr'] ?? null;
$cP = $_POST['dupNbr'] ?? null;
$dupNbr = $cG ?? $cP;
$search = isset($_POST['searchSlot']) ? htmlentities($_POST['searchSlot'], ENT_QUOTES) : null;
// Path to the configuration dir
$path = './modules/centreon-dsm/core/configuration/services/';
// PHP functions
require_once $path . 'DB-Func.php';
require_once './include/common/common-Func.php';
switch ($o) {
case 'a':
include_once $path . 'formSlot.php'; // Add a slot
break;
case 'w':
include_once $path . 'formSlot.php'; // Watch a slot
break;
case 'c':
include_once $path . 'formSlot.php'; // Modify a slot
break;
case 's':
enablePoolInDB($slot_id);
include_once $path . 'listSlot.php'; // Activate a slot
break;
case 'ms':
enablePoolInDB(null, $select ?? []);
include_once $path . 'listSlot.php';
break;
case 'u':
disablePoolInDB($slot_id);
include_once $path . 'listSlot.php'; // Desactivate a slot
break;
case 'mu':
disablePoolInDB(null, $select ?? []);
include_once $path . 'listSlot.php';
break;
case 'm':
multiplePoolInDB($select ?? [], $dupNbr);
include_once $path . 'listSlot.php'; // Duplicate n slots
break;
case 'd':
deletePoolInDB($select ?? []);
include_once $path . 'listSlot.php'; // Delete n slots
break;
default:
include_once $path . 'listSlot.php';
break;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/core/configuration/services/help.php | centreon-dsm/www/modules/centreon-dsm/core/configuration/services/help.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
$help = [];
$help['pool_name'] = dgettext('help', 'The pool name.');
$help['pool_description'] = dgettext('help', 'The pool description.');
$help['pool_host_id'] = dgettext(
'help',
'The pool slot will be attached to this host.<br/><b>The host can have only one pool.</b>'
);
$help['pool_service_template'] = dgettext('help', 'The service template for the slots.');
$help['pool_number'] = dgettext('help', 'The number of slots.');
$help['pool_prefix'] = dgettext('help', 'The prefix for create slots.<br/><i>prefix-</i>0000');
$help['pool_cmd_id'] = dgettext('help', 'The command for slots.');
$help['pool_activate'] = dgettext('help', 'If the pool and its slots are enable.');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/core/configuration/services/formSlot.php | centreon-dsm/www/modules/centreon-dsm/core/configuration/services/formSlot.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (! isset($oreon)) {
exit();
}
/**
* Replaces spaces with underscores in the 'pool_name' field from the form submission.
*
* This function retrieves all submitted form values, specifically targets the 'pool_name' field,
* and replaces any spaces in its value with underscores.
*
* @global HTML_QuickFormCustom $form The form object containing the submitted values.
* @return string the 'pool_name' value with spaces replaced by underscores
*/
function replaceSpacesWithUnderscores()
{
global $form;
$ret = $form->getSubmitValues();
return str_replace(' ', '_', $ret['pool_name']);
}
$valid = false;
$msgErr = '';
$pool = [];
try {
if (($o == 'c' || $o == 'w') && $slot_id) {
$statement = $pearDB->prepareQuery('SELECT * FROM mod_dsm_pool WHERE pool_id = :slot_id LIMIT 1');
$pearDB->executePreparedQuery($statement, [':slot_id' => [(int) $slot_id, PDO::PARAM_INT]], true);
$pool = $pearDB->fetch($statement);
}
// Commands
$Cmds = [];
$dbResult = $pearDB->query(
"SELECT command_id, command_name FROM command WHERE command_type = '2' ORDER BY command_name"
);
while ($Cmd = $dbResult->fetch()) {
$Cmds[$Cmd['command_id']] = $Cmd['command_name'];
}
// pool hosts
$poolHost = [];
$dbResult = $pearDB->query("SELECT host_id, host_name FROM host WHERE host_register = '1' ORDER BY host_name");
while ($data = $dbResult->fetch()) {
$poolHost[$data['host_id']] = $data['host_name'];
}
// pool service_template
$poolST = [null => null];
$dbResult = $pearDB->query(
"SELECT service_id, service_description FROM service WHERE service_register = '0' ORDER BY service_description"
);
while ($data = $dbResult->fetch()) {
$data['service_description'] = str_replace('#S#', '/', $data['service_description']);
$data['service_description'] = str_replace('#BS#', '\\', $data['service_description']);
$poolST[$data['service_id']] = $data['service_description'];
}
// Template / Style for Quickform input
$attrsText = ['size' => '30'];
$attrsTextSmall = ['size' => '10'];
$attrsText2 = ['size' => '60'];
$attrsAdvSelect = ['style' => 'width: 300px; height: 100px;'];
$attrsTextarea = ['rows' => '5', 'cols' => '40'];
$template = "<table><tr><td>{unselected}</td><td align='center'>{add}<br /><br /><br />"
. '{remove}</td><td>{selected}</td></tr></table>';
// Form begin
$form = new HTML_QuickFormCustom('Form', 'post', '?p=' . $p);
if ($o == 'a') {
$form->addElement('header', 'title', _('Add a pool of services'));
} elseif ($o == 'c') {
$form->addElement('header', 'title', _('Modify a pool of services'));
} elseif ($o == 'w') {
$form->addElement('header', 'title', _('View a pool of services'));
}
// pool basic information
$form->addElement('header', 'information', _('General Information'));
$form->addElement('header', 'slotInformation', _('Slots Information'));
$form->addElement('header', 'Notification', _('Notifications Information'));
// No possibility to change name and alias, because there's no interest
$form->addElement('text', 'pool_name', _('Name'), $attrsText);
$form->addElement('text', 'pool_description', _('Description'), $attrsText);
$form->addElement('text', 'pool_number', _('Number of Slots'), $attrsTextSmall);
$form->addElement('text', 'pool_prefix', _('Slot name prefix'), $attrsText);
$form->addElement('select', 'pool_host_id', _('Host Name'), $poolHost);
$form->addElement('select', 'pool_cmd_id', _('Check commands'), $Cmds);
$form->addElement('text', 'pool_args', _('arguments'), $attrsText2);
$form->addElement('select', 'pool_service_template_id', _('Service template based'), $poolST);
// Further informations
$form->addElement('header', 'furtherInfos', _('Additional Information'));
$poolActivation[] = $form->createElement('radio', 'pool_activate', null, _('Enabled'), '1');
$poolActivation[] = $form->createElement('radio', 'pool_activate', null, _('Disabled'), '0');
$form->addGroup($poolActivation, 'pool_activate', _('Status'), ' ');
$form->setDefaults(['pool_activate' => '1']);
$form->addElement('hidden', 'pool_id');
$redirect = $form->addElement('hidden', 'o');
$redirect->setValue($o);
if (is_array($select)) {
$select_str = null;
foreach ($select as $key => $value) {
$select_str .= $key . ',';
}
$select_pear = $form->addElement('hidden', 'select');
$select_pear->setValue($select_str);
}
$form->applyFilter('__ALL__', 'myTrim');
$form->applyFilter('pool_name', 'replaceSpacesWithUnderscores');
$from_list_menu = false;
if ($o != 'mc') {
$form->addRule('pool_name', _('Compulsory Name'), 'required');
$form->addRule('pool_host_id', _('Compulsory Alias'), 'required');
$form->addRule('pool_prefix', _('Compulsory Alias'), 'required');
$form->addRule('pool_number', _('Compulsory Alias'), 'required');
} elseif ($o == 'mc') {
$from_list_menu = $form->getSubmitValue('submitMC') ? false : true;
}
$form->setRequiredNote("<font style='color: red;'>*</font> " . _('Required fields'));
// Smarty template initialization
$tpl = SmartyBC::createSmartyTemplate($path);
if ($o == 'w') {
// Just watch a pool information
$form->addElement(
'button',
'change',
_('Modify'),
[
'class' => 'btc bt_default',
'onClick' => "javascript:window.location.href='?p=" . $p . '&o=c&pool_id=' . $pool_id . "'",
]
);
$form->setDefaults($pool);
$form->freeze();
} elseif ($o == 'c') {
// Modify a pool information
$subC = $form->addElement('submit', 'submitC', _('Save'), ['class' => 'btc bt_success']);
$res = $form->addElement('reset', 'reset', _('Reset'), ['class' => 'btc bt_default']);
$form->setDefaults($pool);
} elseif ($o == 'a') {
// Add a pool information
$subA = $form->addElement('submit', 'submitA', _('Save'), ['class' => 'btc bt_success']);
$res = $form->addElement('reset', 'reset', _('Reset'), ['class' => 'btc bt_default']);
}
if ($form->validate() && $from_list_menu == false) {
$poolObj = $form->getElement('pool_id');
if ($form->getSubmitValue('submitA')) {
$pId = insertpoolInDB();
$valid = true;
$poolObj->setValue($pId);
} elseif ($form->getSubmitValue('submitC')) {
$valid = updatePoolInDB($poolObj->getValue());
}
$o = null;
$form->addElement(
'button',
'change',
_('Modify'),
[
'class' => 'btc bt_default',
'onClick' => "javascript:window.location.href='?p=" . $p . '&o=c&pool_id=' . $poolObj->getValue() . "'",
]
);
$form->freeze();
}
} catch (Throwable $e) {
$valid = false;
$msgErr = 'Internal Error, contact your administrator for more information';
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: "while managing a pool : {$msgErr}",
exception: $e
);
}
if ($valid) {
include $path . 'listSlot.php';
} else {
// Apply a template definition
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$renderer->setRequiredTemplate('{$label} <font color="red" size="1">*</font>');
$renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->assign('o', $o);
$tpl->assign('msgErr', $msgErr);
$helptext = '';
include 'help.php';
foreach ($help as $key => $text) {
$helptext .= '<span style="display:none" id="help:' . $key . '">' . $text . '</span>' . "\n";
}
$tpl->assign('helptext', $helptext);
$tpl->display('formSlot.ihtml');
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/core/configuration/services/listSlot.php | centreon-dsm/www/modules/centreon-dsm/core/configuration/services/listSlot.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (! isset($oreon)) {
exit();
}
require './include/common/autoNumLimit.php';
// create TP cache
$tpCache = [];
$dbResult = $pearDB->query('SELECT tp_name, tp_id FROM timeperiod');
while ($data = $dbResult->fetch()) {
$tpCache[$data['tp_id']] = $data['tp_name'];
}
$dbResult->closeCursor();
if (isset($search)) {
$dbResult = $pearDB->query(
"SELECT COUNT(*) FROM mod_dsm_pool WHERE (pool_name LIKE '%"
. htmlentities($search, ENT_QUOTES) . "%' OR pool_description LIKE '%"
. htmlentities($search, ENT_QUOTES) . "%')"
);
} else {
$dbResult = $pearDB->query('SELECT COUNT(*) FROM mod_dsm_pool');
}
$tmp = $dbResult->fetch();
$rows = $tmp['COUNT(*)'];
require './include/common/checkPagination.php';
// Smarty template initialization
$tpl = SmartyBC::createSmartyTemplate($path);
// start header menu
$tpl->assign('headerMenu_icone', "<img src='./img/icones/16x16/pin_red.gif'>");
$tpl->assign('headerMenu_desc', _('Description'));
$tpl->assign('headerMenu_name', _('Slot Name'));
$tpl->assign('headerMenu_email', _('Email'));
$tpl->assign('headerMenu_prefix', _('Prefix'));
$tpl->assign('headerMenu_number', _('Number'));
$tpl->assign('headerMenu_status', _('Status'));
$tpl->assign('headerMenu_options', _('Options'));
$tpl->assign('searchLabel', _('Search'));
$tpl->assign('search', $search);
$tpl->assign('p', $p);
if ($search) {
$rq = "SELECT
pool_id,
pool_prefix,
pool_name,
pool_description,
pool_number,
pool_activate
FROM mod_dsm_pool
WHERE (
pool_name LIKE '%" . htmlentities($search, ENT_QUOTES) . "%'
OR pool_description LIKE '%" . htmlentities($search, ENT_QUOTES) . "%')
ORDER BY pool_name LIMIT " . $num * $limit . ', ' . $limit;
} else {
$rq = 'SELECT
pool_id,
pool_prefix,
pool_name,
pool_description,
pool_number,
pool_activate
FROM mod_dsm_pool
ORDER BY pool_name
LIMIT ' . $num * $limit . ', ' . $limit;
}
$dbResult = $pearDB->query($rq);
$search = tidySearchKey($search, $advanced_search);
$form = new HTML_QuickFormCustom('select_form', 'POST', '?p=' . $p);
// Different style between each lines
$style = 'one';
// Fill a tab with a mutlidimensionnal Array we put in $tpl
$elemArr = [];
for ($i = 0; $contact = $dbResult->fetch(); $i++) {
$selectedElements = $form->addElement('checkbox', 'select[' . $contact['pool_id'] . ']');
if ($contact['pool_activate']) {
$moptions = "<a href='main.php?p=" . $p . '&pool_id=' . $contact['pool_id'] . '&o=u&limit=' . $limit
. '&num=' . $num . '&search=' . $search . "'><img src='img/icones/16x16/element_previous.gif' "
. "border='0' alt='" . _('Disabled') . "'></a> ";
} else {
$moptions = "<a href='main.php?p=" . $p . '&pool_id=' . $contact['pool_id'] . '&o=s&limit=' . $limit
. '&num=' . $num . '&search=' . $search . "'><img src='img/icones/16x16/element_next.gif' "
. "border='0' alt='" . _('Enabled') . "'></a> ";
}
$moptions .= ' ';
$moptions .= '<input onKeypress="if(event.keyCode > 31 && (event.keyCode < 45 || event.keyCode > 57)) '
. 'event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) return false;" '
. "maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr["
. $contact['pool_id'] . "]' />";
$elemArr[$i] = [
'MenuClass' => 'list_' . $style,
'RowMenu_select' => $selectedElements->toHtml(),
'RowMenu_name' => html_entity_decode($contact['pool_name']),
'RowMenu_link' => '?p=' . $p . '&o=c&pool_id=' . $contact['pool_id'],
'RowMenu_desc' => html_entity_decode($contact['pool_description']),
'RowMenu_number' => html_entity_decode($contact['pool_number'], ENT_QUOTES),
'RowMenu_prefix' => html_entity_decode($contact['pool_prefix'], ENT_QUOTES),
'RowMenu_status' => $contact['pool_activate'] ? _('Enabled') : _('Disabled'),
'RowMenu_options' => $moptions,
];
$style = $style != 'two' ? 'two' : 'one';
}
$tpl->assign('elemArr', $elemArr);
// Different messages we put in the template
$tpl->assign(
'msg',
[
'addL' => '?p=' . $p . '&o=a',
'addT' => _('Add'),
]
);
// Toolbar select
?>
<script type="text/javascript">
function setO(_i) {
document.forms['form'].elements['o'].value = _i;
}
</SCRIPT>
<?php
$attrs1 = [
'onchange' => 'javascript: '
. "if (this.form.elements['o1'].selectedIndex == 1 && confirm('"
. _('Do you confirm the duplication ?') . "')) {"
. " setO(this.form.elements['o1'].value); submit();} "
. "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('"
. _('Do you confirm the deletion ?') . "')) {"
. " setO(this.form.elements['o1'].value); submit();} "
. "else if (this.form.elements['o1'].selectedIndex == 3 || this.form.elements['o1'].selectedIndex == 4 || "
. "this.form.elements['o1'].selectedIndex == 5){"
. " setO(this.form.elements['o1'].value); submit();} "
. "this.form.elements['o1'].selectedIndex = 0",
];
$form->addElement(
'select',
'o1',
null,
[null => _('More actions...'), 'm' => _('Duplicate'), 'd' => _('Delete')],
$attrs1
);
$form->setDefaults(['o1' => null]);
$attrs2 = [
'onchange' => 'javascript: '
. "if (this.form.elements['o2'].selectedIndex == 1 && confirm('"
. _('Do you confirm the duplication ?') . "')) {"
. " setO(this.form.elements['o2'].value); submit();} "
. "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('"
. _('Do you confirm the deletion ?') . "')) {"
. " setO(this.form.elements['o2'].value); submit();} "
. "else if (this.form.elements['o2'].selectedIndex == 3 || this.form.elements['o2'].selectedIndex == 4 || "
. "this.form.elements['o2'].selectedIndex == 5){"
. " setO(this.form.elements['o2'].value); submit();} "
. "this.form.elements['o1'].selectedIndex = 0",
];
$form->addElement(
'select',
'o2',
null,
[null => _('More actions...'), 'm' => _('Duplicate'), 'd' => _('Delete')],
$attrs2
);
$form->setDefaults(['o2' => null]);
$o1 = $form->getElement('o1');
$o1->setValue(null);
$o1->setSelected(null);
$o2 = $form->getElement('o2');
$o2->setValue(null);
$o2->setSelected(null);
$tpl->assign('limit', $limit);
// Fill a tab with a mutlidimensionnal Array we put in $tpl
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display('listSlot.ihtml');
?>
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/core/configuration/services/DB-Func.php | centreon-dsm/www/modules/centreon-dsm/core/configuration/services/DB-Func.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (! isset($oreon)) {
exit();
}
/**
* Get the list of services id for a pool
*
* @param int $poolId The pool id
* @throws CentreonDbException if a database error occurs
* @return array
*/
function getListServiceForPool($poolId)
{
global $pearDB;
try {
if ((int) $poolId <= 0) {
return [];
}
// Get pool informations
$statement = $pearDB->prepareQuery(
<<<'SQL'
SELECT pool_host_id, pool_prefix
FROM mod_dsm_pool
WHERE pool_id = :pool_id
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_id' => [$poolId, PDO::PARAM_INT]], true);
$row = $pearDB->fetch($statement);
if (is_null($row['pool_host_id']) || $row['pool_host_id'] == '') {
$pearDB->closeQuery($statement);
return [];
}
$poolPrefix = $row['pool_prefix'];
$statement = $pearDB->prepareQuery(
<<<'SQL'
SELECT service_id, service_description
FROM service s, host_service_relation hsr
WHERE hsr.host_host_id = :host_id
AND service_id = service_service_id
AND service_description LIKE :pool_prefix
SQL
);
$pearDB->executePreparedQuery($statement, [
':host_id' => [$row['pool_host_id'], PDO::PARAM_INT],
':pool_prefix' => [$poolPrefix . '%', PDO::PARAM_STR],
], true);
$listServices = [];
while ($row = $pearDB->fetch($statement)) {
if (preg_match('/^' . preg_quote($poolPrefix, '/') . '(\d{4})$/', $row['service_description'])) {
$listServices[] = $row['service_id'];
}
}
$pearDB->closeQuery($statement);
return $listServices;
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: "Error fetching list of services for pool ID: {$poolId}",
customContext: ['poolId' => $poolId],
exception: $e
);
throw $e;
}
}
/**
* Return if a host is already used in DSM
*
* @param int $hostId The host id
* @param string $poolPrefix The pool prefix
* @param int|null $poolId The pool id (optional)
* @throws CentreonDbException if a database error occurs
* @return bool
*/
function hostPoolPrefixUsed($hostId, $poolPrefix, $poolId = null)
{
global $pearDB;
try {
$query = <<<'SQL'
SELECT COUNT(*) AS nb
FROM mod_dsm_pool
WHERE pool_host_id = :host_id
AND pool_prefix = :pool_prefix
SQL;
$params = [
':host_id' => [$hostId, PDO::PARAM_INT],
':pool_prefix' => [$poolPrefix, PDO::PARAM_STR],
];
if ((int) $poolId > 0) {
$query .= ' AND pool_id != :pool_id';
$params[':pool_id'] = [$poolId, PDO::PARAM_INT];
}
$statement = $pearDB->prepareQuery($query);
$pearDB->executePreparedQuery($statement, $params, true);
$row = $pearDB->fetch($statement);
$pearDB->closeQuery($statement);
return $row['nb'] > 0;
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: "Error checking if host {$hostId} is already used with prefix '{$poolPrefix}'",
customContext: ['hostId' => $hostId, 'poolPrefix' => $poolPrefix, 'poolId' => $poolId],
exception: $e
);
throw $e;
}
}
/**
* Enable a slot pool system
*
* @param int|null $pool_id The pool ID to enable (optional)
* @param array $pool_arr An array of pool IDs to enable
* @throws CentreonDbException if a database error occurs
*/
function enablePoolInDB($pool_id = null, $pool_arr = [])
{
global $pearDB;
try {
if (! $pool_id && empty($pool_arr)) {
return;
}
if ($pool_id) {
$pool_arr = [$pool_id => '1'];
}
// Update services in Centreon configuration
foreach ($pool_arr as $id => $values) {
if ((int) $id <= 0) {
continue;
}
$statement = $pearDB->prepareQuery(
<<<'SQL'
UPDATE mod_dsm_pool
SET pool_activate = '1'
WHERE pool_id = :pool_id
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_id' => [$id, PDO::PARAM_INT]], true);
$pearDB->closeQuery($statement);
$listServices = getListServiceForPool($id);
if (! empty($listServices)) {
$bindPlaceholders = array_map(fn (int $index) => ':service_id_' . $index, array_keys($listServices));
$bindPlaceholdersAsString = implode(', ', $bindPlaceholders);
$query = sprintf(
<<<'SQL'
UPDATE service
SET service_activate = '1'
WHERE service_id IN (%s)
SQL,
$bindPlaceholdersAsString
);
$bindValues = array_map(fn (int $serviceId) => [$serviceId, PDO::PARAM_INT], $listServices);
$bindParams = array_combine($bindPlaceholders, $bindValues);
$statement = $pearDB->prepareQuery($query);
$pearDB->executePreparedQuery($statement, $bindParams, true);
$pearDB->closeQuery($statement);
}
}
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: 'Error enabling pool(s) in DB',
customContext: ['pool_id' => $pool_id, 'pool_arr' => $pool_arr],
exception: $e
);
throw $e;
}
}
/**
* Disable a slot pool system
*
* @param int|null $pool_id The pool ID to disable (optional)
* @param array $pool_arr An array of pool IDs to disable
* @throws CentreonDbException if a database error occurs
*/
function disablePoolInDB($pool_id = null, $pool_arr = [])
{
global $pearDB;
try {
if (! $pool_id && empty($pool_arr)) {
return;
}
if ($pool_id) {
$pool_arr = [$pool_id => '1'];
}
foreach ($pool_arr as $id => $values) {
if ((int) $id <= 0) {
continue;
}
$statement = $pearDB->prepareQuery(
<<<'SQL'
UPDATE mod_dsm_pool
SET pool_activate = '0'
WHERE pool_id = :pool_id
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_id' => [$id, PDO::PARAM_INT]], true);
$pearDB->closeQuery($statement);
// Update services in Centreon configuration
$listServices = getListServiceForPool($id);
if (! empty($listServices)) {
$bindPlaceholders = array_map(fn (int $index) => ':service_id_' . $index, array_keys($listServices));
$bindPlaceholdersAsString = implode(', ', $bindPlaceholders);
$query = sprintf(
<<<'SQL'
UPDATE service
SET service_activate = '0'
WHERE service_id IN (%s)
SQL,
$bindPlaceholdersAsString
);
$bindValues = array_map(fn (int $serviceId) => [$serviceId, PDO::PARAM_INT], $listServices);
$bindParams = array_combine($bindPlaceholders, $bindValues);
$statement = $pearDB->prepareQuery($query);
$pearDB->executePreparedQuery($statement, $bindParams, true);
$pearDB->closeQuery($statement);
}
}
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: 'Error disabling pool(s) in DB',
customContext: ['pool_id' => $pool_id, 'pool_arr' => $pool_arr],
exception: $e
);
throw $e;
}
}
/**
* Delete a slot pool system
* @param array $pools An array of pool IDs to delete
* @throws CentreonDbException if a database error occurs
*/
function deletePoolInDB($pools = [])
{
global $pearDB;
try {
foreach ($pools as $key => $value) {
// Delete services in Centreon configuration
$listServices = getListServiceForPool($key);
if (! empty($listServices)) {
$bindPlaceholders = array_map(fn (int $index) => ':service_id_' . $index, array_keys($listServices));
$bindPlaceholdersAsString = implode(', ', $bindPlaceholders);
$query = sprintf(
<<<'SQL'
DELETE FROM service
WHERE service_id IN (%s)
SQL,
$bindPlaceholdersAsString
);
$bindValues = array_map(fn (int $serviceId) => [$serviceId, PDO::PARAM_INT], $listServices);
$bindParams = array_combine($bindPlaceholders, $bindValues);
$statement = $pearDB->prepareQuery($query);
$pearDB->executePreparedQuery($statement, $bindParams, true);
$pearDB->closeQuery($statement);
}
$statement = $pearDB->prepareQuery(
<<<'SQL'
DELETE FROM mod_dsm_pool
WHERE pool_id = :pool_id
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_id' => [$key, PDO::PARAM_INT]], true);
$pearDB->closeQuery($statement);
}
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: 'Error deleting pool(s) in DB',
customContext: ['pools' => $pools],
exception: $e
);
throw $e;
}
}
/**
* Update a slot pool in DB
*
* @param int|null $pool_id The pool ID to update
* @throws CentreonDbException if a database error occurs
* @return bool
*/
function updatePoolInDB($pool_id = null)
{
global $form;
if (! $pool_id) {
return false;
}
$ret = $form->getSubmitValues();
// Global function to use
return updatePool($pool_id);
}
/**
* Insert a slot pool in DB
*
* @param array $ret The values for new pool
* @throws CentreonDbException if a database error occurs
* @return int $pool_id The pool id, return -1 if error
*/
function insertPoolInDB($ret = [])
{
return insertPool($ret);
}
/**
* Check Pool Existence
* @param string $pool_name The pool name to check
* @throws CentreonDbException if a database error occurs
* @return int 0 if the pool does not exist, 1 if it does
*/
function testPoolExistence($pool_name)
{
global $pearDB;
try {
$statement = $pearDB->prepareQuery(
<<<'SQL'
SELECT COUNT(*) AS nb
FROM `mod_dsm_pool`
WHERE `pool_name` = :pool_name
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_name' => [$pool_name, PDO::PARAM_STR]], true);
$row = $pearDB->fetch($statement);
$pearDB->closeQuery($statement);
return ($row['nb'] > 0) ? 1 : 0;
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: "Error checking pool existence for pool name: {$pool_name}",
customContext: ['pool_name' => $pool_name],
exception: $e
);
throw $e;
}
}
/**
* Duplicate Pool
*
* @param array $pool An array of pool IDs to duplicate
* @param array $nbrDup An array of the number of duplications for each pool
* @throws CentreonDbException if a database error occurs
*/
function multiplePoolInDB($pool = [], $nbrDup = [])
{
global $pearDB;
try {
foreach ($pool as $key => $value) {
$statement = $pearDB->prepareQuery(
<<<'SQL'
SELECT *
FROM `mod_dsm_pool`
WHERE `pool_id` = :pool_id
LIMIT 1
SQL
);
$pearDB->executePreparedQuery($statement, [':pool_id' => [$key, PDO::PARAM_INT]], true);
if (($row = $pearDB->fetch($statement)) !== false) {
unset($row['pool_id']);
$fields = [
'pool_name' => PDO::PARAM_STR,
'pool_host_id' => PDO::PARAM_INT,
'pool_description' => PDO::PARAM_STR,
'pool_number' => PDO::PARAM_INT,
'pool_prefix' => PDO::PARAM_STR,
'pool_cmd_id' => PDO::PARAM_INT,
'pool_args' => PDO::PARAM_STR,
'pool_activate' => PDO::PARAM_STR,
'pool_service_template_id' => PDO::PARAM_INT,
];
for ($i = 1; $i <= $nbrDup[$key]; $i++) {
$parameters = [];
$row['pool_name'] = isset($row['pool_name']) ? $row['pool_name'] . '_' . $i : null;
$row['pool_host_id'] = null;
$row['pool_activate'] = '0';
foreach ($fields as $field => $type) {
$parameters[":{$field}"] = [$row[$field], $row[$field] === null ? PDO::PARAM_NULL : $type];
}
if (! testPoolExistence($row['pool_name'])) {
$statement = $pearDB->prepareQuery(
<<<'SQL'
INSERT INTO `mod_dsm_pool` (
`pool_name`,
`pool_host_id`,
`pool_description`,
`pool_number`,
`pool_prefix`,
`pool_cmd_id`,
`pool_args`,
`pool_activate`,
`pool_service_template_id`
) VALUES (
:pool_name,
:pool_host_id,
:pool_description,
:pool_number,
:pool_prefix,
:pool_cmd_id,
:pool_args,
:pool_activate,
:pool_service_template_id
)
SQL
);
$pearDB->executePreparedQuery($statement, $parameters, true);
$pearDB->closeQuery($statement);
$statement = $pearDB->executeQuery('SELECT MAX(pool_id) FROM `mod_dsm_pool`');
$cmd_id = $pearDB->fetch($statement);
$pearDB->closeQuery($statement);
}
}
}
}
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: 'Error duplicating pools with pool IDs: ' . implode(', ', array_keys($pool)),
customContext: ['pool' => $pool, 'nbrDup' => $nbrDup],
exception: $e
);
throw $e;
}
}
/**
* Generate Slot services for a pool
*
* @param string $prefix The prefix for the service
* @param int $number The number of services to generate
* @param int $host_id The host ID for the services
* @param int $template The template ID for the services
* @param int|null $cmd The command ID (optional)
* @param string|null $args The command arguments (optional)
* @param string $oldPrefix The old prefix to be replaced
* @throws CentreonDbException if a database error occurs
*/
function generateServices($prefix, $number, $host_id, $template, $cmd, $args, $oldPrefix)
{
global $pearDB;
try {
if (! isset($oldPrefix)) {
$oldPrefix = '213343434334343434343';
}
$statement = $pearDB->prepareQuery(
<<<'SQL'
SELECT service_id, service_description
FROM service s, host_service_relation hsr
WHERE hsr.host_host_id = :host_id
AND service_id = service_service_id
AND service_description LIKE :oldPrefix
ORDER BY service_description ASC
SQL
);
$pearDB->executePreparedQuery($statement, [
':host_id' => [$host_id, PDO::PARAM_INT],
':oldPrefix' => [$oldPrefix . '%', PDO::PARAM_STR],
], true);
$currentNumber = $statement->rowCount();
if ($currentNumber == 0) {
for ($i = 1; $i <= $number; $i++) {
$suffix = '';
for ($t = $i; $t < 1000; $t *= 10) {
$suffix .= '0';
}
$suffix .= $i;
$statementInsert = $pearDB->prepareQuery(
<<<'SQL'
INSERT INTO service (
service_description,
service_template_model_stm_id,
command_command_id,
command_command_id_arg,
service_activate,
service_register,
service_active_checks_enabled,
service_passive_checks_enabled,
service_parallelize_check,
service_obsess_over_service,
service_check_freshness,
service_event_handler_enabled,
service_process_perf_data,
service_retain_status_information,
service_notifications_enabled,
service_is_volatile
) VALUES (
:service_description, :template, :cmd, :args, '1', '1', '0', '1', '2', '2', '2', '2', '2', '2', '2', '2'
)
SQL
);
$pearDB->executePreparedQuery($statementInsert, [
':service_description' => [$prefix . $suffix, PDO::PARAM_STR],
':template' => [$template, PDO::PARAM_INT],
':cmd' => [$cmd ?: null, $cmd ? PDO::PARAM_INT : PDO::PARAM_NULL],
':args' => [$args ?: null, $args ? PDO::PARAM_STR : PDO::PARAM_NULL],
], true);
$pearDB->closeQuery($statementInsert);
$statementMax = $pearDB->prepareQuery(
<<<'SQL'
SELECT MAX(service_id)
FROM service
WHERE service_description = :service_description
AND service_activate = '1'
AND service_register = '1'
SQL
);
$pearDB->executePreparedQuery($statementMax, [':service_description' => [$prefix . $suffix, PDO::PARAM_STR]], true);
$service = $pearDB->fetch($statementMax);
$service_id = $service['MAX(service_id)'];
$pearDB->closeQuery($statementMax);
if ($service_id != 0) {
$statementInsertHostRelation = $pearDB->prepareQuery(
'INSERT INTO host_service_relation (service_service_id, host_host_id)
VALUES (:service_id, :host_id)'
);
$pearDB->executePreparedQuery($statementInsertHostRelation, [
':service_id' => [$service_id, PDO::PARAM_INT],
':host_id' => [$host_id, PDO::PARAM_INT],
], true);
$pearDB->closeQuery($statementInsertHostRelation);
$statementInsertExtended = $pearDB->prepareQuery(
'INSERT INTO extended_service_information (service_service_id) VALUES (:service_id)'
);
$pearDB->executePreparedQuery($statementInsertExtended, [':service_id' => [$service_id, PDO::PARAM_INT]], true);
$pearDB->closeQuery($statementInsertExtended);
}
}
} elseif ($currentNumber <= $number) {
for ($i = 1; $data = $pearDB->fetch($statement); $i++) {
$suffix = str_pad($i, 4, '0', STR_PAD_LEFT);
$statementUpdate = $pearDB->prepareQuery(
<<<'SQL'
UPDATE service
SET service_template_model_stm_id = :template,
service_description = :service_description,
command_command_id = :cmd,
command_command_id_arg = :args
WHERE service_id = :service_id
SQL
);
$pearDB->executePreparedQuery($statementUpdate, [
':template' => [$template, PDO::PARAM_INT],
':service_description' => [$prefix . $suffix, PDO::PARAM_STR],
':cmd' => [$cmd ?: null, $cmd ? PDO::PARAM_INT : PDO::PARAM_NULL],
':args' => [$args ?: null, $args ? PDO::PARAM_STR : PDO::PARAM_NULL],
':service_id' => [$data['service_id'], PDO::PARAM_INT],
], true);
$pearDB->closeQuery($statementUpdate);
$statementDeleteHostRelation = $pearDB->prepareQuery(
'DELETE FROM host_service_relation WHERE service_service_id = :service_id'
);
$pearDB->executePreparedQuery($statementDeleteHostRelation, [':service_id' => [$data['service_id'], PDO::PARAM_INT]], true);
$pearDB->closeQuery($statementDeleteHostRelation);
$statementInsertHostRelation = $pearDB->prepareQuery(
'INSERT INTO host_service_relation (service_service_id, host_host_id)
VALUES (:service_id, :host_id)'
);
$pearDB->executePreparedQuery($statementInsertHostRelation, [
':service_id' => [$data['service_id'], PDO::PARAM_INT],
':host_id' => [$host_id, PDO::PARAM_INT],
], true);
$pearDB->closeQuery($statementInsertHostRelation);
}
while ($i <= $number) {
$suffix = '';
for ($t = $i; $t < 1000; $t *= 10) {
$suffix .= '0';
}
$suffix .= $i;
$statementInsert = $pearDB->prepareQuery(
<<<'SQL'
INSERT INTO service (
service_description,
service_template_model_stm_id,
command_command_id,
command_command_id_arg,
service_activate,
service_register,
service_active_checks_enabled,
service_passive_checks_enabled,
service_parallelize_check,
service_obsess_over_service,
service_check_freshness,
service_event_handler_enabled,
service_process_perf_data,
service_retain_status_information,
service_notifications_enabled,
service_is_volatile
) VALUES (
:service_description, :template, :cmd, :args, '1', '1', '0', '1', '2', '2', '2', '2', '2', '2', '2', '2'
)
SQL
);
$pearDB->executePreparedQuery($statementInsert, [
':service_description' => [$prefix . $suffix, PDO::PARAM_STR],
':template' => [$template, PDO::PARAM_INT],
':cmd' => [$cmd ?: null, $cmd ? PDO::PARAM_INT : PDO::PARAM_NULL],
':args' => [$args ?: null, $args ? PDO::PARAM_STR : PDO::PARAM_NULL],
], true);
$pearDB->closeQuery($statementInsert);
$statementMax = $pearDB->prepareQuery(
<<<'SQL'
SELECT MAX(service_id) FROM service
WHERE service_description = :service_description
AND service_activate = '1'
AND service_register = '1'
SQL
);
$pearDB->executePreparedQuery($statementMax, [':service_description' => [$prefix . $suffix, PDO::PARAM_STR]], true);
$service = $pearDB->fetch($statementMax);
$service_id = $service['MAX(service_id)'];
$pearDB->closeQuery($statementMax);
if ($service_id != 0) {
$statementInsertHostRelation = $pearDB->prepareQuery(
'INSERT INTO host_service_relation (service_service_id, host_host_id)
VALUES (:service_id, :host_id)'
);
$pearDB->executePreparedQuery($statementInsertHostRelation, [
':service_id' => [$service_id, PDO::PARAM_INT],
':host_id' => [$host_id, PDO::PARAM_INT],
], true);
$pearDB->closeQuery($statementInsertHostRelation);
$statementInsertExtended = $pearDB->prepareQuery(
'INSERT INTO extended_service_information (service_service_id) VALUES (:service_id)'
);
$pearDB->executePreparedQuery($statementInsertExtended, [':service_id' => [$service_id, PDO::PARAM_INT]], true);
$pearDB->closeQuery($statementInsertExtended);
}
$i++;
}
} elseif ($currentNumber > $number) {
for ($i = 1; $data = $pearDB->fetch($statement); $i++) {
if ($i > $number) {
$statementDeleteService = $pearDB->prepareQuery('DELETE FROM service WHERE service_id = :service_id');
$pearDB->executePreparedQuery($statementDeleteService, [':service_id' => [$data['service_id'], PDO::PARAM_INT]], true);
$pearDB->closeQuery($statementDeleteService);
}
}
}
$pearDB->closeQuery($statement);
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: "Error generating services for pool with prefix: {$prefix}",
customContext: [
'prefix' => $prefix,
'number' => $number,
'host_id' => $host_id,
'template' => $template,
'cmd' => $cmd,
'args' => $args,
'oldPrefix' => $oldPrefix,
],
exception: $e
);
throw $e;
}
}
/**
* Insert Pool
*
* @param array $ret The values for new pool
* @throws CentreonDbException if a database error occurs
* @return int The pool ID, or -1 if an error occurs
*/
function insertPool($ret = [])
{
global $form, $pearDB;
try {
if (empty($ret)) {
$ret = $form->getSubmitValues();
}
if (hostPoolPrefixUsed($ret['pool_host_id'], $ret['pool_prefix'])) {
throw new Exception(_('Hosts is already using that pool prefix'));
}
$statement = $pearDB->prepareQuery(
<<<'SQL'
INSERT INTO `mod_dsm_pool` (
`pool_name`,
`pool_host_id`,
`pool_description`,
`pool_number`,
`pool_prefix`,
`pool_cmd_id`,
`pool_args`,
`pool_activate`,
`pool_service_template_id`
) VALUES (
:pool_name,
:pool_host_id,
:pool_description,
:pool_number,
:pool_prefix,
:pool_cmd_id,
:pool_args,
:pool_activate,
:pool_service_template_id
)
SQL
);
// Generate all services
generateServices(
$ret['pool_prefix'],
$ret['pool_number'],
$ret['pool_host_id'],
$ret['pool_service_template_id'],
$ret['pool_cmd_id'],
$ret['pool_args'],
'kjqsddlqkjdqslkjdqsldkj'
);
$fields = [
'pool_name' => PDO::PARAM_STR,
'pool_host_id' => PDO::PARAM_INT,
'pool_description' => PDO::PARAM_STR,
'pool_number' => PDO::PARAM_INT,
'pool_prefix' => PDO::PARAM_STR,
'pool_cmd_id' => PDO::PARAM_INT,
'pool_args' => PDO::PARAM_STR,
'pool_activate' => PDO::PARAM_STR,
'pool_service_template_id' => PDO::PARAM_INT,
];
$parameters = [];
foreach ($fields as $field => $type) {
$value = $field === 'pool_activate' ? $ret[$field][$field] : $ret[$field] ?? null;
$parameters[":{$field}"] = [$value, $value !== null ? $type : PDO::PARAM_NULL];
}
$pearDB->executePreparedQuery($statement, $parameters, true);
$pearDB->closeQuery($statement);
$statementMax = $pearDB->executeQuery('SELECT MAX(pool_id) FROM mod_dsm_pool');
$pool_id = $pearDB->fetch($statementMax);
$pearDB->closeQuery($statementMax);
if ($ret['pool_activate']['pool_activate'] == 1) {
enablePoolInDB($pool_id['MAX(pool_id)']);
} else {
disablePoolInDB($pool_id['MAX(pool_id)']);
}
return $pool_id['MAX(pool_id)'];
} catch (CentreonDbException $e) {
CentreonLog::create()->error(
logTypeId: CentreonLog::TYPE_BUSINESS_LOG,
message: 'Error inserting pool with name: ' . ($ret['pool_name'] ?? 'N/A'),
customContext: [
'pool_name' => $ret['pool_name'] ?? null,
'pool_host_id' => $ret['pool_host_id'] ?? null,
'pool_prefix' => $ret['pool_prefix'] ?? null,
],
exception: $e
);
throw $e;
}
}
/**
* Update Pool
*
* @param int|null $pool_id The pool ID
* @throws CentreonDbException if a database error occurs
* @return bool
*/
function updatePool($pool_id = null)
{
global $form, $pearDB;
try {
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | true |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-dsm/www/modules/centreon-dsm/statistics/centreonDSMStats.class.php | centreon-dsm/www/modules/centreon-dsm/statistics/centreonDSMStats.class.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../class/centreonDB.class.php';
require_once __DIR__ . '/../../../class/exceptions/StatisticException.php';
class CentreonDSMStats
{
/** @var CentreonDB */
private $db;
/**
* Constructor
*/
public function __construct()
{
$this->db = new CentreonDB();
}
/**
* Get statistics of module
* @throws StatisticException
* @return array{
* dsm: array{}|array{
* pools: scalar,
* slot_min: scalar,
* slot_max: scalar,
* slot_avg: scalar,
* }
* }
*/
public function getStats(): array
{
try {
$data = $this->getSlotsUsage();
return ['dsm' => $data];
} catch (Throwable $e) {
throw new StatisticException(
message: 'Unable to get Centreon DSM statistics: ' . $e->getMessage(),
previous: $e
);
}
}
/**
* Get Auto Discovery services rules usage
* @return array{}|array{
* pools: scalar,
* slot_min: scalar,
* slot_max: scalar,
* slot_avg: scalar,
* }
*/
public function getSlotsUsage(): array
{
$data = [];
$query = <<<'SQL'
SELECT COUNT(pool_id) AS pools,
MIN(pool_number) AS min,
MAX(pool_number) AS max,
AVG(pool_number) as avg
FROM mod_dsm_pool
SQL;
$result = $this->db->query($query);
while ($row = $result->fetch()) {
$data = [
'pools' => $row['pools'],
'slot_min' => $row['min'],
'slot_max' => $row['max'],
'slot_avg' => $row['avg'],
];
}
return $data;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/.php-cs-fixer.conf.php | centreon-awie/.php-cs-fixer.conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
return [
'legacy' => [
'files' => [
'.php-cs-fixer.conf.php',
'.php-cs-fixer.diff.php',
'.php-cs-fixer.legacy.php',
'rector.conf.php',
'rector.diff.php',
'rector.legacy.php',
],
'directories' => [
'features',
'www',
],
'skip' => [],
],
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/.php-cs-fixer.diff.php | centreon-awie/.php-cs-fixer.diff.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use Tools\PhpCsFixer\Command\RunCsFixerOnDiffCommand;
use Tools\PhpCsFixer\Command\RunCsFixerOnDiffCommandHandler;
require_once __DIR__ . '/../php-tools/vendor/autoload.php';
$pathsConfig = require_once __DIR__ . '/.php-cs-fixer.conf.php';
$args = $_SERVER['argv'] ?? [];
$runCsFixerOnDiffCommand = new RunCsFixerOnDiffCommand(
moduleName: 'centreon-awie',
sections: ['legacy'],
pathsConfig: $pathsConfig,
args: $args
);
$runCsFixerOnDiffCommandHandler = new RunCsFixerOnDiffCommandHandler();
$runCsFixerOnDiffCommandHandler->run($runCsFixerOnDiffCommand);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/.php-cs-fixer.legacy.php | centreon-awie/.php-cs-fixer.legacy.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use PhpCsFixer\Finder;
$config = require_once __DIR__ . '/../php-tools/php-cs-fixer/config/base.unstrict.php';
$pathsConfig = require_once __DIR__ . '/.php-cs-fixer.conf.php';
$finder = Finder::create()
->in($pathsConfig['legacy']['directories'])
->append($pathsConfig['legacy']['files'])
->notPath($pathsConfig['legacy']['skip']);
return $config
->setFinder($finder)
->setCacheFile('.php-cs-fixer.legacy.cache');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/rector.diff.php | centreon-awie/rector.diff.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
use Tools\Rector\Command\RunRectorOnDiffCommand;
use Tools\Rector\Command\RunRectorOnDiffCommandHandler;
require_once __DIR__ . '/../php-tools/vendor/autoload.php';
$pathsConfig = require_once __DIR__ . '/rector.conf.php';
$args = $_SERVER['argv'] ?? [];
$runRectorOnDiffCommand = new RunRectorOnDiffCommand(
moduleName: 'centreon-awie',
sections: ['legacy'],
pathsConfig: $pathsConfig,
args: $args
);
$runRectorOnDiffCommandHandler = new RunRectorOnDiffCommandHandler();
$runRectorOnDiffCommandHandler->run($runRectorOnDiffCommand);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/rector.legacy.php | centreon-awie/rector.legacy.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
$rectorConfig = require_once __DIR__ . '/../php-tools/rector/config/base.unstrict.php';
$pathsConfig = require_once __DIR__ . '/rector.conf.php';
return $rectorConfig
->withCache(__DIR__ . '/var/cache/rector.legacy')
->withPaths($pathsConfig['legacy']['paths'])
->withSkip($pathsConfig['legacy']['skip']);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/rector.conf.php | centreon-awie/rector.conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
return [
'legacy' => [
'paths' => [
// directories
'features',
'www',
// files
'.php-cs-fixer.conf.php',
'.php-cs-fixer.diff.php',
'.php-cs-fixer.legacy.php',
'rector.conf.php',
'rector.diff.php',
'rector.legacy.php',
],
'skip' => [],
],
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/features/bootstrap/CentreonAwieContext.php | centreon-awie/features/bootstrap/CentreonAwieContext.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
use Centreon\Test\Behat\CentreonContext;
class CentreonAwieContext extends CentreonContext
{
/**
* @Given I am logged in a Centreon server with Awie installed
*/
public function iAmLoggedInACentreonServerWithAWIEInstalled(): void
{
$this->launchCentreonWebContainer('awie');
$this->iAmLoggedIn();
}
public function iAmOnTheExportPage(): void
{
$this->visit('main.php?p=61201');
// Check that page is valid for this class.
$mythis = $this;
$this->spin(
function ($context) {
return $context->getSession()->getPage()->has('css', '#poller');
}
);
}
public function iAmOnTheImportPage(): void
{
$this->visit('main.php?p=61202');
$mythis = $this;
$this->spin(
function ($context) {
return $context->getSession()->getPage()->has('css', '#file');
}
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/features/bootstrap/ImportExportContext.php | centreon-awie/features/bootstrap/ImportExportContext.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
/**
* Class
*
* @class ImportExportContext
*/
class ImportExportContext extends CentreonAwieContext
{
/**
* @When I export an object
*/
public function iExportAnObject(): void
{
$this->iAmOnTheExportPage();
$this->assertFind('css', '#contact')->click();
$this->assertFind('css', '.bt_success')->click();
}
/**
* @Then I have a file
*/
public function iHaveAFile(): void
{
$mythis = $this;
$this->spin(
function ($context) {
if ($context->getSession()->getPage()->has('css', '.loadingWrapper')) {
return ! $context->assertFind('css', '.loadingWrapper')->isVisible();
}
return true;
}
);
$cmd = 'ls /tmp';
$output = $this->container->execute(
$cmd,
'web'
);
$output = explode("\n", $output['output']);
$fileCreate = false;
foreach ($output as $file) {
if (str_ends_with("{$file}", 'zip')) {
$fileCreate = true;
}
}
if (! $fileCreate) {
throw new Exception('File not create');
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/conf.php | centreon-awie/www/modules/centreon-awie/conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
$module_conf['centreon-awie']['rname'] = 'Centreon Api Web Import Export';
$module_conf['centreon-awie']['name'] = 'centreon-awie';
$module_conf['centreon-awie']['mod_release'] = '26.01.0';
$module_conf['centreon-awie']['infos'] = 'The Centreon AWIE (Application Web Import Export) module has been '
. 'designed to help users configure several Centreon Web platforms in a faster and easier way, thanks to its '
. 'import/export mechanism.
From a properly configured source environment, you can use the AWIE module to export chosen objects towards a '
. 'target environment. Those objects will be replicated.
Centreon AWIE is based on CLAPI commands but its added value is to allow using Centreon Web UI instead of '
. 'commands lines.
';
$module_conf['centreon-awie']['is_removeable'] = '1';
$module_conf['centreon-awie']['author'] = 'Centreon';
$module_conf['centreon-awie']['stability'] = 'stable';
$module_conf['centreon-awie']['last_update'] = '2025-11-18';
$module_conf['centreon-awie']['images'] = [
'images/image1.png',
];
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/centreon-awie.conf.php | centreon-awie/www/modules/centreon-awie/centreon-awie.conf.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
$currentPath = __DIR__;
if (! defined('_MODULE_PATH_')) {
define('_MODULE_PATH_', _CENTREON_PATH_ . '/www/modules/centreon-awie/');
}
// Autoload
$sAppPath = _MODULE_PATH_ . '/core/class/';
spl_autoload_register(function ($sClass) use ($sAppPath): void {
$sFilePath = '';
$explodedClassname = explode('\\', $sClass);
$sCentreonExport = array_shift($explodedClassname);
$sFilePath .= $sAppPath . implode('/', $explodedClassname);
$sFilePath .= '.php';
if (file_exists($sFilePath)) {
require_once $sFilePath;
}
});
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/class/ZipAndDownload.class.php | centreon-awie/www/modules/centreon-awie/class/ZipAndDownload.class.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
class ZipAndDownload
{
/**
* ZipAndDownload constructor.
* @param string $fileNames
* @param string $filePath
* @param string $fileExtension
*/
public function __construct($fileNames, $filePath = '/tmp', $fileExtension = '.txt')
{
$archivePath = $filePath . '/' . $fileNames . '.zip';
$filePath .= '/' . $fileNames . $fileExtension;
$zip = new ZipArchive();
// create the file and throw the error if unsuccessful
if ($zip->open($archivePath, ZIPARCHIVE::CREATE) !== true) {
exit("cannot open <{$archivePath}>\n");
}
$zip->addFile($filePath, basename($filePath));
$zip->close();
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=' . basename($archivePath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($archivePath));
readfile($archivePath);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/class/ClapiObject.class.php | centreon-awie/www/modules/centreon-awie/class/ClapiObject.class.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
class ClapiObject
{
/** @var array<mixed> */
protected $dbConfigCentreon = [];
/** @var array<mixed> */
protected $dbConfigCentreonStorage = [];
/** @var mixed */
protected $db;
/** @var mixed */
protected $dbMon;
/** @var array<mixed> */
protected $clapiParameters = [];
/** @var CentreonClapi\CentreonAPI */
protected $clapiConnector;
/** @var Pimple\Container */
protected $dependencyInjector;
/**
* @param Pimple\Container $dependencyInjector
* @param array<mixed> $clapiParameters
*/
public function __construct($dependencyInjector, $clapiParameters)
{
$this->dependencyInjector = $dependencyInjector;
$this->clapiParameters = $clapiParameters;
$this->connectToClapi();
}
/**
* @param string $key
* @param string $value
* @return void
*/
public function addClapiParameter($key, $value): void
{
$this->clapiParameters[$key] = $value;
}
/**
* Export
*
* @param bool $withoutClose boolean disable using of PHP exit function (default: false)
* @return mixed
*/
public function export($withoutClose = false)
{
$this->clapiConnector->setOption($this->clapiParameters);
return $this->clapiConnector->export($withoutClose);
}
/**
* @param string $fileName
* @return mixed
*/
public function import($fileName)
{
return $this->clapiConnector->import($fileName);
}
/**
* @return void
*/
private function connectToClapi(): void
{
CentreonClapi\CentreonUtils::setUserName($this->clapiParameters['username']);
$this->clapiConnector = CentreonClapi\CentreonAPI::getInstance(
'',
'',
'',
_CENTREON_PATH_,
$this->clapiParameters,
$this->dependencyInjector
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/class/Export.class.php | centreon-awie/www/modules/centreon-awie/class/Export.class.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
/**
* Class Export
*/
class Export
{
/** @var array<mixed> */
protected $bash = [];
/** @var string */
protected $user = '';
/** @var string */
protected $pwd = '';
/** @var string */
protected $tmpFile = '';
/** @var string */
protected $tmpName = '';
/** @var CentreonDB */
protected $db;
/** @var ClapiObject */
protected $clapiConnector;
/**
* Export constructor.
* @param ClapiObject $clapiConnector
* @param Pimple\Container $dependencyInjector
*/
public function __construct($clapiConnector, $dependencyInjector)
{
$this->db = $dependencyInjector['configuration_db'];
$this->clapiConnector = $clapiConnector;
$this->tmpName = 'centreon-clapi-export-' . time();
$this->tmpFile = '/tmp/' . $this->tmpName . '.txt';
}
/**
* @param string $object
* @param array<mixed> $value
* @return array{
* result: string,
* error: string,
* }|null
*/
public function generateGroup($object, $value)
{
if ($object == 'cmd') {
foreach ($value as $cmdType => $val) {
$type = explode('_', $cmdType);
return $this->generateCmd($type[0]);
}
} elseif ($object == 'INSTANCE') {
return $this->generateInstance($value);
} elseif (isset($value[$object])) {
return $this->generateObject($object);
} elseif (! empty($value[$object . '_filter'])) {
$filter = ';' . $value[$object . '_filter'];
return $this->generateObject($object, $filter);
}
return null;
}
/**
* @param string $object
* @param string $filter
* @return array{
* result: string,
* error: string,
* }
*/
public function generateObject($object, $filter = '')
{
$content = ['result' => '', 'error' => ''];
$result = '';
if ($object == 'ACL') {
$acl = $this->generateAcl();
$result .= $acl['result'];
} else {
ob_start();
$option = $object . $filter;
$this->clapiConnector->addClapiParameter('select', $option);
try {
$this->clapiConnector->export(true);
$result .= ob_get_contents();
ob_end_clean();
} catch (Exception $e) {
$result .= $e->getMessage();
ob_end_clean();
}
}
if (preg_match('#Unknown object#i', $result)) {
$content['error'] = $result;
} else {
$content['result'] = $result;
}
return $content;
}
/**
* @param array<string> $content
* @return string
*/
public function clapiExport($content)
{
$fileHandler = fopen($this->tmpFile, 'w');
foreach ($content as $command) {
fwrite($fileHandler, mb_convert_encoding($command, 'UTF-8', 'ISO-8859-1'));
}
fclose($fileHandler);
return $this->tmpName;
}
/**
* @param string $type
* @return array{
* result: string,
* error: string,
* }
*/
private function generateCmd($type)
{
$cmdScript = ['result' => '', 'error' => ''];
$cmdTypeRelation = [
'n' => 1,
'c' => 2,
'm' => 3,
'd' => 4,
];
$query = 'SELECT `command_name` FROM `command`WHERE `command_type` =' . $cmdTypeRelation[$type];
$res = $this->db->query($query);
while ($row = $res->fetch()) {
$result = $this->generateObject('CMD', ';' . $row['command_name']);
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
}
return $cmdScript;
}
/**
* @param array<mixed> $value
* @return array{
* result: string,
* error: string,
* }
*/
private function generateInstance($value)
{
$cmdScript = [];
if (isset($value['INSTANCE'])) {
// export instance
$result = $this->generateObject('INSTANCE');
$cmdScript['result'] = $result['result'];
$cmdScript['error'] = $result['error'];
// export resource cfg
$result = $this->generateObject('RESOURCECFG');
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
// export broker cfg
$result = $this->generateObject('CENTBROKERCFG');
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
// export engine cfg
$result = $this->generateObject('ENGINECFG');
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
} elseif (! empty($value['INSTANCE_filter'])) {
$query = 'SELECT `id` FROM `nagios_server` WHERE `name` = :name';
$statement = $this->db->prepare($query);
$statement->bindValue(':name', $value['INSTANCE_filter'], PDO::PARAM_STR);
$statement->execute();
$pollerId = null;
while ($row = $statement->fetch()) {
$pollerId = $row['id'];
}
// export instance
$filter = ';' . $value['INSTANCE_filter'];
$result = $this->generateObject('INSTANCE', $filter);
$cmdScript['result'] = $result['result'];
$cmdScript['error'] = $result['error'];
// check is missed pollerId
if ($pollerId === null) {
return $cmdScript;
}
// export resource cfg
$query = 'SELECT r.resource_name FROM cfg_resource r, cfg_resource_instance_relations cr '
. 'WHERE cr.instance_id = :pollerId'
. ' AND cr.resource_id = r.resource_id';
$statement = $this->db->prepare($query);
$statement->bindValue(':pollerId', $pollerId, PDO::PARAM_INT);
$statement->execute();
while ($row = $statement->fetch()) {
$filter = ';' . $row['resource_name'];
$result = $this->generateObject('RESOURCECFG', $filter);
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
}
// export broker cfg
$query = 'SELECT b.config_name FROM cfg_centreonbroker b WHERE b.ns_nagios_server = :pollerId';
$statement = $this->db->prepare($query);
$statement->bindValue(':pollerId', $pollerId, PDO::PARAM_INT);
$statement->execute();
while ($row = $statement->fetch()) {
$filter = ';' . $row['config_name'];
$result = $this->generateObject('CENTBROKERCFG', $filter);
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
}
// export engine cfg
$query = 'SELECT n.nagios_name FROM cfg_nagios n WHERE n.nagios_server_id = :pollerId';
$statement = $this->db->prepare($query);
$statement->bindValue(':pollerId', $pollerId, PDO::PARAM_INT);
$statement->execute();
while ($row = $statement->fetch()) {
$filter = ';' . $row['nagios_name'];
$result = $this->generateObject('ENGINECFG', $filter);
$cmdScript['result'] .= $result['result'];
$cmdScript['error'] .= $result['error'];
}
}
return $cmdScript;
}
/**
* @return array{
* result: string,
* error: string,
* }
*/
private function generateAcl()
{
$aclScript = [
'result' => '',
'error' => '',
];
$oAcl = ['ACLMENU', 'ACLACTION', 'ACLRESOURCE', 'ACLGROUP'];
foreach ($oAcl as $acl) {
$result = $this->generateObject($acl);
$aclScript['result'] .= $result['result'];
$aclScript['error'] .= $result['error'];
}
return $aclScript;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/core/submitExport.php | centreon-awie/www/modules/centreon-awie/core/submitExport.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../../config/centreon.config.php';
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/class/ZipAndDownload.class.php';
$oExport = new ZipAndDownload($_POST['pathFile']);
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/core/launchImport.php | centreon-awie/www/modules/centreon-awie/core/launchImport.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../../config/centreon.config.php';
require_once _CENTREON_PATH_ . '/bootstrap.php';
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/centreon-awie.conf.php';
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/class/ClapiObject.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreon.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreonUser.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreonSession.class.php';
require_once _CENTREON_PATH_ . '/www/include/common/common-Func.php';
define('_CLAPI_LIB_', _CENTREON_PATH_ . '/lib');
define('_CLAPI_CLASS_', _CENTREON_PATH_ . '/www/class/centreon-clapi');
set_include_path(
implode(
PATH_SEPARATOR,
[
realpath(_CLAPI_LIB_),
realpath(_CLAPI_CLASS_),
get_include_path(),
]
)
);
require_once _CLAPI_CLASS_ . '/centreonUtils.class.php';
require_once _CLAPI_CLASS_ . '/centreonAPI.class.php';
$pearDB = new CentreonDB();
$centreonSession = new CentreonSession();
$centreonSession->start();
// Exit if no session cookie
if (! isset($_COOKIE['PHPSESSID']) || empty($_COOKIE['PHPSESSID'])) {
echo json_encode(['error' => 'Authentication required']);
exit;
}
// Exit if invalid session
if (! isset($_SESSION['centreon']) || ! isset($_SESSION['centreon']->user)) {
echo json_encode(['error' => 'Invalid or expired session']);
exit;
}
// Check CSRF token
if (! isset($_POST['centreon_token']) || ! isCSRFTokenValid()) {
echo json_encode(['error' => 'Invalid security token']);
exit;
}
purgeCSRFToken();
// Exit if user is not admin
if ((bool) $_SESSION['centreon']->user->admin !== true) {
echo json_encode(['error' => 'Permission denied']);
exit;
}
// Exit if user is a service account
if (isServiceAccount($_SESSION['centreon']->user->user_id)) {
echo json_encode(['error' => 'Permission denied for service accounts']);
exit;
}
$username = $_SESSION['centreon']->user->alias;
/** @var Pimple\Container $dependencyInjector */
$clapiConnector = new ClapiObject($dependencyInjector, ['username' => $username]);
$importReturn = [];
/**
* Upload file
*/
if (! isset($_FILES['clapiImport'])) {
$importReturn['error'] = 'File is empty';
echo json_encode($importReturn);
exit;
}
$uploadDir = _CENTREON_CACHEDIR_ . '/';
$uploadFile = $uploadDir . basename($_FILES['clapiImport']['name']);
$tmpLogFile = $uploadDir . 'log' . time() . '.htm';
if (! is_dir($uploadDir)) {
mkdir($uploadDir);
}
$moveFile = move_uploaded_file($_FILES['clapiImport']['tmp_name'], $uploadFile);
if (! $moveFile) {
$importReturn['error'] = 'Upload failed';
echo json_encode($importReturn);
exit;
}
/**
* Unzip file
*/
$zip = new ZipArchive();
$confPath = _CENTREON_CACHEDIR_ . '/filesUpload/';
$openResult = $zip->open($uploadFile);
if ($openResult === true) {
$zip->extractTo($confPath);
$zip->close();
} elseif ($openResult !== 0 /** {@see ZipArchive::ER_OK} */) {
$importReturn['error'] = 'Unzip failed';
echo json_encode($importReturn);
exit;
}
/**
* Set log_contact
*/
CentreonClapi\CentreonUtils::setUserName($username);
/**
* Using CLAPI command to import configuration
* Exemple -> "./centreon -u admin -p centreon -i /tmp/clapi-export.txt"
*/
$finalFile = $confPath . basename($uploadFile, '.zip') . '.txt';
try {
ob_start();
$clapiConnector->import($finalFile);
ob_end_clean();
$importReturn['response'] = 'Import successful';
} catch (Exception $e) {
$importReturn['error'] = $e->getMessage();
}
unlink($uploadFile);
unlink($finalFile);
echo json_encode($importReturn);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/core/generateExport.php | centreon-awie/www/modules/centreon-awie/core/generateExport.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once __DIR__ . '/../../../../bootstrap.php';
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', false);
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/class/Export.class.php';
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/class/ClapiObject.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreon.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreonUser.class.php';
require_once _CENTREON_PATH_ . '/www/class/centreonSession.class.php';
require_once _CENTREON_PATH_ . '/www/include/common/common-Func.php';
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/centreon-awie.conf.php';
define('_CLAPI_LIB_', _CENTREON_PATH_ . '/lib');
define('_CLAPI_CLASS_', _CENTREON_PATH_ . '/www/class/centreon-clapi');
set_include_path(implode(PATH_SEPARATOR, [
realpath(_CLAPI_LIB_),
realpath(_CLAPI_CLASS_),
get_include_path(),
]));
require_once _CLAPI_CLASS_ . '/centreonUtils.class.php';
require_once _CLAPI_CLASS_ . '/centreonAPI.class.php';
$formValue = [
'export_cmd',
'TP',
'CONTACT',
'CG',
'export_HOST',
'export_HTPL',
'export_HG',
'HC',
'export_SERVICE',
'export_STPL',
'export_SG',
'SC',
'ACL',
'LDAP',
'export_INSTANCE',
];
$pearDB = new CentreonDB();
$centreonSession = new CentreonSession();
$centreonSession->start();
// Exit if no session cookie
if (! isset($_COOKIE['PHPSESSID']) || empty($_COOKIE['PHPSESSID'])) {
echo json_encode(['error' => 'Authentication required']);
exit;
}
// Exit if invalid session
if (! isset($_SESSION['centreon']) || ! isset($_SESSION['centreon']->user)) {
echo json_encode(['error' => 'Invalid or expired session']);
exit;
}
// Check CSRF token
if (! isset($_POST['centreon_token']) || ! isCSRFTokenValid()) {
echo json_encode(['error' => 'Invalid security token']);
exit;
}
purgeCSRFToken();
// Exit if user is not admin
if ((bool) $_SESSION['centreon']->user->admin !== true) {
echo json_encode(['error' => 'Permission denied']);
exit;
}
// Exit if user is a service account
if (isServiceAccount($_SESSION['centreon']->user->user_id)) {
echo json_encode(['error' => 'Permission denied for service accounts']);
exit;
}
$username = $_SESSION['centreon']->user->alias;
/** @var Pimple\Container $dependencyInjector */
$clapiConnector = new ClapiObject($dependencyInjector, ['username' => $username]);
// Set log_contact
CentreonClapi\CentreonUtils::setUserName($username);
$scriptContent = [];
$ajaxReturn = [];
$oExport = new Export($clapiConnector, $dependencyInjector);
foreach ($_POST as $object => $value) {
if (in_array($object, $formValue)) {
$type = explode('_', $object);
if ($type[0] == 'export') {
$generateContent = $oExport->generateGroup($type[1], $value);
if (! empty($generateContent)) {
if (! empty($generateContent['error'])) {
$ajaxReturn['error'][] = $generateContent['error'];
}
if (! empty($generateContent['result'])) {
$scriptContent[] = $generateContent['result'];
}
}
} elseif ($type[0] != 'submitC') {
$generateContent = $oExport->generateObject($type[0]);
if (! empty($generateContent['error'])) {
$ajaxReturn['error'][] = $generateContent['error'];
}
if (! empty($generateContent['result'])) {
$scriptContent[] = $generateContent['result'];
}
}
} else {
$ajaxReturn['error'][] = 'Unknown object : ' . $object;
}
}
$ajaxReturn['fileGenerate'] = $oExport->clapiExport($scriptContent);
echo json_encode($ajaxReturn);
exit;
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/core/formExporter.php | centreon-awie/www/modules/centreon-awie/core/formExporter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
if (! isset($oreon)) {
exit();
}
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/centreon-awie.conf.php';
require_once _CENTREON_PATH_ . '/www/include/common/common-Func.php';
$export = './modules/centreon-awie/core/submitExport.php';
// Smarty template initialization
$path = _MODULE_PATH_ . '/core/templates/';
$tpl = SmartyBC::createSmartyTemplate($path);
$csrfToken = createCSRFToken();
$tpl->assign('csrfToken', $csrfToken);
$tpl->assign('formPath', $export);
$tpl->display('formExport.tpl');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon-awie/www/modules/centreon-awie/core/formImporter.php | centreon-awie/www/modules/centreon-awie/core/formImporter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
require_once _CENTREON_PATH_ . '/www/modules/centreon-awie/centreon-awie.conf.php';
require_once _CENTREON_PATH_ . '/www/include/common/common-Func.php';
$export ??= null;
$import = realpath(__DIR__);
// Smarty template initialization
$path = _MODULE_PATH_ . '/core/templates/';
$tpl = SmartyBC::createSmartyTemplate($path);
$csrfToken = createCSRFToken();
$tpl->assign('formPath', $export);
$tpl->assign('csrfToken', $csrfToken);
$tpl->display('formImport.tpl');
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.