diff --git a/dyndns/src/main/java/de/bstly/we/dyndns/businesslogic/DyndnsManager.java b/dyndns/src/main/java/de/bstly/we/dyndns/businesslogic/DyndnsManager.java new file mode 100644 index 0000000..262db74 --- /dev/null +++ b/dyndns/src/main/java/de/bstly/we/dyndns/businesslogic/DyndnsManager.java @@ -0,0 +1,75 @@ +/** + * + */ +package de.bstly.we.dyndns.businesslogic; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.xbill.DNS.Message; +import org.xbill.DNS.Name; +import org.xbill.DNS.Resolver; +import org.xbill.DNS.SimpleResolver; +import org.xbill.DNS.TSIG; +import org.xbill.DNS.Type; +import org.xbill.DNS.Update; + +import de.bstly.we.businesslogic.SystemPropertyManager; + +/** + * The Class DyndnsTokenManager. + */ +@Component +public class DyndnsManager { + + 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"; + public static final String SYSTEM_PROPERTY_DYNDNS_ZONE = "dyndns.zone"; + public static final String SYSTEM_PROPERTY_DYNDNS_TTL = "dyndns.ttl"; + + private Logger logger = LoggerFactory.getLogger(DyndnsManager.class); + + @Autowired + private SystemPropertyManager systemPropertyManager; + + public void setRecord(String name, Optional ip, Optional ipv6) throws Exception { + String zoneValue = systemPropertyManager.get(SYSTEM_PROPERTY_DYNDNS_ZONE); + + if (!StringUtils.hasText(zoneValue)) { + logger.warn("Missing DynDNS zone, cannot set record"); + return; + } + + long ttl = systemPropertyManager.getLong(SYSTEM_PROPERTY_DYNDNS_TTL, 300); + + Name zone = Name.fromString(zoneValue); + Name host = Name.fromString(name.toLowerCase(), zone); + Update update = new Update(zone); + if (ip.isPresent()) { + update.replace(host, Type.A, ttl, ip.get()); + } + if (ipv6.isPresent()) { + update.replace(host, Type.AAAA, ttl, 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, keyName, key)); + res.setTCP(true); + + Message response = res.send(update); + + logger.debug( + "\nDynDNS for '" + name + "' with\nIP:\t" + ip.orElse("-") + "\nIPV6:\t" + ipv6.orElse("-") + "\n\n" + + response.toString()); + } + +} 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 74f7e20..c9a588c 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,8 +5,6 @@ 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; @@ -14,19 +12,12 @@ 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; -import org.xbill.DNS.TSIG; -import org.xbill.DNS.Type; -import org.xbill.DNS.Update; import de.bstly.we.businesslogic.PermissionManager; -import de.bstly.we.businesslogic.SystemPropertyManager; import de.bstly.we.businesslogic.UserAliasManager; import de.bstly.we.controller.BaseController; import de.bstly.we.controller.support.EntityResponseStatusException; +import de.bstly.we.dyndns.businesslogic.DyndnsManager; import de.bstly.we.dyndns.businesslogic.DyndnsTokenManager; import de.bstly.we.dyndns.businesslogic.DyndnsTokenPermissions; import de.bstly.we.dyndns.model.DyndnsToken; @@ -39,22 +30,16 @@ 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 private UserAliasManager userAliasManager; @Autowired private DyndnsTokenManager dyndnsTokenManager; @Autowired + private DyndnsManager dyndnsManager; + @Autowired private PermissionManager permissionManager; @Autowired private PasswordEncoder passwordEncoder; - @Autowired - private SystemPropertyManager systemPropertyManager; @GetMapping public void updateDns(@RequestParam("username") String name, @RequestParam("token") String token, @@ -84,28 +69,7 @@ public class DyndnsController extends BaseController { } try { - Name zone = Name.fromString("we.bstly.de."); - Name host = Name.fromString(name.toLowerCase(), zone); - Update update = new Update(zone); - if (ip.isPresent()) { - update.replace(host, Type.A, 300, ip.get()); - } - if (ipv6.isPresent()) { - 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, keyName, key)); - res.setTCP(true); - - Message response = res.send(update); - - logger.debug("\nDynDNS for '" + name + "' with\nIP:\t" + ip.orElse("-") + "\nIPV6:\t" + ipv6.orElse("-") + "\n\n" + - response.toString()); + dyndnsManager.setRecord(name, ip, ipv6); } catch (Exception e) { e.printStackTrace(); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); diff --git a/membership/src/main/java/de/bstly/we/membership/businesslogic/MembershipManager.java b/membership/src/main/java/de/bstly/we/membership/businesslogic/MembershipManager.java index 4abc4be..c31ad60 100644 --- a/membership/src/main/java/de/bstly/we/membership/businesslogic/MembershipManager.java +++ b/membership/src/main/java/de/bstly/we/membership/businesslogic/MembershipManager.java @@ -458,11 +458,22 @@ public class MembershipManager { membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder); + logger.debug("Create membership fee order: " + membershipFeeOrder.toString()); + JsonObject expire = new JsonObject(); expire.addProperty("expires", pretixDateFormat.format(Date.from(expires))); membershipFeeOrder = pretixManager.extendOrder(membershipFeeOrder.get("code").getAsString(), expire); - logger.debug("Create membership fee order: " + membershipFeeOrder.toString()); + logger.debug("Extend membership fee order: " + membershipFeeOrder.get("code").getAsString() + " to " + + pretixDateFormat.format(Date.from(expires))); + + /* + * if (orderSendmail) { + * pretixManager.sendEmail(membershipFeeOrder.get("code").getAsString()); + * logger.debug("Resend link membership fee order: " + + * membershipFeeOrder.get("code").getAsString()); + * } + */ } else // send reminder mail for membership fee order if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0 diff --git a/pom.xml b/pom.xml index 47e1f3a..4b7aebd 100755 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 17 5.0.0 9.37.3 - 3.0.3-SNAPSHOT + 3.0.4-SNAPSHOT