Search in sources :

Example 6 with DNSRecord

use of org.nhindirect.config.model.DNSRecord in project nhin-d by DirectProject.

the class DNSResource method addDNSRecord.

/**
     * Adds a DNS record.
     * @param uriInfo Injected URI context used for building the location URI.
     * @param record The DNS record to add.
     * @return Status fo 201 if the DNS record was added to the system or a status of 409 if the record already exists.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addDNSRecord(@Context UriInfo uriInfo, DNSRecord record) {
    if (!record.getName().endsWith("."))
        record.setName(record.getName() + ".");
    // check to see if it already exists
    try {
        final Collection<org.nhindirect.config.store.DNSRecord> records = dnsDao.get(record.getName(), record.getType());
        for (org.nhindirect.config.store.DNSRecord compareRecord : records) // do a binary compare of the data
        if (Arrays.equals(record.getData(), compareRecord.getData()))
            return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up DNS records.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    try {
        dnsDao.add(Arrays.asList(EntityModelConversion.toEntityDNSRecord(record)));
        final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
        final URI newLoc = newLocBuilder.path("dns?type=" + record.getType() + "&name=" + record.getName()).build();
        return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error adding DNS record.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 7 with DNSRecord

use of org.nhindirect.config.model.DNSRecord in project nhin-d by DirectProject.

the class EntityModelConversion method toModelDNSRecord.

public static DNSRecord toModelDNSRecord(org.nhindirect.config.store.DNSRecord record) {
    if (record == null)
        return null;
    final DNSRecord retVal = new DNSRecord();
    retVal.setCreateTime(record.getCreateTime());
    retVal.setData(record.getData());
    retVal.setDclass(record.getDclass());
    retVal.setId(record.getId());
    retVal.setName(record.getName());
    retVal.setTtl(record.getTtl());
    retVal.setType(record.getType());
    return retVal;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord)

Example 8 with DNSRecord

use of org.nhindirect.config.model.DNSRecord in project nhin-d by DirectProject.

the class DNSController method addSOASetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addSOADNSRecord", method = RequestMethod.POST)
public ModelAndView addSOASetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (SoadnsForm != null && !SoadnsForm.getName().equalsIgnoreCase("") && SoadnsForm.getTtl() != 0L) {
        final DNSRecord rec = DNSEntryForm.entityToModelRecord(DNSRecordUtils.createSOARecord(SoadnsForm.getName(), SoadnsForm.getTtl(), SoadnsForm.getDomain(), SoadnsForm.getAdmin(), (int) SoadnsForm.getSerial(), SoadnsForm.getRefresh(), SoadnsForm.getRetry(), SoadnsForm.getExpire(), SoadnsForm.getMinimum()));
        try {
            dnsService.addDNSRecord(rec);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    final ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    mav.setViewName("dns");
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DNSRecord

use of org.nhindirect.config.model.DNSRecord in project nhin-d by DirectProject.

the class DNSController method removeAnchors.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removesettings", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @ModelAttribute("AdnsForm") DNSEntryForm AdnsForm, @ModelAttribute("NSdnsForm") DNSEntryForm NSdnsForm, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, HttpSession session, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter domain/removesettings");
    // A records
    try {
        Collection<DNSRecord> arecords = null;
        if (dnsService != null && AdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected As")) && AdnsForm.getRemove() != null) {
            int cnt = AdnsForm.getRemove().size();
            arecords = dnsService.getDNSRecord(DNSType.A.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // A4 records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && AAdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteA4DnsEntries") || actionPath.equalsIgnoreCase("Remove Selected A4s")) && AAdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.AAAA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AAdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CNAME records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCNAMEDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CNAMEs")) && CdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CNAME.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // MX records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && MXdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteMXDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected MXs")) && MXdnsForm.getRemove() != null) {
            int cnt = MXdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.MX.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = MXdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CERT records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CertdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCERTDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CERTs")) && CertdnsForm.getRemove() != null) {
            int cnt = CertdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CERT.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CertdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SRV records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && SrvdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSRVDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SRVs")) && SrvdnsForm.getRemove() != null) {
            int cnt = SrvdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.SRV.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SrvdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SOA records
    try {
        Collection<DNSRecord> soarecords = null;
        if (dnsService != null && SoadnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSOADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SOAs")) && SoadnsForm.getRemove() != null) {
            int cnt = SoadnsForm.getRemove().size();
            soarecords = dnsService.getDNSRecord(DNSType.SOA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SoadnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // NS records
    try {
        Collection<DNSRecord> nsrecords = null;
        if (dnsService != null && NSdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteNSDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected NSs")) && NSdnsForm.getRemove() != null) {
            int cnt = NSdnsForm.getRemove().size();
            nsrecords = dnsService.getDNSRecord(DNSType.NS.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = NSdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // additional post clean up to redisplay
    ModelAndView mav = new ModelAndView("dns");
    if (AdnsForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + AdnsForm.getRemove().toString());
    }
    /*
		 * if (configSvc != null && simpleForm != null && actionPath != null &&
		 * actionPath.equalsIgnoreCase("delete") && simpleForm.getRemove() !=
		 * null) { int cnt = simpleForm.getRemove().size(); try{
		 * Collection<String> settingstoberemovedlist = simpleForm.getRemove();
		 * if (log.isDebugEnabled())
		 * log.debug(" Trying to remove settings from database");
		 * configSvc.deleteSetting(settingstoberemovedlist); if
		 * (log.isDebugEnabled())
		 * log.debug(" SUCCESS Trying to remove settings"); } catch
		 * (ConfigurationServiceException e) { if (log.isDebugEnabled())
		 * log.error(e); } }
		 */
    refreshModelFromService(model);
    model.addAttribute("dnsEntryForm", 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());
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with DNSRecord

use of org.nhindirect.config.model.DNSRecord in project nhin-d by DirectProject.

the class DNSController method addSRVSetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addSRVDNSRecord", method = RequestMethod.POST)
public ModelAndView addSRVSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (SrvdnsForm != null && !SrvdnsForm.getName().equalsIgnoreCase("") && SrvdnsForm.getTtl() != 0L && !SrvdnsForm.getDest().equalsIgnoreCase("")) {
        final DNSRecord rec = DNSEntryForm.entityToModelRecord(DNSRecordUtils.createSRVRecord("_" + SrvdnsForm.getService() + "._" + SrvdnsForm.getProtocol() + "." + SrvdnsForm.getName(), SrvdnsForm.getDest(), SrvdnsForm.getTtl(), SrvdnsForm.getPort(), SrvdnsForm.getPriority(), SrvdnsForm.getWeight()));
        try {
            dnsService.addDNSRecord(rec);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    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());
    ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    mav.setViewName("dns");
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DNSRecord (org.nhindirect.config.model.DNSRecord)10 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)5 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)4 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ARecord (org.xbill.DNS.ARecord)3 CERTRecord (org.xbill.DNS.CERTRecord)3 MXRecord (org.xbill.DNS.MXRecord)3 SOARecord (org.xbill.DNS.SOARecord)3 SRVRecord (org.xbill.DNS.SRVRecord)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2 Certificate (org.nhindirect.config.model.Certificate)2 AAAARecord (org.xbill.DNS.AAAARecord)2 CNAMERecord (org.xbill.DNS.CNAMERecord)2