Compare commits

...

5 Commits

Author SHA1 Message Date
tracer 010914b7bd added test support 2022-10-06 16:18:25 +02:00
tracer c166b5774c modified constructor 2022-09-29 19:26:12 +02:00
tracer 9dca565296 renamed ApiToken to apikey 2022-09-29 19:25:18 +02:00
tracer bc1b9c1204 renamed some inline variables 2022-09-29 19:24:22 +02:00
tracer 402934f02c added encryption to the first functions 2022-09-29 19:23:47 +02:00
5 changed files with 704 additions and 680 deletions

View File

@ -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; echo COLOR_YELLOW . str_pad(string: $this->name, length: $longestCommandLength + 1) . COLOR_WHITE . $this->description . COLOR_DEFAULT . PHP_EOL;
foreach ($this->commands as $command) { foreach ($this->commands as $command) {
echo COLOR_GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName(); echo COLOR_GREEN . str_pad(string: ' ', length: $longestCommandLength + 1, pad_type: STR_PAD_LEFT) . $this->name . ':' . $command->getName();
foreach ($command->getMandatoryParameters() as $parameter) { foreach ($command->getMandatoryParameters() as $optionals) {
echo ' <' . $parameter . '>'; echo ' <' . $optionals . '>';
} }
foreach ($command->getOptionalParameters() as $parameter) { foreach ($command->getOptionalParameters() as $mandatory) {
echo ' {' . $parameter . '}'; echo ' {' . $mandatory . '}';
} }
echo COLOR_WHITE . ' ' . $command->getDescription(); echo COLOR_WHITE . ' ' . $command->getDescription();
echo COLOR_DEFAULT . PHP_EOL; echo COLOR_DEFAULT . PHP_EOL;

View File

@ -7,49 +7,58 @@ namespace App\Controller;
*/ */
class ConfigController class ConfigController
{ {
private array $config; private array $config;
public function __construct(bool $verbose = false, bool $quiet = false) { /**
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local"; * @param bool $verbose
if (!file_exists(filename: $configFile)) { * @param bool $quiet
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json"; * @param bool $test
} */
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false)
{
if (!file_exists(filename: $configFile)) { if ($test) {
echo 'Missing config file' . PHP_EOL; $configFile = dirname(path: __DIR__, levels: 2) . "/config.json.test";
if (confirm(message: 'Should I create a new config based on config.json.sample?')) { if (!file_exists(filename: $configFile)) {
copy(from: 'config.json.sample', to: 'config.json'); echo 'No testing (config.json.test) config has benn setup.' . PHP_EOL;
echo 'Config file has been generated. Adjust it to your needs, then proceed to database setup.' . PHP_EOL; die(1);
} else { }
echo 'You first have to setup the bindAPI. Bye.' . PHP_EOL;
exit(0);
}
exit(1);
}
$configJSON = file_get_contents(filename: $configFile);
if (json_decode(json: $configJSON) === null) {
echo 'Config file is not valid JSON.' . PHP_EOL;
echo $configJSON . PHP_EOL;
exit(1);
}
$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 { } else {
$this->config['quiet'] = false; $configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
} if (!file_exists(filename: $configFile)) {
} $configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
}
public function getConfig(string $configKey): string { if (!file_exists(filename: $configFile)) {
return $this->config[$configKey]; echo 'Missing config file' . PHP_EOL;
} if (confirm(message: 'Should I create a new config based on config.json.sample?')) {
copy(from: 'config.json.sample', to: 'config.json');
echo 'Config file has been generated. Adjust it to your needs, then proceed to database setup.' . PHP_EOL;
} else {
echo 'You first have to setup the bindAPI. Bye.' . PHP_EOL;
exit(0);
}
exit(1);
}
}
$configJSON = file_get_contents(filename: $configFile);
if (json_decode(json: $configJSON) === null) {
echo 'Config file is not valid JSON.' . PHP_EOL;
echo $configJSON . PHP_EOL;
exit(1);
}
$this->config = json_decode(json: $configJSON, associative: true);
$this->config['verbose'] = (bool)$verbose;
$this->config['quiet'] = (bool)$quiet;
$this->config['test'] = (bool)$test;
}
public function getConfig(string $configKey): string
{
return $this->config[$configKey];
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -16,8 +16,8 @@ class Apikey
public function __construct( public function __construct(
private int $id = 0, private int $id = 0,
private string $name = '', private string $name = '',
private string $apiTokenPrefix = '', private string $apikey = '',
private string $apiToken = '', private string $apikeyPrefix = '',
private readonly string $passphrase = '' private readonly string $passphrase = ''
) )
{ {
@ -27,31 +27,39 @@ class Apikey
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey'); $encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
$this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.'); $this->apikey = strtok(string: $this->passphrase, token: '.');
try { try {
$this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey); $this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
} catch (Exception|SodiumException $e) { } catch (Exception|SodiumException $e) {
die($e->getMessage() . PHP_EOL); die($e->getMessage() . PHP_EOL);
} }
} }
} }
/**
* @return string
*/
public function getPassphrase(): string
{
return $this->passphrase;
}
/** /**
* @return String * @return String
*/ */
public function getApiToken(): string public function getApikey(): string
{ {
return $this->apiToken; return $this->apikey;
} }
/** /**
* @return string * @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 * @param String $apiToken
*/ */
public function setApiToken(string $apiToken): void public function setApikey(string $apikey): void
{ {
$this->apiToken = $apiToken; $this->apikey = $apikey;
} }

View File

@ -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)
{ {
} }