From 90a62128c02d56d66f68c5eaed16944978985ab5 Mon Sep 17 00:00:00 2001 From: Nils Blume Date: Tue, 22 Aug 2023 14:19:35 +0200 Subject: [PATCH] added return option for client validation --- src/Config.php | 19 ++++++++++++++++--- src/Handler.php | 21 +++++++++++++++++++-- src/Payload.php | 2 +- update.php | 14 +------------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Config.php b/src/Config.php index ae4d0a9..a53be79 100644 --- a/src/Config.php +++ b/src/Config.php @@ -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); - } /** @@ -116,7 +121,7 @@ final class Config { return $this->log; } - + /** * @return string */ @@ -132,4 +137,12 @@ final class Config { return $this->debug; } -} \ No newline at end of file + + /** + * @return bool + */ + public function isReturnIp() + { + return $this->returnIp; + } +} diff --git a/src/Handler.php b/src/Handler.php index 8bf4e11..17206e7 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -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; } } diff --git a/src/Payload.php b/src/Payload.php index 921dc14..09da2ed 100644 --- a/src/Payload.php +++ b/src/Payload.php @@ -182,7 +182,7 @@ final class Payload { return $this->txt; } - + /** * @return bool */ diff --git a/update.php b/update.php index aab42c2..24bac06 100755 --- a/update.php +++ b/update.php @@ -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();