Compare commits
No commits in common. "b536316a84755b624fcd144f6075586491bd3a2d" and "d5bdb1bade0cf52b2b4e0e4571eb203fef810d30" have entirely different histories.
b536316a84
...
d5bdb1bade
|
@ -26,13 +26,11 @@ require dirname(path: __DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
|
||||||
$shortOpts = 'v::'; // version
|
$shortOpts = 'v::'; // version
|
||||||
$shortOpts = 'q::'; // version
|
|
||||||
$shortOpts .= "V::"; // verbose
|
$shortOpts .= "V::"; // verbose
|
||||||
$shortOpts .= "h::"; // help
|
$shortOpts .= "h::"; // help
|
||||||
|
|
||||||
$longOpts = [
|
$longOpts = [
|
||||||
'version::',
|
'version::',
|
||||||
'quiet::',
|
|
||||||
'verbose::',
|
'verbose::',
|
||||||
'help::'
|
'help::'
|
||||||
];
|
];
|
||||||
|
@ -49,13 +47,6 @@ if (array_key_exists(key: 'h', array: $options) || array_key_exists(key: 'help',
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists(key: 'q', array: $options) || array_key_exists(key: 'quiet', array: $options)) {
|
|
||||||
$quiet = true;
|
|
||||||
} else {
|
|
||||||
$quiet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
|
if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbose', array: $options)) {
|
||||||
$verbose = true;
|
$verbose = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,8 +56,8 @@ if (array_key_exists(key: 'V', array: $options) || array_key_exists(key: 'verbos
|
||||||
$arguments = array_slice(array: $argv, offset: $restIndex);
|
$arguments = array_slice(array: $argv, offset: $restIndex);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$app = new BindAPI(verbose: $verbose, quiet: $quiet);
|
$app = new BindAPI(verbose: $verbose );
|
||||||
$app->runCommand(arguments: $arguments);
|
$app->runCommand(argumentsCount: count(value: $arguments), arguments: $arguments);
|
||||||
|
|
||||||
} catch (DependencyException|NotFoundException|Exception $e) {
|
} catch (DependencyException|NotFoundException|Exception $e) {
|
||||||
echo $e->getMessage() . PHP_EOL;
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
|
|
@ -8,12 +8,8 @@ use App\Repository\DomainRepository;
|
||||||
use App\Repository\DynDNSRepository;
|
use App\Repository\DynDNSRepository;
|
||||||
use DI\Container;
|
use DI\Container;
|
||||||
use DI\ContainerBuilder;
|
use DI\ContainerBuilder;
|
||||||
use DI\DependencyException;
|
|
||||||
use DI\NotFoundException;
|
|
||||||
use Exception;
|
|
||||||
use Monolog\Formatter\LineFormatter;
|
use Monolog\Formatter\LineFormatter;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Level;
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use function DI\autowire;
|
use function DI\autowire;
|
||||||
|
|
||||||
|
@ -25,10 +21,11 @@ class BindAPI
|
||||||
private Logger $logger;
|
private Logger $logger;
|
||||||
private Container $container;
|
private Container $container;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($verbose = false, $quiet = false)
|
public function __construct($verbose = false)
|
||||||
{
|
{
|
||||||
// init the logger
|
// init the logger
|
||||||
$dateFormat = "Y:m:d H:i:s";
|
$dateFormat = "Y:m:d H:i:s";
|
||||||
|
@ -37,9 +34,9 @@ class BindAPI
|
||||||
|
|
||||||
$debug = (new ConfigController)->getConfig(configKey: 'debug');
|
$debug = (new ConfigController)->getConfig(configKey: 'debug');
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 2) . '/bindAPI.log', level: Level::Debug);
|
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 2) . '/bindAPI.log', level: Logger::DEBUG);
|
||||||
} else {
|
} else {
|
||||||
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 2) . '/bindAPI.log', level: Level::Info);
|
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 2) . '/bindAPI.log', level: Logger::INFO);
|
||||||
}
|
}
|
||||||
$stream->setFormatter(formatter: $formatter);
|
$stream->setFormatter(formatter: $formatter);
|
||||||
|
|
||||||
|
@ -51,7 +48,6 @@ class BindAPI
|
||||||
$containerBuilder = new ContainerBuilder();
|
$containerBuilder = new ContainerBuilder();
|
||||||
$containerBuilder->addDefinitions([
|
$containerBuilder->addDefinitions([
|
||||||
ConfigController::class => autowire()
|
ConfigController::class => autowire()
|
||||||
->constructorParameter(parameter: 'quiet', value: $quiet)
|
|
||||||
->constructorParameter(parameter: 'verbose', value: $verbose),
|
->constructorParameter(parameter: 'verbose', value: $verbose),
|
||||||
CLIController::class => autowire()
|
CLIController::class => autowire()
|
||||||
->constructorParameter(parameter: 'logger', value: $this->logger),
|
->constructorParameter(parameter: 'logger', value: $this->logger),
|
||||||
|
@ -69,8 +65,8 @@ class BindAPI
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws DependencyException
|
* @throws \DI\DependencyException
|
||||||
* @throws NotFoundException
|
* @throws \DI\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function runCommand(array $arguments): void
|
public function runCommand(array $arguments): void
|
||||||
{
|
{
|
||||||
|
@ -81,8 +77,8 @@ class BindAPI
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws DependencyException
|
* @throws \DI\DependencyException
|
||||||
* @throws NotFoundException
|
* @throws \DI\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function handleRequest(string $requestMethod, array $uri): void
|
public function handleRequest(string $requestMethod, array $uri): void
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,68 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Commands;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Command
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly string $name,
|
|
||||||
private readonly Closure $callback,
|
|
||||||
private readonly array $mandatoryParameters = [],
|
|
||||||
private readonly array $optionalParameters = [],
|
|
||||||
private readonly string $description = ''
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// no body
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName(): string
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getMandatoryParameters(): array
|
|
||||||
{
|
|
||||||
return $this->mandatoryParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getOptionalParameters(): array
|
|
||||||
{
|
|
||||||
return $this->optionalParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getDescription(): ?string
|
|
||||||
{
|
|
||||||
return $this->description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Closure
|
|
||||||
*/
|
|
||||||
public function getCallback(): Closure
|
|
||||||
{
|
|
||||||
return $this->callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function exec(): void
|
|
||||||
{
|
|
||||||
call_user_func(callback: $this->callback);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Commands;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class CommandGroup
|
|
||||||
{
|
|
||||||
private array $commands = [];
|
|
||||||
|
|
||||||
public function __construct(private readonly string $name, private readonly string $description)
|
|
||||||
{
|
|
||||||
// no body
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function addCommand(Command $command): ?CommandGroup
|
|
||||||
{
|
|
||||||
$this->commands[] = $command;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getName(): string
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function printCommands(int $longestCommandLength): void
|
|
||||||
{
|
|
||||||
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->getOptionalParameters() as $parameter) {
|
|
||||||
echo ' {' . $parameter . '}';
|
|
||||||
}
|
|
||||||
echo COLOR_WHITE . ' ' . $command->getDescription();
|
|
||||||
echo COLOR_DEFAULT . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findCommandByName(string $command): ?Command
|
|
||||||
{
|
|
||||||
foreach ($this->commands as $currentCommand) {
|
|
||||||
if ($command === $currentCommand->getName()) {
|
|
||||||
return $currentCommand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function exec(string $subcommand): void
|
|
||||||
{
|
|
||||||
if ($command = $this->findCommandByName(command: $subcommand)) {
|
|
||||||
$command->exec();
|
|
||||||
} else {
|
|
||||||
echo COLOR_DEFAULT . 'Command ' . COLOR_YELLOW . $this->name . ':' . $subcommand . COLOR_DEFAULT . ' not found.' . PHP_EOL;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Commands;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class CommandGroupContainer
|
|
||||||
{
|
|
||||||
private array $commandGroups = [];
|
|
||||||
|
|
||||||
public function addCommandGroup(CommandGroup $commandGroup): CommandGroupContainer
|
|
||||||
{
|
|
||||||
$this->commandGroups[] = $commandGroup;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function printCommands(): void
|
|
||||||
{
|
|
||||||
$longestCommandLength = $this->getLongestCommandLength();
|
|
||||||
foreach ($this->commandGroups as $commandGroup) {
|
|
||||||
$commandGroup->printCommands($longestCommandLength);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getLongestCommandLength(): int
|
|
||||||
{
|
|
||||||
$longest = 0;
|
|
||||||
|
|
||||||
foreach ($this->commandGroups as $group) {
|
|
||||||
$len = strlen(string: $group->getName());
|
|
||||||
if ($len > $longest) {
|
|
||||||
$longest = $len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $longest;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $command
|
|
||||||
* @return ?CommandGroup
|
|
||||||
*/
|
|
||||||
private function findGroupByName(string $command): ?CommandGroup
|
|
||||||
{
|
|
||||||
foreach ($this->commandGroups as $group) {
|
|
||||||
if ($group->getName() === $command) {
|
|
||||||
return $group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function run(string $command, string $subcommand): void
|
|
||||||
{
|
|
||||||
if ($group = $this->findGroupByName(command: $command)) {
|
|
||||||
$group->exec(subcommand: $subcommand);
|
|
||||||
} else {
|
|
||||||
echo COLOR_DEFAULT . 'Unknown command ' . COLOR_YELLOW . $command . COLOR_DEFAULT . '.' . PHP_EOL;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,7 @@ class ConfigController
|
||||||
{
|
{
|
||||||
private array $config;
|
private array $config;
|
||||||
|
|
||||||
public function __construct(bool $verbose = false, bool $quiet = false) {
|
public function __construct(bool $verbose = false) {
|
||||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
|
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json.local";
|
||||||
if (!file_exists(filename: $configFile)) {
|
if (!file_exists(filename: $configFile)) {
|
||||||
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
|
$configFile = dirname(path: __DIR__, levels: 2) . "/config.json";
|
||||||
|
@ -41,11 +41,6 @@ class ConfigController
|
||||||
} else {
|
} else {
|
||||||
$this->config['verbose'] = false;
|
$this->config['verbose'] = false;
|
||||||
}
|
}
|
||||||
if ($quiet) {
|
|
||||||
$this->config['quiet'] = true;
|
|
||||||
} else {
|
|
||||||
$this->config['quiet'] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfig(string $configKey): string {
|
public function getConfig(string $configKey): string {
|
||||||
|
|
|
@ -98,30 +98,16 @@ class DomainController
|
||||||
'name' => $domain->getName()
|
'name' => $domain->getName()
|
||||||
];
|
];
|
||||||
if (!empty($nameserver->getAaaa())) {
|
if (!empty($nameserver->getAaaa())) {
|
||||||
$this->checkController->sendCommand(
|
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 6, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body);
|
||||||
requestType: 'DELETE',
|
|
||||||
serverName: $nameserver->getName(),
|
|
||||||
versionIP: 6,
|
|
||||||
apiKey: $nameserver->getApikey(),
|
|
||||||
command: 'delete',
|
|
||||||
serverType: 'nameserver',
|
|
||||||
body: $body);
|
|
||||||
} else {
|
} else {
|
||||||
$this->checkController->sendCommand(
|
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 4, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body);
|
||||||
requestType: 'DELETE',
|
|
||||||
serverName: $nameserver->getName(),
|
|
||||||
versionIP: 4,
|
|
||||||
apiKey: $nameserver->getApikey(),
|
|
||||||
command: 'delete',
|
|
||||||
serverType: 'nameserver',
|
|
||||||
body: $body);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Domain $domain
|
* @param \App\Entity\Domain $domain
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -244,34 +230,25 @@ class DomainController
|
||||||
$domains = $this->domainRepository->findAll();
|
$domains = $this->domainRepository->findAll();
|
||||||
|
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$idString = '(' . strval(value: $domain->getId()) . ') ';
|
echo COLOR_YELLOW . str_pad(string: $domain->getName(), length: $maxNameLength + 1) . COLOR_DEFAULT;
|
||||||
echo COLOR_YELLOW .
|
|
||||||
str_pad(string: $domain->getName(), length: $maxNameLength + 1)
|
|
||||||
. COLOR_DEFAULT
|
|
||||||
. str_pad(string: $idString, length: 7, pad_type: STR_PAD_LEFT);
|
|
||||||
|
|
||||||
$hasError = false;
|
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
echo 'Master Zone lies on this panel.';
|
echo 'Master Zone lies on this panel.';
|
||||||
} else {
|
} else {
|
||||||
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
if (!str_contains(haystack: $localZones, needle: $domain->getName())) {
|
||||||
echo COLOR_RED . 'is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
echo COLOR_RED . ' is missing in ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT;
|
||||||
$hasError = true;
|
|
||||||
} else {
|
} else {
|
||||||
echo COLOR_GREEN . 'OK';
|
echo $domain->getName() . ' exists in ' . COLOR_YELLOW . $this->localZoneFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||||
|
|
||||||
if (!file_exists(filename: $zoneFile)) {
|
if (!file_exists(filename: $zoneFile)) {
|
||||||
echo ' Missing zone file for ' . COLOR_YELLOW . $zoneFile . COLOR_DEFAULT;
|
echo "Missing zone file for $zoneFile . Update zone to create it";
|
||||||
$hasError = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hasError) {
|
|
||||||
echo " Update zone (Domain) to create it.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo COLOR_DEFAULT . PHP_EOL;
|
echo COLOR_DEFAULT . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +256,7 @@ class DomainController
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Domain $domain
|
* @param \App\Entity\Domain $domain
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -290,11 +267,11 @@ class DomainController
|
||||||
|
|
||||||
// check if we're a master zone
|
// check if we're a master zone
|
||||||
if ($this->isMasterZone(domain: $domain)) {
|
if ($this->isMasterZone(domain: $domain)) {
|
||||||
//echo 'We are zone master for ' . $domainName . PHP_EOL;
|
echo 'We are zone master for ' . $domainName . PHP_EOL;
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($zoneFile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
if ($zonefile = fopen(filename: $this->localZonesDir . $domainName, mode: 'w')) {
|
||||||
$panelName = $domain->getPanel();
|
$panelName = $domain->getPanel();
|
||||||
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
if (!$panel = $this->panelRepository->findByName(name: $panelName)) {
|
||||||
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
echo "Error: Panel $panelName doesn't exist." . PHP_EOL;
|
||||||
|
@ -302,18 +279,18 @@ class DomainController
|
||||||
}
|
}
|
||||||
$a = $panel->getA();
|
$a = $panel->getA();
|
||||||
$aaaa = $panel->getAaaa();
|
$aaaa = $panel->getAaaa();
|
||||||
fputs(stream: $zoneFile, data: 'zone "' . $domainName . '"' . ' IN {' . PHP_EOL);
|
fputs(stream: $zonefile, data: 'zone "' . $domainName . '"' . ' IN {' . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "\ttype slave;" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "\tfile \"" . $this->zoneCachePath . $domainName . '.db";' . PHP_EOL);
|
fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $domainName . '.db";' . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "\tmasters {" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL);
|
||||||
if (!empty($a)) {
|
if (!empty($a)) {
|
||||||
fputs(stream: $zoneFile, data: "\t\t" . $a . ';' . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t\t" . $a . ';' . PHP_EOL);
|
||||||
}
|
}
|
||||||
if (!empty($aaaa)) {
|
if (!empty($aaaa)) {
|
||||||
fputs(stream: $zoneFile, data: "\t\t" . $aaaa . ';' . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t\t" . $aaaa . ';' . PHP_EOL);
|
||||||
}
|
}
|
||||||
fputs(stream: $zoneFile, data: "\t};" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t};" . PHP_EOL);
|
||||||
fputs(stream: $zoneFile, data: "};" . PHP_EOL);
|
fputs(stream: $zonefile, data: "};" . PHP_EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,11 @@ class EncryptionController
|
||||||
*/
|
*/
|
||||||
function safeEncrypt(string $message, string $key): string
|
function safeEncrypt(string $message, string $key): string
|
||||||
{
|
{
|
||||||
$binKey = sodium_hex2bin(string: $key);
|
|
||||||
$nonce = random_bytes(length: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
$nonce = random_bytes(length: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||||
|
|
||||||
$cipher = base64_encode(string: $nonce . sodium_crypto_secretbox(message: $message, nonce: $nonce, key: $binKey));
|
$cipher = base64_encode(string: $nonce . sodium_crypto_secretbox(message: $message, nonce: $nonce, key: $key));
|
||||||
sodium_memzero(string: $message);
|
sodium_memzero(string: $message);
|
||||||
sodium_memzero(string: $key);
|
sodium_memzero(string: $key);
|
||||||
sodium_memzero(string: $binKey);
|
|
||||||
return $cipher;
|
return $cipher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,23 +39,19 @@ class EncryptionController
|
||||||
*/
|
*/
|
||||||
function safeDecrypt(string $encrypted, string $key): string
|
function safeDecrypt(string $encrypted, string $key): string
|
||||||
{
|
{
|
||||||
$binKey = sodium_hex2bin(string: $key);
|
|
||||||
|
|
||||||
$decoded = base64_decode(string: $encrypted);
|
$decoded = base64_decode(string: $encrypted);
|
||||||
if ($decoded === false) {
|
if ($decoded === false) {
|
||||||
throw new Exception(message: 'Decoding broken. Wrong payload.');
|
throw new Exception(message: 'Decoding broken. Wrong key?');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mb_strlen(string: $decoded, encoding: '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) {
|
if (mb_strlen(string: $decoded, encoding: '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) {
|
||||||
throw new Exception(message: 'Decoding broken. Incomplete message.');
|
throw new Exception(message: 'Decoding broken. Incomplete message.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$nonce = mb_substr(string: $decoded, start: 0, length: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, encoding: '8bit');
|
$nonce = mb_substr(string: $decoded, start: 0, length: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, encoding: '8bit');
|
||||||
$ciphertext = mb_substr(string: $decoded, start: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, length: null, encoding: '8bit');
|
$ciphertext = mb_substr(string: $decoded, start: SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, length: null, encoding: '8bit');
|
||||||
|
|
||||||
$plain = sodium_crypto_secretbox_open(ciphertext: $ciphertext, nonce: $nonce, key: $binKey);
|
$plain = sodium_crypto_secretbox_open(ciphertext: $ciphertext, nonce: $nonce, key: $key);
|
||||||
if ($plain === false) {
|
if ($plain === false) {
|
||||||
throw new Exception(message: ' Incorrect key.');
|
throw new Exception(message: 'The message was tampered with in transit');
|
||||||
}
|
}
|
||||||
sodium_memzero(string: $ciphertext);
|
sodium_memzero(string: $ciphertext);
|
||||||
sodium_memzero(string: $key);
|
sodium_memzero(string: $key);
|
||||||
|
|
|
@ -11,6 +11,7 @@ use App\Repository\DomainRepository;
|
||||||
use App\Repository\DynDNSRepository;
|
use App\Repository\DynDNSRepository;
|
||||||
use App\Repository\PanelRepository;
|
use App\Repository\PanelRepository;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use OpenApi\Annotations as OA;
|
||||||
use OpenApi\Attributes as OAT;
|
use OpenApi\Attributes as OAT;
|
||||||
use UnhandledMatchError;
|
use UnhandledMatchError;
|
||||||
|
|
||||||
|
@ -57,13 +58,13 @@ class RequestController
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ApiController $apiController
|
* @param \App\Controller\ApiController $apiController
|
||||||
* @param ApikeyRepository $apikeyRepository
|
* @param \App\Repository\ApikeyRepository $apikeyRepository
|
||||||
* @param DomainController $domainController
|
* @param \App\Controller\DomainController $domainController
|
||||||
* @param DomainRepository $domainRepository
|
* @param \App\Repository\DomainRepository $domainRepository
|
||||||
* @param DynDNSRepository $dynDNSRepository
|
* @param \App\Repository\DynDNSRepository $dynDNSRepository
|
||||||
* @param PanelRepository $panelRepository
|
* @param \App\Repository\PanelRepository $panelRepository
|
||||||
* @param Logger $logger
|
* @param \Monolog\Logger $logger
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ApiController $apiController,
|
private readonly ApiController $apiController,
|
||||||
|
|
|
@ -2,106 +2,89 @@
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Controller\ConfigController;
|
|
||||||
use App\Controller\EncryptionController;
|
|
||||||
use Exception;
|
|
||||||
use SodiumException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Apikey
|
class Apikey
|
||||||
{
|
{
|
||||||
|
private int $id;
|
||||||
|
private string $name;
|
||||||
|
private string $apiTokenPrefix;
|
||||||
|
private string $apiToken;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(string $name, string $apiTokenPrefix, string $apiToken, int $id = 0)
|
||||||
private int $id = 0,
|
{
|
||||||
private string $name = '',
|
$this->id = $id;
|
||||||
private string $apiTokenPrefix = '',
|
$this->name = $name;
|
||||||
private string $apiToken = '',
|
$this->apiTokenPrefix = $apiTokenPrefix;
|
||||||
private readonly string $passphrase = ''
|
$this->apiToken = $apiToken;
|
||||||
)
|
}
|
||||||
{
|
|
||||||
if ($this->passphrase) {
|
|
||||||
$configController = new ConfigController();
|
|
||||||
$encryptionController = new EncryptionController();
|
|
||||||
|
|
||||||
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
|
||||||
|
|
||||||
$this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
|
||||||
} catch (Exception|SodiumException $e) {
|
|
||||||
die($e->getMessage() . PHP_EOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function getApiToken(): string
|
public function getApiToken(): string
|
||||||
{
|
{
|
||||||
return $this->apiToken;
|
return $this->apiToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getApiTokenPrefix(): string
|
public function getApiTokenPrefix(): string
|
||||||
{
|
{
|
||||||
return $this->apiTokenPrefix;
|
return $this->apiTokenPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getId(): int
|
public function getId(): int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
*/
|
*/
|
||||||
public function setId(int $id): void
|
public function setId(int $id): void
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $apiTokenPrefix
|
* @param string $apiTokenPrefix
|
||||||
*/
|
*/
|
||||||
public function setApiTokenPrefix(string $apiTokenPrefix): void
|
public function setApiTokenPrefix(string $apiTokenPrefix): void
|
||||||
{
|
{
|
||||||
$this->apiTokenPrefix = $apiTokenPrefix;
|
$this->apiTokenPrefix = $apiTokenPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $apiToken
|
* @param String $apiToken
|
||||||
*/
|
*/
|
||||||
public function setApiToken(string $apiToken): void
|
public function setApiToken(string $apiToken): void
|
||||||
{
|
{
|
||||||
$this->apiToken = $apiToken;
|
$this->apiToken = $apiToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $name
|
* @param String $name
|
||||||
*/
|
*/
|
||||||
public function setName(string $name): void
|
public function setName(string $name): void
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,11 +2,7 @@
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Controller\ConfigController;
|
|
||||||
use App\Controller\EncryptionController;
|
|
||||||
use Exception;
|
|
||||||
use OpenApi\Attributes as OAT;
|
use OpenApi\Attributes as OAT;
|
||||||
use SodiumException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -15,60 +11,24 @@ use SodiumException;
|
||||||
|
|
||||||
class Nameserver
|
class Nameserver
|
||||||
{
|
{
|
||||||
/**
|
private int $id;
|
||||||
* @param string $name
|
private String $name;
|
||||||
* @param int $id
|
private String $a;
|
||||||
* @param string $a
|
private String $aaaa;
|
||||||
* @param string $aaaa
|
private String $apikey;
|
||||||
* @param string $passphrase
|
|
||||||
* @param string $apikey
|
public function __construct(String $name, int $id = 0, String $a = '', String $aaaa = '', String $apikey = '')
|
||||||
* @param string $apikeyPrefix
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private string $name,
|
|
||||||
private int $id = 0,
|
|
||||||
private string $a = '',
|
|
||||||
private string $aaaa = '',
|
|
||||||
private readonly string $passphrase = '',
|
|
||||||
private string $apikey = '',
|
|
||||||
private string $apikeyPrefix = '')
|
|
||||||
{
|
{
|
||||||
if ($this->passphrase) {
|
$this->id = $id;
|
||||||
$configController = new ConfigController();
|
$this->name = $name;
|
||||||
$encryptionController = new EncryptionController();
|
$this->a = $a;
|
||||||
|
$this->aaaa = $aaaa;
|
||||||
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
$this->apikey = $apikey;
|
||||||
|
}
|
||||||
[$this->apikeyPrefix] = explode(separator: '.', string: $this->passphrase);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
|
||||||
} catch (Exception|SodiumException $e) {
|
|
||||||
die($e->getMessage() . PHP_EOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getApikeyPrefix(): string
|
|
||||||
{
|
|
||||||
return $this->apikeyPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $apikeyPrefix
|
|
||||||
*/
|
|
||||||
public function setApikeyPrefix(string $apikeyPrefix): void
|
|
||||||
{
|
|
||||||
$this->apikeyPrefix = $apikeyPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return String
|
||||||
*/
|
*/
|
||||||
#[OAT\Property(type: 'string')]
|
#[OAT\Property(type: 'string')]
|
||||||
public function getA(): string
|
public function getA(): string
|
||||||
|
@ -77,7 +37,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $a
|
* @param String $a
|
||||||
*/
|
*/
|
||||||
public function setA(string $a): void
|
public function setA(string $a): void
|
||||||
{
|
{
|
||||||
|
@ -85,7 +45,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return String
|
||||||
*/
|
*/
|
||||||
#[OAT\Property(type: 'string')]
|
#[OAT\Property(type: 'string')]
|
||||||
public function getAaaa(): string
|
public function getAaaa(): string
|
||||||
|
@ -94,7 +54,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $aaaa
|
* @param String $aaaa
|
||||||
*/
|
*/
|
||||||
public function setAaaa(string $aaaa): void
|
public function setAaaa(string $aaaa): void
|
||||||
{
|
{
|
||||||
|
@ -102,7 +62,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return String
|
||||||
*/
|
*/
|
||||||
#[OAT\Property(type: 'string')]
|
#[OAT\Property(type: 'string')]
|
||||||
public function getApikey(): string
|
public function getApikey(): string
|
||||||
|
@ -111,7 +71,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $apikey
|
* @param String $apikey
|
||||||
*/
|
*/
|
||||||
public function setApikey(string $apikey): void
|
public function setApikey(string $apikey): void
|
||||||
{
|
{
|
||||||
|
@ -136,7 +96,7 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return String
|
||||||
*/
|
*/
|
||||||
#[OAT\Property(type: 'string')]
|
#[OAT\Property(type: 'string')]
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
|
@ -145,19 +105,11 @@ class Nameserver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param String $name
|
||||||
*/
|
*/
|
||||||
public function setName(string $name): void
|
public function setName(string $name): void
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPassphrase(): string
|
|
||||||
{
|
|
||||||
return $this->passphrase;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,160 +2,133 @@
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Controller\ConfigController;
|
|
||||||
use App\Controller\EncryptionController;
|
|
||||||
use Exception;
|
|
||||||
use SodiumException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Panel
|
class Panel
|
||||||
{
|
{
|
||||||
/**
|
private int $id;
|
||||||
* @param string $name
|
private String $name;
|
||||||
* @param int $id
|
private String $a;
|
||||||
* @param string $a
|
private String $aaaa;
|
||||||
* @param string $aaaa
|
private String $apikey;
|
||||||
* @param string $passphrase
|
private int $self;
|
||||||
* @param string $apikey
|
|
||||||
* @param string $apikeyPrefix
|
|
||||||
* @param string $self
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
private string $name,
|
|
||||||
private int $id = 0,
|
|
||||||
private string $a = '',
|
|
||||||
private string $aaaa = '',
|
|
||||||
private readonly string $passphrase = '',
|
|
||||||
private string $apikey = '',
|
|
||||||
private string $apikeyPrefix = '',
|
|
||||||
private string $self = 'no',
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if ($this->passphrase) {
|
|
||||||
$configController = new ConfigController();
|
|
||||||
$encryptionController = new EncryptionController();
|
|
||||||
|
|
||||||
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
/**
|
||||||
|
* @param String $name
|
||||||
|
* @param int $id
|
||||||
|
* @param String $a
|
||||||
|
* @param String $aaaa
|
||||||
|
* @param String $apikey
|
||||||
|
* @param int $self
|
||||||
|
*/
|
||||||
|
public function __construct(String $name, int $id = 0, String $a = '', String $aaaa = '', String $apikey = '', int $self = 0)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->a = $a;
|
||||||
|
$this->aaaa = $aaaa;
|
||||||
|
$this->apikey = $apikey;
|
||||||
|
$this->self = $self;
|
||||||
|
}
|
||||||
|
|
||||||
$this->apikeyPrefix = strtok(string: $this->passphrase, token: '.');
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSelf(): int
|
||||||
|
{
|
||||||
|
return $this->self;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
/**
|
||||||
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
* @param int $self
|
||||||
} catch (Exception|SodiumException $e) {
|
*/
|
||||||
die($e->getMessage() . PHP_EOL);
|
public function setSelf(int $self): void
|
||||||
}
|
{
|
||||||
}
|
$this->self = $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPassphrase(): string
|
|
||||||
{
|
|
||||||
return $this->passphrase;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function getName(): string
|
public function getA(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function setName(string $name): void
|
public function getAaaa(): string
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
return $this->aaaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function getId(): int
|
public function getApikey(): string
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->apikey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function setId(int $id): void
|
public function getId(): int
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param int $id
|
||||||
*/
|
*/
|
||||||
public function getA(): string
|
public function setId(int $id): void
|
||||||
{
|
{
|
||||||
return $this->a;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param String $apikey
|
||||||
*/
|
*/
|
||||||
public function getSelf(): string
|
public function setApikey(string $apikey): void
|
||||||
{
|
{
|
||||||
return $this->self;
|
$this->apikey = $apikey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $self
|
|
||||||
*/
|
|
||||||
public function setSelf(string $self): void
|
|
||||||
{
|
|
||||||
$this->self = $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param String $name
|
||||||
*/
|
*/
|
||||||
public function getAaaa(): string
|
public function setName(string $name): void
|
||||||
{
|
{
|
||||||
return $this->aaaa;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @param String $a
|
||||||
*/
|
*/
|
||||||
public function getApikey(): string
|
public function setA(string $a): void
|
||||||
{
|
{
|
||||||
return $this->apikey;
|
$this->a = $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* @param String $aaaa
|
||||||
* @param string $a
|
*/
|
||||||
*/
|
public function setAaaa(string $aaaa): void
|
||||||
public function setA(string $a): void
|
{
|
||||||
{
|
$this->aaaa = $aaaa;
|
||||||
$this->a = $a;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $aaaa
|
|
||||||
*/
|
|
||||||
public function setAaaa(string $aaaa): void
|
|
||||||
{
|
|
||||||
$this->aaaa = $aaaa;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getApikeyPrefix(): string
|
|
||||||
{
|
|
||||||
return $this->apikeyPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Controller\DatabaseConnection;
|
use App\Controller\DatabaseConnection;
|
||||||
|
use App\Entity\Domain;
|
||||||
use App\Entity\Panel;
|
use App\Entity\Panel;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
@ -12,249 +13,243 @@ use PDOException;
|
||||||
*/
|
*/
|
||||||
class PanelRepository
|
class PanelRepository
|
||||||
{
|
{
|
||||||
public function __construct(private readonly DatabaseConnection $databaseConnection)
|
public function __construct(private readonly DatabaseConnection $databaseConnection)
|
||||||
{
|
{}
|
||||||
// no body
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function findSelf(): array
|
||||||
* @return array|null
|
{
|
||||||
*/
|
$sql = "
|
||||||
public function findSelf(): ?array
|
SELECT id, name, a, aaaa, apikey, self
|
||||||
{
|
|
||||||
$sql = "
|
|
||||||
SELECT id, name, a, aaaa, apikey, apikey_prefix, self
|
|
||||||
FROM " . DatabaseConnection::TABLE_PANELS . "
|
FROM " . DatabaseConnection::TABLE_PANELS . "
|
||||||
WHERE self = 1";
|
WHERE self = 1";
|
||||||
|
|
||||||
$panels = [];
|
$panels = [];
|
||||||
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||||
$panel = new Panel(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix'], self: $result['self']);
|
$panel = new Panel(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], self: $result['self']);
|
||||||
$panels[] = $panel;
|
$panels[] = $panel;
|
||||||
}
|
}
|
||||||
return $panels;
|
return $panels;
|
||||||
}
|
} catch (PDOException $e) {
|
||||||
|
exit($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function findAll(): ?array
|
}
|
||||||
{
|
|
||||||
$panels = [];
|
/**
|
||||||
$sql = "
|
* @return array
|
||||||
SELECT id, name, a, aaaa, apikey, apikey_prefix, self
|
*/
|
||||||
|
public function findAll(): array
|
||||||
|
{
|
||||||
|
$panels = [];
|
||||||
|
$sql = "
|
||||||
|
SELECT id, name, a, aaaa, apikey, self
|
||||||
FROM " . DatabaseConnection::TABLE_PANELS . "
|
FROM " . DatabaseConnection::TABLE_PANELS . "
|
||||||
ORDER BY name";
|
ORDER BY name";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||||
$panel = new Panel(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix'], self: $result['self']);
|
$panel = new Panel(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], self: $result['self']);
|
||||||
$panels[] = $panel;
|
$panels[] = $panel;
|
||||||
}
|
}
|
||||||
return $panels;
|
return $panels;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
*
|
*
|
||||||
* @return null|Panel
|
* @return null|\App\Entity\Panel
|
||||||
*/
|
*/
|
||||||
public function findByID(int $id): ?Panel
|
public function findByID(int $id): ?Panel
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, name, a, aaaa, apikey, apikey_prefix, self
|
SELECT id, name, a, aaaa, apikey, self
|
||||||
FROM . " . DatabaseConnection::TABLE_PANELS . "
|
FROM . " . DatabaseConnection::TABLE_PANELS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: ':id', var: $id);
|
$statement->bindParam(param: ':id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||||
return new Panel(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix'], self: $result['self']);
|
return new Panel(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], self: $result['self']);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $name
|
* @param String $name
|
||||||
*
|
*
|
||||||
* @return Panel|null
|
* @return \App\Entity\Panel|bool
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name): ?Panel
|
public function findByName(string $name): Panel|bool
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, name, a, aaaa, apikey, apikey_prefix, self
|
SELECT id, name, a, aaaa, apikey, self
|
||||||
FROM " . DatabaseConnection::TABLE_PANELS . "
|
FROM " . DatabaseConnection::TABLE_PANELS . "
|
||||||
WHERE name = :name";
|
WHERE name = :name";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||||
return new Panel(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix'], self: $result['self']);
|
return new Panel(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], self: $result['self']);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Panel $panel
|
* @param String $name
|
||||||
* @return int|null
|
* @param String $a
|
||||||
*/
|
* @param String $aaaa
|
||||||
public function insert(Panel $panel): ?int
|
* @param String $apikey
|
||||||
{
|
*
|
||||||
$name = $panel->getName();
|
* @return string|false
|
||||||
$a = $panel->getA();
|
*/
|
||||||
$aaaa = $panel->getAaaa();
|
public function insert(string $name, string $a, string $aaaa, String $apikey, int $self): bool|string
|
||||||
$apikey = $panel->getApikey();
|
{
|
||||||
$apikeyPrefix = $panel->getApikeyPrefix();
|
$sql = "
|
||||||
$self = $panel->getSelf();
|
INSERT INTO " . DatabaseConnection::TABLE_PANELS . " (name, a, aaaa, apikey, self)
|
||||||
|
VALUES (:name, :a, :aaaa, :apikey, :self)";
|
||||||
|
|
||||||
$sql = "
|
try {
|
||||||
INSERT INTO " . DatabaseConnection::TABLE_PANELS . " (name, a, aaaa, apikey, apikey_prefix, self)
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
VALUES (:name, :a, :aaaa, :apikey, :prefix, :self)";
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
|
$statement->bindParam(param: ':a', var: $a);
|
||||||
|
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||||
|
$statement->bindParam(param: ':apikey', var: $apikey);
|
||||||
|
$statement->bindParam(param: ':self', var: $self);
|
||||||
|
$statement->execute();
|
||||||
|
|
||||||
try {
|
return $this->databaseConnection->getConnection()->lastInsertId();
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
} catch (PDOException $e) {
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
exit($e->getMessage());
|
||||||
$statement->bindParam(param: ':a', var: $a);
|
}
|
||||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
}
|
||||||
$statement->bindParam(param: ':apikey', var: $apikey);
|
|
||||||
$statement->bindParam(param: ':prefix', var: $apikeyPrefix);
|
|
||||||
$statement->bindParam(param: ':self', var: $self);
|
|
||||||
$statement->execute();
|
|
||||||
|
|
||||||
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
exit($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Panel $panel
|
* @param Int $id
|
||||||
* @return int|null
|
* @param String $name
|
||||||
*/
|
* @param String $a
|
||||||
public function update(Panel $panel): ?int
|
* @param String $aaaa
|
||||||
{
|
* @param String $apikey
|
||||||
$id = $panel->getId();
|
*
|
||||||
$name = $panel->getName();
|
* @return false|int
|
||||||
$a = $panel->getA();
|
*/
|
||||||
$aaaa = $panel->getAaaa();
|
public function update(int $id, string $name, string $a, string $aaaa, String $apikey, int $self): bool|int
|
||||||
$apikey = $panel->getApikey();
|
{
|
||||||
$apikeyPrefix = $panel->getApikeyPrefix();
|
$current = $this->findByID(id: $id);
|
||||||
$passphrase = $panel->getPassphrase();
|
|
||||||
|
|
||||||
$current = $this->findByID(id: $id);
|
if (empty($name)) {
|
||||||
|
$name = $current->getName();
|
||||||
|
}
|
||||||
|
if (empty($a)) {
|
||||||
|
$a = $current->getA();
|
||||||
|
}
|
||||||
|
if (empty($aaaa)) {
|
||||||
|
$aaaa = $current->getAaaa();
|
||||||
|
}
|
||||||
|
if (empty($apikey)) {
|
||||||
|
$apikey = $current->getApikey();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($self)) {
|
||||||
|
echo "self is empty";
|
||||||
|
$self = $current->getSelf();
|
||||||
|
} else {
|
||||||
|
if ($self == -1) {
|
||||||
|
$self = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($name)) {
|
$sql = "
|
||||||
$name = $current->getName();
|
|
||||||
}
|
|
||||||
if (empty($a)) {
|
|
||||||
$a = $current->getA();
|
|
||||||
}
|
|
||||||
if (empty($aaaa)) {
|
|
||||||
$aaaa = $current->getAaaa();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($passphrase)) {
|
|
||||||
$apikey = $current->getApikey();
|
|
||||||
$apikeyPrefix = $current->getApikeyPrefix();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($self)) {
|
|
||||||
$self = $current->getSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$sql = "
|
|
||||||
UPDATE " . DatabaseConnection::TABLE_PANELS . " SET
|
UPDATE " . DatabaseConnection::TABLE_PANELS . " SET
|
||||||
name = :name,
|
name = :name,
|
||||||
a = :a,
|
a = :a,
|
||||||
aaaa = :aaaa,
|
aaaa = :aaaa,
|
||||||
apikey = :apikey,
|
apikey = :apikey,
|
||||||
apikey_prefix = :apikey_prefix,
|
|
||||||
self = :self
|
self = :self
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->bindParam(param: 'name', var: $name);
|
$statement->bindParam(param: 'name', var: $name);
|
||||||
$statement->bindParam(param: 'a', var: $a);
|
$statement->bindParam(param: 'a', var: $a);
|
||||||
$statement->bindParam(param: 'aaaa', var: $aaaa);
|
$statement->bindParam(param: 'aaaa', var: $aaaa);
|
||||||
$statement->bindParam(param: 'apikey', var: $apikey);
|
$statement->bindParam(param: 'apikey', var: $apikey);
|
||||||
$statement->bindParam(param: 'apikey_prefix', var: $apikeyPrefix);
|
$statement->bindParam(param: 'self', var: $self);
|
||||||
$statement->bindParam(param: 'self', var: $self);
|
$statement->execute();
|
||||||
$statement->execute();
|
|
||||||
|
|
||||||
return intval(value: $statement->rowCount());
|
return $statement->rowCount();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
*
|
*
|
||||||
* @return int|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function delete($id): ?int
|
public function delete($id): int
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
DELETE FROM " . DatabaseConnection::TABLE_PANELS . "
|
DELETE FROM " . DatabaseConnection::TABLE_PANELS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
return intval(value: $statement->rowCount());
|
return $statement->rowCount();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $field
|
* @param String $field
|
||||||
*
|
*
|
||||||
* @return int|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getLongestEntry(string $field): ?int
|
public function getLongestEntry(String $field): int
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_PANELS;
|
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_PANELS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$result = $statement->fetch();
|
$result = $statement->fetch();
|
||||||
return $result['length'];
|
return $result['length'];
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue