| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | |
| | |
| | | createEtcHostsProc(hive), |
| | | createNetworkInterfacesProc(hive), |
| | | createIPTablesProc(), |
| | | createZonefileProc(em, pac), |
| | | createSudouersProc(hive), |
| | | createProftpdConfProc(hive), |
| | | createMakePacDirectoryStructure(unixUser), |
| | |
| | | return new ShellProcessor("mk-iptables-rules Accounting"); |
| | | } |
| | | |
| | | private Processor createZonefileProc(final EntityManager em, final Pac pac) { |
| | | final Map<String, Object> zonefileTemplateVars = new HashMap<String, Object>(); |
| | | 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<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", 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); |
| | | } |