From d3ceb761a8cd67447566d15d81a82573377c6098 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Wed, 31 Oct 2012 15:34:49 +0100 Subject: [PATCH] Backup MX for External MX affects Postfix transport. --- .../mods/dom/DomainProcessorFactory.java | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 5712f0e..376d9b0 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -59,7 +59,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, pacInetAddr), queueName + ".hostsharing.net"); } for (String queueName : config.getProperty("queues.mail").split(",")) { - mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, domName, pac), queueName + ".hostsharing.net"); + mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net"); } templateVars = new HashMap(); templateVars.put("PAC", pacName); @@ -95,7 +95,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { WaitingTasksProcessor processor = new WaitingTasksProcessor(createApacheVHostSetupProcessor(em, dom, templateVars)); Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.mail").split(",")) { - processor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net"); + processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net"); } return processor; } @@ -111,8 +111,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net"); } for (String queueName : config.getProperty("queues.mail").split(",")) { - mainProcessor.appendProcessor(queueName, createMailinDeleteProcessor(domName), queueName + ".hostsharing.net"); - mainProcessor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net"); + mainProcessor.appendProcessor(queueName, createMailinUnsetupProcessor(em, dom), queueName + ".hostsharing.net"); } mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost"); return mainProcessor; @@ -176,17 +175,30 @@ public class DomainProcessorFactory implements EntityProcessorFactory { " && invoke-rc.d bind9 reload"); } - private Processor createMailinSetupProcessor(EntityManager em, String domName, Pac pac) throws ProcessorException { + private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException { String inetAddr = pac.getCurINetAddr().getInetAddr(); - return new CompoundProcessor( + CompoundProcessor cp = new CompoundProcessor( createPostgreyConfiguration(em), new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", - domName + " anything\n" + - "." + domName + " anything\n"), - new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport", - domName + " smtp:" + inetAddr + ":225\n" + - "." + domName + " smtp:" + inetAddr + ":225\n") - ); + dom.getName() + " anything\n" + + "." + dom.getName() + " anything\n")); + Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); + query.setParameter("domname", dom.getName()); + query.setParameter("option", "backupmxforexternalmx"); + if (query.getResultList().isEmpty()) { + cp.appendProcessor( + new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport", + dom.getName() + " smtp:" + inetAddr + ":225\n" + + "." + dom.getName() + " smtp:" + inetAddr + ":225\n") + ); + } else { + cp.appendProcessor( + new ShellProcessor( + "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " + + "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport") + ); + } + return cp; } private Processor createPostgreyConfiguration(EntityManager em) throws ProcessorException { @@ -213,12 +225,14 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ); } - private Processor createMailinDeleteProcessor(String domName) { - Processor mailQueueProcessor = new ShellProcessor( - "postmap -d '" + domName + "' /etc/postfix-mailin/relaydomains && " + - "postmap -d '" + domName + "' /etc/postfix-mailin/transport && " + - "postmap -d '." + domName + "' /etc/postfix-mailin/relaydomains && " + - "postmap -d '." + domName + "' /etc/postfix-mailin/transport"); + private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException { + Processor mailQueueProcessor = new CompoundProcessor( + createPostgreyConfiguration(em), + new ShellProcessor( + "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/relaydomains && " + + "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " + + "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/relaydomains && " + + "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport")); return mailQueueProcessor; }