Search in sources :

Example 1 with SOARecord

use of org.xbill.DNS.SOARecord in project nhin-d by DirectProject.

the class DNSRecordCommands_removeRecords_Test method testRemoveOnlyARecords_AssertOnlyARecordRemoved.

public void testRemoveOnlyARecords_AssertOnlyARecordRemoved() throws Exception {
    new TestPlan() {

        private List<Record> recordsToAdd;

        private List<Record> expectedRemainingRecords;

        @Override
        protected List<Record> getRecordsToAdd() throws Exception {
            recordsToAdd = new ArrayList<Record>();
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.1")));
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.2")));
            recordsToAdd.add(new MXRecord(Name.fromString("example.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail1.example.domain.com.")));
            recordsToAdd.add(new MXRecord(Name.fromString("example2.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail2.exampl2.domain.com.")));
            recordsToAdd.add(new SOARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, Name.fromString("ns1.example.domain.com."), Name.fromString("gm2552.example.domain.com."), 1, 3600, 60, 60, 3600));
            return recordsToAdd;
        }

        @Override
        protected List<DnsRecord> getRecordsToRemove(List<DnsRecord> addedRecords) throws Exception {
            List<DnsRecord> retVal = new ArrayList<DnsRecord>();
            expectedRemainingRecords = new ArrayList<Record>();
            for (DnsRecord addedRecord : addedRecords) {
                if (addedRecord.getType() == Type.A)
                    retVal.add(addedRecord);
                else
                    expectedRemainingRecords.add(toRecord(addedRecord));
            }
            return retVal;
        }

        @Override
        protected void doAssertions(List<Record> remainingRecords) throws Exception {
            assertNotNull(remainingRecords);
            assertEquals(3, remainingRecords.size());
            for (Record expectedRemaining : expectedRemainingRecords) {
                int index = remainingRecords.indexOf(expectedRemaining);
                assertTrue(index >= 0);
                Record checkRecord = remainingRecords.get(index);
                assertTrue(checkRecord.getType() != Type.A);
                assertEquals(checkRecord, expectedRemaining);
            }
        }
    }.perform();
}
Also used : BaseTestPlan(org.nhindirect.dns.util.BaseTestPlan) ArrayList(java.util.ArrayList) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) DnsRecord(org.nhind.config.DnsRecord) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) Record(org.xbill.DNS.Record) ArrayList(java.util.ArrayList) List(java.util.List) SOARecord(org.xbill.DNS.SOARecord) DnsRecord(org.nhind.config.DnsRecord)

Example 2 with SOARecord

use of org.xbill.DNS.SOARecord in project nhin-d by DirectProject.

the class DNSController method refreshModelFromService.

public void refreshModelFromService(Model model) {
    // GET A RECORDS
    Collection<DNSRecord> arecords = null;
    arecords = getDnsRecords(DNSType.A.getValue());
    final Collection<DNSEntryForm> aform = new ArrayList<DNSEntryForm>();
    if (arecords != null) {
        for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
            final DNSRecord t = (DNSRecord) iter.next();
            try {
                final ARecord newrec = (ARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                final DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getAddress());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                aform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsARecordResults", aform);
    // GET A4 RECORDS
    Collection<DNSRecord> a4records = null;
    a4records = getDnsRecords(DNSType.AAAA.getValue());
    final Collection<DNSEntryForm> a4form = new ArrayList<DNSEntryForm>();
    if (a4records != null) {
        for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
            final DNSRecord t = (DNSRecord) iter.next();
            try {
                final AAAARecord newrec = (AAAARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                final DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getAddress());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                a4form.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsA4RecordResults", a4form);
    // GET CNAME RECORDS
    Collection<DNSRecord> crecords = null;
    crecords = getDnsRecords(DNSType.CNAME.getValue());
    final Collection<DNSEntryForm> cform = new ArrayList<DNSEntryForm>();
    if (crecords != null) {
        for (Iterator<DNSRecord> iter = crecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                final CNAMERecord newrec = (CNAMERecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                final DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                cform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsCnameRecordResults", cform);
    // GET MX RECORDS
    Collection<DNSRecord> mxrecords = null;
    mxrecords = getDnsRecords(DNSType.MX.getValue());
    final Collection<DNSEntryForm> mxform = new ArrayList<DNSEntryForm>();
    if (mxrecords != null) {
        for (Iterator<DNSRecord> iter = mxrecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                final MXRecord newrec = (MXRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                final DNSEntryForm tmp = new DNSEntryForm();
                tmp.setPriority(newrec.getPriority());
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                mxform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsMxRecordResults", mxform);
    // GET Cert RECORDS
    Collection<DNSRecord> certrecords = null;
    certrecords = getDnsRecords(DNSType.CERT.getValue());
    // get the thumbprint and assign
    // create a new collection 
    final Collection<SrvRecord> form = new ArrayList<SrvRecord>();
    CertContainer cont;
    if (certrecords != null) {
        for (Iterator<DNSRecord> iter = certrecords.iterator(); iter.hasNext(); ) {
            final DNSRecord t = (DNSRecord) iter.next();
            final SrvRecord srv = new SrvRecord();
            srv.setCreateTime(t.getCreateTime());
            srv.setData(t.getData());
            srv.setDclass(t.getDclass());
            srv.setId(t.getId());
            srv.setName(t.getName());
            srv.setTtl(t.getTtl());
            srv.setType(t.getType());
            srv.setThumb("");
            try {
                final CERTRecord newrec = (CERTRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                String thumb = "";
                byte[] certData = newrec.getCert();
                if (certData != null) {
                    // get the owner from the certificate information
                    // first transform into a certificate
                    cont = toCertContainer(certData);
                    if (cont != null && cont.getCert() != null) {
                        Certificate cert2 = new Certificate();
                        cert2.setData(certData);
                        thumb = getThumbPrint(cont.getCert());
                        srv.setThumb(thumb);
                    }
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            form.add(srv);
        }
    }
    model.addAttribute("dnsCertRecordResults", form);
    // GET SRV RECORDS
    Collection<DNSRecord> srvrecords = null;
    srvrecords = getDnsRecords(DNSType.SRV.getValue());
    // create a new collection 
    final Collection<SrvRecord> form2 = new ArrayList<SrvRecord>();
    if (srvrecords != null) {
        for (Iterator<DNSRecord> iter = srvrecords.iterator(); iter.hasNext(); ) {
            final DNSRecord t = (DNSRecord) iter.next();
            final SrvRecord srv = new SrvRecord();
            try {
                SRVRecord srv4 = (SRVRecord) SRVRecord.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                srv.setCreateTime(t.getCreateTime());
                srv.setData(t.getData());
                srv.setDclass(t.getDclass());
                srv.setId(t.getId());
                srv.setName(t.getName());
                final String name = t.getName();
                // parse the name to get service, protocol, priority , weight,
                // port
                int firstpos = name.indexOf("_");
                if (firstpos == 0) {
                    // then this can be parsed as a srv record
                    // ("_"+SrvdnsForm.getService()+"._"+SrvdnsForm.getProtocol()+"._"+SrvdnsForm.getPriority()+"._"+SrvdnsForm.getWeight()+"._"+SrvdnsForm.getPort()+"._"+SrvdnsForm.getDest()+"."+SrvdnsForm.getName()
                    int secondpos = name.indexOf("._");
                    int thirdpos = name.indexOf(".", secondpos + 2);
                    // from first to second is service
                    final String service_ = name.substring(firstpos + 1, secondpos);
                    srv.setService(service_);
                    // from second to third is protocol
                    final String protocol_ = name.substring(secondpos + 2, thirdpos);
                    ;
                    srv.setProtocol(protocol_);
                    int last2pos = name.indexOf(".", thirdpos);
                    final String name_ = name.substring(last2pos + 1, name.length());
                    srv.setName(name_);
                }
                srv.setTtl(t.getTtl());
                srv.setType(t.getType());
                srv.setPort(srv4.getPort());
                srv.setWeight(srv4.getWeight());
                srv.setPriority("" + srv4.getPriority());
                srv.setTarget("" + srv4.getTarget().toString());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            form2.add(srv);
        }
    }
    model.addAttribute("dnsSrvRecordResults", form2);
    // GET SOA RECORDS
    Collection<DNSRecord> soarecords = null;
    soarecords = getDnsRecords(DNSType.SOA.getValue());
    final Collection<DNSEntryForm> soaform = new ArrayList<DNSEntryForm>();
    if (soarecords != null) {
        for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                final SOARecord newrec = (SOARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                final DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setAdmin("" + newrec.getAdmin());
                tmp.setExpire(newrec.getExpire());
                tmp.setMinimum(newrec.getMinimum());
                tmp.setRefresh(newrec.getRefresh());
                tmp.setRetry(newrec.getRetry());
                tmp.setSerial(newrec.getSerial());
                tmp.setDest("" + newrec.getHost());
                tmp.setDomain("" + newrec.getHost());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                soaform.add(tmp);
            } catch (TextParseException e) {
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsSOARecordResults", soaform);
    // GET NS RECORDS
    Collection<DNSRecord> nsrecords = null;
    nsrecords = getDnsRecords(DNSType.NS.getValue());
    final Collection<DNSEntryForm> nsform = new ArrayList<DNSEntryForm>();
    if (nsrecords != null) {
        for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
            final DNSRecord t = (DNSRecord) iter.next();
            try {
                NSRecord newrec = (NSRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                nsform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsNSRecordResults", nsform);
    // *****************
    model.addAttribute("NSdnsForm", new DNSEntryForm());
    model.addAttribute("SoadnsForm", new DNSEntryForm());
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) AAAARecord(org.xbill.DNS.AAAARecord) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) IOException(java.io.IOException) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextParseException(org.xbill.DNS.TextParseException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) CNAMERecord(org.xbill.DNS.CNAMERecord) SOARecord(org.xbill.DNS.SOARecord) AAAARecord(org.xbill.DNS.AAAARecord) ARecord(org.xbill.DNS.ARecord) CERTRecord(org.xbill.DNS.CERTRecord) MXRecord(org.xbill.DNS.MXRecord) NSRecord(org.xbill.DNS.NSRecord) DNSRecord(org.nhindirect.config.model.DNSRecord) SRVRecord(org.xbill.DNS.SRVRecord) SOARecord(org.xbill.DNS.SOARecord) TextParseException(org.xbill.DNS.TextParseException) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.model.Certificate)

Example 3 with SOARecord

use of org.xbill.DNS.SOARecord in project nhin-d by DirectProject.

the class MainController method refreshModelFromService.

public void refreshModelFromService(Model model) {
    // GET A RECORDS
    Collection<DNSRecord> arecords = null;
    arecords = getDnsRecords(DNSType.A.getValue());
    Collection<DNSEntryForm> aform = new ArrayList<DNSEntryForm>();
    if (arecords != null) {
        for (DNSRecord t : arecords) {
            try {
                ARecord newrec = (ARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getAddress());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                aform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsARecordResults", aform);
    // GET A4 RECORDS
    Collection<DNSRecord> a4records = null;
    a4records = getDnsRecords(DNSType.AAAA.getValue());
    Collection<DNSEntryForm> a4form = new ArrayList<DNSEntryForm>();
    if (a4records != null) {
        for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                AAAARecord newrec = (AAAARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getAddress());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                a4form.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsA4RecordResults", a4form);
    // GET CNAME RECORDS
    Collection<DNSRecord> crecords = null;
    crecords = getDnsRecords(DNSType.CNAME.getValue());
    Collection<DNSEntryForm> cform = new ArrayList<DNSEntryForm>();
    if (crecords != null) {
        for (Iterator<DNSRecord> iter = crecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                CNAMERecord newrec = (CNAMERecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                cform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsCnameRecordResults", cform);
    // GET MX RECORDS
    Collection<DNSRecord> mxrecords = null;
    mxrecords = getDnsRecords(DNSType.MX.getValue());
    Collection<DNSEntryForm> mxform = new ArrayList<DNSEntryForm>();
    if (mxrecords != null) {
        for (Iterator<DNSRecord> iter = mxrecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                MXRecord newrec = (MXRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setPriority(newrec.getPriority());
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                mxform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsMxRecordResults", mxform);
    // GET Cert RECORDS
    Collection<DNSRecord> certrecords = null;
    certrecords = getDnsRecords(DNSType.CERT.getValue());
    // get the thumbprint and assign
    // create a new collection 
    Collection<SrvRecord> form = new ArrayList<SrvRecord>();
    CertContainer cont;
    if (certrecords != null) {
        for (Iterator<DNSRecord> iter = certrecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            SrvRecord srv = new SrvRecord();
            srv.setCreateTime(t.getCreateTime());
            srv.setData(t.getData());
            srv.setDclass(t.getDclass());
            srv.setId(t.getId());
            srv.setName(t.getName());
            srv.setTtl(t.getTtl());
            srv.setType(t.getType());
            srv.setThumb("");
            try {
                CERTRecord newrec = (CERTRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                String thumb = "";
                byte[] certData = newrec.getCert();
                if (certData != null) {
                    // get the owner from the certificate information
                    // first transform into a certificate
                    cont = CertUtils.toCertContainer(certData);
                    if (cont != null && cont.getCert() != null) {
                        Certificate cert2 = new Certificate();
                        cert2.setData(certData);
                        thumb = getThumbPrint(cont.getCert());
                        srv.setThumb(thumb);
                    }
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            form.add(srv);
        }
    }
    model.addAttribute("dnsCertRecordResults", form);
    // GET SRV RECORDS
    Collection<DNSRecord> srvrecords = null;
    srvrecords = getDnsRecords(DNSType.SRV.getValue());
    // create a new collection 
    Collection<SrvRecord> form2 = new ArrayList<SrvRecord>();
    if (srvrecords != null) {
        for (Iterator<DNSRecord> iter = srvrecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            SrvRecord srv = new SrvRecord();
            try {
                SRVRecord srv4 = (SRVRecord) SRVRecord.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                srv.setCreateTime(t.getCreateTime());
                srv.setData(t.getData());
                srv.setDclass(t.getDclass());
                srv.setId(t.getId());
                srv.setName(t.getName());
                String name = t.getName();
                // parse the name to get service, protocol, priority , weight,
                // port
                int firstpos = name.indexOf("_");
                if (firstpos == 0) {
                    // then this can be parsed as a srv record
                    // ("_"+SrvdnsForm.getService()+"._"+SrvdnsForm.getProtocol()+"._"+SrvdnsForm.getPriority()+"._"+SrvdnsForm.getWeight()+"._"+SrvdnsForm.getPort()+"._"+SrvdnsForm.getDest()+"."+SrvdnsForm.getName()
                    int secondpos = name.indexOf("._");
                    int thirdpos = name.indexOf(".", secondpos + 2);
                    // from first to second is service
                    String service_ = name.substring(firstpos + 1, secondpos);
                    srv.setService(service_);
                    // from second to third is protocol
                    String protocol_ = name.substring(secondpos + 2, thirdpos);
                    ;
                    srv.setProtocol(protocol_);
                    int last2pos = name.indexOf(".", thirdpos);
                    String name_ = name.substring(last2pos + 1, name.length());
                    srv.setName(name_);
                }
                srv.setTtl(t.getTtl());
                srv.setType(t.getType());
                srv.setPort(srv4.getPort());
                srv.setWeight(srv4.getWeight());
                srv.setPriority("" + srv4.getPriority());
                srv.setTarget("" + srv4.getTarget().toString());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            form2.add(srv);
        }
    }
    model.addAttribute("dnsSrvRecordResults", form2);
    // GET SOA RECORDS
    Collection<DNSRecord> soarecords = null;
    soarecords = getDnsRecords(DNSType.SOA.getValue());
    Collection<DNSEntryForm> soaform = new ArrayList<DNSEntryForm>();
    if (soarecords != null) {
        for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                SOARecord newrec = (SOARecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setAdmin("" + newrec.getAdmin());
                tmp.setExpire(newrec.getExpire());
                tmp.setMinimum(newrec.getMinimum());
                tmp.setRefresh(newrec.getRefresh());
                tmp.setRetry(newrec.getRetry());
                tmp.setSerial(newrec.getSerial());
                tmp.setDest("" + newrec.getHost());
                tmp.setDomain("" + newrec.getHost());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                soaform.add(tmp);
            } catch (TextParseException e) {
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsSOARecordResults", soaform);
    // GET NS RECORDS
    Collection<DNSRecord> nsrecords = null;
    nsrecords = getDnsRecords(DNSType.NS.getValue());
    Collection<DNSEntryForm> nsform = new ArrayList<DNSEntryForm>();
    if (nsrecords != null) {
        for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
            DNSRecord t = (DNSRecord) iter.next();
            try {
                NSRecord newrec = (NSRecord) Record.newRecord(Name.fromString(t.getName()), t.getType(), t.getDclass(), t.getTtl(), t.getData());
                DNSEntryForm tmp = new DNSEntryForm();
                tmp.setId(t.getId());
                tmp.setDest("" + newrec.getTarget());
                tmp.setTtl(newrec.getTTL());
                tmp.setName("" + newrec.getName());
                nsform.add(tmp);
            } catch (TextParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    model.addAttribute("dnsNSRecordResults", nsform);
    // *****************
    model.addAttribute("NSdnsForm", new DNSEntryForm());
    model.addAttribute("SoadnsForm", new DNSEntryForm());
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) AAAARecord(org.xbill.DNS.AAAARecord) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) IOException(java.io.IOException) CertContainer(org.nhindirect.config.model.utils.CertUtils.CertContainer) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextParseException(org.xbill.DNS.TextParseException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) CNAMERecord(org.xbill.DNS.CNAMERecord) SOARecord(org.xbill.DNS.SOARecord) AAAARecord(org.xbill.DNS.AAAARecord) ARecord(org.xbill.DNS.ARecord) CERTRecord(org.xbill.DNS.CERTRecord) MXRecord(org.xbill.DNS.MXRecord) NSRecord(org.xbill.DNS.NSRecord) DNSRecord(org.nhindirect.config.model.DNSRecord) SRVRecord(org.xbill.DNS.SRVRecord) SOARecord(org.xbill.DNS.SOARecord) TextParseException(org.xbill.DNS.TextParseException) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.model.Certificate)

Example 4 with SOARecord

use of org.xbill.DNS.SOARecord in project nhin-d by DirectProject.

the class DNSRecordCommands_removeRecords_Test method testRemoveAllExceptARecords_AssertAllExceptARecordRemoved.

public void testRemoveAllExceptARecords_AssertAllExceptARecordRemoved() throws Exception {
    new TestPlan() {

        private List<Record> recordsToAdd;

        private List<Record> expectedRemainingRecords;

        @Override
        protected List<Record> getRecordsToAdd() throws Exception {
            recordsToAdd = new ArrayList<Record>();
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.1")));
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.2")));
            recordsToAdd.add(new MXRecord(Name.fromString("example.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail1.example.domain.com.")));
            recordsToAdd.add(new MXRecord(Name.fromString("example2.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail2.exampl2.domain.com.")));
            recordsToAdd.add(new SOARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, Name.fromString("ns1.example.domain.com."), Name.fromString("gm2552.example.domain.com."), 1, 3600, 60, 60, 3600));
            return recordsToAdd;
        }

        @Override
        protected List<DnsRecord> getRecordsToRemove(List<DnsRecord> addedRecords) throws Exception {
            List<DnsRecord> retVal = new ArrayList<DnsRecord>();
            expectedRemainingRecords = new ArrayList<Record>();
            for (DnsRecord addedRecord : addedRecords) {
                if (addedRecord.getType() != Type.A)
                    retVal.add(addedRecord);
                else
                    expectedRemainingRecords.add(toRecord(addedRecord));
            }
            return retVal;
        }

        @Override
        protected void doAssertions(List<Record> remainingRecords) throws Exception {
            assertNotNull(remainingRecords);
            assertEquals(2, remainingRecords.size());
            for (Record expectedRemaining : expectedRemainingRecords) {
                int index = remainingRecords.indexOf(expectedRemaining);
                assertTrue(index >= 0);
                Record checkRecord = remainingRecords.get(index);
                assertTrue(checkRecord.getType() == Type.A);
                assertEquals(checkRecord, expectedRemaining);
            }
        }
    }.perform();
}
Also used : BaseTestPlan(org.nhindirect.dns.util.BaseTestPlan) ArrayList(java.util.ArrayList) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) DnsRecord(org.nhind.config.DnsRecord) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) Record(org.xbill.DNS.Record) ArrayList(java.util.ArrayList) List(java.util.List) SOARecord(org.xbill.DNS.SOARecord) DnsRecord(org.nhind.config.DnsRecord)

Example 5 with SOARecord

use of org.xbill.DNS.SOARecord in project nhin-d by DirectProject.

the class ServiceTest method testSOA.

//  @Test
public void testSOA() {
    DNSEntryForm SoadnsForm = new DNSEntryForm();
    SoadnsForm.setName("savvy");
    SoadnsForm.setTtl(84555L);
    SoadnsForm.setAdmin("ns.savvy.com");
    SoadnsForm.setDomain("ns2.savvy.com");
    SoadnsForm.setSerial(4L);
    SoadnsForm.setRefresh(6L);
    SoadnsForm.setRetry(8L);
    SoadnsForm.setExpire(66L);
    SoadnsForm.setMinimum(22L);
    Collection<DNSRecord> records = new ArrayList<DNSRecord>();
    records.add(DNSRecordUtils.createSOARecord(SoadnsForm.getName(), SoadnsForm.getTtl(), SoadnsForm.getDomain(), SoadnsForm.getAdmin(), (int) SoadnsForm.getSerial(), SoadnsForm.getRefresh(), SoadnsForm.getRetry(), SoadnsForm.getExpire(), SoadnsForm.getMinimum()));
    try {
        configSvc.addDNS(records);
        Collection<DNSRecord> arecords = configSvc.getDNSByType(DNSType.SOA.getValue());
        for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
            DNSRecord arec = iter.next();
            SOARecord newrec = (SOARecord) Record.newRecord(Name.fromString(arec.getName()), arec.getType(), arec.getDclass(), arec.getTtl(), arec.getData());
            System.out.println("A admin: " + newrec.getAdmin());
            System.out.println("A name: " + newrec.getName());
        }
    } catch (ConfigurationServiceException e) {
        e.printStackTrace();
    } catch (TextParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) SOARecord(org.xbill.DNS.SOARecord) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

SOARecord (org.xbill.DNS.SOARecord)7 ArrayList (java.util.ArrayList)5 ARecord (org.xbill.DNS.ARecord)5 MXRecord (org.xbill.DNS.MXRecord)5 NSRecord (org.xbill.DNS.NSRecord)4 SRVRecord (org.xbill.DNS.SRVRecord)4 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)3 AAAARecord (org.xbill.DNS.AAAARecord)3 CNAMERecord (org.xbill.DNS.CNAMERecord)3 Record (org.xbill.DNS.Record)3 TextParseException (org.xbill.DNS.TextParseException)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 X509Certificate (java.security.cert.X509Certificate)2 List (java.util.List)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2 DnsRecord (org.nhind.config.DnsRecord)2 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)2 Certificate (org.nhindirect.config.model.Certificate)2 DNSRecord (org.nhindirect.config.model.DNSRecord)2