HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-04-02 10e6407a57daa54abe808daa8500cea0d3ff3e02
use template to generate named.pri-zones
1 files added
2 files modified
56 ■■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 46 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm 8 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -39,7 +39,7 @@
        Domain dom = (Domain) entity;
        UnixUser domUser = dom.getUser();
        Pac pac = domUser.getPac();
        WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(dom));
        WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(em, dom));
        mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, dom), "Setup EMail");
        Config config = Config.getInstance();
        for (String queueName : config.getProperty("queues.dns").split(",")) {
@@ -82,7 +82,19 @@
        return mainProcessor;
    }
    private Processor createHiveDNSSetupProcessor(Domain dom) throws ProcessorException {
    private Processor createDNSServerConfigProcessor(EntityManager em) {
        Query query = em.createQuery("SELECT d FROM Domains d");
        HashMap<String, Object> templateVars = new HashMap<String, Object>();
        templateVars.put("domains", query.getResultList());
        return new CompoundProcessor(
            new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm",
                        templateVars, "/etc/bind/named-hsh.conf.tmp", true),
            new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " +
                    "|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )")
        );
    }
    private Processor createHiveDNSSetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
        Map<String, Object> templateVars = new HashMap<String, Object>();
        templateVars.put("sio", Long.toString(System.currentTimeMillis()/1000L));
        String domName = dom.getName();
@@ -91,14 +103,18 @@
            new VelocityProcessor("/de/hsadmin/mods/dom/zonefile.vm", templateVars, dom, zonefileTargetPath, false);
        Processor zonefileACLProcessor = 
            new ShellProcessor("chown root:bind " + zonefileTargetPath + " && chmod 644 " + zonefileTargetPath);
        // TODO Use templates and regenerate the file.
        Processor prizonesFileProcessor =
            new ShellProcessor("echo 'zone \"" + domName + "\" { type master; file \"pri." + domName + "\"; };' >>/etc/bind/named.pri-zones" +
                " && sort /etc/bind/named.pri-zones | uniq >/etc/bind/named.pri-zones.tmp" +
                " && mv /etc/bind/named.pri-zones.tmp /etc/bind/named.pri-zones");
        Processor dnsReloadProcessor = new ShellProcessor("invoke-rc.d bind9 reload");
        Query query = em.createQuery("SELECT d FROM Domains d WHERE d.user.pac.hive.name = :hivename");
        query.setParameter("hivename", dom.getUser().getHiveName());
        templateVars = new HashMap<String, Object>();
        templateVars.put("domains", query.getResultList());
        Processor prizonesFileProcessor = new CompoundProcessor(
            new VelocityProcessor("/de/hsadmin/mods/dom/named-pri-zones.vm",
                        templateVars, 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 )")
        );
        Processor dnsSetupProcessor = 
            new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor, dnsReloadProcessor);
            new CompoundProcessor(zonefileTemplateProcessor, zonefileACLProcessor, prizonesFileProcessor);
        return dnsSetupProcessor;
    }
@@ -122,18 +138,6 @@
            emailAdrProcessor.appendProcessor(eMailAddressProcessorFactory.createCreateProcessor(em, eMailAddress));
        }
        return emailAdrProcessor;
    }
    private Processor createDNSServerConfigProcessor(EntityManager em) {
        Query query = em.createQuery("SELECT d FROM Domains d");
        HashMap<String, Object> templateVars = new HashMap<String, Object>();
        templateVars.put("domains", query.getResultList());
        return new CompoundProcessor(
            new VelocityProcessor("/de/hsadmin/mods/dom/named-hsh-conf.vm",
                        templateVars, "/etc/bind/named-hsh.conf.tmp", true),
            new ShellProcessor(" ( diff -q /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && rm /etc/bind/named-hsh.conf.tmp ) " +
                    "|| ( mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf && invoke-rc.d bind9 reload )")
        );
    }
    private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
@@ -5,4 +5,4 @@
#foreach( $domain in ${domains} )
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; };
#end
#end
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm
New file
@@ -0,0 +1,8 @@
//
// This file is managed by HSAdmin.
// Do not edit manually. Changes will be overwritten.
//
#foreach( $domain in ${domains} )
zone "${domain.name}" { type master; file "pri.${domain.name}"; };
#end