Search in sources :

Example 11 with InternetDomainName

use of com.google.common.net.InternetDomainName in project nomulus by google.

the class DnsUpdateWriter method publishHost.

@Override
public void publishHost(String hostName) {
    // Get the superordinate domain name of the host.
    InternetDomainName host = InternetDomainName.from(hostName);
    ImmutableList<String> hostParts = host.parts();
    Optional<InternetDomainName> tld = Registries.findTldForName(host);
    // host not managed by our registry, no need to update DNS.
    if (!tld.isPresent()) {
        return;
    }
    ImmutableList<String> tldParts = tld.get().parts();
    ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1, hostParts.size());
    String domain = Joiner.on(".").join(domainParts);
    // Refresh the superordinate domain, always delete the host first to ensure idempotency,
    // and only publish the host if it is a glue record.
    publishDomain(domain, hostName);
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 12 with InternetDomainName

use of com.google.common.net.InternetDomainName in project nomulus by google.

the class WhoisReader method parseCommand.

/**
 * Given a WHOIS command string, parse it into its command type and target string. See class level
 * comments for a full description of the command syntax accepted.
 */
private WhoisCommand parseCommand(String command, boolean fullOutput, DateTime now) throws WhoisException {
    // Split the string into tokens based on whitespace.
    List<String> tokens = filterEmptyStrings(command.split("\\s"));
    if (tokens.isEmpty()) {
        throw new WhoisException(now, SC_BAD_REQUEST, "No WHOIS command specified.");
    }
    final String arg1 = tokens.get(0);
    // Check if the first token is equal to the domain lookup command.
    if (arg1.equalsIgnoreCase(DOMAIN_LOOKUP_COMMAND)) {
        if (tokens.size() != 2) {
            throw new WhoisException(now, SC_BAD_REQUEST, String.format("Wrong number of arguments to '%s' command.", DOMAIN_LOOKUP_COMMAND));
        }
        // Try to parse the argument as a domain name.
        try {
            logger.atInfo().log("Attempting domain lookup command using domain name '%s'.", tokens.get(1));
            return commandFactory.domainLookup(InternetDomainName.from(canonicalizeHostname(tokens.get(1))), fullOutput, whoisRedactedEmailText);
        } catch (IllegalArgumentException iae) {
            // If we can't interpret the argument as a host name, then return an error.
            throw new WhoisException(now, SC_BAD_REQUEST, String.format("Could not parse argument to '%s' command", DOMAIN_LOOKUP_COMMAND));
        }
    }
    // Check if the first token is equal to the nameserver lookup command.
    if (arg1.equalsIgnoreCase(NAMESERVER_LOOKUP_COMMAND)) {
        if (tokens.size() != 2) {
            throw new WhoisException(now, SC_BAD_REQUEST, String.format("Wrong number of arguments to '%s' command.", NAMESERVER_LOOKUP_COMMAND));
        }
        // Try to parse the argument as an IP address.
        try {
            logger.atInfo().log("Attempting nameserver lookup command using %s as an IP address.", tokens.get(1));
            return commandFactory.nameserverLookupByIp(InetAddresses.forString(tokens.get(1)));
        } catch (IllegalArgumentException iae) {
        // Silently ignore this exception.
        }
        // Try to parse the argument as a host name.
        try {
            logger.atInfo().log("Attempting nameserver lookup command using %s as a hostname.", tokens.get(1));
            return commandFactory.nameserverLookupByHost(InternetDomainName.from(canonicalizeHostname(tokens.get(1))));
        } catch (IllegalArgumentException iae) {
        // Silently ignore this exception.
        }
        // If we can't interpret the argument as either a host name or IP address, return an error.
        throw new WhoisException(now, SC_BAD_REQUEST, String.format("Could not parse argument to '%s' command", NAMESERVER_LOOKUP_COMMAND));
    }
    // Check if the first token is equal to the registrar lookup command.
    if (arg1.equalsIgnoreCase(REGISTRAR_LOOKUP_COMMAND)) {
        if (tokens.size() == 1) {
            throw new WhoisException(now, SC_BAD_REQUEST, String.format("Too few arguments to '%s' command.", REGISTRAR_LOOKUP_COMMAND));
        }
        String registrarLookupArgument = Joiner.on(' ').join(tokens.subList(1, tokens.size()));
        logger.atInfo().log("Attempting registrar lookup command using registrar %s.", registrarLookupArgument);
        return commandFactory.registrarLookup(registrarLookupArgument);
    }
    // If we have a single token, then try to interpret that in various ways.
    if (tokens.size() == 1) {
        // Try to parse it as an IP address. If successful, then this is a lookup on a nameserver.
        try {
            logger.atInfo().log("Attempting nameserver lookup using %s as an IP address.", arg1);
            return commandFactory.nameserverLookupByIp(InetAddresses.forString(arg1));
        } catch (IllegalArgumentException iae) {
        // Silently ignore this exception.
        }
        // Try to parse it as a domain name or host name.
        try {
            final InternetDomainName targetName = InternetDomainName.from(canonicalizeHostname(arg1));
            // We don't know at this point whether we have a domain name or a host name. We have to
            // search through our configured TLDs to see if there's one that prefixes the name.
            Optional<InternetDomainName> tld = findTldForName(targetName);
            if (!tld.isPresent()) {
                // This target is not under any configured TLD, so just try it as a registrar name.
                logger.atInfo().log("Attempting registrar lookup using %s as a registrar.", arg1);
                return commandFactory.registrarLookup(arg1);
            }
            // (SLD) and we should do a domain lookup on it.
            if (targetName.parent().equals(tld.get())) {
                logger.atInfo().log("Attempting domain lookup using %s as a domain name.", targetName);
                return commandFactory.domainLookup(targetName, fullOutput, whoisRedactedEmailText);
            }
            // The target is more than one level above the TLD, so we'll assume it's a nameserver.
            logger.atInfo().log("Attempting nameserver lookup using %s as a hostname.", targetName);
            return commandFactory.nameserverLookupByHost(targetName);
        } catch (IllegalArgumentException e) {
        // Silently ignore this exception.
        }
    // Purposefully fall through to code below.
    }
    // The only case left is that there are multiple tokens with no particular command given. We'll
    // assume this is a registrar lookup, since there's really nothing else it could be.
    String registrarLookupArgument = Joiner.on(' ').join(tokens);
    logger.atInfo().log("Attempting registrar lookup employing %s as a registrar.", registrarLookupArgument);
    return commandFactory.registrarLookup(registrarLookupArgument);
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 13 with InternetDomainName

use of com.google.common.net.InternetDomainName in project domain_hunter_pro by bit4woo.

the class DomainNameUtils method isTLDDomain.

/**
 * 是否是TLD域名。比如 baidu.net 是baidu.com的TLD域名
 * 注意:www.baidu.com不是baidu.com的TLD域名,但是是子域名!!!
 *
 * 这里的rootDomain不一定是 topPrivate。比如 examplepay.example.sg 和examplepay.example.io
 * @param domain
 * @param rootDomain
 */
// 范围太广,误报太多
@Deprecated
private static boolean isTLDDomain(String domain, String rootDomain) {
    try {
        InternetDomainName suffixDomain = InternetDomainName.from(domain).publicSuffix();
        InternetDomainName suffixRootDomain = InternetDomainName.from(rootDomain).publicSuffix();
        if (suffixDomain != null && suffixRootDomain != null) {
            String suffixOfDomain = suffixDomain.toString();
            // TODO 校验一下;gettitle控制
            String suffixOfRootDomain = suffixRootDomain.toString();
            // 域名后缀比较
            if (suffixOfDomain.equalsIgnoreCase(suffixOfRootDomain)) {
                return false;
            }
            // 去除后缀然后比较
            String tmpDomain = Commons.replaceLast(domain, suffixOfDomain, "");
            String tmpRootdomain = Commons.replaceLast(rootDomain, suffixOfRootDomain, "");
            if (tmpDomain.endsWith("." + tmpRootdomain) || tmpDomain.equalsIgnoreCase(tmpRootdomain)) {
                return true;
            }
        }
        return false;
    } catch (java.lang.IllegalArgumentException e) {
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName) MalformedURLException(java.net.MalformedURLException)

Example 14 with InternetDomainName

use of com.google.common.net.InternetDomainName in project domain_hunter_pro by bit4woo.

the class TargetTableModel method getTLDDomainToAdd.

public String getTLDDomainToAdd(String domain) {
    domain = DomainNameUtils.cleanDomain(domain);
    Set<String> targetDomains = fetchTargetDomainSet();
    for (String rootdomain : targetDomains) {
        rootdomain = DomainNameUtils.cleanDomain(rootdomain);
        if (DomainNameUtils.isWhiteListTLD(domain, rootdomain)) {
            InternetDomainName suffixDomain = InternetDomainName.from(domain).publicSuffix();
            InternetDomainName suffixRootDomain = InternetDomainName.from(rootdomain).publicSuffix();
            if (suffixDomain != null && suffixRootDomain != null) {
                String suffixOfDomain = suffixDomain.toString();
                String suffixOfRootDomain = suffixRootDomain.toString();
                String result = Commons.replaceLast(rootdomain, suffixOfRootDomain, suffixOfDomain);
                return result;
            }
        }
    }
    return domain;
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 15 with InternetDomainName

use of com.google.common.net.InternetDomainName in project nomulus by google.

the class DomainClaimsCheckFlow method run.

@Override
public EppResponse run() throws EppException {
    extensionManager.register(LaunchCheckExtension.class, AllocationTokenExtension.class);
    validateRegistrarIsLoggedIn(registrarId);
    extensionManager.validate();
    if (eppInput.getSingleExtension(AllocationTokenExtension.class).isPresent()) {
        throw new DomainClaimsCheckNotAllowedWithAllocationTokens();
    }
    ImmutableList<String> domainNames = ((Check) resourceCommand).getTargetIds();
    verifyTargetIdCount(domainNames, maxChecks);
    Set<String> seenTlds = new HashSet<>();
    ImmutableList.Builder<LaunchCheck> launchChecksBuilder = new ImmutableList.Builder<>();
    for (String domainName : ImmutableSet.copyOf(domainNames)) {
        InternetDomainName parsedDomain = validateDomainName(domainName);
        validateDomainNameWithIdnTables(parsedDomain);
        String tld = parsedDomain.parent().toString();
        // Only validate access to a TLD the first time it is encountered.
        if (seenTlds.add(tld)) {
            if (!isSuperuser) {
                checkAllowedAccessToTld(registrarId, tld);
                checkHasBillingAccount(registrarId, tld);
                Registry registry = Registry.get(tld);
                DateTime now = clock.nowUtc();
                verifyNotInPredelegation(registry, now);
                verifyClaimsPeriodNotEnded(registry, now);
            }
        }
        Optional<String> claimKey = ClaimsListDao.get().getClaimKey(parsedDomain.parts().get(0));
        launchChecksBuilder.add(LaunchCheck.create(LaunchCheckName.create(claimKey.isPresent(), domainName), claimKey.orElse(null)));
    }
    return responseBuilder.setOnlyExtension(LaunchCheckResponseExtension.create(CLAIMS, launchChecksBuilder.build())).build();
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName) ImmutableList(com.google.common.collect.ImmutableList) LaunchCheck(google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheck) Check(google.registry.model.domain.DomainCommand.Check) AllocationTokenExtension(google.registry.model.domain.token.AllocationTokenExtension) Registry(google.registry.model.tld.Registry) DateTime(org.joda.time.DateTime) LaunchCheck(google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheck) HashSet(java.util.HashSet)

Aggregations

InternetDomainName (com.google.common.net.InternetDomainName)23 DateTime (org.joda.time.DateTime)5 Registry (google.registry.model.tld.Registry)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 AllocationToken (google.registry.model.domain.token.AllocationToken)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DomainCommand (google.registry.model.domain.DomainCommand)2 Check (google.registry.model.domain.DomainCommand.Check)2 AllocationTokenExtension (google.registry.model.domain.token.AllocationTokenExtension)2 TldState (google.registry.model.tld.Registry.TldState)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Maps (com.google.common.collect.Maps)1