HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2019-06-18 4f863a4cc21e862965208679025a64e709ff4ebe
maintain named-pri-zones
3 files modified
37 ■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 26 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java 9 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -2,8 +2,10 @@
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 @@
            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<String> 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<String, Object> namedZonesTemplateVars = new HashMap<String, Object>();
        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 @@
    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");
    }
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
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
@@ -76,6 +76,7 @@
            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 @@
                createSudouersProc(hive),
                createProftpdConfProc(hive),
                createHttpdVirtualProc(hive),
                createHiveDNSRemoveProcessor(domainName),
                createAccountingRulesProc()), "remove packet");
            return waiting;
        } else {
@@ -90,6 +92,13 @@
        }
    }
    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");
    }