HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2017-06-28 279ad0ad0d8b83ded8ac1a37a087cbeecbef4e9a
extract method
1 files modified
42 ■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 42 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -51,30 +51,15 @@
        return mainProcessor;
    }
    public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
    public <T extends AbstractEntity> Processor createUpdateProcessor(final EntityManager em, final T entity) throws ProcessorException {
        final Domain dom = (Domain) entity;
        final UnixUser domUser = dom.getUser();
        final Pac pac = domUser.getPac();
        final Processor apacheVHostSetupProcessor = createApacheVHostSetupProcessor(em, dom);
        final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom);
        final String domName = dom.getName();
        final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
        query.setParameter("domname", domName);
        query.setParameter("option", "letsencrypt");
        Processor linkLetsencryptCertsProcessor = new NullProcessor();
        if (!query.getResultList().isEmpty()) {
            linkLetsencryptCertsProcessor = new ShellProcessor(
                    "rm -f /etc/apache2/pems-enabled/" + domName + ".crt" +
                    " && rm -f /etc/apache2/pems-enabled/" + domName + ".key" +
                    " && rm -f /etc/apache2/pems-enabled/" + domName + ".chain" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".key /etc/apache2/pems-enabled/" + domName + ".key" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".crt /etc/apache2/pems-enabled/" + domName + ".crt" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".chain /etc/apache2/pems-enabled/" + domName + ".chain");
        }
        final Processor triggerAcmebotProcessor = createTriggerAcmebotProcessor(em, dom);
        final WaitingTasksProcessor processor = new WaitingTasksProcessor(
                new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, linkLetsencryptCertsProcessor));
                new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, triggerAcmebotProcessor));
        final Config config = Config.getInstance();
        for (String queueName : config.getProperty("queues.mail").split(",")) {
            processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
@@ -82,7 +67,7 @@
        return processor;
    }
    public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
    public <T extends AbstractEntity> Processor createDeleteProcessor(final EntityManager em, final T entity) throws ProcessorException {
        final Domain dom = (Domain) entity;
        final String domName = dom.getName();
        final WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(                         
@@ -344,6 +329,25 @@
        return vhostDelProcessor;
    }
    private Processor createTriggerAcmebotProcessor(final EntityManager em, final Domain dom) {
        final String domName = dom.getName();
        final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
        query.setParameter("domname", domName);
        query.setParameter("option", "letsencrypt");
        if (query.getResultList().isEmpty()) {
            return new NullProcessor();
        } else {
            return new ShellProcessor(
                    "rm -f /etc/apache2/pems-enabled/" + domName + ".crt" +
                    " && rm -f /etc/apache2/pems-enabled/" + domName + ".key" +
                    " && rm -f /etc/apache2/pems-enabled/" + domName + ".chain" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".key /etc/apache2/pems-enabled/" + domName + ".key" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".crt /etc/apache2/pems-enabled/" + domName + ".crt" +
                    " && ln -s /etc/apache2/pems-generated/" + domName + ".chain /etc/apache2/pems-enabled/" + domName + ".chain" +
                    " && sudo -u acmebot /usr/sbin/acmebot -d " + domName);
        }
    }
    private Processor createACMEBotProcessor(final EntityManager em, final Domain dom) throws ProcessorException {
        final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.user.pac.hive.name = :hivename");
        final String hiveName = dom.getHiveName();