From e6fb369f8873e43bec9f81785c797fd9cd238999 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Wed, 06 Mar 2013 17:16:24 +0100
Subject: [PATCH] clean imports

---
 hsarback/src/de/hsadmin/mods/cust/Customer.java              |    1 -
 hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm           |    8 ++++++++
 hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java |   30 ++++++++++++------------------
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/cust/Customer.java b/hsarback/src/de/hsadmin/mods/cust/Customer.java
index a0dde52..4d5de2d 100644
--- a/hsarback/src/de/hsadmin/mods/cust/Customer.java
+++ b/hsarback/src/de/hsadmin/mods/cust/Customer.java
@@ -23,7 +23,6 @@
 import javax.persistence.Transient;
 
 import de.hsadmin.core.model.AbstractEntity;
-import de.hsadmin.core.model.AnnFieldIO;
 import de.hsadmin.core.model.AnnModuleImpl;
 import de.hsadmin.mods.pac.Pac;
 import de.hsadmin.mods.user.UnixUser;
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 @@
 		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 @@
 			);
 		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 @@
 		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<String, Object> templateVars = new HashMap<String, Object>();
+		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

--
Gitblit v1.9.0-SNAPSHOT