From a1d97ed10fc24bb33d302e650e9615b9efbfc058 Mon Sep 17 00:00:00 2001
From: Purodha Blissenbach <purodha.blissenbach@hostsharing.net>
Date: Thu, 16 Aug 2012 14:43:24 +0200
Subject: [PATCH] implement greylisting domain option

---
 hsarback/database/data.sql                                          |    4 ++--
 hsarback/src/de/hsadmin/mods/dom/postgrey-whitelist-recipients.jtpl |   11 +++++++++++
 hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java        |   16 ++++++++++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/hsarback/database/data.sql b/hsarback/database/data.sql
index 9372b06..dd710b6 100644
--- a/hsarback/database/data.sql
+++ b/hsarback/database/data.sql
@@ -155,6 +155,6 @@
 -- table: domain_option
 --
 INSERT INTO domain_option (domain_option_name) 
-	VALUES ('greylisting');
+	VALUES ('nogreylisting');
 INSERT INTO domain_option (domain_option_name)
-	VALUES ('htdocsfallback');
+	VALUES ('nohtdocsfallback');
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
index cdc4598..79eac77 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -1,5 +1,6 @@
 package de.hsadmin.mods.dom;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -53,7 +54,7 @@
 			mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, hiveInetAddr), queueName + ".hostsharing.net");
 		}
 		for (String queueName : config.getProperty("queues.mail").split(",")) {
-			mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pac), queueName + ".hostsharing.net");
+			mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, domName, pac), queueName + ".hostsharing.net");
 		}
 		templateVars = new HashMap<String, String>();
 		templateVars.put("PAC", pacName);
@@ -162,8 +163,19 @@
 				" && invoke-rc.d bind9 reload");
 	}
 
-	private Processor createMailinSetupProcessor(String domName, Pac pac) {
+	private Processor createMailinSetupProcessor(EntityManager em, String domName, Pac pac) throws ProcessorException {
+		ArrayList<Map<String, String>> domsMaps = new ArrayList<Map<String, String>>();
+		Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option");
+		query.setParameter("option", "nogreylisting");
+		List<Domain> result = query.getResultList();
+		for (Domain dom : result) {
+			HashMap<String, String> hashMap = new HashMap<String, String>();
+			domsMaps.add(hashMap);
+		}
 		return new CompoundProcessor(
+			new TemplateProcessor("/de/hdsadmin/mods/dom/postgrey-whitelist-recipients.jtpl",
+									hashMap, domsMaps.iterator(), "/etc/postgeay/whitelist_recipients", true),
+			new ShellProcessor("invoke-rc.d postgrey reload"),
 			new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", 
 						domName + " anything\n" +
 						"." + domName + " anything\n"), 
diff --git a/hsarback/src/de/hsadmin/mods/dom/postgrey-whitelist-recipients.jtpl b/hsarback/src/de/hsadmin/mods/dom/postgrey-whitelist-recipients.jtpl
new file mode 100644
index 0000000..e787e1c
--- /dev/null
+++ b/hsarback/src/de/hsadmin/mods/dom/postgrey-whitelist-recipients.jtpl
@@ -0,0 +1,11 @@
+<!-- BEGIN: main -->### Do not edit this file manually
+### Generated by HSAdmin Queue Server
+
+abuse@
+postmaster@
+
+################################################################################
+
+<!-- BEGIN: iterate -->{DOM}
+<!-- END: iterate -->
+<!-- END: main -->

--
Gitblit v1.9.0-SNAPSHOT