added 404 fpr DynDNS

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-03-10 20:05:42 +01:00
parent 4d0be96915
commit 5a71d5efde
1 changed files with 66 additions and 60 deletions

View File

@ -13,9 +13,9 @@ use DI\ContainerBuilder;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use OpenApi\Attributes as OAT;
use UnhandledMatchError;
use function DI\autowire;
use OpenApi\Attributes as OAT;
/**
*
@ -499,15 +499,15 @@ class RequestController
*
* @return string
*/
private function getDomain(String $host): string
private function getDomain(string $host): string
{
$host = strtolower(string: trim(string: $host));
$count = substr_count(haystack: $host, needle: '.');
if ($count == 2){
if ($count == 2) {
if (strlen(string: explode(separator: '.', string: $host)[1]) > 3) {
$host = explode(separator: '.', string: $host, limit: 2)[1];
}
} else if ($count > 2) {
} elseif ($count > 2) {
$host = $this->getDomain(host: explode(separator: '.', string: $host, limit: 2)[1]);
}
return $host;
@ -544,19 +544,19 @@ class RequestController
if (!empty($panel->getAaaa())) {
$domainData = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $panel->getApikey(),
command: 'domains/name/' . $domainName,
serverType: 'panel');
serverName : $panel->getName(),
versionIP : 6,
apiKey : $panel->getApikey(),
command : 'domains/name/' . $domainName,
serverType : 'panel');
} else {
$domainData = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $panel->getApikey(),
command: 'domains/name/' . $domainName,
serverType: 'panel');
serverName : $panel->getName(),
versionIP : 4,
apiKey : $panel->getApikey(),
command : 'domains/name/' . $domainName,
serverType : 'panel');
}
$domainDecodedData = json_decode(json: $domainData['data']);
@ -565,27 +565,30 @@ class RequestController
if (!empty($panel->getAaaa())) {
$dnsData = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $panel->getApikey(),
command: 'dns/' . $domainID,
serverType: 'panel');
serverName : $panel->getName(),
versionIP : 6,
apiKey : $panel->getApikey(),
command : 'dns/' . $domainID,
serverType : 'panel');
} else {
$dnsData = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $panel->getApikey(),
command: 'dns/' . $domainID,
serverType: 'panel');
serverName : $panel->getName(),
versionIP : 4,
apiKey : $panel->getApikey(),
command : 'dns/' . $domainID,
serverType : 'panel');
}
$dnsDataDecoded = json_decode(json: $dnsData['data']);
$soa = $dnsDataDecoded->records->soa;
$others = $dnsDataDecoded->records->other;
$updateHost = function(object $host) use ($hostName, $a, $aaaa) {
$hostFound = false;
$updateHost = function (object $host) use ($hostName, $a, $aaaa, &$hostFound) {
if ($host->host == $hostName) {
$hostFound = true;
if ($host->type == 'A') {
if (!empty($a)) {
$host->value = $a;
@ -600,6 +603,7 @@ class RequestController
array_map(callback: $updateHost, array: $others);
if ($hostFound) {
$newDnsData = json_encode(value: [
'records' => [
'soa' => $soa,
@ -610,32 +614,34 @@ class RequestController
if (!empty($panel->getAaaa())) {
$result = $this->apiController->sendCommand(
requestType: 'PUT',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $panel->getApikey(),
command: 'dns/' . $domainID,
serverType: 'panel',
body: json_decode(json: $newDnsData, associative: true)
serverName : $panel->getName(),
versionIP : 6,
apiKey : $panel->getApikey(),
command : 'dns/' . $domainID,
serverType : 'panel',
body : json_decode(json: $newDnsData, associative: true)
);
} else {
$result = $this->apiController->sendCommand(
requestType: 'PUT',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $panel->getApikey(),
command: 'dns/' . $domainID,
serverType: 'panel',
body: json_decode(json: $newDnsData, associative: true)
serverName : $panel->getName(),
versionIP : 4,
apiKey : $panel->getApikey(),
command : 'dns/' . $domainID,
serverType : 'panel',
body : json_decode(json: $newDnsData, associative: true)
);
}
if ($result['header'] == 200) {
$this->header = '200 OK';
$this->status = json_encode(value: ['message' => 'Domain successfully updated']);
$this->status = json_encode(value: ['message' => 'DynDNS host successfully updated']);
}
} else {
$this->header = '404 Not Found';
$this->status = 'Host ' . COLOR_YELLOW . $hostName . ' not found';
}
}
}
}
}