use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.
the class DNSController method convertDNSRecords.
private Collection<DNSEntryForm> convertDNSRecords(Collection<DNSRecord> entries) {
if (log.isDebugEnabled())
log.debug("Enter");
Collection<DNSEntryForm> forms = new ArrayList<DNSEntryForm>();
if (entries != null) {
for (Iterator<DNSRecord> iter = entries.iterator(); iter.hasNext(); ) {
DNSEntryForm form = new DNSEntryForm(iter.next());
forms.add(form);
}
}
if (log.isDebugEnabled())
log.debug("Exit");
return forms;
}
use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.
the class MainController method convertDNSRecords.
private Collection<DNSEntryForm> convertDNSRecords(Collection<DNSRecord> entries) {
if (log.isDebugEnabled())
log.debug("Enter");
Collection<DNSEntryForm> forms = new ArrayList<DNSEntryForm>();
if (entries != null) {
for (Iterator<DNSRecord> iter = entries.iterator(); iter.hasNext(); ) {
DNSEntryForm form = new DNSEntryForm(iter.next());
forms.add(form);
}
}
if (log.isDebugEnabled())
log.debug("Exit");
return forms;
}
use of org.nhindirect.config.ui.form.DNSEntryForm 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());
}
use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.
the class DNSController method showDNSEntries.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showDNSEntries(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute DNSEntryForm entryForm, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter");
final ModelAndView mav = new ModelAndView("dns");
model.addAttribute("dnsEntryForm", new DNSEntryForm());
if (dnsService != null) {
refreshModelFromService(model);
}
return mav;
}
use of org.nhindirect.config.ui.form.DNSEntryForm in project nhin-d by DirectProject.
the class MainController method search.
/**
* Execute the search and return the results
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView search(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter search");
String message = "Search complete";
ModelAndView mav = new ModelAndView();
// check to see if new domain requested
if (actionPath.equalsIgnoreCase("gotosettings")) {
if (log.isDebugEnabled())
log.debug("trying to go to the settings page");
String action = "add";
model.addAttribute("action", action);
mav.setViewName("settings");
mav.addObject("actionPath", actionPath);
SettingsForm form = (SettingsForm) session.getAttribute("settingsForm");
if (form == null) {
form = new SettingsForm();
}
model.addAttribute("settingsForm", form);
// retrieve list of settings for settingsResults
List<Setting> results = null;
if (configSvc != null) {
try {
Collection<Setting> settings = configSvc.getAllSettings();
if (settings != null)
results = new ArrayList<Setting>(settings);
else
results = new ArrayList<Setting>();
} catch (ConfigurationServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("simpleForm", new SimpleForm());
model.addAttribute("settingsResults", results);
} else if (actionPath.equalsIgnoreCase("gotocertificates")) {
if (log.isDebugEnabled())
log.debug("trying to go to the certificates page");
String action = "Update";
model.addAttribute("action", action);
mav.setViewName("certificates");
mav.addObject("actionPath", actionPath);
CertificateForm form = (CertificateForm) session.getAttribute("certificateForm");
if (form == null) {
form = new CertificateForm();
}
model.addAttribute("certificateForm", form);
// retrieve list of settings for settingsResults
List<Certificate> results = null;
if (configSvc != null) {
try {
Collection<Certificate> certs = configSvc.listCertificates(1, 10000, CertificateGetOptions.DEFAULT);
if (certs != null)
results = new ArrayList<Certificate>(certs);
else
results = new ArrayList<Certificate>();
} catch (ConfigurationServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("simpleForm", new SimpleForm());
model.addAttribute("certificatesResults", results);
} else if (actionPath.equalsIgnoreCase("newdomain")) {
if (log.isDebugEnabled())
log.debug("trying to go to the new domain page");
HashMap<String, String> msgs = new HashMap<String, String>();
mav.addObject("msgs", msgs);
model.addAttribute("simpleForm", new SimpleForm());
AddressForm addrform = new AddressForm();
addrform.setId(0L);
model.addAttribute("addressForm", addrform);
// TODO: once certificates and anchors are available change code accordingly
CertificateForm cform = new CertificateForm();
cform.setId(0L);
AnchorForm aform = new AnchorForm();
aform.setId(0L);
model.addAttribute("certificateForm", cform);
model.addAttribute("anchorForm", aform);
String action = "Add";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
mav.setViewName("domain");
mav.addObject("actionPath", actionPath);
mav.addObject("statusList", EntityStatus.getEntityStatusList());
} else if (actionPath.equalsIgnoreCase("gotodns")) {
if (log.isDebugEnabled())
log.debug("trying to go to the DNS page");
HashMap<String, String> msgs = new HashMap<String, String>();
mav.addObject("msgs", msgs);
String action = "Update";
model.addAttribute("action", action);
// get all DNSType.A.getValue() records
// GET A RECORDS
Collection<DNSRecord> arecords = null;
arecords = getDnsRecords(DNSType.A.getValue());
model.addAttribute("dnsARecordResults", arecords);
// GET A4 RECORDS
Collection<DNSRecord> a4records = null;
a4records = getDnsRecords(DNSType.AAAA.getValue());
model.addAttribute("dnsA4RecordResults", a4records);
// GET C RECORDS
Collection<DNSRecord> crecords = null;
crecords = getDnsRecords(DNSType.CNAME.getValue());
model.addAttribute("dnsCnameRecordResults", crecords);
// GET Cert RECORDS
Collection<DNSRecord> certrecords = null;
certrecords = getDnsRecords(DNSType.CERT.getValue());
model.addAttribute("dnsCertRecordResults", certrecords);
// GET MX RECORDS
Collection<DNSRecord> mxrecords = null;
mxrecords = getDnsRecords(DNSType.MX.getValue());
model.addAttribute("dnsMxRecordResults", mxrecords);
// GET SRV RECORDS
Collection<DNSRecord> srvrecords = null;
srvrecords = getDnsRecords(DNSType.SRV.getValue());
model.addAttribute("dnsSrvRecordResults", srvrecords);
mav.setViewName("dns");
mav.addObject("actionPath", actionPath);
model.addAttribute("AdnsForm", new DNSEntryForm());
model.addAttribute("AAdnsForm", new DNSEntryForm());
model.addAttribute("CdnsForm", new DNSEntryForm());
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("MXdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
refreshModelFromService(model);
model.addAttribute("simpleForm", new SimpleForm());
} else {
SearchDomainForm form = (SearchDomainForm) session.getAttribute("searchDomainForm");
if (form == null) {
form = new SearchDomainForm();
}
model.addAttribute(form);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
String domain = form.getDomainName();
EntityStatus status = form.getStatus();
List<Domain> results = null;
if (configSvc != null) {
Collection<Domain> domains = configSvc.searchDomain(domain, status);
if (domains != null) {
results = new ArrayList<Domain>(domains);
} else {
results = new ArrayList<Domain>();
}
}
if (AjaxUtils.isAjaxRequest(requestedWith)) {
// prepare model for rendering success message in this request
model.addAttribute("message", new Message(MessageType.success, message));
model.addAttribute("ajaxRequest", true);
model.addAttribute("searchResults", results);
return null;
}
mav.setViewName("main");
mav.addObject("statusList", EntityStatus.getEntityStatusList());
mav.addObject("searchResults", results);
}
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
Aggregations