update ddns module
This commit is contained in:
parent
1488a3b8b7
commit
6d7407979d
@ -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<String> ip, Optional<String> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,8 +5,6 @@ package de.bstly.we.dyndns.controller;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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.PermissionManager;
|
||||||
import de.bstly.we.businesslogic.SystemPropertyManager;
|
|
||||||
import de.bstly.we.businesslogic.UserAliasManager;
|
import de.bstly.we.businesslogic.UserAliasManager;
|
||||||
import de.bstly.we.controller.BaseController;
|
import de.bstly.we.controller.BaseController;
|
||||||
import de.bstly.we.controller.support.EntityResponseStatusException;
|
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.DyndnsTokenManager;
|
||||||
import de.bstly.we.dyndns.businesslogic.DyndnsTokenPermissions;
|
import de.bstly.we.dyndns.businesslogic.DyndnsTokenPermissions;
|
||||||
import de.bstly.we.dyndns.model.DyndnsToken;
|
import de.bstly.we.dyndns.model.DyndnsToken;
|
||||||
@ -39,22 +30,16 @@ import de.bstly.we.model.User;
|
|||||||
@RequestMapping("/dyndns")
|
@RequestMapping("/dyndns")
|
||||||
public class DyndnsController extends BaseController {
|
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
|
@Autowired
|
||||||
private UserAliasManager userAliasManager;
|
private UserAliasManager userAliasManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private DyndnsTokenManager dyndnsTokenManager;
|
private DyndnsTokenManager dyndnsTokenManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private DyndnsManager dyndnsManager;
|
||||||
|
@Autowired
|
||||||
private PermissionManager permissionManager;
|
private PermissionManager permissionManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
@Autowired
|
|
||||||
private SystemPropertyManager systemPropertyManager;
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public void updateDns(@RequestParam("username") String name, @RequestParam("token") String token,
|
public void updateDns(@RequestParam("username") String name, @RequestParam("token") String token,
|
||||||
@ -84,28 +69,7 @@ public class DyndnsController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Name zone = Name.fromString("we.bstly.de.");
|
dyndnsManager.setRecord(name, ip, ipv6);
|
||||||
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());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
@ -458,11 +458,22 @@ public class MembershipManager {
|
|||||||
|
|
||||||
membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder);
|
membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder);
|
||||||
|
|
||||||
|
logger.debug("Create membership fee order: " + membershipFeeOrder.toString());
|
||||||
|
|
||||||
JsonObject expire = new JsonObject();
|
JsonObject expire = new JsonObject();
|
||||||
expire.addProperty("expires", pretixDateFormat.format(Date.from(expires)));
|
expire.addProperty("expires", pretixDateFormat.format(Date.from(expires)));
|
||||||
membershipFeeOrder = pretixManager.extendOrder(membershipFeeOrder.get("code").getAsString(), expire);
|
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
|
} else
|
||||||
// send reminder mail for membership fee order
|
// send reminder mail for membership fee order
|
||||||
if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0
|
if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0
|
||||||
|
2
pom.xml
2
pom.xml
@ -14,7 +14,7 @@
|
|||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<querydsl.version>5.0.0</querydsl.version>
|
<querydsl.version>5.0.0</querydsl.version>
|
||||||
<nimbus.version>9.37.3</nimbus.version>
|
<nimbus.version>9.37.3</nimbus.version>
|
||||||
<revision>3.0.3-SNAPSHOT</revision>
|
<revision>3.0.4-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
Loading…
Reference in New Issue
Block a user