Skip to content

Commit

Permalink
Issue #81: Update box addresses from DynDNS after registration failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
haumacher committed Nov 3, 2024
1 parent 3af0156 commit af672a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import de.haumacher.phoneblock.answerbot.CustomerConfig;
import de.haumacher.phoneblock.answerbot.CustomerOptions;
import de.haumacher.phoneblock.db.DB;
import de.haumacher.phoneblock.db.DBAnswerBotDynDns;
import de.haumacher.phoneblock.db.DBAnswerBotSip;
import de.haumacher.phoneblock.db.DBService;
import de.haumacher.phoneblock.db.DBUserSettings;
Expand Down Expand Up @@ -318,6 +319,22 @@ private void registerBots() {
private String getHost(AnswerBotSip bot) throws UnknownHostException {
String host = bot.getHost();
if (host == null || host.isEmpty()) {
// Lookup DynDNS address.
DBAnswerBotDynDns dynDns;
try (SqlSession tx = _dbService.db().openSession()) {
Users users = tx.getMapper(Users.class);

dynDns = users.getDynDnsForAB(bot.getId());
}

if (dynDns == null) {
throw new UnknownHostException("Neither host name nor DynDNS configured for: " + bot.getUserName());
} else {
// Update addresses.
bot.setIpv4(dynDns.getIpv4());
bot.setIpv6(dynDns.getIpv6());
}

String ipv6 = bot.getIpv6();
if (ipv6 != null && !ipv6.isEmpty()) {
LOG.info("Using DynDNS IPv6 address for '" + bot.getUserName() + "': " + ipv6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public interface Users {
@Select("select ABID, USERID, CREATED, UPDATED, DYNDNS_USER, DYNDNS_PASSWD, IP4, IP6 from ANSWERBOT_DYNDNS where DYNDNS_USER=#{dynDnsUser}")
DBAnswerBotDynDns getDynDns(String dynDnsUser);

@Select("select ABID, USERID, CREATED, UPDATED, DYNDNS_USER, DYNDNS_PASSWD, IP4, IP6 from ANSWERBOT_DYNDNS where ABID=#{abId}")
DBAnswerBotDynDns getDynDnsForAB(long abId);

@Select("select ABID, USERID, CREATED, UPDATED, DYNDNS_USER, DYNDNS_PASSWD, IP4, IP6 from ANSWERBOT_DYNDNS")
List<DBAnswerBotDynDns> getDynDnsUsers();

Expand Down

0 comments on commit af672a6

Please sign in to comment.