From f024759495b3ddfcf38588955739a59e627523b8 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Wed, 6 Mar 2013 16:18:27 +0100 Subject: [PATCH] Migrated DNS secodaries configuration to velocity. --- .../mods/dom/DomainProcessorFactory.java | 30 ++++++++----------- .../src/de/hsadmin/mods/dom/named-hsh-conf.vm | 8 +++++ 2 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 81ebbaa..d329536 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -43,7 +43,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, dom), "Setup EMail"); Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.dns").split(",")) { - mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(dom.getName(), pac.getHive().getInetAddr().getInetAddr()), queueName + ".hostsharing.net"); + mainProcessor.appendProcessor(queueName, createDNSServerConfigProcessor(em), queueName + ".hostsharing.net"); } for (String queueName : config.getProperty("queues.mail").split(",")) { mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net"); @@ -73,7 +73,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ); Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.dns").split(",")) { - mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net"); + mainProcessor.appendProcessor(queueName, createDNSServerConfigProcessor(em), queueName + ".hostsharing.net"); } for (String queueName : config.getProperty("queues.mail").split(",")) { mainProcessor.appendProcessor(queueName, createMailinUnsetupProcessor(em, dom), queueName + ".hostsharing.net"); @@ -124,22 +124,16 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return emailAdrProcessor; } - private Processor createDNSServerSetupProcessor(String domName, String hiveInetAddr) { - Processor seczonesFileProcessor; - seczonesFileProcessor = - new ShellProcessor("echo 'zone \"" + domName + "\" { type slave; file \"sec." + domName + "\"; masters { " + hiveInetAddr + "; }; };' >>/etc/bind/named-hsh.conf" + - " && sort /etc/bind/named-hsh.conf | uniq >/etc/bind/named-hsh.conf.tmp" + - " && mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf" + - " && invoke-rc.d bind9 reload"); - return seczonesFileProcessor; - } - - private Processor createDNSServerRemoveProcessor(String domName) { - // TODO Use templates and regenerate the file. - return new ShellProcessor("grep -v '\"sec." + domName + "\"' /etc/bind/named-hsh.conf >/etc/bind/named-hsh.conf.tmp" + - " && mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf" + - " && rm /var/cache/bind/sec." + domName + - " && invoke-rc.d bind9 reload"); + 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 { diff --git a/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm new file mode 100644 index 0000000..09a553c --- /dev/null +++ b/hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm @@ -0,0 +1,8 @@ +// +// This file is managed by HSAdmin. +// Do not edit manually. Changes will be overwritten. +// + +#foreach( $domain in ${domains} ) +zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetaddr}; }; }; +#end \ No newline at end of file