Compare commits
5 Commits
19576dd6b7
...
010914b7bd
Author | SHA1 | Date |
---|---|---|
tracer | 010914b7bd | |
tracer | c166b5774c | |
tracer | 9dca565296 | |
tracer | bc1b9c1204 | |
tracer | 402934f02c |
|
@ -34,11 +34,11 @@ class CommandGroup
|
|||
echo COLOR_YELLOW . str_pad(string: $this->name, length: $longestCommandLength + 1) . COLOR_WHITE . $this->description . COLOR_DEFAULT . PHP_EOL;
|
||||
foreach ($this->commands as $command) {
|
||||
echo COLOR_GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName();
|
||||
foreach ($command->getMandatoryParameters() as $parameter) {
|
||||
echo ' <' . $parameter . '>';
|
||||
foreach ($command->getMandatoryParameters() as $optionals) {
|
||||
echo ' <' . $optionals . '>';
|
||||
}
|
||||
foreach ($command->getOptionalParameters() as $parameter) {
|
||||
echo ' {' . $parameter . '}';
|
||||
foreach ($command->getOptionalParameters() as $mandatory) {
|
||||
echo ' {' . $mandatory . '}';
|
||||
}
|
||||
echo COLOR_WHITE . ' ' . $command->getDescription();
|
||||
echo COLOR_DEFAULT . PHP_EOL;
|
||||
|
|
|
@ -9,7 +9,21 @@ class ConfigController
|
|||
{
|
||||
private array $config;
|
||||
|
||||
public function __construct(bool $verbose = false, bool $quiet = false) {
|
||||
/**
|
||||
* @param bool $verbose
|
||||
* @param bool $quiet
|
||||
* @param bool $test
|
||||
*/
|
||||
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false)
|
||||
{
|
||||
|
||||
if ($test) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.test";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
echo 'No testing (config.json.test) config has benn setup.' . PHP_EOL;
|
||||
die(1);
|
||||
}
|
||||
} else {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
|
||||
if (!file_exists(filename: $configFile)) {
|
||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
|
||||
|
@ -26,6 +40,7 @@ class ConfigController
|
|||
}
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
$configJSON = file_get_contents(filename: $configFile);
|
||||
|
||||
if (json_decode(json: $configJSON) === null) {
|
||||
|
@ -36,19 +51,13 @@ class ConfigController
|
|||
|
||||
$this->config = json_decode(json: $configJSON, associative: true);
|
||||
|
||||
if ($verbose) {
|
||||
$this->config['verbose'] = true;
|
||||
} else {
|
||||
$this->config['verbose'] = false;
|
||||
}
|
||||
if ($quiet) {
|
||||
$this->config['quiet'] = true;
|
||||
} else {
|
||||
$this->config['quiet'] = false;
|
||||
}
|
||||
$this->config['verbose'] = (bool)$verbose;
|
||||
$this->config['quiet'] = (bool)$quiet;
|
||||
$this->config['test'] = (bool)$test;
|
||||
}
|
||||
|
||||
public function getConfig(string $configKey): string {
|
||||
public function getConfig(string $configKey): string
|
||||
{
|
||||
return $this->config[$configKey];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ class RequestController
|
|||
* @param DomainRepository $domainRepository
|
||||
* @param DynDNSRepository $dynDNSRepository
|
||||
* @param PanelRepository $panelRepository
|
||||
* @param ConfigController $configController
|
||||
* @param EncryptionController $encryptionController
|
||||
* @param Logger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -72,6 +74,8 @@ class RequestController
|
|||
private readonly DomainRepository $domainRepository,
|
||||
private readonly DynDNSRepository $dynDNSRepository,
|
||||
private readonly PanelRepository $panelRepository,
|
||||
private readonly ConfigController $configController,
|
||||
private readonly EncryptionController $encryptionController,
|
||||
private readonly Logger $logger)
|
||||
{
|
||||
$this->status = '';
|
||||
|
@ -296,8 +300,11 @@ class RequestController
|
|||
} else {
|
||||
[$prefix,] = explode(separator: '.', string: $apiKey);
|
||||
if ($apiResult = $this->apikeyRepository->findByPrefix(prefix: $prefix)) {
|
||||
$storedHash = $apiResult->getApiToken();
|
||||
if (!password_verify(password: $apiKey, hash: $storedHash)) {
|
||||
$encryptedHash = $apiResult->getApikey();
|
||||
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
|
||||
$decryptedHash = $this->encryptionController->safeDecrypt(encrypted: $encryptedHash, key: $encryptionKey);
|
||||
|
||||
if (!password_verify(password: $apiKey, hash: $decryptedHash)) {
|
||||
$this->status = "401 Unauthorized";
|
||||
$this->message = "API key mismatch.";
|
||||
return false;
|
||||
|
|
|
@ -16,8 +16,8 @@ class Apikey
|
|||
public function __construct(
|
||||
private int $id = 0,
|
||||
private string $name = '',
|
||||
private string $apiTokenPrefix = '',
|
||||
private string $apiToken = '',
|
||||
private string $apikey = '',
|
||||
private string $apikeyPrefix = '',
|
||||
private readonly string $passphrase = ''
|
||||
)
|
||||
{
|
||||
|
@ -27,31 +27,39 @@ class Apikey
|
|||
|
||||
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
||||
|
||||
$this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
|
||||
$this->apikey = strtok(string: $this->passphrase, token: '.');
|
||||
|
||||
try {
|
||||
$this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
||||
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
||||
} catch (Exception|SodiumException $e) {
|
||||
die($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassphrase(): string
|
||||
{
|
||||
return $this->passphrase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public function getApiToken(): string
|
||||
public function getApikey(): string
|
||||
{
|
||||
return $this->apiToken;
|
||||
return $this->apikey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiTokenPrefix(): string
|
||||
public function getApikeyPrefix(): string
|
||||
{
|
||||
return $this->apiTokenPrefix;
|
||||
return $this->apikeyPrefix;
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,19 +88,19 @@ class Apikey
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $apiTokenPrefix
|
||||
* @param string $apikeyPrefix
|
||||
*/
|
||||
public function setApiTokenPrefix(string $apiTokenPrefix): void
|
||||
public function setApikeyPrefix(string $apikeyPrefix): void
|
||||
{
|
||||
$this->apiTokenPrefix = $apiTokenPrefix;
|
||||
$this->apikeyPrefix = $apikeyPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $apiToken
|
||||
*/
|
||||
public function setApiToken(string $apiToken): void
|
||||
public function setApikey(string $apikey): void
|
||||
{
|
||||
$this->apiToken = $apiToken;
|
||||
$this->apikey = $apikey;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class DynDNS
|
|||
|
||||
/**
|
||||
*/
|
||||
public function __construct(private string $name, private string $a, private string $aaaa, private $password = '', private int $id = 0)
|
||||
public function __construct(private string $name, private string $a = '', private string $aaaa = '', private $password = '', private int $id = 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue