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

Commit

Permalink
Clean(platform): Clean appKey method and usage 22.04.x (#11452)
Browse files Browse the repository at this point in the history
* Clean(platform): Clean appKey method and usage (#11336)

* removing appKey from information table in baseConf and 22.10 update script

* removing appKey from NotifyMasterService.php

* removing appKey from CentreonRemoteServer.php

* applying suggested changes

* Applying suggested changes

Co-authored-by: Kevin Duret <kduret@centreon.com>

* adding 22.04.2 update script file with changes

* revert 22.04 beta 1 script to its original

Co-authored-by: Kevin Duret <kduret@centreon.com>
  • Loading branch information
hyahiaoui-ext and kduret authored Jul 29, 2022
1 parent b04ce8a commit 0f71be5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
13 changes: 2 additions & 11 deletions src/CentreonRemote/Application/Webservice/CentreonRemoteServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ public function postAddToWaitList(): string
throw new \RestBadRequestException('Can not access your address.');
}

if (
!isset($_POST['app_key'])
|| !$_POST['app_key']
|| empty($appKey = filter_var($_POST['app_key'], FILTER_SANITIZE_STRING))
) {
throw new \RestBadRequestException('Please send \'app_key\' in the request.');
}

if (
!isset($_POST['version'])
|| !$_POST['version']
Expand Down Expand Up @@ -147,15 +139,14 @@ public function postAddToWaitList(): string
}

$createdAt = date('Y-m-d H:i:s');
$insertQuery = "INSERT INTO `remote_servers` (`ip`, `app_key`, `version`, `is_connected`,
$insertQuery = "INSERT INTO `remote_servers` (`ip`, `version`, `is_connected`,
`created_at`, `http_method`, `http_port`, `no_check_certificate`)
VALUES (:ip, :app_key, :version, 0, '{$createdAt}',
VALUES (:ip, :version, 0, '{$createdAt}',
:http_method, :http_port, :no_check_certificate
)";

$insert = $this->pearDB->prepare($insertQuery);
$insert->bindValue(':ip', $ip, \PDO::PARAM_STR);
$insert->bindValue(':app_key', $appKey, \PDO::PARAM_STR);
$insert->bindValue(':version', $version, \PDO::PARAM_STR);
$insert->bindValue(':http_method', $httpScheme, \PDO::PARAM_STR);
$insert->bindValue(':http_port', $httpPort, \PDO::PARAM_INT);
Expand Down
9 changes: 0 additions & 9 deletions src/CentreonRemote/Domain/Service/NotifyMasterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,10 @@ public function pingMaster($ip, $data, $noCheckCertificate = false, $noProxy = f

$url = "{$ip}/centreon/api/external.php?object=centreon_remote_server&action=addToWaitList";
$repository = $this->dbManager->getRepository(InformationsRepository::class);
$applicationKey = $repository->getOneByKey('appKey');
$version = $repository->getOneByKey('version');

if (empty($applicationKey)) {
return [
'status' => self::FAIL,
'details' => self::NO_APP_KEY
];
}

try {
$curlData = [
'app_key' => $applicationKey->getValue(),
'version' => $version->getValue(),
'http_method' => $data['remoteHttpMethod'] ?? 'http',
'http_port' => $data['remoteHttpPort'] ?? '',
Expand Down
1 change: 0 additions & 1 deletion www/install/createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,6 @@ CREATE TABLE IF NOT EXISTS contact_feature (
CREATE TABLE IF NOT EXISTS `remote_servers` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ip` VARCHAR(255) NOT NULL,
`app_key` VARCHAR(40) NOT NULL,
`version` VARCHAR(16) NOT NULL,
`is_connected` TINYINT(1) NOT NULL DEFAULT 0,
`created_at` TIMESTAMP NOT NULL,
Expand Down
51 changes: 51 additions & 0 deletions www/install/php/Update-22.04.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* Copyright 2005 - 2022 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
*
* http://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.2: ';
$errorMessage = '';

try {
$pearDB->beginTransaction();

$errorMessage = "Unable to delete 'appKey' information from database";
$pearDB->query("DELETE FROM `informations` WHERE `key` = 'appKey'");

$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);
}
2 changes: 0 additions & 2 deletions www/install/steps/process/insertBaseConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@
$link->exec("INSERT INTO `options` (`key`, `value`) VALUES ('gmt','" . $timezoneId . "')");

# Generate random key for this instance and set it to be not central and not remote
$uniqueKey = md5(uniqid(rand(), true));
$informationsTableInsert = "INSERT INTO `informations` (`key`,`value`) VALUES
('appKey', '{$uniqueKey}'),
('isRemote', 'no'),
('isCentral', 'yes')";

Expand Down

0 comments on commit 0f71be5

Please sign in to comment.