From f6a1d3cb571af8a2760e4cf29d6507056ca358d6 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 13 Dec 2023 20:39:59 +0100 Subject: [PATCH] setup dyndns service --- .../dyndns/controller/DyndnsController.java | 22 ++++++++++++++----- pom.xml | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dyndns/src/main/java/de/bstly/we/dyndns/controller/DyndnsController.java b/dyndns/src/main/java/de/bstly/we/dyndns/controller/DyndnsController.java index 84c246c..84da034 100644 --- a/dyndns/src/main/java/de/bstly/we/dyndns/controller/DyndnsController.java +++ b/dyndns/src/main/java/de/bstly/we/dyndns/controller/DyndnsController.java @@ -5,6 +5,8 @@ package de.bstly.we.dyndns.controller; import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.security.crypto.password.PasswordEncoder; @@ -12,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.xbill.DNS.Message; import org.xbill.DNS.Name; import org.xbill.DNS.Resolver; import org.xbill.DNS.SimpleResolver; @@ -36,7 +39,10 @@ import de.bstly.we.model.User; @RequestMapping("/dyndns") public class DyndnsController extends BaseController { + private Logger logger = LoggerFactory.getLogger(DyndnsController.class); + public static final String SYSTEM_PROPERTY_DYNDNS_HOSTNAME = "dyndns.hostname"; + public static final String SYSTEM_PROPERTY_DYNDNS_KEY_NAME = "dyndns.keyname"; public static final String SYSTEM_PROPERTY_DYNDNS_KEY = "dyndns.key"; @Autowired @@ -78,24 +84,28 @@ public class DyndnsController extends BaseController { } try { - Name zone = Name.fromString(name + ".we.bstly.de."); - Name host = Name.fromString("host", zone); + Name zone = Name.fromString("we.bstly.de."); + Name host = Name.fromString(name, zone); Update update = new Update(zone); if (ip.isPresent()) { - update.replace(host, Type.A, 3600, ip.get()); + update.replace(host, Type.A, 300, ip.get()); } if (ipv6.isPresent()) { - update.replace(host, Type.AAAA, 3600, ipv6.get()); + update.replace(host, Type.AAAA, 300, ipv6.get()); } String hostname = systemPropertyManager.get(SYSTEM_PROPERTY_DYNDNS_HOSTNAME, "127.0.0.1"); + String keyName = systemPropertyManager.get(SYSTEM_PROPERTY_DYNDNS_KEY_NAME, ""); String key = systemPropertyManager.get(SYSTEM_PROPERTY_DYNDNS_KEY, ""); Resolver res = new SimpleResolver(hostname); - res.setTSIGKey(new TSIG(TSIG.HMAC_SHA512, host, key)); + res.setTSIGKey(new TSIG(TSIG.HMAC_SHA512, keyName, key)); res.setTCP(true); - res.send(update); + Message response = res.send(update); + + logger.debug("\nDynDNS for " + name + "with\nIP:\t" + ip.orElse("-") + "\nIPV6:\t" + ipv6.orElse("-") + "\n\n" + + response.toString()); } catch (Exception e) { e.printStackTrace(); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); diff --git a/pom.xml b/pom.xml index 56d6b50..a9bd7a5 100755 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 17 5.0.0 9.37.3 - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT