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));
}
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);
}
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;
}
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;
}
}
}
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();
}
Aggregations