42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace com\fwdekker\deathnotifier\validator;
|
|
|
|
use com\fwdekker\deathnotifier\Config;
|
|
|
|
|
|
/**
|
|
* Validates that the input equals the CLI secret.
|
|
*/
|
|
class EqualsCliSecretRule extends Rule
|
|
{
|
|
/**
|
|
* The default value of the CLI secret.
|
|
*/
|
|
private const CLI_SECRET_DEFAULT = "REPLACE THIS WITH A SECRET VALUE";
|
|
|
|
|
|
/**
|
|
* Validates that the input equals the CLI secret.
|
|
*
|
|
* @param array<int|string, mixed> $inputs the list of inputs in which the value at {@see $key} should be checked
|
|
* @param string $key the key in {@see $inputs} of the input to check
|
|
* @return void if the checked input equals the CLI secret
|
|
* @throws InvalidInputException if the checked input is not set, the CLI secret is a blank string, the CLI secret
|
|
* is at its default value, or if the checked input does not equal the CLI secret
|
|
*/
|
|
public function check(array $inputs, string $key): void
|
|
{
|
|
$cli_password = Config::get()["admin"]["cli_secret"];
|
|
|
|
if (trim($cli_password) === "" || $cli_password === self::CLI_SECRET_DEFAULT)
|
|
throw new InvalidInputException(
|
|
$this->override_message ?? "The CLI is disabled because the CLI secret is not set.",
|
|
$key
|
|
);
|
|
|
|
if (!isset($inputs[$key]) || !password_verify($inputs[$key], Config::get()["admin"]["cli_secret"]))
|
|
throw new InvalidInputException($this->override_message ?? "Incorrect password.", $key);
|
|
}
|
|
}
|