commit c2d7c114d68f007480d4d0fe34ffed66b9c473a4
parent eb34f44292f894d01f2f77c71a5e0bb2e51ab44b
Author: Felix Kretschmer <5871630+fernwerker@users.noreply.github.com>
Date: Sun, 10 Nov 2019 19:00:12 +0100
Merge pull request #8 from b2un0/master
* ad ability to update also wildcard record
Diffstat:
3 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/examples/update-dyndns.sh b/examples/update-dyndns.sh
@@ -8,6 +8,7 @@ DOMAIN="my-home-nas.de"
#DOMAIN="nas.my-home.de"
SCRIPT="https://<url of your webspace>/update.php"
FORCE=0
+MODE="both" # can be undefined, "@", "*" or "both"
IPV4=$(curl -4 -q ident.me)
IPV6=$(curl -6 -q ident.me)
@@ -15,11 +16,11 @@ IPV6=$(curl -6 -q ident.me)
echo ${IPV4}
echo ${IPV6}
-# PAYLOAD_IPV4="force=${FORCE}&user=${USER}&password=${PASS}&ipv4=${IPV4}&domain=${DOMAIN}"
+# PAYLOAD_IPV4="force=${FORCE}&user=${USER}&password=${PASS}&ipv4=${IPV4}&domain=${DOMAIN}&mode=${MODE}"
# curl -X POST --data "${PAYLOAD_IPV4}" ${SCRIPT}
-# PAYLOAD_IPV6="force=${FORCE}&user=${USER}&password=${PASS}&ipv6=${IPV6}&domain=${DOMAIN}"
+# PAYLOAD_IPV6="force=${FORCE}&user=${USER}&password=${PASS}&ipv6=${IPV6}&domain=${DOMAIN}&mode=${MODE"}
# curl -X POST --data "${PAYLOAD_IPV6}" ${SCRIPT}
-PAYLOAD_BOTH="force=${FORCE}&user=${USER}&password=${PASS}&ipv4=${IPV4}&ipv6=${IPV6}&domain=${DOMAIN}"
+PAYLOAD_BOTH="force=${FORCE}&user=${USER}&password=${PASS}&ipv4=${IPV4}&ipv6=${IPV6}&domain=${DOMAIN}&mode=${MODE}"
curl -X POST --data "${PAYLOAD_BOTH}" ${SCRIPT}
diff --git a/src/Handler.php b/src/Handler.php
@@ -75,11 +75,11 @@ final class Handler
if (!$this->config->isLog()) {
return;
}
-
+
if (!file_exists($this->config->getLogFile())) {
- if (!touch($this->config->getLogFile())) {
- printf('[ERROR] unable to create %s %s', $this->config->getLogFile(), PHP_EOL);
- }
+ if (!touch($this->config->getLogFile())) {
+ printf('[ERROR] unable to create %s %s', $this->config->getLogFile(), PHP_EOL);
+ }
}
// save only the newest 100 log entries for each domain
@@ -125,7 +125,7 @@ final class Handler
$changes = false;
foreach ($infoHandle->responsedata->dnsrecords as $key => $record) {
- $recordHostnameReal = ($record->hostname !== '@') ? $record->hostname . '.' . $this->payload->getHostname() : $this->payload->getHostname();
+ $recordHostnameReal = (!in_array($record->hostname, $this->payload->getMatcher())) ? $record->hostname . '.' . $this->payload->getHostname() : $this->payload->getHostname();
if ($recordHostnameReal === $this->payload->getDomain()) {
@@ -137,7 +137,7 @@ final class Handler
)
) {
$record->destination = $this->payload->getIpv4();
- $this->doLog(sprintf('IPv4 for %s set to %s', $recordHostnameReal, $this->payload->getIpv4()));
+ $this->doLog(sprintf('IPv4 for %s set to %s', $record->hostname . '.' . $this->payload->getHostname(), $this->payload->getIpv4()));
$changes = true;
}
@@ -149,7 +149,7 @@ final class Handler
)
) {
$record->destination = $this->payload->getIpv6();
- $this->doLog(sprintf('IPv6 for %s set to %s', $recordHostnameReal, $this->payload->getIpv6()));
+ $this->doLog(sprintf('IPv6 for %s set to %s', $record->hostname . '.' . $this->payload->getHostname(), $this->payload->getIpv6()));
$changes = true;
}
}
diff --git a/src/Payload.php b/src/Payload.php
@@ -22,6 +22,11 @@ final class Payload
/**
* @var string
*/
+ private $mode;
+
+ /**
+ * @var string
+ */
private $ipv4;
/**
@@ -88,6 +93,23 @@ final class Payload
}
/**
+ * @return array
+ */
+ public function getMatcher()
+ {
+ switch ($this->mode) {
+ case 'both':
+ return ['@', '*'];
+
+ case '*':
+ return ['*'];
+
+ default:
+ return ['@'];
+ }
+ }
+
+ /**
* there is no good way to get the correct "registrable" Domain without external libs!
*
* @see https://github.com/jeremykendall/php-domain-parser