Compare commits
No commits in common. "c8cb2049a07c9817a682825aeb74669c578e1694" and "0a67c168628698c4121fcec11872c3ec8534ecf6" have entirely different histories.
c8cb2049a0
...
0a67c16862
|
@ -94,9 +94,6 @@
|
|||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"204": {
|
||||
"description": "No Content"
|
||||
},
|
||||
"401": {
|
||||
"description": "API key is missing or invalid."
|
||||
},
|
||||
|
|
|
@ -57,7 +57,7 @@ class RequestController
|
|||
private DomainController $domainController;
|
||||
private DomainRepository $domainRepository;
|
||||
private PanelRepository $panelRepository;
|
||||
private DynDNSRepository $dynDNSRepository;
|
||||
private DynDNSRepository $DynDNSRepository;
|
||||
private Container $container;
|
||||
private string $header;
|
||||
private array $result;
|
||||
|
@ -561,21 +561,20 @@ class RequestController
|
|||
$this->header = '404 Not Found';
|
||||
$this->message = 'Domain ' . $domainName . ' not found';
|
||||
} else {
|
||||
|
||||
// check if address has changed
|
||||
if ($dynDNS = $this->dynDNSRepository->findByName(name: $host)) {
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: 'found host: ' . $host);
|
||||
$this->log->debug(message: "a: $a");
|
||||
$this->log->debug(message: "aaaa: $aaaa");
|
||||
}
|
||||
echo 'found host';
|
||||
print_r($dynDNS);
|
||||
|
||||
print("a: $a");
|
||||
print("aaaa: $aaaa");
|
||||
|
||||
$ipChanged = false;
|
||||
|
||||
if (!empty($a)) {
|
||||
if ($a != $dynDNS->getA()) {
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: $a . ' != ' . $dynDNS->getA());
|
||||
}
|
||||
echo $a . '!=' . $dynDNS->getA();
|
||||
$dynDNS->setA(a: $a);
|
||||
$ipChanged = true;
|
||||
}
|
||||
|
@ -583,129 +582,125 @@ class RequestController
|
|||
|
||||
if (!empty($aaaa)) {
|
||||
if ($aaaa != $dynDNS->getAaaa()) {
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: $aaaa . ' != ' . $dynDNS->getAaaa());
|
||||
}
|
||||
$dynDNS->setAaaa(aaaa: $aaaa);
|
||||
|
||||
$ipChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ipChanged) {
|
||||
if (!$ipChanged) {
|
||||
$this->header = '304 Not Modified';
|
||||
$this->message = 'Not modified';
|
||||
|
||||
} else {
|
||||
$this->dynDNSRepository->update(dynDNS: $dynDNS);
|
||||
}
|
||||
} else {
|
||||
$dynDNS = new DynDNS(name: $host, a: $a, aaaa: $aaaa);
|
||||
$this->dynDNSRepository->insert(dynDNS: $dynDNS);
|
||||
$ipChanged = true;
|
||||
}
|
||||
|
||||
|
||||
if ($ipChanged) {
|
||||
$panel = $this->panelRepository->findByName(name: $domain->getPanel());
|
||||
|
||||
if (!empty($panel->getAaaa())) {
|
||||
$domainData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
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');
|
||||
}
|
||||
|
||||
$domainDecodedData = json_decode(json: $domainData['data']);
|
||||
$domainID = $domainDecodedData->id;
|
||||
|
||||
if (!empty($panel->getAaaa())) {
|
||||
$dnsData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
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');
|
||||
}
|
||||
|
||||
$dnsDataDecoded = json_decode(json: $dnsData['data']);
|
||||
$soa = $dnsDataDecoded->records->soa;
|
||||
$others = $dnsDataDecoded->records->other;
|
||||
|
||||
$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;
|
||||
}
|
||||
} else {
|
||||
if (!empty($aaaa)) {
|
||||
$host->value = $aaaa;
|
||||
}
|
||||
$panel = $this->panelRepository->findByName(name: $domain->getPanel());
|
||||
|
||||
if (!empty($panel->getAaaa())) {
|
||||
$domainData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
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');
|
||||
}
|
||||
|
||||
$domainDecodedData = json_decode(json: $domainData['data']);
|
||||
$domainID = $domainDecodedData->id;
|
||||
|
||||
if (!empty($panel->getAaaa())) {
|
||||
$dnsData = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
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');
|
||||
}
|
||||
|
||||
$dnsDataDecoded = json_decode(json: $dnsData['data']);
|
||||
$soa = $dnsDataDecoded->records->soa;
|
||||
$others = $dnsDataDecoded->records->other;
|
||||
|
||||
$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;
|
||||
}
|
||||
} else {
|
||||
if (!empty($aaaa)) {
|
||||
$host->value = $aaaa;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
array_map(callback: $updateHost, array: $others);
|
||||
|
||||
if ($hostFound) {
|
||||
$newDnsData = json_encode(value: [
|
||||
'records' => [
|
||||
'soa' => $soa,
|
||||
'other' => $others
|
||||
]
|
||||
]);
|
||||
|
||||
array_map(callback: $updateHost, array: $others);
|
||||
|
||||
if ($hostFound) {
|
||||
$newDnsData = json_encode(value: [
|
||||
'records' => [
|
||||
'soa' => $soa,
|
||||
'other' => $others
|
||||
]
|
||||
]);
|
||||
|
||||
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)
|
||||
);
|
||||
} 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)
|
||||
);
|
||||
}
|
||||
if ($result['header'] == 200) {
|
||||
$this->header = '200 OK';
|
||||
$this->message = 'DynDNS host successfully updated';
|
||||
}
|
||||
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)
|
||||
);
|
||||
} else {
|
||||
$this->header = '404 Not Found';
|
||||
$this->message = 'Host ' . $hostName . ' not found';
|
||||
$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)
|
||||
);
|
||||
}
|
||||
if ($result['header'] == 200) {
|
||||
$this->header = '200 OK';
|
||||
$this->message = 'DynDNS host successfully updated';
|
||||
}
|
||||
} else {
|
||||
$this->header = '204 No content';
|
||||
$this->message = 'No content';
|
||||
$this->header = '404 Not Found';
|
||||
$this->message = 'Host ' . $hostName . ' not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue