diff --git a/bubble-server/src/main/java/bubble/model/cloud/BubbleDomain.java b/bubble-server/src/main/java/bubble/model/cloud/BubbleDomain.java index 4f930f9a..a377f252 100644 --- a/bubble-server/src/main/java/bubble/model/cloud/BubbleDomain.java +++ b/bubble-server/src/main/java/bubble/model/cloud/BubbleDomain.java @@ -13,6 +13,7 @@ import org.cobbzilla.wizard.model.Identifiable; import org.cobbzilla.wizard.model.IdentifiableBase; import org.cobbzilla.wizard.model.entityconfig.annotations.*; import org.cobbzilla.wizard.validation.HasValue; +import org.cobbzilla.wizard.validation.ValidationResult; import org.hibernate.annotations.Type; import javax.persistence.Column; @@ -25,6 +26,7 @@ import java.util.stream.Collectors; import static bubble.ApiConstants.EP_DOMAINS; import static bubble.model.cloud.AnsibleRole.sameRoleName; +import static org.apache.commons.lang3.StringUtils.countMatches; import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.dns.DnsType.NS; import static org.cobbzilla.util.dns.DnsType.SOA; @@ -141,13 +143,23 @@ public class BubbleDomain extends IdentifiableBase implements AccountTemplate { return addRole(current); } - public String networkFromFqdn(String fqdn) { - if (fqdn.endsWith("."+getName())) { - final String prefix = fqdn.substring(0, fqdn.length() - ("." + getName()).length()); - final int lastDot = prefix.lastIndexOf('.'); - return lastDot == -1 ? prefix : prefix.substring(lastDot+1); + public String networkFromFqdn(String fqdn, ValidationResult errors) { + if (!fqdn.endsWith("."+getName())) { + errors.addViolation("err.fqdn.outOfNetwork"); + return null; } - return die("networkFromFqdn("+fqdn+"): expected suffix ."+getName()); + final String prefix = fqdn.substring(0, fqdn.length() - ("." + getName()).length()); + final int dotCount = countMatches(prefix, '.'); + if (dotCount != -1) { + errors.addViolation("err.fqdn.invalid"); + return null; + } + final int lastDot = prefix.lastIndexOf('.'); + if (lastDot == -1) { + errors.addViolation("err.fqdn.invalid"); + return null; + } + return prefix.substring(lastDot+1); } public DnsRecordMatch matchSOA() { diff --git a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java index 9634d8ba..19a2ebc1 100644 --- a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java +++ b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java @@ -23,7 +23,6 @@ import bubble.resources.account.AccountOwnedResource; import bubble.server.BubbleConfiguration; import bubble.service.AuthenticatorService; import lombok.extern.slf4j.Slf4j; -import org.apache.poi.util.StringUtil; import org.cobbzilla.wizard.validation.ValidationResult; import org.glassfish.grizzly.http.server.Request; import org.glassfish.jersey.server.ContainerRequest; @@ -39,7 +38,8 @@ import java.util.stream.Collectors; import static bubble.ApiConstants.*; import static bubble.model.cloud.BubbleNetwork.validateHostname; -import static org.cobbzilla.util.string.ValidationRegexes.*; +import static org.cobbzilla.util.string.ValidationRegexes.HOST_PATTERN; +import static org.cobbzilla.util.string.ValidationRegexes.validateRegexMatches; import static org.cobbzilla.wizard.resources.ResourceUtil.*; @Slf4j @@ -137,14 +137,8 @@ public class AccountPlansResource extends AccountOwnedResource