From 0b9a72836ea3019d5cd432ab955577cc73791d87 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 2 Apr 2013 14:21:44 +0200 Subject: [PATCH] use template to generate named.pri-zones --- .../mods/dom/DomainProcessorFactory.java | 46 ++++++++++--------- .../src/de/hsadmin/mods/dom/named-hsh-conf.vm | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index d329536..8b92cf5 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -39,7 +39,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { Domain dom = (Domain) entity; UnixUser domUser = dom.getUser(); Pac pac = domUser.getPac(); - WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(dom)); + WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(em, dom)); mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, dom), "Setup EMail"); Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.dns").split(",")) { @@ -82,7 +82,19 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return mainProcessor; } - private Processor createHiveDNSSetupProcessor(Domain dom) throws ProcessorException { + private Processor createDNSServerConfigProcessor(EntityManager em) { + Query query = em.createQuery("SELECT d FROM Domains d"); + HashMap templateVars = new HashMap(); + templateVars.put("domains", query.getResultList()); + return new CompoundProcessor( + new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm", + templateVars, "/etc/bind/named-hsh.conf.tmp", true), + new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " + + "|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )") + ); + } + + private Processor createHiveDNSSetupProcessor(EntityManager em, Domain dom) throws ProcessorException { Map templateVars = new HashMap(); templateVars.put("sio", Long.toString(System.currentTimeMillis()/1000L)); String domName = dom.getName(); @@ -91,14 +103,18 @@ public class DomainProcessorFactory implements EntityProcessorFactory { new VelocityProcessor("/de/hsadmin/mods/dom/zonefile.vm", templateVars, dom, zonefileTargetPath, false); Processor zonefileACLProcessor = new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath); - // TODO Use templates and regenerate the file. - Processor prizonesFileProcessor = - new ShellProcessor("echo 'zone \"" + domName + "\" { type master; file \"pri." + domName + "\"; };' >>/etc/bind/named.pri-zones" + - " && sort /etc/bind/named.pri-zones | uniq >/etc/bind/named.pri-zones.tmp" + - " && mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones"); - Processor dnsReloadProcessor = new ShellProcessor("invoke-rc.d bind9 reload"); + Query query = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hivename"); + query.setParameter("hivename", dom.getUser().getHiveName()); + templateVars = new HashMap(); + templateVars.put("domains", query.getResultList()); + Processor prizonesFileProcessor = new CompoundProcessor( + new VelocityProcessor("/de/hsadmin/mods/dom/named-pri-zones.vm", + templateVars, dom, "/etc/bind/named.pri-zones.tmp", true), + new ShellProcessor(" ( diff -q /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && rm /etc/bind/named.pri-zones.tmp ) " + + "|| ( mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && invoke-rc.d bind9 reload )") + ); Processor dnsSetupProcessor = - new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor, dnsReloadProcessor); + new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor); return dnsSetupProcessor; } @@ -124,18 +140,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return emailAdrProcessor; } - private Processor createDNSServerConfigProcessor(EntityManager em) { - Query query = em.createQuery("SELECT d FROM Domains d"); - HashMap templateVars = new HashMap(); - templateVars.put("domains", query.getResultList()); - return new CompoundProcessor( - new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm", - templateVars, "/etc/bind/named-hsh.conf.tmp", true), - new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " + - "|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )") - ); - } - private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException { String inetAddr = pac.getCurINetAddr().getInetAddr(); CompoundProcessor cp = new CompoundProcessor( diff --git a/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm index 1db3678..be4f101 100644 --- a/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm +++ b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm @@ -5,4 +5,4 @@ #foreach( $domain in ${domains} ) zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; }; -#end \ No newline at end of file +#end