From 4f863a4cc21e862965208679025a64e709ff4ebe Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 18 Jun 2019 18:18:09 +0200 Subject: [PATCH] maintain named-pri-zones --- .../mods/dom/DomainProcessorFactory.java | 26 ++++++++++++++++--- .../de/hsadmin/mods/dom/named-pri-zones.vm | 2 +- .../hsadmin/mods/pac/PacProcessorFactory.java | 9 +++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 1e33a6d..54ae349 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -2,8 +2,10 @@ 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; @@ -106,10 +108,26 @@ public class DomainProcessorFactory implements EntityProcessorFactory { new VelocityProcessor("/de/hsadmin/mods/dom/zonefile.vm", zonefileTemplateVars, dom, zonefileTargetPath, false); final Processor zonefileACLProcessor = new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath); - final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hivename"); - query.setParameter("hivename", dom.getUser().getHiveName()); + 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 domsNames = new HashSet<>(); + 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"); + domsQuery.setParameter("hivename", hiveName); + final List pacsList = pacsQuery.getResultList(); + for (final Object obj : pacsList) { + if (obj instanceof Pac) { + domsNames.add(((Pac) obj).getName() + ".hostsharing.net"); + } + } final Map namedZonesTemplateVars = new HashMap(); - namedZonesTemplateVars.put("domains", query.getResultList()); + 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), @@ -124,7 +142,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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" + - " && rm /etc/bind/pri." + domName + + " && rm -f /etc/bind/pri." + domName + " && invoke-rc.d bind9 reload"); } diff --git a/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm b/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm index ba2286d..f04eb26 100644 --- a/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm +++ b/hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm @@ -4,5 +4,5 @@ // #foreach( $domain in ${domains} ) -zone "${domain.name}" { type master; file "pri.${domain.name}"; }; +zone "${domain}" { type master; file "pri.${domain}"; }; #end diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index 2ed39ed..f20efad 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -76,6 +76,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { Hive hive = pac.getHive(); hive.getPacs().remove(pac); WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName())); + final String domainName = pac.getName() + ".hostsharing.net"; waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor( createIfDown(pac), createEtcHostsProc(hive), @@ -83,6 +84,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { createSudouersProc(hive), createProftpdConfProc(hive), createHttpdVirtualProc(hive), + createHiveDNSRemoveProcessor(domainName), createAccountingRulesProc()), "remove packet"); return waiting; } else { @@ -90,6 +92,13 @@ public class PacProcessorFactory implements EntityProcessorFactory { } } + 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" + + " && rm -f /etc/bind/pri." + domName + + " && invoke-rc.d bind9 reload"); + } + private Processor createAccountingRulesProc() { return new ShellProcessor("mk-iptables-rules Accounting"); }