Fix edge cases. Ignore postmap errors.

This commit is contained in:
Michael Hierweck 2017-09-15 08:45:34 +02:00
parent 5097cdd638
commit ff4af07450
3 changed files with 34 additions and 29 deletions

View File

@ -231,12 +231,15 @@ public class DomainModuleImpl extends AbstractModuleImpl {
throw new HSAdminException("invalid domain option: " + opt.getName() + " for wildcard subdomain");
}
if ("backupmxforexternalmx".equals(opt.getName())) {
final Query query = em.createQuery("SELECT e FROM EMailAddress e WHERE e.domain = :domname");
final Query query = em.createQuery(
"SELECT e FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name()
+ " e WHERE e.domain = :domname");
query.setParameter("domname", updatedDom.getName());
if (!query.getResultList().isEmpty()) {
throw new HSAdminException("domain option backupmaxforexternalmx may not be activated when email addresses exist");
throw new HSAdminException(
"domain option backupmaxforexternalmx may not be activated when email addresses exist");
}
}
}
}
needsWriteAccessOn(oldDom, "update");
return super.update(existingEntity);

View File

@ -149,7 +149,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
final String inetAddr = pac.getCurINetAddr().getInetAddr();
final CompoundProcessor cp = new CompoundProcessor(
createPostgreyConfiguration(em),
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains",
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true",
dom.getName() + " anything\n" +
"." + dom.getName() + " anything\n"));
final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
@ -157,22 +157,22 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
query.setParameter("option", "backupmxforexternalmx");
if (query.getResultList().isEmpty()) {
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport",
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
"@" + dom.getName() + "\n")
);
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true",
dom.getName() + " smtp:" + inetAddr + ":225\n" +
"." + dom.getName() + " smtp:" + inetAddr + ":225\n")
);
cp.appendProcessor(
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
"@" + dom.getName() + "\n")
);
);
} else {
cp.appendProcessor(
new ShellProcessor("postmap -d - /etc/postfix-mailin/transport",
new ShellProcessor("postmap -d - /etc/postfix-mailin/transport || true",
dom.getName() + "\n" +
"." + dom.getName() + "\n")
);
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients",
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true",
"@" + dom.getName() + " anything\n")
);
}
@ -204,11 +204,12 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
final CompoundProcessor mailQueueProcessor = new CompoundProcessor(createPostgreyConfiguration(em));
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
dom.getName() + "\n" +
"." + dom.getName() + "\n" +
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relaydomains || true",
dom.getName() + "\n" +
"." + dom.getName() + "\n"));
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
"@" + dom.getName() + "\n"));
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/transports",
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/transports || true",
dom.getName() + "\n" +
"." + dom.getName() + "\n"));
return mailQueueProcessor;

View File

@ -16,22 +16,22 @@ import de.hsadmin.core.util.Config;
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
// TODO: combine both keys in a single call (optimization)
CompoundProcessor cp = new CompoundProcessor();
EMailAddress email = (EMailAddress) entity;
if (emailAddressCount(em, email) == 1) {
// first email address added
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
email.getFullDomain() + " -"));
if (emailAddressCount(em, email) > 0) {
// first email address added (but the initial email addresses are created at once)
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
email.getFullDomain() + " -\n" +
"." + email.getFullDomain() + " -\n"));
}
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
email.getEMailAddress() + " " + email.getTarget()));
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
email.getEMailAddress() + " " + email.getTarget() + "\n"));
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName,
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients",
email.getEMailAddress() + " anything"),
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true",
email.getEMailAddress() + " anything\n"),
"Add to relayrecipients");
}
return waitingTasksProcessor;
@ -48,16 +48,17 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
EMailAddress email = (EMailAddress) entity;
if (emailAddressCount(em, email) == 0) {
// last email address removed
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual",
email.getFullDomain() + "\n"));
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true",
email.getFullDomain() + "\n" +
"." + email.getFullDomain() + "\n"));
}
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual",
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true",
email.getEMailAddress() + "\n"));
Config config = Config.getInstance();
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName,
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
email.getEMailAddress() + "\n"),
"Remove from relayrecipients");
}