HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2017-09-15 ff4af074503894250d1b3648e230343be84940ec
Fix edge cases. Ignore postmap errors.
3 files modified
63 ■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 9 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 27 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java 27 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -231,12 +231,15 @@
                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);
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -149,7 +149,7 @@
        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 @@
        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 @@
    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;
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java
@@ -16,22 +16,22 @@
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 @@
        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");
        }