From d3d0d75a82f54db345a49effbe62561b9224a767 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Tue, 27 Jun 2017 13:56:41 +0200 Subject: [PATCH] Provide domain.properties for ACMEBot. --- .../mods/dom/DomainProcessorFactory.java | 48 +++++-------------- .../mods/dom/acmebot-domain.properties.vm | 8 ++++ 2 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 0f1d4be..21c57f3 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -54,7 +54,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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 templateVars = new HashMap(); + 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")); } } diff --git a/hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm b/hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm new file mode 100644 index 0000000..5654258 --- /dev/null +++ b/hsarback/src/de/hsadmin/mods/dom/acmebot-domain.properties.vm @@ -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