changed methods moved from Controller to Repository

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-03-21 14:32:10 +01:00
parent c9b1d097c1
commit 9b2c7f3495

View File

@ -167,6 +167,7 @@ class BindAPI
echo COLOR_GREEN . "\t domains:create <name> {panel=<name>}" . PHP_EOL;
echo COLOR_GREEN . "\t domains:update <ID> {name=<name>} {panel=<name>}" . PHP_EOL;
echo COLOR_GREEN . "\t domains:delete <ID>" . PHP_EOL;
echo COLOR_GREEN . "\t domains:dyndns hostname.domain.tld {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
echo COLOR_YELLOW . "apikeys" . COLOR_DEFAULT . "\t API keys to access this server" . PHP_EOL;
echo COLOR_GREEN . "\t apikeys:list" . PHP_EOL;
@ -633,7 +634,7 @@ class BindAPI
$arguments = $this->parseArguments();
$id = $this->arguments[1] ?? 0;
$id = intval(value: $this->arguments[1]) ?? 0;
$name = $arguments['name'] ?? '';
$a = $arguments['a'] ?? '';
$aaaa = $arguments['aaaa'] ?? '';
@ -643,11 +644,11 @@ class BindAPI
echo 'An ID is required' . PHP_EOL;
exit(1);
}
if (!$this->panelController->findByID(id: $id)) {
if (!$this->panelRepository->findByID(id: $id)) {
echo "Panel with ID : $id doesn't exist." . PHP_EOL;
exit(1);
}
if ($this->panelController->update(id: $id, name: $name, a: $a, aaaa: $aaaa, apikey: $apikey) !== false) {
if ($this->panelRepository->update(id: $id, name: $name, a: $a, aaaa: $aaaa, apikey: $apikey) !== false) {
echo 'Panel has been updated' . PHP_EOL;
} else {
echo 'Error while updating domain server.' . PHP_EOL;
@ -986,6 +987,7 @@ class BindAPI
'create' => $this->handleDomainsCreate(),
'update' => $this->handleDomainsUpdate(),
'delete' => $this->handleDomainsDelete(),
'dyndns' => $this->handleDomainsDynDns(),
};
} catch (UnhandledMatchError) {
echo "Unknown Command: $subcommand" . PHP_EOL;
@ -1348,4 +1350,56 @@ class BindAPI
{
$this->domainController->checkDomains();
}
/**
* @throws \DI\NotFoundException
* @throws \DI\DependencyException
*/
private function handleDomainsDynDns()
{
$hostname = $this->arguments[1] ?? '';
if (empty($hostname)) {
echo 'You need to supply at least the hostname' . PHP_EOL;
exit(1);
}
if ($this->config['verbose']) {
echo "Updating DynDNS host: $hostname" . PHP_EOL;
}
$nameserver = $this->nameserverRepository->findFirst();
if (!empty($nameserver->getAaaa())) {
$result = $this->apiController->sendCommand(
requestType: 'POST',
serverName : $nameserver->getName(),
versionIP : 6,
apiKey : $nameserver->getApikey(),
command : 'dyndns/' . $hostname,
serverType : 'nameserver');
} else {
$result = $this->apiController->sendCommand(
requestType: 'POST',
serverName : $nameserver->getName(),
versionIP : 4,
apiKey : $nameserver->getApikey(),
command : 'dyndns/' . $hostname,
serverType : 'nameserver');
}
if ($result['header'] == 200) {
if ($this->config['verbose']) {
$data = $result['data'];
$decodedData = json_decode(json: $data, associative: true);
echo $decodedData['message'] . PHP_EOL;
}
} else {
echo 'Something went wrong:' . PHP_EOL;
print_r(value: $result);
exit(1);
}
exit(0);
}
}