delegate hive dns config to salt

This commit is contained in:
Peter Hormanns 2020-05-27 12:21:12 +02:00
parent 1cf0d1314b
commit 67a3a59800
3 changed files with 2 additions and 64 deletions

View File

@ -2,10 +2,8 @@ package de.hsadmin.mods.dom;
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 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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");
@ -114,46 +112,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
);
}
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) {
return new ShellProcessor("grep -v '\"pri." + domName + "\"' /etc/bind/named.pri-zones > /etc/bind/named.pri-zones.tmp" +
" && mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones" +

View File

@ -1,8 +0,0 @@
//
// This file is managed by HSAdmin.
// Do not edit manually. Changes will be overwritten.
//
#foreach( $domain in ${domains} )
zone "${domain}" { type master; file "pri.${domain}"; };
#end

View File

@ -9,7 +9,6 @@ import java.util.Map;
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;
@ -151,17 +150,6 @@ public class JsonPillarServlet extends HttpServlet {
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("}");
writer.close();
transaction.close();