HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2017-06-27 d3d0d75a82f54db345a49effbe62561b9224a767
Provide domain.properties for ACMEBot.
1 files added
1 files modified
56 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 48 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm 8 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -54,7 +54,7 @@
        UnixUser domUser = dom.getUser();
        Pac pac = domUser.getPac();
        final Processor apacheVHostSetupProcessor = createApacheVHostSetupProcessor(em, dom);
        final Processor letencryptSetupProcessor = createLetencryptSetupProcessor(em, dom);
        final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom);
        WaitingTasksProcessor processor = new WaitingTasksProcessor(new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor));
        Config config = Config.getInstance();
        for (String queueName : config.getProperty("queues.mail").split(",")) {
@@ -77,7 +77,7 @@
            mainProcessor.appendProcessor(queueName, createMailinUnsetupProcessor(em, dom), queueName + ".hostsharing.net");
        }
        mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost");
        mainProcessor.appendProcessor(dom.getHiveName(), createLetencryptUnsetProcessor(dom), "remove letsencrypt config");
        mainProcessor.appendProcessor(dom.getHiveName(), createACMEBotProcessor(em, dom), "remove letsencrypt config");
        return mainProcessor;
    }
@@ -326,39 +326,17 @@
        return vhostDelProcessor;
    }
    private Processor createLetencryptSetupProcessor(final EntityManager em, final Domain dom) {
        final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
        final String domName = dom.getName();
        query.setParameter("domname", domName);
        query.setParameter("option", "letsencrypt");
        if (query.getResultList().isEmpty()) {
            // remove LE config
            return createLetencryptUnsetProcessor(dom);
        } else {
            // setup LE
            return new ShellProcessor(
                    "mkdir -p /var/lib/letsencrypt/webroot/" + domName +
                    " && chown root:root /var/lib/letsencrypt/webroot/" + domName +
                    " && chmod 0755 /var/lib/letsencrypt/webroot/" + domName +
                    " && mkdir -p /var/lib/letsencrypt/webroot/" + domName + "/.well-known" +
                    " && chown root:root /var/lib/letsencrypt/webroot/" + domName + "/.well-known" +
                    " && chmod 0755 /var/lib/letsencrypt/webroot/" + domName + "/.well-known" +
                    " && mkdir -p /var/lib/letsencrypt/webroot/" + domName + "/.well-known/acme-challenge" +
                    " && chown root:root /var/lib/letsencrypt/webroot/" + domName + "/.well-known/acme-challenge" +
                    " && chmod 0755 /var/lib/letsencrypt/webroot/" + domName + "/.well-known/acme-challenge" +
                    " && mkdir -p /etc/letsencrypt/renewal/" +
                    " && mkdir -p /etc/letsencrypt/live/" + domName +
                    " && mkdir -p /etc/letsencrypt/archive/" + domName +
                    " && echo \"subs=" + dom.getValidsubdomainnames() + "\" > /etc/letsencrypt/renewal/" + domName + ".conf" );
        }
    }
    private Processor createLetencryptUnsetProcessor(final Domain dom) {
        final String domName = dom.getName();
        return new ShellProcessor("rm -rf  /var/lib/letsencrypt/webroot/" + domName +
                    " && rm -rf /etc/letsencrypt/archive/" + domName +
                    " && rm -rf /etc/letsencrypt/live/" + domName +
                    " && rm -f /etc/letsencrypt/renewal/" + domName + ".conf");
    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();
        final Map<String, Object> templateVars = new HashMap<String, Object>();
        query.setParameter("hivename", hiveName);
        query.setParameter("option", "letsencrypt");
        templateVars.put("domains", query.getResultList());
        return new CompoundProcessor(
                new CreateFileProcessor("/de/hsadmin/mods/dom/acmebot-domain.properties.vm", templateVars, dom,
                        "/etc/hostsharing/acmebot/domain.properties.tmp", "acmebot", "acmebot", "640", false),
                new ShellProcessor("mv /etc/hostsharing/acmebot/domain.properties.tmp /etc/hostsharing/acmebot/domain.properties"));
    }
}
hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm
New file
@@ -0,0 +1,8 @@
#
# This file is managed by HSAdmin.
# Do not edit manually. Changes will be overwritten.
#
#foreach( $domain in $domains )
${domain.name} = ${domain.getValidsubdomainnames}
#end