Search in sources :

Example 1 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class ConfigServiceDNSStore method processGenericRecordRequest.

/**
	 * Processes all DNS requests except CERT records.
	 * @param name The record name.
	 * @param type The record type.
	 * @return Returns a set of record responses to the request.
	 * @throws DNSException
	 */
protected RRset processGenericRecordRequest(String name, int type) throws DNSException {
    DnsRecord[] records;
    try {
        records = proxy.getDNSByNameAndType(name, type);
    } catch (Exception e) {
        throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "DNS service proxy call for DNS records failed: " + e.getMessage(), e);
    }
    if (records == null || records.length == 0)
        return null;
    RRset retVal = new RRset();
    try {
        for (DnsRecord record : records) {
            Record rec = Record.newRecord(Name.fromString(record.getName()), record.getType(), record.getDclass(), record.getTtl(), record.getData());
            retVal.addRR(rec);
        }
    } catch (Exception e) {
        throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "Failure while parsing generic record data: " + e.getMessage(), e);
    }
    return retVal;
}
Also used : RRset(org.xbill.DNS.RRset) CERTRecord(org.xbill.DNS.CERTRecord) Record(org.xbill.DNS.Record) DnsRecord(org.nhind.config.DnsRecord) DnsRecord(org.nhind.config.DnsRecord) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException)

Example 2 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands method verifyIsUnique.

/*
	 * ensures that a record is unique in the configuration service
	 */
private boolean verifyIsUnique(DnsRecord record, boolean details) {
    DnsRecord existing = find(record);
    if (existing != null) {
        System.out.println("Record already exists");
        print(existing);
        return false;
    }
    return true;
}
Also used : DnsRecord(org.nhind.config.DnsRecord)

Example 3 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands method fromRecord.

/*
	 * Convert a dnsjava record to a DnsRecord for use with the proxy.
	 */
private DnsRecord fromRecord(Record rec) {
    DnsRecord retVal = new DnsRecord();
    retVal.setData(rec.rdataToWireCanonical());
    retVal.setDclass(rec.getDClass());
    retVal.setName(rec.getName().toString());
    retVal.setTtl(rec.getTTL());
    retVal.setType(rec.getType());
    return retVal;
}
Also used : DnsRecord(org.nhind.config.DnsRecord)

Example 4 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands method addSOA.

/**
	 * Adds an SOA records to the configuration service.
	 * @param args Contains the SOA record attributes.
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_SOA_Add", usage = ADD_SOA_USAGE)
public void addSOA(String[] args) {
    DnsRecord record = fromRecord(parser.parseSOA(args));
    addDNS(record);
}
Also used : DnsRecord(org.nhind.config.DnsRecord) Command(org.nhindirect.dns.tools.utils.Command)

Example 5 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands method match.

/**
	 * Looks up all records for a given domain and any sub domains.
	 * @param args The first entry in the array contains the domain name (required).
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_Match", usage = "Resolve all records for the given domain")
public void match(String[] args) {
    String domain = StringArrayUtil.getRequiredValue(args, 0);
    DnsRecord[] records = null;
    Pattern pattern = Pattern.compile(domain);
    ArrayList<DnsRecord> matchedRecords = new ArrayList<DnsRecord>();
    try {
        records = proxy.getDNSByType(Type.ANY);
    } catch (Exception e) {
        throw new RuntimeException("Error accessing configuration service: " + e.getMessage(), e);
    }
    if (records == null || records.length == 0) {
        System.out.println("No records found");
        return;
    } else {
        for (DnsRecord record : records) {
            Matcher matcher = pattern.matcher(record.getName());
            if (matcher.find()) {
                matchedRecords.add(record);
            }
        }
    }
    if (matchedRecords.size() == 0) {
        System.out.println("No records found");
        return;
    }
    print(matchedRecords.toArray(new DnsRecord[matchedRecords.size()]));
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DnsRecord(org.nhind.config.DnsRecord) RemoteException(java.rmi.RemoteException) Command(org.nhindirect.dns.tools.utils.Command)

Aggregations

DnsRecord (org.nhind.config.DnsRecord)32 Command (org.nhindirect.dns.tools.utils.Command)14 Record (org.xbill.DNS.Record)7 ArrayList (java.util.ArrayList)6 RemoteException (java.rmi.RemoteException)4 CertificateConversionException (org.nhindirect.config.model.exceptions.CertificateConversionException)3 CERTRecord (org.xbill.DNS.CERTRecord)3 SOARecord (org.xbill.DNS.SOARecord)3 File (java.io.File)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 BaseTestPlan (org.nhindirect.dns.util.BaseTestPlan)2 ARecord (org.xbill.DNS.ARecord)2 MXRecord (org.xbill.DNS.MXRecord)2 Test (org.junit.Test)1 ConfigurationServiceProxy (org.nhind.config.ConfigurationServiceProxy)1 DNSRecord (org.nhindirect.config.store.DNSRecord)1 RRset (org.xbill.DNS.RRset)1