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

Clean(platform): Clean appKey method and usage #11336

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2270,7 +2270,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
3 changes: 3 additions & 0 deletions www/install/php/Update-22.10.0-beta.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
$errorMessage = "Unable to delete 'oreon_web_path' option from database";
$pearDB->query("DELETE FROM `options` WHERE `key` = 'oreon_web_path'");

$errorMessage = "Unable to delete 'appKey' information from database";
$pearDB->query("DELETE FROM `informations` WHERE `key` = 'appKey'");
hyahiaoui-ext marked this conversation as resolved.
Show resolved Hide resolved

$pearDB->commit();
} catch (\Exception $e) {
if ($pearDB->inTransaction()) {
Expand Down
2 changes: 2 additions & 0 deletions www/install/sql/centreon/Update-DB-22.10.0-beta.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ ALTER TABLE cfg_nagios MODIFY `enable_predictive_service_dependency_checks` enum
ALTER TABLE cfg_nagios MODIFY `debug_verbosity` enum('0','1');

ALTER TABLE contact DROP COLUMN `enable_one_click_export`;

ALTER TABLE remote_servers DROP COLUMN `app_key`;
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