Fix edge cases. Ignore postmap errors.
This commit is contained in:
parent
5097cdd638
commit
ff4af07450
@ -231,12 +231,15 @@ public class DomainModuleImpl extends AbstractModuleImpl {
|
|||||||
throw new HSAdminException("invalid domain option: " + opt.getName() + " for wildcard subdomain");
|
throw new HSAdminException("invalid domain option: " + opt.getName() + " for wildcard subdomain");
|
||||||
}
|
}
|
||||||
if ("backupmxforexternalmx".equals(opt.getName())) {
|
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());
|
query.setParameter("domname", updatedDom.getName());
|
||||||
if (!query.getResultList().isEmpty()) {
|
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");
|
needsWriteAccessOn(oldDom, "update");
|
||||||
return super.update(existingEntity);
|
return super.update(existingEntity);
|
||||||
|
@ -149,7 +149,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
|
|||||||
final String inetAddr = pac.getCurINetAddr().getInetAddr();
|
final String inetAddr = pac.getCurINetAddr().getInetAddr();
|
||||||
final CompoundProcessor cp = new CompoundProcessor(
|
final CompoundProcessor cp = new CompoundProcessor(
|
||||||
createPostgreyConfiguration(em),
|
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" +
|
||||||
"." + 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");
|
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");
|
query.setParameter("option", "backupmxforexternalmx");
|
||||||
if (query.getResultList().isEmpty()) {
|
if (query.getResultList().isEmpty()) {
|
||||||
cp.appendProcessor(
|
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" +
|
||||||
"." + 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 {
|
} else {
|
||||||
cp.appendProcessor(
|
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" +
|
||||||
"." + dom.getName() + "\n")
|
"." + dom.getName() + "\n")
|
||||||
);
|
);
|
||||||
cp.appendProcessor(
|
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")
|
"@" + dom.getName() + " anything\n")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -204,11 +204,12 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
|
|||||||
|
|
||||||
private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
|
private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
|
||||||
final CompoundProcessor mailQueueProcessor = new CompoundProcessor(createPostgreyConfiguration(em));
|
final CompoundProcessor mailQueueProcessor = new CompoundProcessor(createPostgreyConfiguration(em));
|
||||||
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
|
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relaydomains || true",
|
||||||
dom.getName() + "\n" +
|
dom.getName() + "\n" +
|
||||||
"." + dom.getName() + "\n" +
|
"." + dom.getName() + "\n"));
|
||||||
|
mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
|
||||||
"@" + dom.getName() + "\n"));
|
"@" + 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" +
|
||||||
"." + dom.getName() + "\n"));
|
"." + dom.getName() + "\n"));
|
||||||
return mailQueueProcessor;
|
return mailQueueProcessor;
|
||||||
|
@ -16,22 +16,22 @@ import de.hsadmin.core.util.Config;
|
|||||||
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
|
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
|
||||||
// TODO: combine both keys in a single call (optimization)
|
|
||||||
CompoundProcessor cp = new CompoundProcessor();
|
CompoundProcessor cp = new CompoundProcessor();
|
||||||
EMailAddress email = (EMailAddress) entity;
|
EMailAddress email = (EMailAddress) entity;
|
||||||
if (emailAddressCount(em, email) == 1) {
|
if (emailAddressCount(em, email) > 0) {
|
||||||
// first email address added
|
// first email address added (but the initial email addresses are created at once)
|
||||||
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
|
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
|
||||||
email.getFullDomain() + " -"));
|
email.getFullDomain() + " -\n" +
|
||||||
|
"." + email.getFullDomain() + " -\n"));
|
||||||
}
|
}
|
||||||
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
|
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
|
||||||
email.getEMailAddress() + " " + email.getTarget()));
|
email.getEMailAddress() + " " + email.getTarget() + "\n"));
|
||||||
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
|
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
|
||||||
Config config = Config.getInstance();
|
Config config = Config.getInstance();
|
||||||
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
||||||
waitingTasksProcessor.appendProcessor(queueName,
|
waitingTasksProcessor.appendProcessor(queueName,
|
||||||
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients",
|
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true",
|
||||||
email.getEMailAddress() + " anything"),
|
email.getEMailAddress() + " anything\n"),
|
||||||
"Add to relayrecipients");
|
"Add to relayrecipients");
|
||||||
}
|
}
|
||||||
return waitingTasksProcessor;
|
return waitingTasksProcessor;
|
||||||
@ -48,16 +48,17 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
|
|||||||
EMailAddress email = (EMailAddress) entity;
|
EMailAddress email = (EMailAddress) entity;
|
||||||
if (emailAddressCount(em, email) == 0) {
|
if (emailAddressCount(em, email) == 0) {
|
||||||
// last email address removed
|
// last email address removed
|
||||||
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual",
|
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true",
|
||||||
email.getFullDomain() + "\n"));
|
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"));
|
email.getEMailAddress() + "\n"));
|
||||||
Config config = Config.getInstance();
|
Config config = Config.getInstance();
|
||||||
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
|
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
|
||||||
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
for (String queueName : config.getProperty("queues.mail").split(",")) {
|
||||||
waitingTasksProcessor.appendProcessor(queueName,
|
waitingTasksProcessor.appendProcessor(queueName,
|
||||||
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
|
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
|
||||||
email.getEMailAddress() + "\n"),
|
email.getEMailAddress() + "\n"),
|
||||||
"Remove from relayrecipients");
|
"Remove from relayrecipients");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user