use template to generate named.pri-zones

This commit is contained in:
Peter Hormanns 2013-04-02 14:21:44 +02:00
parent 2e99a98acf
commit 10e6407a57
3 changed files with 34 additions and 22 deletions

View File

@ -39,7 +39,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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;
}
@ -124,18 +140,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
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 {
String inetAddr = pac.getCurINetAddr().getInetAddr();
CompoundProcessor cp = new CompoundProcessor(

View File

@ -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

View 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