X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomain.java;h=19594d7d3678d95ef94f6250231f7a76cd28cd0d;hb=5c20d966d8bfd34868ad3d428aed27986049f6b1;hp=1d31db61c2dee3dcf95dc122d74f4e5694344271;hpb=a0232b6e40e7e09767f0444d24e18bf12dafc362;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index 1d31db61..19594d7d 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -73,6 +73,12 @@ public class Domain implements IdCachable, Verifyable { if ( !s.equals(publicSuffix)) { throw new GigiApiException("You may only register a domain with exactly one lable before the public suffix."); } + if (("." + s).matches("(.[0-9]*)*")) { + // This is not reached because we currently have no TLD that is + // numbers only. But who knows.. + // Better safe than sorry. + throw new GigiApiException("IP Addresses are not allowed"); + } checkPunycode(parts[0], s.substring(parts[0].length() + 1)); } @@ -171,7 +177,7 @@ public class Domain implements IdCachable, Verifyable { LinkedList configs = this.configs; if (configs == null) { configs = new LinkedList<>(); - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=?")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=? AND `deleted` IS NULL")) { ps.setInt(1, id); GigiResultSet rs = ps.executeQuery(); while (rs.next()) { @@ -194,6 +200,14 @@ public class Domain implements IdCachable, Verifyable { configs = null; } + public void clearPings() throws GigiApiException { + try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `pingconfig` SET `deleted`=CURRENT_TIMESTAMP WHERE `deleted` is NULL AND `domainid`=?")) { + ps.setInt(1, id); + ps.execute(); + } + configs = null; + } + public synchronized void verify(String hash) throws GigiApiException { try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')")) { ps.setString(1, hash); @@ -235,14 +249,14 @@ public class Domain implements IdCachable, Verifyable { return em; } - public static int searchUserIdByDomain(String domain) { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `memid` FROM `domains` WHERE `domain` = ?")) { + public static Domain searchUserIdByDomain(String domain) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `domains` WHERE `domain` = ?")) { ps.setString(1, domain); GigiResultSet res = ps.executeQuery(); if (res.next()) { - return res.getInt(1); + return getById(res.getInt(1)); } else { - return -1; + return null; } } }