From 97bfe29c61481015c6ae5b68a12fd3b662335abb Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 18 Jun 2019 18:41:27 +0200 Subject: [PATCH] dont create pac domain --- .../hsadmin/core/qserv/VelocityProcessor.java | 11 +++++ .../de/hsadmin/mods/pac/PacModuleImpl.java | 6 --- .../hsadmin/mods/pac/PacProcessorFactory.java | 47 +++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/hsarback/src/de/hsadmin/core/qserv/VelocityProcessor.java b/hsarback/src/de/hsadmin/core/qserv/VelocityProcessor.java index c7d0790..033a574 100644 --- a/hsarback/src/de/hsadmin/core/qserv/VelocityProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/VelocityProcessor.java @@ -33,6 +33,17 @@ public class VelocityProcessor extends AbstractProcessor { private boolean overwriteTarget; private String errorMessage; + public VelocityProcessor(String templateName, Map templateVars, String targetPath, boolean overwriteTarget) { + errorMessage = ""; + this.targetPath = targetPath; + this.overwriteTarget = overwriteTarget; + VelocityContext context = new VelocityContext(); + for (String key : templateVars.keySet()) { + context.put(key, templateVars.get(key)); + } + mergeTemplate(templateName, context); + } + public VelocityProcessor(String templateName, Hive hive, String targetPath, boolean overwriteTarget) { errorMessage = ""; this.targetPath = targetPath; diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index 2c4d970..15c0af8 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -19,7 +19,6 @@ import de.hsadmin.core.util.TextUtil; import de.hsadmin.hostsharing.BasePacType; import de.hsadmin.mods.cust.Contact; import de.hsadmin.mods.cust.Customer; -import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.user.UnixUser; public class PacModuleImpl extends AbstractModuleImpl { @@ -113,11 +112,6 @@ public class PacModuleImpl extends AbstractModuleImpl { admin.setUserId(nUID); users.add(admin); newPacEntity = super.add(newEntity); - GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); - Domain pacDomain = new Domain(); - pacDomain.setName(pac.getName() + ".hostsharing.net"); - pacDomain.setUser(admin); - helperModule.add(pacDomain); } else { newPacEntity = super.add(newEntity); } diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java index f20efad..4684d9c 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java @@ -1,8 +1,13 @@ package de.hsadmin.mods.pac; +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; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.qserv.CompoundProcessor; @@ -17,6 +22,7 @@ import de.hsadmin.core.qserv.WaitingTasksProcessor; import de.hsadmin.core.util.PasswordTool; import de.hsadmin.hostsharing.BasePacType; import de.hsadmin.hostsharing.QuotaLimit; +import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.user.UnixUser; @@ -38,6 +44,7 @@ public class PacProcessorFactory implements EntityProcessorFactory { createEtcHostsProc(hive), createNetworkInterfacesProc(hive), createIPTablesProc(), + createZonefileProc(em, pac), createSudouersProc(hive), createProftpdConfProc(hive), createMakePacDirectoryStructure(unixUser), @@ -130,6 +137,46 @@ public class PacProcessorFactory implements EntityProcessorFactory { return new ShellProcessor("mk-iptables-rules Accounting"); } + private Processor createZonefileProc(final EntityManager em, final Pac pac) { + final Map zonefileTemplateVars = new HashMap(); + zonefileTemplateVars.put("sio", Long.toString(System.currentTimeMillis()/1000L)); + final String domName = pac.getName() + ".hostsharing.net"; + final String zonefileTargetPath = "/etc/bind/pri." + domName; + final Processor zonefileTemplateProcessor = + new VelocityProcessor("/de/hsadmin/mods/pac/pac-zonefile.vm", zonefileTemplateVars, zonefileTargetPath, false); + final Processor zonefileACLProcessor = + new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath); + final String hiveName = pac.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", domsNames); + final Processor prizonesFileProcessor = new CompoundProcessor( + new VelocityProcessor("/de/hsadmin/mods/dom/named-pri-zones.vm", + namedZonesTemplateVars, "/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(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor); + return dnsSetupProcessor; + } + private Processor createSudouersProc(Hive hive) throws ProcessorException { return new VelocityProcessor("/de/hsadmin/mods/pac/sudoers-pacs.vm", hive, "/etc/sudoers.d/pacs", true); }