HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2012-10-31 d3ceb761a8cd67447566d15d81a82573377c6098
Backup MX for External MX affects Postfix transport.
1 files modified
46 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 46 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -59,7 +59,7 @@
            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<String, String>();
        templateVars.put("PAC", pacName);
@@ -95,7 +95,7 @@
        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 @@
            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 @@
                " && 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"),
                        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", 
                        domName + " smtp:" + inetAddr + ":225\n" +
                        "." + domName + " smtp:" + inetAddr + ":225\n")
                            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 @@
        );
    }
    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;
    }