HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2020-05-27 67a3a59800ac098fc2f41ce0e7cd8d6e708232da
delegate hive dns config to salt
1 files deleted
2 files modified
66 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 46 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm 8 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java 12 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -2,10 +2,8 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@@ -37,7 +35,7 @@
        UnixUser domUser = dom.getUser();
        Pac pac = domUser.getPac();
        WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(
                new CompoundProcessor(createHiveDNSSetupProcessor(em, dom))
                new CompoundProcessor(new ShellProcessor("salt-call state.sls pacs"))
            );
        Config config = Config.getInstance();
        for (String queueName : config.getProperty("queues.dns").split(",")) {
@@ -61,7 +59,7 @@
        final Processor letencryptSetupProcessor = createACMEBotProcessor(em, dom);
        final Processor triggerAcmebotProcessor = createTriggerAcmebotProcessor(em, dom);
        final WaitingTasksProcessor processor = new WaitingTasksProcessor(
                new CompoundProcessor(apacheVHostSetupProcessor, letencryptSetupProcessor, triggerAcmebotProcessor));
                new CompoundProcessor(new ShellProcessor("salt-call state.sls pacs"), 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");
@@ -112,46 +110,6 @@
            new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " +
                    "|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )")
        );        
    }
    private Processor createHiveDNSSetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
        final String domName = dom.getName();
        final String zonefileTargetPath = "/etc/bind/pri." + domName;
        final Processor getZonefileProcessor = new ShellProcessor("echo \"{DEFAULT_ZONEFILE}\" | /usr/local/sbin/gen-zonefile " + domName + " > " + zonefileTargetPath);
        final Processor zonefileACLProcessor =
            new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath);
        final String hiveName = dom.getUser().getHiveName();
        final Query domsQuery = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hivename");
        domsQuery.setParameter("hivename", hiveName);
        final List<?> domsList = domsQuery.getResultList();
        final Set<String> domsNames = new HashSet<String>();
        for (final Object obj : domsList) {
            if (obj instanceof Domain) {
                domsNames.add(((Domain) obj).getName());
            }
        }
        final Query pacsQuery = em.createQuery("SELECT p FROM Pacs p WHERE p.hive.name = :hivename");
        pacsQuery.setParameter("hivename", hiveName);
        final List<?> pacsList = pacsQuery.getResultList();
        for (final Object obj : pacsList) {
            if (obj instanceof Pac) {
                final Pac p = (Pac) obj;
                if ("PAC/WEB".equals(p.getBasepac().getName())) {
                    domsNames.add(p.getName() + ".hostsharing.net");
                }
            }
        }
        final Map<String, Object> namedZonesTemplateVars = new HashMap<String, Object>();
        namedZonesTemplateVars.put("domains", domsNames);
        final Processor prizonesFileProcessor = new CompoundProcessor(
            new VelocityProcessor("/de/hsadmin/mods/dom/named-pri-zones.vm",
                    namedZonesTemplateVars, dom, "/etc/bind/named.pri-zones.tmp", true),
            new ShellProcessor(" ( diff -q /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && rm /etc/bind/named.pri-zones.tmp ) " +
                    "|| ( mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones && invoke-rc.d bind9 reload )")
        );
        final Processor dnsSetupProcessor =
            new CompoundProcessor(getZonefileProcessor, zonefileACLProcessor, prizonesFileProcessor);
        return dnsSetupProcessor;
    }
    private ShellProcessor createHiveDNSRemoveProcessor(String domName) {
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm
File was deleted
hsarback/src/de/hsadmin/pillar/JsonPillarServlet.java
@@ -9,7 +9,6 @@
import java.util.Set;
import java.util.TreeSet;
import javax.annotation.processing.SupportedSourceVersion;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.ServletException;
@@ -149,17 +148,6 @@
            }
            writer.println("      }");
            writer.println("    }");
        }
        writer.println("  ]");
        writer.println("  , \"zones\": [");
        firstLoop = true;
        for (final String zone : dnsZones) {
            if (firstLoop) {
                firstLoop = false;
                writer.println("      \"" + zone + "\"");
            } else {
                writer.println("      , \"" + zone + "\"");
            }
        }
        writer.println("  ]");
        writer.println("}");