Search in sources :

Example 61 with Name

use of org.xbill.DNS.Name in project resteasy-extensions by resteasy.

the class EagleDNS method addTSIG.

// @SuppressWarnings("unused")
// private void addPrimaryZone(String zname, String zonefile) throws IOException {
// Name origin = null;
// if (zname != null) {
// origin = Name.fromString(zname, Name.root);
// }
// Zone newzone = new Zone(origin, zonefile);
// primaryZoneMap.put(newzone.getOrigin(), newzone);
// }
// 
// @SuppressWarnings("unused")
// private void addSecondaryZone(String zone, String remote) throws IOException, ZoneTransferException {
// Name zname = Name.fromString(zone, Name.root);
// Zone newzone = new Zone(zname, DClass.IN, remote);
// primaryZoneMap.put(zname, newzone);
// }
@SuppressWarnings("unused")
private void addTSIG(String algstr, String namestr, String key) throws IOException {
    Name name = Name.fromString(namestr, Name.root);
    TSIGs.put(name, new TSIG(algstr, namestr, key));
}
Also used : TSIG(org.xbill.DNS.TSIG) Name(org.xbill.DNS.Name)

Example 62 with Name

use of org.xbill.DNS.Name in project resteasy-extensions by resteasy.

the class DBZone method toZone.

public Zone toZone() throws IOException {
    Name zoneName = Name.fromString(name);
    Name primaryNS = Name.fromString(this.primaryDNS);
    SOARecord soaRecord = new SOARecord(zoneName, DClass.value(dclass), ttl, primaryNS, Name.fromString(this.adminEmail), serial, refresh, retry, expire, minimum);
    // Record primaryNSRecord = Record.newRecord(primaryNS, Type.NS, DClass.value(dclass), ttl);
    int recordCount;
    if (this.records != null) {
        recordCount = 1 + this.records.size();
    } else {
        recordCount = 1;
    }
    Record[] recordArray = new Record[recordCount];
    recordArray[0] = soaRecord;
    if (records != null) {
        int pos = 1;
        for (DBRecord record : this.records) {
            recordArray[pos] = record.getRecord(ttl, zoneName);
            pos++;
        }
    }
    return new Zone(zoneName, recordArray);
}
Also used : Zone(org.xbill.DNS.Zone) SOARecord(org.xbill.DNS.SOARecord) Record(org.xbill.DNS.Record) SOARecord(org.xbill.DNS.SOARecord) Name(org.xbill.DNS.Name)

Example 63 with Name

use of org.xbill.DNS.Name in project resteasy-extensions by resteasy.

the class FileZoneProvider method getPrimaryZones.

public Collection<Zone> getPrimaryZones() {
    File zoneDir = new File(this.zoneFileDirectory);
    if (!zoneDir.exists() || !zoneDir.isDirectory()) {
        log.error("Zone file directory specified for FileZoneProvider " + name + " does not exist!");
        return null;
    } else if (!zoneDir.canRead()) {
        log.error("Zone file directory specified for FileZoneProvider " + name + " is not readable!");
        return null;
    }
    File[] files = zoneDir.listFiles();
    updateZoneFiles(files);
    if (files == null || files.length == 0) {
        log.info("No zone files found for FileZoneProvider " + name + " in directory " + zoneDir.getPath());
        return null;
    }
    ArrayList<Zone> zones = new ArrayList<Zone>(files.length);
    for (File zoneFile : files) {
        if (!zoneFile.canRead()) {
            log.error("FileZoneProvider " + name + " unable to access zone file " + zoneFile);
            continue;
        }
        Name origin;
        try {
            origin = Name.fromString(zoneFile.getName(), Name.root);
            Zone zone = new Zone(origin, zoneFile.getPath());
            log.debug("FileZoneProvider " + name + " successfully parsed zone file " + zoneFile.getName());
            zones.add(zone);
        } catch (TextParseException e) {
            log.error("FileZoneProvider " + name + " unable to parse zone file " + zoneFile.getName(), e);
        } catch (IOException e) {
            log.error("Unable to parse zone file " + zoneFile + " in FileZoneProvider " + name, e);
        }
    }
    if (!zones.isEmpty()) {
        return zones;
    }
    return null;
}
Also used : Zone(org.xbill.DNS.Zone) SecondaryZone(se.unlogic.eagledns.SecondaryZone) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) Name(org.xbill.DNS.Name) TextParseException(org.xbill.DNS.TextParseException)

Example 64 with Name

use of org.xbill.DNS.Name in project ca3sCore by kuehne-trustable-de.

the class ChallengeController method checkChallengeDNS.

private boolean checkChallengeDNS(AcmeChallenge challengeDao) {
    String identifierValue = challengeDao.getValue();
    String token = challengeDao.getToken();
    final Name nameToLookup;
    try {
        final Name nameOfIdentifier = fromString(identifierValue, root);
        nameToLookup = concatenate(ACME_CHALLENGE_PREFIX, nameOfIdentifier);
    } catch (TextParseException | NameTooLongException e) {
        throw new RuntimeException(identifierValue + " invalid", e);
    }
    final Lookup lookupOperation = new Lookup(nameToLookup, TXT);
    lookupOperation.setResolver(dnsResolver);
    lookupOperation.setCache(null);
    LOG.info("DNS lookup: {} records of '{}' (via resolver '{}')", string(TXT), nameToLookup, this.dnsResolver.getAddress());
    final Instant startedAt = Instant.now();
    final org.xbill.DNS.Record[] lookupResult = lookupOperation.run();
    final Duration lookupDuration = Duration.between(startedAt, Instant.now());
    LOG.info("DNS lookup yields: {} (took {})", Arrays.toString(lookupResult), lookupDuration);
    final Collection<String> retrievedToken = extractTokenFrom(lookupResult);
    if (retrievedToken.isEmpty()) {
        LOG.info("Found no DNS entry solving '{}'", identifierValue);
        return false;
    } else {
        final boolean matchingDnsEntryFound = retrievedToken.stream().anyMatch(token::equals);
        if (matchingDnsEntryFound) {
            return true;
        } else {
            LOG.info("Did not find matching token '{}' in TXT record DNS response", token);
            return false;
        }
    }
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) Name(org.xbill.DNS.Name)

Example 65 with Name

use of org.xbill.DNS.Name in project datarouter by hotpads.

the class DnsUpdater method deleteCname.

public String deleteCname(String subdomain) throws TextParseException {
    Name zone = new Name(settings.zone.get());
    var update = new Update(zone);
    Message response;
    try {
        update.delete(new Name(subdomain, zone), Type.CNAME);
        SimpleResolver resolver = makeResolver();
        response = resolver.send(update);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    checkSuccess(response);
    return response.toString();
}
Also used : Message(org.xbill.DNS.Message) IOException(java.io.IOException) Update(org.xbill.DNS.Update) SimpleResolver(org.xbill.DNS.SimpleResolver) Name(org.xbill.DNS.Name)

Aggregations

Name (org.xbill.DNS.Name)110 Record (org.xbill.DNS.Record)38 Message (org.xbill.DNS.Message)19 SRVRecord (org.xbill.DNS.SRVRecord)18 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)12 UnknownHostException (java.net.UnknownHostException)11 Lookup (org.xbill.DNS.Lookup)10 TextParseException (org.xbill.DNS.TextParseException)10 ARecord (org.xbill.DNS.ARecord)9 CNAMERecord (org.xbill.DNS.CNAMERecord)9 ExtendedResolver (org.xbill.DNS.ExtendedResolver)9 RRset (org.xbill.DNS.RRset)9 SimpleResolver (org.xbill.DNS.SimpleResolver)9 Zone (org.xbill.DNS.Zone)9 NSRecord (org.xbill.DNS.NSRecord)8 TSIG (org.xbill.DNS.TSIG)7 TXTRecord (org.xbill.DNS.TXTRecord)7 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6