adapted to /domains/name path
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
ac21b53bb9
commit
5d4586aff3
|
@ -162,8 +162,8 @@ class BindAPI
|
||||||
|
|
||||||
echo COLOR_YELLOW . "domains" . COLOR_DEFAULT . " domains this server is responsible for" . PHP_EOL;
|
echo COLOR_YELLOW . "domains" . COLOR_DEFAULT . " domains this server is responsible for" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t domains:list" . PHP_EOL;
|
echo COLOR_GREEN . "\t domains:list" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t domains:create <name> {panel_id=<ID>} | {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
|
echo COLOR_GREEN . "\t domains:create <name> {panel=<name>} | {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t domains:update <ID> {name=<name>} {panel_id=<ID>} | {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
|
echo COLOR_GREEN . "\t domains:update <ID> {name=<name>} {panel=<name>} | {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
|
||||||
echo COLOR_GREEN . "\t domains:delete <ID>" . PHP_EOL;
|
echo COLOR_GREEN . "\t domains:delete <ID>" . PHP_EOL;
|
||||||
|
|
||||||
echo COLOR_YELLOW . "apikeys" . COLOR_DEFAULT . "\t API keys for other nameservers" . PHP_EOL;
|
echo COLOR_YELLOW . "apikeys" . COLOR_DEFAULT . "\t API keys for other nameservers" . PHP_EOL;
|
||||||
|
@ -219,7 +219,7 @@ class BindAPI
|
||||||
$id = intval(value: $this->arguments[1] ?? 0);
|
$id = intval(value: $this->arguments[1] ?? 0);
|
||||||
|
|
||||||
if ($id != 0) {
|
if ($id != 0) {
|
||||||
if ($panel = $this->panelController->findByID(id: $id)) {
|
if ($panel = $this->panelRepository->findByID(id: $id)) {
|
||||||
$this->checkSinglePanel(panel: $panel);
|
$this->checkSinglePanel(panel: $panel);
|
||||||
} else {
|
} else {
|
||||||
echo "Unknown panel ID: $id" . PHP_EOL;
|
echo "Unknown panel ID: $id" . PHP_EOL;
|
||||||
|
@ -367,7 +367,7 @@ class BindAPI
|
||||||
serverName: $nameServer->getName(),
|
serverName: $nameServer->getName(),
|
||||||
versionIP: 6,
|
versionIP: 6,
|
||||||
apiKey: $nameServer->getApikey(),
|
apiKey: $nameServer->getApikey(),
|
||||||
command: 'domains/' . $domainName,
|
command: 'domains/name/' . $domainName,
|
||||||
serverType: 'nameserver');
|
serverType: 'nameserver');
|
||||||
} else {
|
} else {
|
||||||
$result = $this->apiController->sendCommand(
|
$result = $this->apiController->sendCommand(
|
||||||
|
@ -375,16 +375,19 @@ class BindAPI
|
||||||
serverName: $nameServer->getName(),
|
serverName: $nameServer->getName(),
|
||||||
versionIP: 4,
|
versionIP: 4,
|
||||||
apiKey: $nameServer->getApikey(),
|
apiKey: $nameServer->getApikey(),
|
||||||
command: 'domains',
|
command: 'domains/name/',
|
||||||
serverType: 'nameserver' . $domainName);
|
serverType: 'nameserver' . $domainName);
|
||||||
}
|
}
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if ($result['header'] == 200) {
|
|
||||||
|
switch ($result['header']) {
|
||||||
|
case 200:
|
||||||
echo COLOR_GREEN . ' OK';
|
echo COLOR_GREEN . ' OK';
|
||||||
} else {
|
break;
|
||||||
|
case 404:
|
||||||
echo COLOR_RED . $result['header'] . COLOR_DEFAULT;
|
echo COLOR_RED . $result['header'] . COLOR_DEFAULT;
|
||||||
$arguments = $this->parseArguments();
|
$arguments = $this->parseArguments();
|
||||||
if (!empty($arguments['fix']) && $arguments['fix'] == 'yes') {
|
if (!empty($arguments['fix']) && $arguments['fix'] == 'yes') {
|
||||||
|
@ -400,7 +403,7 @@ class BindAPI
|
||||||
serverName: $nameServer['name'],
|
serverName: $nameServer['name'],
|
||||||
versionIP: 6,
|
versionIP: 6,
|
||||||
apiKey: $nameServer['apikey'],
|
apiKey: $nameServer['apikey'],
|
||||||
command: 'domains',
|
command: 'domains/name',
|
||||||
serverType: 'nameserver',
|
serverType: 'nameserver',
|
||||||
body: $body);
|
body: $body);
|
||||||
} else {
|
} else {
|
||||||
|
@ -409,7 +412,7 @@ class BindAPI
|
||||||
serverName: $nameServer['name'],
|
serverName: $nameServer['name'],
|
||||||
versionIP: 4,
|
versionIP: 4,
|
||||||
apiKey: $nameServer['apikey'],
|
apiKey: $nameServer['apikey'],
|
||||||
command: 'domains',
|
command: 'domains/name',
|
||||||
serverType: 'nameserver',
|
serverType: 'nameserver',
|
||||||
body: $body);
|
body: $body);
|
||||||
}
|
}
|
||||||
|
@ -418,6 +421,11 @@ class BindAPI
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
echo 'Server error' . PHP_EOL;
|
||||||
|
print_r(value: $result);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
@ -949,16 +957,28 @@ class BindAPI
|
||||||
}
|
}
|
||||||
if (!empty($domains)) {
|
if (!empty($domains)) {
|
||||||
$table = new ConsoleTable();
|
$table = new ConsoleTable();
|
||||||
$table->setHeaders(content: ['ID', 'Name', 'Panel', 'A', 'AAAA']);
|
$table->setHeaders(content: ['ID', 'Name', 'Content']);
|
||||||
/** @var Domain $domain */
|
/** @var Domain $domain */
|
||||||
foreach ($domains as $domain) {
|
foreach ($domains as $domain) {
|
||||||
$row = [];
|
$row = [];
|
||||||
try {
|
try {
|
||||||
$row[] = $domain->getId();
|
$row[] = $domain->getId();
|
||||||
$row[] = $domain->getName();
|
$row[] = $domain->getName();
|
||||||
$row[] = $domain->getPanelID();
|
$content = json_decode(json: $domain->getContent());
|
||||||
$row[] = $domain->getA();
|
$column = '';
|
||||||
$row[] = $domain->getAAAA();
|
if (!empty($content->panel)) {
|
||||||
|
$column = 'Panel: ' . $content->panel;
|
||||||
|
}
|
||||||
|
if (!empty($content->custom)) {
|
||||||
|
$column .= 'Custom: ';
|
||||||
|
if (!empty($content->custom->a)) {
|
||||||
|
$column .= 'A: ' . $content->custom->a;
|
||||||
|
}
|
||||||
|
if (!empty($content->custom->aaaa)) {
|
||||||
|
$column .= ' AAAA: ' . $content->custom->a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$row[] = $column;
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
|
@ -992,12 +1012,14 @@ class BindAPI
|
||||||
|
|
||||||
$arguments = $this->parseArguments();
|
$arguments = $this->parseArguments();
|
||||||
|
|
||||||
$a = $arguments['a'] ?? "";
|
|
||||||
$aaaa = $arguments['aaaa'] ?? "";
|
|
||||||
$panelID = $arguments['panel_id'] ?? 0;
|
|
||||||
|
|
||||||
if (empty($a) && empty($aaaa) && empty($panelID)) {
|
$a = $arguments['a'] ?? '';
|
||||||
echo 'At least one IP address or panel ID is required.' . PHP_EOL;
|
$aaaa = $arguments['aaaa'] ?? '';
|
||||||
|
$panel = $arguments['panel'] ?? '';
|
||||||
|
|
||||||
|
print("panel: $panel");
|
||||||
|
if (empty($a) && empty($aaaa) && empty($panel)) {
|
||||||
|
echo 'At least one IP address or panel is required.' . PHP_EOL;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1006,16 +1028,27 @@ class BindAPI
|
||||||
echo "Domain: $name already exists." . PHP_EOL;
|
echo "Domain: $name already exists." . PHP_EOL;
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($panelID)) {
|
if (!empty($panel)) {
|
||||||
if ($panel = $this->panelController->findByID(id: $panelID)) {
|
if ($this->panelRepository->findByName(name: $panel)) {
|
||||||
$a = $panel['a'];
|
$content = $this->domainController->createPanelContent(panel: $panel);
|
||||||
$aaaa = $panel['aaaa'];
|
} else {
|
||||||
|
echo 'Unknown panel: ' . $panel;
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$content = [];
|
||||||
|
if (!empty($a)) {
|
||||||
|
$content['a'] = $a;
|
||||||
}
|
}
|
||||||
$domain = new Domain(name: $name, id: $panelID, panelID: $a, a: $aaaa);
|
if (!empty($aaaa)) {
|
||||||
|
$content['aaaa'] = $aaaa;
|
||||||
|
}
|
||||||
|
$content = $this->domainController->createIPContent(ip: $content);
|
||||||
|
}
|
||||||
|
$domain = new Domain(name: $name, content: $content);
|
||||||
$result = $this->domainRepository->insert(domain: $domain);
|
$result = $this->domainRepository->insert(domain: $domain);
|
||||||
echo "Domain $name has been created with id $result" . PHP_EOL;
|
echo "Domain $name has been created with id $result" . PHP_EOL;
|
||||||
$this->domainController->createZoneFile(domain: $domain);
|
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
} catch (DependencyException|NotFoundException $e) {
|
} catch (DependencyException|NotFoundException $e) {
|
||||||
|
@ -1033,7 +1066,7 @@ class BindAPI
|
||||||
|
|
||||||
$id = intval(value: $this->arguments[1] ?? 0);
|
$id = intval(value: $this->arguments[1] ?? 0);
|
||||||
$name = $arguments['name'] ?? '';
|
$name = $arguments['name'] ?? '';
|
||||||
$panelID = intval(value: $arguments['panel_id'] ?? 0);
|
$panel = $arguments['panel'] ?? '';
|
||||||
$a = $arguments['a'] ?? '';
|
$a = $arguments['a'] ?? '';
|
||||||
$aaaa = $arguments['aaaa'] ?? '';
|
$aaaa = $arguments['aaaa'] ?? '';
|
||||||
|
|
||||||
|
@ -1045,15 +1078,39 @@ class BindAPI
|
||||||
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 (!empty($panelID)) {
|
|
||||||
$panel = $this->panelController->findByID(id: $panelID);
|
$content = [];
|
||||||
$a = $panel['a'];
|
if (!empty($panel)) {
|
||||||
$aaaa = $panel['aaaa'];
|
$panel = $this->panelRepository->findByName(name: $panel);
|
||||||
|
$content = $this->domainController->createPanelContent(panel: $panel->getName());
|
||||||
|
} else {
|
||||||
|
$addresses = [];
|
||||||
|
if (!empty($a)) {
|
||||||
|
$addresses[] = [
|
||||||
|
'a' => $a
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (!empty($aaaa)) {
|
||||||
|
$addresses[] = [
|
||||||
|
'aaaa' => $aaaa
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (!empty($addresses)) {
|
||||||
|
$content = $this->domainController->createIPContent(ip: $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($name) && empty($content)) {
|
||||||
|
echo 'Either a new name or new content (panel or addresses) is needed.' . PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (empty($content)) {
|
||||||
|
$newDomain = new Domain(name: $name, id: $domain->getId(), content: '');
|
||||||
|
} else {
|
||||||
|
$newDomain = new Domain(name: $name, id: $domain->getId(), content: $content);
|
||||||
}
|
}
|
||||||
$newDomain = new Domain(name: $name, id: $panelID, panelID: $a, a: $aaaa);
|
|
||||||
if ($this->domainRepository->update(domain: $newDomain) !== false) {
|
if ($this->domainRepository->update(domain: $newDomain) !== false) {
|
||||||
echo 'Domain server has been updated' . PHP_EOL;
|
echo 'Domain server has been updated' . PHP_EOL;
|
||||||
$this->domainController->createZoneFile(domain: $domain);
|
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||||
} else {
|
} else {
|
||||||
echo 'Error while updating domain server.' . PHP_EOL;
|
echo 'Error while updating domain server.' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -1080,6 +1137,7 @@ class BindAPI
|
||||||
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->domainRepository->delete(domain: $domain);
|
||||||
$this->domainController->deleteZone(domain: $domain);
|
$this->domainController->deleteZone(domain: $domain);
|
||||||
echo "The domain with ID $id has been deleted." . PHP_EOL;
|
echo "The domain with ID $id has been deleted." . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue