diff --git a/src/Centreon/Domain/Repository/InformationsRepository.php b/src/Centreon/Domain/Repository/InformationsRepository.php index a64e7800561..968df737ebc 100644 --- a/src/Centreon/Domain/Repository/InformationsRepository.php +++ b/src/Centreon/Domain/Repository/InformationsRepository.php @@ -71,9 +71,14 @@ public function authorizeMaster(string $ip): void $sql = "DELETE FROM `informations` WHERE `key` = 'authorizedMaster'"; $stmt = $this->db->prepare($sql); $stmt->execute(); + + /* + * resolve the address down to IP + */ + $ipAddress = gethostbyname($ip); $sql = "INSERT INTO `informations` (`key`, `value`) VALUES ('authorizedMaster', :ip)"; $stmt = $this->db->prepare($sql); - $stmt->bindParam(':ip', $ip, PDO::PARAM_STR); + $stmt->bindParam(':ip', $ipAddress, PDO::PARAM_STR); $stmt->execute(); } } diff --git a/src/CentreonRemote/Application/Clapi/CentreonRemoteServer.php b/src/CentreonRemote/Application/Clapi/CentreonRemoteServer.php index b9926093250..3e4528a88ff 100644 --- a/src/CentreonRemote/Application/Clapi/CentreonRemoteServer.php +++ b/src/CentreonRemote/Application/Clapi/CentreonRemoteServer.php @@ -39,18 +39,12 @@ public static function getName() : string public function enableRemote(string $string_ip) { $ipList = explode(',', $string_ip); - foreach ($ipList as $ip) { - if (!filter_var($ip, FILTER_VALIDATE_IP)) { - printf("Incorrect IP parameter: '%s', please pass `-v IP` of the master server\n", $ip); - return null; - } - } echo "Starting Centreon Remote enable process: \n"; echo "Limiting Menu Access..."; $result = $this->getDi()['centreon.db-manager']->getRepository(TopologyRepository::class)->disableMenus(); - echo ($result) ? 'Success' : 'Fail' . "\n"; + echo ($result) ? 'Success' . "\n" : 'Fail' . "\n"; echo "Limiting Actions..."; $this->getDi()['centreon.db-manager']->getRepository(InformationsRepository::class)->toggleRemote('yes'); @@ -67,7 +61,6 @@ public function enableRemote(string $string_ip) echo "Done\n"; echo "Notifying Master..."; - $result = $this->getDi()['centreon.notifymaster']->pingMaster($ip); $result = ""; foreach ($ipList as $ip) { $result = $this->getDi()['centreon.notifymaster']->pingMaster($ip); diff --git a/src/CentreonRemote/Application/Validator/WizardConfigurationRequestValidator.php b/src/CentreonRemote/Application/Validator/WizardConfigurationRequestValidator.php index b08083b1b95..389826967ce 100644 --- a/src/CentreonRemote/Application/Validator/WizardConfigurationRequestValidator.php +++ b/src/CentreonRemote/Application/Validator/WizardConfigurationRequestValidator.php @@ -58,23 +58,11 @@ private function validateServerGeneralFields(): void ); } - if (!filter_var($_POST['server_ip'], FILTER_VALIDATE_IP)) { - throw new \RestBadRequestException( - sprintf(_('%s is not valid.'), 'server_ip') - ); - } - if (!isset($_POST['centreon_central_ip']) || !$_POST['centreon_central_ip']) { throw new \RestBadRequestException( sprintf(_($missingParameterMessage), 'centreon_central_ip') ); } - - if (!filter_var($_POST['centreon_central_ip'], FILTER_VALIDATE_IP)) { - throw new \RestBadRequestException( - sprintf(_('%s is not valid.'), 'centreon_central_ip') - ); - } } /** diff --git a/src/CentreonRemote/Application/Webservice/CentreonRemoteServer.php b/src/CentreonRemote/Application/Webservice/CentreonRemoteServer.php index 071b6e0924c..b5e145929c6 100644 --- a/src/CentreonRemote/Application/Webservice/CentreonRemoteServer.php +++ b/src/CentreonRemote/Application/Webservice/CentreonRemoteServer.php @@ -65,11 +65,7 @@ public function postAddToWaitList(): string $ip = $_SERVER['REMOTE_ADDR'] ?? null; if (!$ip) { - throw new \RestBadRequestException('Can not access your IP address.'); - } - - if (!filter_var($ip, FILTER_VALIDATE_IP)) { - throw new \RestBadRequestException('IP is not valid.'); + throw new \RestBadRequestException('Can not access your address.'); } if (!isset($_POST['app_key']) || !$_POST['app_key']) { @@ -85,7 +81,7 @@ public function postAddToWaitList(): string $result = $statement->fetch(); if ((bool) $result['count']) { - throw new \RestConflictException('IP already in wait list.'); + throw new \RestConflictException('Address already in wait list.'); } $createdAt = date('Y-m-d H:i:s'); diff --git a/src/CentreonRemote/Domain/Service/NotifyMasterService.php b/src/CentreonRemote/Domain/Service/NotifyMasterService.php index c286ed9bfa1..9681ecec0b1 100644 --- a/src/CentreonRemote/Domain/Service/NotifyMasterService.php +++ b/src/CentreonRemote/Domain/Service/NotifyMasterService.php @@ -16,7 +16,6 @@ class NotifyMasterService const CANT_CONNECT = 'Could not connect'; const TIMEOUT = 'Timeout'; const UNKNOWN_ERROR = 'Unknown Error'; - const WRONG_IP = 'Wrong IP'; const NO_APP_KEY = 'No Application Key found'; /** @@ -36,13 +35,21 @@ class NotifyMasterService private $curl; /** - * @return Curl + * @return void */ public function setCurl(Curl $curl): void { $this->curl = $curl; } + /** + * @return Curl + */ + public function getCurl(): Curl + { + return $this->curl; + } + /** * NotifyMasterService constructor. * @@ -61,12 +68,6 @@ public function __construct(CentreonDBManagerService $dbManager) */ public function pingMaster($ip) { - if (!filter_var($ip, FILTER_VALIDATE_IP)) { - return [ - 'status' => self::FAIL, - 'details' => self::WRONG_IP - ]; - } $url = "{$ip}/centreon/api/external.php?object=centreon_remote_server&action=addToWaitList"; $repository = $this->dbManager->getRepository(InformationsRepository::class); @@ -85,10 +86,11 @@ public function pingMaster($ip) 'app_key' => $applicationKey->getValue(), 'version' => $version->getValue(), ]; - $this->curl->post($url, $curlData); - if ($curl->error) { - switch ($curl->error_code) { + $this->getCurl()->post($url, $curlData); + + if ($this->getCurl()->error) { + switch ($this->getCurl()->error_code) { case 6: $details = self::CANT_RESOLVE_HOST; break; diff --git a/www/front_src/src/helpers/validators.js b/www/front_src/src/helpers/validators.js index a5592378745..0b97d17287b 100755 --- a/www/front_src/src/helpers/validators.js +++ b/www/front_src/src/helpers/validators.js @@ -8,14 +8,12 @@ export const serverNameValidator = serverName => export const serverIpAddressValidator = serverIpAddress => { let message = ""; message = !serverIpAddress || serverIpAddress.length < 1 ? "The field is required" : ""; - message = (message === "" ? validateIPaddress(serverIpAddress) : message) ; return message; } export const centralIpAddressValidator = centralIpAddress => { let message = ""; message = !centralIpAddress || centralIpAddress.length < 1 ? "The field is required" : ""; - message = (message === "" ? validateIPaddress(centralIpAddress) : message) ; return message; }