Compare commits

...

2 Commits

Author SHA1 Message Date
tracer f1732c4f26 added error check on domain creation
Signed-off-by: tracer <tracer@24unix.net>
2022-02-13 16:35:38 +01:00
tracer 8f2545dd7e changed API call from panel_id to name
Signed-off-by: tracer <tracer@24unix.net>
2022-02-13 16:35:02 +01:00
2 changed files with 31 additions and 22 deletions

View File

@ -336,12 +336,14 @@ class BindAPI
} }
/** /**
* @param String $domainName * @param String $domainName
* @param $panel * @param \App\Entity\Panel $panel
* *
* @return void * @return void
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
*/ */
function checkNS(string $domainName, $panel) function checkNS(string $domainName, Panel $panel)
{ {
if ($this->config['debug']) { if ($this->config['debug']) {
$this->log->debug(message: "checkNS()"); $this->log->debug(message: "checkNS()");
@ -385,34 +387,35 @@ class BindAPI
switch ($result['header']) { switch ($result['header']) {
case 200: case 200:
echo COLOR_GREEN . ' OK'; echo COLOR_GREEN . ' OK';
break; break;
case 404: 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') {
echo 'trying to fix …'; echo 'trying to fix …';
$body = [ $body = [
'name' => $domainName, 'name' => $domainName,
'panel_id' => $panel['id'] 'panel' => $panel->getName(),
]; 'content' => $this->domainController->createPanelContent(panel: $panel->getName())
];
try { try {
if (!empty($nameServer['aaaa'])) { if (!empty($nameServer->getAaaa())) {
$this->apiController->sendCommand( $create = $this->apiController->sendCommand(
requestType: 'POST', requestType: 'POST',
serverName: $nameServer['name'], serverName: $nameServer->getName(),
versionIP: 6, versionIP: 6,
apiKey: $nameServer['apikey'], apiKey: $nameServer->getApikey(),
command: 'domains/name', command: 'domains',
serverType: 'nameserver', serverType: 'nameserver',
body: $body); body: $body);
} else { } else {
$this->apiController->sendCommand( $create = $this->apiController->sendCommand(
requestType: 'POST', requestType: 'POST',
serverName: $nameServer['name'], serverName: $nameServer->getName(),
versionIP: 4, versionIP: 4,
apiKey: $nameServer['apikey'], apiKey: $nameServer->getAPikey(),
command: 'domains/name', command: 'domains',
serverType: 'nameserver', serverType: 'nameserver',
body: $body); body: $body);
} }
@ -420,6 +423,7 @@ class BindAPI
echo $e->getMessage(); echo $e->getMessage();
exit(1); exit(1);
} }
print_r($create);
} }
break; break;
default: default:

View File

@ -361,14 +361,14 @@ class RequestController
function handleDomainPostRequest(): void function handleDomainPostRequest(): void
{ {
$name = $_POST['name'] ?? ''; $name = $_POST['name'] ?? '';
$panelID = intval(value: $_POST['panel_id'] ?? 0); $panel = $_POST['panel'] ?? '';
$content = $_POST['content'] ?? ''; $content = $_POST['content'] ?? '';
if (empty($name)) { if (empty($name)) {
$this->header = "400 Bad Request"; $this->header = "400 Bad Request";
$this->status = "400 Bad Request"; $this->status = "400 Bad Request";
$this->message = "A name is required"; $this->message = "A name is required";
} else { } else {
if (empty($a) && empty($aaaa) && empty($panelID)) { if (empty($a) && empty($aaaa) && empty($panel)) {
$this->header = "400 Bad Request"; $this->header = "400 Bad Request";
$this->status = "400 Bad Request"; $this->status = "400 Bad Request";
$this->message = "At least one IP address or panel ID is required."; $this->message = "At least one IP address or panel ID is required.";
@ -379,9 +379,14 @@ class RequestController
$this->message = "Domain: $name already exists."; $this->message = "Domain: $name already exists.";
} else { } else {
$domain = new Domain(name: $name, content: $content); $domain = new Domain(name: $name, content: $content);
$result = $this->domainRepository->insert(domain: $domain); if ($result = $this->domainRepository->insert(domain: $domain)) {
$this->status = "201 Created"; $this->status = "201 Created";
$this->message = $result; $this->message = $result;
} else {
$this->header = "500 Server error";
$this->status = "500 Server error";
$this->message = $result;
}
} }
} }
} }