1
0
Fork 0
mirror of https://github.com/fernwerker/ownDynDNS.git synced 2025-07-10 22:25:13 +02:00

added return option for client validation

This commit is contained in:
Nils Blume 2023-08-22 14:19:35 +02:00
parent bd7d5bc672
commit 90a62128c0
4 changed files with 37 additions and 19 deletions

View file

@ -45,6 +45,12 @@ final class Config
*/
private $debug;
/**
* @var bool
*/
private $returnIp = true;
public function __construct(array $config)
{
foreach (get_object_vars($this) as $key => $val) {
@ -66,7 +72,6 @@ final class Config
!empty($this->apiPassword) &&
!empty($this->customerId) &&
!empty($this->logFile);
}
/**
@ -132,4 +137,12 @@ final class Config
{
return $this->debug;
}
/**
* @return bool
*/
public function isReturnIp()
{
return $this->returnIp;
}
}

View file

@ -135,6 +135,9 @@ final class Handler
$changes = false;
$ipv4changes = false;
$ipv6changes = false;
$txtchanges = false;
foreach ($infoHandle->responsedata->dnsrecords as $key => $record) {
$recordHostnameReal = (!in_array($record->hostname, $this->payload->getMatcher())) ? $record->hostname . '.' . $this->payload->getHostname() : $this->payload->getHostname();
@ -151,6 +154,7 @@ final class Handler
$record->destination = $this->payload->getIpv4();
$this->doLog(sprintf('IPv4 for %s set to %s', $record->hostname . '.' . $this->payload->getHostname(), $this->payload->getIpv4()));
$changes = true;
$ipv4changes = true;
}
// update AAAA Record if exists and IP has changed
@ -163,9 +167,10 @@ final class Handler
$record->destination = $this->payload->getIpv6();
$this->doLog(sprintf('IPv6 for %s set to %s', $record->hostname . '.' . $this->payload->getHostname(), $this->payload->getIpv6()));
$changes = true;
$ipv6changes = true;
}
// update TXT Record if exists and IP has changed
// update TXT Record if exists and content has changed
if ('TXT' === $record->type && $this->payload->getTxt() &&
(
$this->payload->isForce()
@ -175,11 +180,12 @@ final class Handler
$record->destination = $this->payload->getTxt();
$this->doLog(sprintf('TXT for %s set to %s', $record->hostname . '.' . $this->payload->getHostname(), $this->payload->getTxt()));
$changes = true;
$txtchanges = true;
}
}
}
if (true === $changes) {
if ($changes) {
$recordSet = new Soap\Dnsrecordset();
$recordSet->dnsrecords = $infoHandle->responsedata->dnsrecords;
@ -210,6 +216,17 @@ final class Handler
$this->doLog(sprintf('api logout failed, message: %s', $loginHandle->longmessage));
}
if ($this->config->isReturnIp()) {
if ($ipv4changes) {
echo "IPv4 changed: " . $this->payload->getIpv4() . "\n";
}
if ($ipv6changes) {
echo "IPv6 changed: " . $this->payload->getIpv6() . "\n";
}
if ($txtchanges) {
echo "TXT changed: " . $this->payload->getTxt() . "\n";
}
}
return $this;
}
}

View file

@ -17,16 +17,4 @@ if (!file_exists('.env')) {
$config = parse_ini_file('.env', false, INI_SCANNER_TYPED);
// Get the domains from the URL parameter and split them from the comma separated string
$domains = explode(',', $_REQUEST['domain']);
// Loop through each domain and call the Handler
foreach ($domains as $domain) {
// Create a new request object with the current domain
$request = $_REQUEST;
$request['domain'] = trim($domain);
// Call the Handler with the current domain
(new netcup\DNS\API\Handler($config, $request))->doRun();
}
(new netcup\DNS\API\Handler($config, $_REQUEST))->doRun();