added missing named parameters, added strict_types

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-26 19:01:52 +01:00
parent 8fc195a558
commit 67baa731c3
1 changed files with 126 additions and 162 deletions

View File

@ -1,12 +1,14 @@
<?php <?php declare(strict_types=1);
namespace App\Controller; namespace App\Controller;
define('COLOR_RED', "\033[31m"); error_reporting(error_level: E_ALL);
define('COLOR_GREEN', "\033[32m");
define('COLOR_YELLOW', "\033[33m");
define('COLOR_BLUE', "\033[34m"); define(constant_name: 'COLOR_RED', value: "\033[31m");
define('COLOR_DEFAULT', "\033[39m"); define(constant_name: 'COLOR_GREEN', value: "\033[32m");
define(constant_name: 'COLOR_YELLOW', value: "\033[33m");
define(constant_name: 'COLOR_BLUE', value: "\033[34m");
define(constant_name: 'COLOR_DEFAULT', value: "\033[39m");
// TODO add to all Controllers // TODO add to all Controllers
error_reporting(error_level: E_ALL); error_reporting(error_level: E_ALL);
@ -35,10 +37,10 @@ class BindAPI
public function __construct(private array $config, private int $argumentsCount, private array $arguments) public function __construct(private array $config, private int $argumentsCount, private array $arguments)
{ {
$this->databaseConnection = new DatabaseConnection(config: $this->config); $this->databaseConnection = new DatabaseConnection(config: $this->config);
$this->panelController = new PanelController($this->databaseConnection); $this->panelController = new PanelController(databaseConnection: $this->databaseConnection);
$this->apiUsers = new ApiKeys($this->databaseConnection); $this->apiUsers = new ApiKeys(databaseConnection: $this->databaseConnection);
$this->domainController = new DomainController($this->databaseConnection, $this->panelController); $this->domainController = new DomainController(databaseConnection: $this->databaseConnection, panelController: $this->panelController);
$this->nameserverController = new NameserverController($this->databaseConnection); $this->nameserverController = new NameserverController(databaseConnection: $this->databaseConnection);
$this->checkController = new CheckController(); $this->checkController = new CheckController();
} }
@ -61,89 +63,38 @@ class BindAPI
} }
/** /**
* @param bool|array $panel * @param array $server
* @param String $type
* *
* @return bool * @return bool
*/ */
public function checkNSPing(bool|array $nameserver): Bool public function checkPing(array $server, String $type): Bool
{ {
$error = false;
if ($type == 'nameserver') {
$maxName = $this->nameserverController->getLongestEntry(field: 'name'); $maxName = $this->nameserverController->getLongestEntry(field: 'name');
$maxA = $this->nameserverController->getLongestEntry(field: 'a'); $maxA = $this->nameserverController->getLongestEntry(field: 'a');
$maxAAAA = $this->nameserverController->getLongestEntry(field: 'aaaa'); $maxAAAA = $this->nameserverController->getLongestEntry(field: 'aaaa');
$error = false;
if ($this->config['verbose']) {
print(COLOR_YELLOW . str_pad(string: $nameserver['name'], length: $maxName));
}
$a = $nameserver['a'] ?? '';
if (!empty($a)) {
if ($this->config['verbose']) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' ';
}
if ($result = $this->checkController->sendCommand(serverName: $nameserver['name'], versionIP: 4, apiKey: $nameserver['apikey'], command: 'ping', type: 'nameserver')) {
if ($this->config['verbose']) {
if ($result == 'pong') {
echo COLOR_GREEN . $result;
} else { } else {
echo COLOR_BLUE . $result; // TODO 'skip';
}
}
} else {
$error = true;
}
}
$aaaa = $nameserver['aaaa'] ?? '';
if (!empty($aaaa)) {
if ($this->config['verbose']) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' ';
}
if ($result = $this->checkController->sendCommand(serverName: $nameserver['name'], versionIP: 6, apiKey: $nameserver['apikey'], command: 'ping', type: 'nameserver')) {
if ($this->config['verbose']) {
if ($result == 'pong') {
echo COLOR_GREEN . $result;
} else {
echo COLOR_BLUE . $result; // TODO 'skip';
}
}
} else {
$error = true;
}
}
if ($this->config['verbose']) {
echo PHP_EOL;
}
return $error;
}
/**
* @param bool|array $panel
*
* @return bool
*/
public function checkPanelPing(bool|array $panel): Bool
{
$maxName = $this->panelController->getLongestEntry(field: 'name'); $maxName = $this->panelController->getLongestEntry(field: 'name');
$maxA = $this->panelController->getLongestEntry(field: 'a'); $maxA = $this->panelController->getLongestEntry(field: 'a');
$maxAAAA = $this->panelController->getLongestEntry(field: 'aaaa'); $maxAAAA = $this->panelController->getLongestEntry(field: 'aaaa');
$error = false;
if ($this->config['verbose']) {
print(COLOR_YELLOW . str_pad(string: $panel['name'], length: $maxName));
} }
$a = $panel['a'] ?? ''; if ($this->config['verbose']) {
print(COLOR_YELLOW . str_pad(string: $server['name'], length: $maxName));
}
$a = $server['a'] ?? '';
if (!empty($a)) { if (!empty($a)) {
if ($this->config['verbose']) { if ($this->config['verbose']) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' '; echo COLOR_DEFAULT . ' ' . str_pad(string: $a, length: $maxA, pad_type: STR_PAD_LEFT) . ' ';
} }
if ($result = $this->checkController->sendPanelCommand(serverName: $panel['name'], versionIP: 4, apiKey: $panel['apikey'], command: 'ping')) { if ($result = $this->checkController->sendCommand(serverName: $server['name'], versionIP: 4, apiKey: $server['apikey'], command: 'ping', type: $type)) {
if ($this->config['verbose']) { if ($this->config['verbose']) {
if ($result == 'pong') { if ($result['data'] == 'pong') {
echo COLOR_GREEN . $result; echo COLOR_GREEN . $result['data'];
} else { } else {
echo COLOR_BLUE . 'skip'; echo COLOR_BLUE . 'skip';
} }
@ -152,17 +103,17 @@ class BindAPI
$error = true; $error = true;
} }
} }
$aaaa = $panel['aaaa'] ?? ''; $aaaa = $server['aaaa'] ?? '';
if (!empty($aaaa)) { if (!empty($aaaa)) {
if ($this->config['verbose']) { if ($this->config['verbose']) {
echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' '; echo COLOR_DEFAULT . ' ' . str_pad(string: $aaaa, length: $maxAAAA, pad_type: STR_PAD_LEFT) . ' ';
} }
if ($result = $this->checkController->sendPanelCommand(serverName: $panel['name'], versionIP: 6, apiKey: $panel['apikey'], command: 'ping')) { if ($result = $this->checkController->sendCommand(serverName: $server['name'], versionIP: 6, apiKey: $server['apikey'], command: 'ping', type: $type)) {
if ($this->config['verbose']) { if ($this->config['verbose']) {
if ($result == 'pong') { if ($result['data'] == 'pong') {
echo COLOR_GREEN . $result; echo COLOR_GREEN . $result['data'];
} else { } else {
echo COLOR_BLUE . 'skip'; echo COLOR_BLUE . $result['data']; // TODO 'skip';
} }
} }
} else { } else {
@ -176,6 +127,8 @@ class BindAPI
} }
function handleChecks(String $subcommand) function handleChecks(String $subcommand)
{ {
try { try {
@ -192,15 +145,12 @@ class BindAPI
/** /**
* @param String $domain * @param String $domain
* *
* @return bool|void
*/ */
function checkNS(String $domain) function checkNS(String $domain)
{ {
$nameServers = $this->nameserverController->findAll(); $nameServers = $this->nameserverController->findAll();
$i = 1;
foreach($nameServers as $nameServer) { foreach($nameServers as $nameServer) {
print("nameserver $i"); echo COLOR_DEFAULT . ' ' . $nameServer['name'];
$i++;
if (!empty($nameServer['aaaa'])) { if (!empty($nameServer['aaaa'])) {
$result = $this->checkController->sendCommand(serverName: $nameServer['name'], $result = $this->checkController->sendCommand(serverName: $nameServer['name'],
versionIP: 6, versionIP: 6,
@ -215,9 +165,9 @@ class BindAPI
type: 'nameserver' . $domain); type: 'nameserver' . $domain);
} }
if ($result['header'] == 200) { if ($result['header'] == 200) {
print("OK"); echo COLOR_GREEN . ' OK';
} else { } else {
print("missing"); echo COLOR_RED . ' missing';
} }
} }
echo PHP_EOL; echo PHP_EOL;
@ -227,13 +177,10 @@ class BindAPI
function handleCheckPanels() function handleCheckPanels()
{ {
$id = $this->getId(); $id = $this->getId();
$maxDomain = $this->panelController->getLongestEntry(field:'name'); print("id: $id " . PHP_EOL);
print("$maxDomain");
die();
if ($id != 0) { if ($id != 0) {
if ($panel = $this->panelController->findByID($id)) { if ($panel = $this->panelController->findByID(id: $id)) {
if (!empty($panel['aaaa'])) { if (!empty($panel['aaaa'])) {
$result = $this->checkController->sendCommand(serverName: $panel['name'], $result = $this->checkController->sendCommand(serverName: $panel['name'],
versionIP: 6, versionIP: 6,
@ -248,10 +195,18 @@ class BindAPI
type: 'panel'); type: 'panel');
} }
$domains = json_decode($result['data']); $domains = json_decode(json: $result['data']);
$maxDomainName = 0;
// TODO this is ugly code
foreach ($domains as $domain) {
if (($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) && (strlen(string: $domain->domain) > $maxDomainName)) {
$maxDomainName = strlen(string: $domain->domain);
}
}
foreach ($domains as $domain) { foreach ($domains as $domain) {
if ($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) { if ($domain->id_parent_domain == 0 && !str_contains(haystack: $domain->domain, needle: $panel['name'])) {
echo PHP_EOL . COLOR_DEFAULT . "check: " . COLOR_YELLOW . str_pad($domain->domain, $maxDomain); echo PHP_EOL . COLOR_DEFAULT . "check: " . COLOR_YELLOW . str_pad(string: $domain->domain, length: $maxDomainName);
if ($this->checkNS($domain->domain)) { if ($this->checkNS($domain->domain)) {
echo COLOR_GREEN . ' OK'; echo COLOR_GREEN . ' OK';
} else { } else {
@ -263,6 +218,8 @@ class BindAPI
echo "Unknown Panel ID: $id" . PHP_EOL; echo "Unknown Panel ID: $id" . PHP_EOL;
exit(1); exit(1);
} }
} else {
echo "check all …" . PHP_EOL;
} }
} }
@ -289,11 +246,11 @@ class BindAPI
try { try {
match ($command) { match ($command) {
'check' => $this->handleChecks($subcommand), 'check' => $this->handleChecks(subcommand: $subcommand),
'panels' => $this->handlePanels($subcommand), 'panels' => $this->handlePanels(subcommand: $subcommand),
'apikeys' => $this->handleApiKeys($subcommand), 'apikeys' => $this->handleApiKeys(subcommand: $subcommand),
'domains' => $this->handleDomains($subcommand), 'domains' => $this->handleDomains(subcommand: $subcommand),
'nameservers' => $this->handleNameservers($subcommand) 'nameservers' => $this->handleNameservers(subcommand: $subcommand)
}; };
} catch(UnhandledMatchError) { } catch(UnhandledMatchError) {
echo 'Unknown command: ' . $command . PHP_EOL; echo 'Unknown command: ' . $command . PHP_EOL;
@ -361,8 +318,7 @@ class BindAPI
'list' => $this->handleNameserversList(), 'list' => $this->handleNameserversList(),
'update' => $this->handleNameserversUpdate(), 'update' => $this->handleNameserversUpdate(),
'delete' => $this->handleNameserversDelete(), 'delete' => $this->handleNameserversDelete(),
'apiping' => $this->handleNameserversAPIPing(), 'apiping' => $this->handleAPIPing(type: 'nameserver')
}; };
} catch (UnhandledMatchError) { } catch (UnhandledMatchError) {
echo 'Unknown action: ' . $subcommand . PHP_EOL; echo 'Unknown action: ' . $subcommand . PHP_EOL;
@ -379,18 +335,22 @@ class BindAPI
{ {
try { try {
match ($subcommand) { match ($subcommand) {
'apiping' => $this->handlePanelsAPIPing(),
'create' => $this->handlePanelsCreate(), 'create' => $this->handlePanelsCreate(),
'list' => $this->handlePanelsList(), 'list' => $this->handlePanelsList(),
'update' => $this->handlePanelsUpdate(), 'update' => $this->handlePanelsUpdate(),
'delete' => $this->handlePanelsDelete(), 'delete' => $this->handlePanelsDelete(),
'apiping' => $this->handleAPIPing(type: 'panel')
}; };
} catch (UnhandledMatchError) { } catch (UnhandledMatchError) {
echo 'Unknown action: ' . $subcommand . PHP_EOL; echo 'Unknown action: ' . $subcommand . PHP_EOL;
} }
} }
/*
*
* TODO remove
*/
/*
function handleNameserversAPIPing() function handleNameserversAPIPing()
{ {
// TODO get apikey from stdin // TODO get apikey from stdin
@ -411,8 +371,8 @@ class BindAPI
} }
if ($id != 0) { if ($id != 0) {
if ($nameserver = $this->nameserverController->findByID($id)) { if ($nameserver = $this->nameserverController->findByID(id: $id)) {
if (!$this->checkNSPing($nameserver)) { if (!$this->checkPing(server: $nameserver, type: 'nameserver')) {
$error = true; $error = true;
} }
} else { } else {
@ -424,7 +384,7 @@ class BindAPI
} else { } else {
$nameservers = $this->nameserverController->findAll(); $nameservers = $this->nameserverController->findAll();
foreach ($nameservers as $nameserver) { foreach ($nameservers as $nameserver) {
if (!$this->checkNSPing(nameserver: $nameserver)) { if (!$this->checkPing(server: $nameserver, type: 'nameserver')) {
$error = true; $error = true;
} }
} }
@ -436,37 +396,40 @@ class BindAPI
exit(0); exit(0);
} }
} }
*/
function handleAPIPing(String $type)
function handlePanelsAPIPing()
{ {
$error = false; $error = false;
if (!empty($this->arguments[1])) { $id = $this->getId();
$id = intval(value: $this->arguments[1] ?? 0);
if ($id != $this->arguments[1]) {
echo 'ID has to be a number.' . PHP_EOL;
exit(1);
}
} else {
$id = 0;
}
if ($id != 0) { if ($id != 0) {
if ($panel = $this->panelController->findByID($id)) { if ($type == 'panel') {
if (!$this->checkPanelPing($panel)) { $server = $this->panelController->findByID(id: $id);
} else {
$server = $this->nameserverController->findByID(id: $id);
}
if ($server) {
if (!$this->checkPing(server: $server, type: $type)) {
$error = true; $error = true;
} }
} else { } else {
if ($this->config['verbose']) { if ($this->config['verbose']) {
echo 'Unknown panel ID: $id' . PHP_EOL; echo "Unknown $type ID: $id" . PHP_EOL;
} }
$error = true; $error = true;
} }
} else { } else {
$panels = $this->panelController->findAll(); if ($type == 'panel') {
foreach ($panels as $panel) { $servers = $this->panelController->findAll();
if (!$this->checkPanelPing(panel: $panel)) { } else {
$servers = $this->nameserverController->findAll();
}
foreach ($servers as $server) {
if (!$this->checkPing(server: $server, type: $type)) {
$error = true; $error = true;
} }
} }
@ -509,11 +472,11 @@ class BindAPI
} }
$apikey = $arguments['apikey'] ?? ''; $apikey = $arguments['apikey'] ?? '';
if ($this->panelController->findByName($name)) { if ($this->panelController->findByName(name: $name)) {
echo "Panel: $name already exists." . PHP_EOL; echo "Panel: $name already exists." . PHP_EOL;
exit(1); exit(1);
} else { } else {
$result = $this->panelController->insert($name, $a, $aaaa, $apikey); $result = $this->panelController->insert(name: $name, a: $a, aaaa: $aaaa, apikey: $apikey);
echo "Panel $name has been created with id $result" . PHP_EOL; echo "Panel $name has been created with id $result" . PHP_EOL;
exit(0); exit(0);
} }
@ -549,11 +512,11 @@ class BindAPI
} }
$apikey = $argiments['apikey'] ?? ''; $apikey = $argiments['apikey'] ?? '';
if ($this->nameserverController->findByName($name)) { if ($this->nameserverController->findByName(name: $name)) {
echo "Nameserver: $name already exists." . PHP_EOL; echo "Nameserver: $name already exists." . PHP_EOL;
exit(1); exit(1);
} else { } else {
$result = $this->nameserverController->insert($name, $a, $aaaa, $apikey); $result = $this->nameserverController->insert(name: $name, a: $a, aaaa: $aaaa, apikey: $apikey);
echo "Nameserver $name has been created with id $result" . PHP_EOL; echo "Nameserver $name has been created with id $result" . PHP_EOL;
exit(0); exit(0);
} }
@ -569,7 +532,7 @@ class BindAPI
foreach ($this->arguments as $argument) { foreach ($this->arguments as $argument) {
if (str_contains(haystack: $argument, needle: '=')) { if (str_contains(haystack: $argument, needle: '=')) {
[$key, $value] = explode(separator: '=', string: $argument); [$key, $value] = explode(separator: '=', string: $argument);
$arguments[strtolower($key)] = $value; $arguments[strtolower(string: $key)] = $value;
} }
} }
return $arguments; return $arguments;
@ -584,10 +547,10 @@ class BindAPI
$panels = $this->panelController->findAll(); $panels = $this->panelController->findAll();
if ($panels) { if ($panels) {
$table = new ConsoleTable(); $table = new ConsoleTable();
$table->setHeaders(['ID', 'Name', 'A', 'AAAA', 'API Key']); $table->setHeaders(content: ['ID', 'Name', 'A', 'AAAA', 'API Key']);
foreach ($panels as $panel) { foreach ($panels as $panel) {
$token = strtok(string: $panel['apikey'], token: '.'); $token = strtok(string: $panel['apikey'], token: '.');
$table->addRow([$panel['id'], $panel['name'], $panel['a'], $panel['aaaa'], $token]); $table->addRow(data: [$panel['id'], $panel['name'], $panel['a'], $panel['aaaa'], $token]);
} }
$table->setPadding(value: 2); $table->setPadding(value: 2);
$table->display(); $table->display();
@ -612,11 +575,11 @@ class BindAPI
echo 'An ID is required' . PHP_EOL; echo 'An ID is required' . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->panelController->findByID($id)) { if (!$this->panelController->findByID(id: $id)) {
echo "Panel with ID : $id doesn't exist." . PHP_EOL; echo "Panel with ID : $id doesn't exist." . PHP_EOL;
exit(1); exit(1);
} }
if ($this->panelController->update($id, $name, $a, $aaaa, $apikey) !== false) { if ($this->panelController->update(id: $id, name: $name, a: $a, aaaa: $aaaa, apikey: $apikey) !== false) {
echo 'Panel has been updated' . PHP_EOL; echo 'Panel has been updated' . PHP_EOL;
} else { } else {
echo 'Error while updating domain server.' . PHP_EOL; echo 'Error while updating domain server.' . PHP_EOL;
@ -630,19 +593,20 @@ class BindAPI
exit(1); exit(1);
} }
$id = intval($this->arguments[1]) ?? 0; $id = intval(value: $this->arguments[1]) ?? 0;
if ($id == 0) { if ($id == 0) {
echo "Panel with ID $id not found." . PHP_EOL; echo "Panel with ID $id not found." . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->panelController->findByID($id)) { if (!$this->panelController->findByID(id: $id)) {
echo "There is no panel with ID $id." . PHP_EOL; echo "There is no panel with ID $id." . PHP_EOL;
exit(1); exit(1);
} }
$this->panelController->delete($id); $this->panelController->delete(id: $id);
echo "The panel with ID $id has been deleted." .PHP_EOL; echo "The panel with ID $id has been deleted." .PHP_EOL;
} }
/** /**
* @param string $subcommand * @param string $subcommand
* *
@ -684,9 +648,9 @@ class BindAPI
$keys = $this->apiUsers->findAll(); $keys = $this->apiUsers->findAll();
if ($keys) { if ($keys) {
$table = new ConsoleTable(); $table = new ConsoleTable();
$table->setHeaders(['ID', 'Name', 'API key prefix']); $table->setHeaders(content: ['ID', 'Name', 'API key prefix']);
foreach ($keys as $key) { foreach ($keys as $key) {
$table->addRow([$key['id'], $key['name'], $key['api_token_prefix']]); $table->addRow(data: [$key['id'], $key['name'], $key['api_token_prefix']]);
} }
$table->setPadding(value: 2); $table->setPadding(value: 2);
$table->display(); $table->display();
@ -706,8 +670,8 @@ class BindAPI
echo 'You need to add the ID of the API key.' . PHP_EOL; echo 'You need to add the ID of the API key.' . PHP_EOL;
exit(1); exit(1);
} }
if ($this->apiUsers->findByID($id)) { if ($this->apiUsers->findByID(id: $id)) {
$this->apiUsers->delete($id); $this->apiUsers->delete(id: $id);
echo 'API key ' . $id . ' has been deleted.' . PHP_EOL; echo 'API key ' . $id . ' has been deleted.' . PHP_EOL;
exit(0); exit(0);
} else { } else {
@ -716,6 +680,7 @@ class BindAPI
} }
} }
/** /**
* @param string $subcommand * @param string $subcommand
* *
@ -745,10 +710,10 @@ class BindAPI
$domains = $this->nameserverController->findAll(); $domains = $this->nameserverController->findAll();
if ($domains) { if ($domains) {
$table = new ConsoleTable(); $table = new ConsoleTable();
$table->setHeaders(['ID', 'Name', 'A', 'AAAA', 'API Key']); $table->setHeaders(content: ['ID', 'Name', 'A', 'AAAA', 'API Key']);
foreach ($domains as $domain) { foreach ($domains as $domain) {
$token = strtok(string: $domain['apikey'], token: '.'); $token = strtok(string: $domain['apikey'], token: '.');
$table->addRow([$domain['id'], $domain['name'], $domain['a'], $domain['aaaa'], $token]); $table->addRow(data: [$domain['id'], $domain['name'], $domain['a'], $domain['aaaa'], $token]);
} }
$table->setPadding(value: 2); $table->setPadding(value: 2);
$table->display(); $table->display();
@ -769,9 +734,9 @@ class BindAPI
$domains = $this->domainController->findAll(); $domains = $this->domainController->findAll();
if ($domains) { if ($domains) {
$table = new ConsoleTable(); $table = new ConsoleTable();
$table->setHeaders(['ID', 'Name', 'Panel', 'A', 'AAAA']); $table->setHeaders(content: ['ID', 'Name', 'Panel', 'A', 'AAAA']);
foreach ($domains as $domain) { foreach ($domains as $domain) {
$table->addRow([$domain['id'], $domain['name'], $domain['panel_id'], $domain['a'], $domain['aaaa']]); $table->addRow(data: [$domain['id'], $domain['name'], $domain['panel_id'], $domain['a'], $domain['aaaa']]);
} }
$table->setPadding(value: 2); $table->setPadding(value: 2);
$table->display(); $table->display();
@ -812,11 +777,11 @@ class BindAPI
exit(0); exit(0);
} }
if ($this->domainController->findByName($name)) { if ($this->domainController->findByName(name: $name)) {
echo "Domain: $name already exists." . PHP_EOL; echo "Domain: $name already exists." . PHP_EOL;
exit(1); exit(1);
} else { } else {
$result = $this->domainController->insert($name, $panelID, $a, $aaaa); $result = $this->domainController->insert(name: $name, panelID: $panelID, a: $a, aaaa: $aaaa);
echo "Domain $name has been created with id $result" . PHP_EOL; echo "Domain $name has been created with id $result" . PHP_EOL;
exit(0); exit(0);
} }
@ -828,7 +793,7 @@ class BindAPI
$id = $this->arguments[1] ?? 0; $id = $this->arguments[1] ?? 0;
$name = $arguments['name'] ?? ''; $name = $arguments['name'] ?? '';
print_r($arguments); //findme print_r(value: $arguments); //findme
$panelID = intval(value: $arguments['panel_id'] ?? 0); $panelID = intval(value: $arguments['panel_id'] ?? 0);
$a = $arguments['a'] ?? ''; $a = $arguments['a'] ?? '';
$aaaa = $arguments['aaaa'] ?? ''; $aaaa = $arguments['aaaa'] ?? '';
@ -837,11 +802,11 @@ class BindAPI
echo 'An ID is required' . PHP_EOL; echo 'An ID is required' . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->domainController->findByID($id)) { if (!$this->domainController->findByID(id: $id)) {
echo "Domain with ID : $id doesn't exist." . PHP_EOL; echo "Domain with ID : $id doesn't exist." . PHP_EOL;
exit(1); exit(1);
} }
if ($this->domainController->update($id, $name, $panelID, $a, $aaaa) !== false) { if ($this->domainController->update(id: $id, name: $name, panelID: $panelID, a: $a, aaaa: $aaaa) !== false) {
echo 'Domain server has been updated' . PHP_EOL; echo 'Domain server has been updated' . PHP_EOL;
} else { } else {
echo 'Error while updating domain server.' . PHP_EOL; echo 'Error while updating domain server.' . PHP_EOL;
@ -849,7 +814,6 @@ class BindAPI
} }
function handleNameserversUpdate() function handleNameserversUpdate()
{ {
$arguments = $this->parseArguments(); $arguments = $this->parseArguments();
@ -864,11 +828,11 @@ class BindAPI
echo 'An ID is required' . PHP_EOL; echo 'An ID is required' . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->nameserverController->findByID($id)) { if (!$this->nameserverController->findByID(id: $id)) {
echo "Nameserver with ID : $id doesn't exist." . PHP_EOL; echo "Nameserver with ID : $id doesn't exist." . PHP_EOL;
exit(1); exit(1);
} }
if ($this->nameserverController->update($id, $name, $a, $aaaa, $apikey) !== false) { if ($this->nameserverController->update(id: $id, name: $name, a: $a, aaaa: $aaaa, apikey: $apikey) !== false) {
echo 'Nameserver server has been updated' . PHP_EOL; echo 'Nameserver server has been updated' . PHP_EOL;
} else { } else {
echo 'Error while updating nameserver.' . PHP_EOL; echo 'Error while updating nameserver.' . PHP_EOL;
@ -882,16 +846,16 @@ class BindAPI
exit(1); exit(1);
} }
$id = intval($this->arguments[1]) ?? 0; $id = intval(value: $this->arguments[1]) ?? 0;
if ($id == 0) { if ($id == 0) {
echo "Nameserver with ID $id not found." . PHP_EOL; echo "Nameserver with ID $id not found." . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->nameserverController->findByID($id)) { if (!$this->nameserverController->findByID(id: $id)) {
echo "There is no nameserver with ID $id." . PHP_EOL; echo "There is no nameserver with ID $id." . PHP_EOL;
exit(1); exit(1);
} }
$this->nameserverController->delete($id); $this->nameserverController->delete(id: $id);
echo "The nameserver with ID $id has been deleted." .PHP_EOL; echo "The nameserver with ID $id has been deleted." .PHP_EOL;
} }
@ -903,16 +867,16 @@ function handleDomainsDelete()
exit(1); exit(1);
} }
$id = intval($this->arguments[1]) ?? 0; $id = intval(value: $this->arguments[1]) ?? 0;
if ($id == 0) { if ($id == 0) {
echo "Domain with ID $id not found." . PHP_EOL; echo "Domain with ID $id not found." . PHP_EOL;
exit(1); exit(1);
} }
if (!$this->domainController->findByID($id)) { if (!$this->domainController->findByID(id: $id)) {
echo "There is no domain with ID $id." . PHP_EOL; echo "There is no domain with ID $id." . PHP_EOL;
exit(1); exit(1);
} }
$this->domainController->delete($id); $this->domainController->delete(id: $id);
echo "The domain with ID $id has been deleted." .PHP_EOL; echo "The domain with ID $id has been deleted." .PHP_EOL;
} }
} }