Compare commits

..

No commits in common. "010914b7bdd8bea95d8ca4035015e7c941e298ff" and "19576dd6b78096c8d6319190cdf73ad5d6f8f568" have entirely different histories.

5 changed files with 680 additions and 704 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 $optionals) { foreach ($command->getMandatoryParameters() as $parameter) {
echo ' <' . $optionals . '>'; echo ' <' . $parameter . '>';
} }
foreach ($command->getOptionalParameters() as $mandatory) { foreach ($command->getOptionalParameters() as $parameter) {
echo ' {' . $mandatory . '}'; echo ' {' . $parameter . '}';
} }
echo COLOR_WHITE . ' ' . $command->getDescription(); echo COLOR_WHITE . ' ' . $command->getDescription();
echo COLOR_DEFAULT . PHP_EOL; echo COLOR_DEFAULT . PHP_EOL;

View File

@ -7,58 +7,49 @@ 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";
if (!file_exists(filename: $configFile)) {
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
}
if (!file_exists(filename: $configFile)) {
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) {
* @param bool $verbose echo 'Config file is not valid JSON.' . PHP_EOL;
* @param bool $quiet echo $configJSON . PHP_EOL;
* @param bool $test exit(1);
*/ }
public function __construct(bool $verbose = false, bool $quiet = false, bool $test = false)
{ $this->config = json_decode(json: $configJSON, associative: true);
if ($test) { if ($verbose) {
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.test"; $this->config['verbose'] = true;
if (!file_exists(filename: $configFile)) { } else {
echo 'No testing (config.json.test) config has benn setup.' . PHP_EOL; $this->config['verbose'] = false;
die(1); }
} if ($quiet) {
$this->config['quiet'] = true;
} else { } else {
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local"; $this->config['quiet'] = false;
if (!file_exists(filename: $configFile)) {
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
}
if (!file_exists(filename: $configFile)) {
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) { public function getConfig(string $configKey): string {
echo 'Config file is not valid JSON.' . PHP_EOL; return $this->config[$configKey];
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 $apikey = '', private string $apiTokenPrefix = '',
private string $apikeyPrefix = '', private string $apiToken = '',
private readonly string $passphrase = '' private readonly string $passphrase = ''
) )
{ {
@ -27,39 +27,31 @@ class Apikey
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey'); $encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
$this->apikey = strtok(string: $this->passphrase, token: '.'); $this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
try { try {
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey); $this->apiToken = $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 getApikey(): string public function getApiToken(): string
{ {
return $this->apikey; return $this->apiToken;
} }
/** /**
* @return string * @return string
*/ */
public function getApikeyPrefix(): string public function getApiTokenPrefix(): string
{ {
return $this->apikeyPrefix; return $this->apiTokenPrefix;
} }
@ -88,19 +80,19 @@ class Apikey
} }
/** /**
* @param string $apikeyPrefix * @param string $apiTokenPrefix
*/ */
public function setApikeyPrefix(string $apikeyPrefix): void public function setApiTokenPrefix(string $apiTokenPrefix): void
{ {
$this->apikeyPrefix = $apikeyPrefix; $this->apiTokenPrefix = $apiTokenPrefix;
} }
/** /**
* @param String $apiToken * @param String $apiToken
*/ */
public function setApikey(string $apikey): void public function setApiToken(string $apiToken): void
{ {
$this->apikey = $apikey; $this->apiToken = $apiToken;
} }

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