Move Postgrey configuration processor back to domain module.

This commit is contained in:
Michael Hierweck 2017-09-12 13:43:33 +02:00
parent 775f9f98e6
commit 53e5c85bce
3 changed files with 42 additions and 28 deletions

View File

@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
@ -13,5 +18,6 @@
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -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;
@ -43,6 +44,9 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
mainProcessor.appendProcessor(hiveName, createApacheVHostSetupProcessor(em, dom), "Setup Apache VHost");
mainProcessor.appendProcessor(hiveName, createACMEBotProcessor(em, dom), "Setup ACMEBot");
mainProcessor.appendProcessor(hiveName, createTriggerAcmebotProcessor(em, dom), "Trigger ACMEBot");
for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createPostgreyConfigurationUpdateProcessor(em), queueName + ".hostsharing.net");
}
return mainProcessor;
}
@ -53,6 +57,10 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
final Processor triggerAcmebotProcessor = createTriggerAcmebotProcessor(em, dom);
final WaitingTasksProcessor processor = new WaitingTasksProcessor(
new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, triggerAcmebotProcessor));
final Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) {
processor.appendProcessor(queueName, createPostgreyConfigurationUpdateProcessor(em), queueName + ".hostsharing.net");
}
return processor;
}
@ -68,6 +76,9 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
}
mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost");
mainProcessor.appendProcessor(dom.getHiveName(), createACMEBotProcessor(em, dom), "remove letsencrypt config");
for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createPostgreyConfigurationUpdateProcessor(em), queueName + ".hostsharing.net");
}
return mainProcessor;
}
@ -290,4 +301,27 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
new ShellProcessor("mv /etc/hostsharing/acmebot/domain.properties.tmp /etc/hostsharing/acmebot/domain.properties"));
}
private Processor createPostgreyConfigurationUpdateProcessor(EntityManager em) throws ProcessorException {
final List<Domain> whitelistDoms = new ArrayList<Domain>();
final Query query = em.createQuery("SELECT DISTINCT dom FROM Domains dom WHERE NOT EXISTS "
+ "(SELECT postgreyDom FROM Domains postgreyDom "
+ "WHERE postgreyDom.domainoptions.name = :option"
+ "AND postgreyDom.name = dom.name)");
query.setParameter("option", "greylisting");
final List<?> result = query.getResultList();
for (Object dom : result) {
if (dom instanceof Domain) {
whitelistDoms.add((Domain) dom);
}
}
final HashMap<String, Object> templateVars = new HashMap<String, Object>();
templateVars.put("whitelist", whitelistDoms);
return new CompoundProcessor(
new VelocityProcessor("/de/hsadmin/mods/dom/postgrey-whitelist-recipients.vm", templateVars,
"/etc/postgrey/whitelist_recipients.tmp", true),
new ShellProcessor(
" ( diff -q /etc/postgrey/whitelist_recipients.tmp /etc/postgrey/whitelist_recipients && rm /etc/postgrey/whitelist_recipients.tmp ) "
+ "|| ( mv /etc/postgrey/whitelist_recipients.tmp /etc/postgrey/whitelist_recipients && invoke-rc.d postgrey reload )"));
}
}

View File

@ -1,7 +1,5 @@
package de.hsadmin.mods.email;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.persistence.EntityManager;
@ -13,7 +11,6 @@ import de.hsadmin.core.qserv.EntityProcessorFactory;
import de.hsadmin.core.qserv.Processor;
import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.core.qserv.ShellProcessor;
import de.hsadmin.core.qserv.VelocityProcessor;
import de.hsadmin.core.qserv.WaitingTasksProcessor;
import de.hsadmin.core.util.Config;
import de.hsadmin.mods.dom.Domain;
@ -97,32 +94,9 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
return result.size();
}
private Processor createPostgreyConfigurationUpdateProcessor(EntityManager em) throws ProcessorException {
final List<Domain> whitelistDoms = new ArrayList<Domain>();
final Query query = em.createQuery("SELECT DISTINCT dom FROM Domains dom WHERE NOT EXISTS "
+ "(SELECT postgreyDom FROM Domains postgreyDom "
+ "WHERE postgreyDom.domainoptions.name = :option"
+ "AND postgreyDom.name = dom.name)");
query.setParameter("option", "greylisting");
final List<?> result = query.getResultList();
for (Object dom : result) {
if (dom instanceof Domain) {
whitelistDoms.add((Domain) dom);
}
}
final HashMap<String, Object> templateVars = new HashMap<String, Object>();
templateVars.put("whitelist", whitelistDoms);
return new CompoundProcessor(
new VelocityProcessor("/de/hsadmin/mods/dom/postgrey-whitelist-recipients.vm", templateVars,
"/etc/postgrey/whitelist_recipients.tmp", true),
new ShellProcessor(
" ( diff -q /etc/postgrey/whitelist_recipients.tmp /etc/postgrey/whitelist_recipients && rm /etc/postgrey/whitelist_recipients.tmp ) "
+ "|| ( mv /etc/postgrey/whitelist_recipients.tmp /etc/postgrey/whitelist_recipients && invoke-rc.d postgrey reload )"));
}
private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
final String inetAddr = pac.getCurINetAddr().getInetAddr();
final CompoundProcessor cp = new CompoundProcessor(createPostgreyConfigurationUpdateProcessor(em));
final CompoundProcessor cp = new CompoundProcessor();
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains",
dom.getName() + " anything\n" +
"." + dom.getName() + " anything\n"));
@ -133,7 +107,7 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
}
private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
final CompoundProcessor cp = new CompoundProcessor(createPostgreyConfigurationUpdateProcessor(em));
final CompoundProcessor cp = new CompoundProcessor();
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relaydomains",
dom.getName() + "\n" +
"." + dom.getName() + "\n"));