From b9f140d19d20d0ae4972dc675e1dfe09c3156250 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 16 Aug 2012 15:47:20 +0200 Subject: [PATCH] Domain createprocessor works with domainoptions --- hsarback/.classpath | 2 ++ hsarback/.gitignore | 2 ++ .../core/qserv/CreateFileProcessor.java | 15 ++++++++-- .../mods/dom/DomainProcessorFactory.java | 28 +++++++++++++------ .../hsadmin/mods/dom/httpd-vhost-dynamic.jtpl | 6 ++-- .../hsadmin/mods/dom/httpd-vhost-static.jtpl | 6 ++-- .../test/de/hsadmin/remote/DomainTest.java | 6 ++-- 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 hsarback/.gitignore diff --git a/hsarback/.classpath b/hsarback/.classpath index d5d5365..0fc2432 100644 --- a/hsarback/.classpath +++ b/hsarback/.classpath @@ -1,6 +1,7 @@ + @@ -26,5 +27,6 @@ + diff --git a/hsarback/.gitignore b/hsarback/.gitignore new file mode 100644 index 0000000..3f99a46 --- /dev/null +++ b/hsarback/.gitignore @@ -0,0 +1,2 @@ +/build +/webapp diff --git a/hsarback/src/de/hsadmin/core/qserv/CreateFileProcessor.java b/hsarback/src/de/hsadmin/core/qserv/CreateFileProcessor.java index 147d352..fda5ab8 100644 --- a/hsarback/src/de/hsadmin/core/qserv/CreateFileProcessor.java +++ b/hsarback/src/de/hsadmin/core/qserv/CreateFileProcessor.java @@ -1,20 +1,31 @@ package de.hsadmin.core.qserv; +import java.util.Iterator; import java.util.Map; public class CreateFileProcessor extends AbstractProcessor { private static final long serialVersionUID = -2947609532975712444L; - private CompoundProcessor compoundProcessor; + private Processor compoundProcessor; public CreateFileProcessor(String templateName, Map templateValues, String targetPath, String owner, String group, String modeMask, boolean overwriteTarget) throws ProcessorException { TemplateProcessor templateProcessor = new TemplateProcessor(templateName, templateValues, targetPath, overwriteTarget); + compoundProcessor = createCompound(targetPath, owner, group, modeMask, templateProcessor); + } + + public CreateFileProcessor(String templateName, Map templateValues, Iterator> iterateValues, String targetPath, String owner, String group, String modeMask, boolean overwriteTarget) throws ProcessorException { + TemplateProcessor templateProcessor = new TemplateProcessor(templateName, templateValues, iterateValues, targetPath, overwriteTarget); + compoundProcessor = createCompound(targetPath, owner, group, modeMask, templateProcessor); + } + + private Processor createCompound(String targetPath, String owner, String group, + String modeMask, TemplateProcessor templateProcessor) { ShellProcessor shellProcessor = new ShellProcessor( "chown " + owner + ":" + group + " " + targetPath + " && " + "chmod " + modeMask + " " + targetPath); - compoundProcessor = new CompoundProcessor(templateProcessor, shellProcessor); + return new CompoundProcessor(templateProcessor, shellProcessor); } @Override diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 79eac77..24c9afe 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -66,7 +66,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { templateVars.put("DOM_IPNUMBEREX", getOldIPAddress(pac)); templateVars.put("DOMAIN", domName); templateVars.put("USER_NAME", domUser.getComment()); - mainProcessor.appendProcessor(hiveName, createApacheVHostSetupProcessor(dom, templateVars), "Setup Apache VHost"); + mainProcessor.appendProcessor(hiveName, createApacheVHostSetupProcessor(em, dom, templateVars), "Setup Apache VHost"); if (dom.isPacDomain()) { mainProcessor.appendProcessor(hiveName, createMovePacDomainContent(em, dom), "Move pac domain content"); } @@ -167,14 +167,18 @@ public class DomainProcessorFactory implements EntityProcessorFactory { ArrayList> domsMaps = new ArrayList>(); Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option"); query.setParameter("option", "nogreylisting"); - List result = query.getResultList(); - for (Domain dom : result) { - HashMap hashMap = new HashMap(); - domsMaps.add(hashMap); + List result = query.getResultList(); + for (Object dom : result) { + if (dom instanceof Domain) { + HashMap hashMap = new HashMap(); + hashMap.put("DOM", ((Domain) dom).getName()); + domsMaps.add(hashMap); + } } return new CompoundProcessor( - new TemplateProcessor("/de/hdsadmin/mods/dom/postgrey-whitelist-recipients.jtpl", - hashMap, domsMaps.iterator(), "/etc/postgeay/whitelist_recipients", true), + new TemplateProcessor("/de/hsadmin/mods/dom/postgrey-whitelist-recipients.jtpl", + new HashMap(), + domsMaps.iterator(), "/etc/postgrey/whitelist_recipients", true), new ShellProcessor("invoke-rc.d postgrey reload"), new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", domName + " anything\n" + @@ -263,12 +267,20 @@ public class DomainProcessorFactory implements EntityProcessorFactory { return domDirsProcessor; } - private Processor createApacheVHostSetupProcessor(Domain dom, Map templateVars) + private Processor createApacheVHostSetupProcessor(EntityManager em, Domain dom, Map templateVars) throws ProcessorException { String domName = dom.getName(); int level = domName.split("\\.").length; String linkPrefix = Integer.toString(100 - level); String pac = dom.getUser().getPac().getName(); + Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); + query.setParameter("option", "nohtdocsfallback"); + query.setParameter("domname", dom.getName()); + List result = query.getResultList(); + List> iterateMaps = new ArrayList>(); + if (!result.isEmpty()) { + iterateMaps.add(new HashMap()); + } Processor domSetupProcessor = new CompoundProcessor( createDomainDirectoriesProcessor(dom, templateVars), new CreateFileProcessor(selectVHostTemplate(dom), templateVars, "/etc/apache2/sites-available/" + domName, "root", "root", "644", true), diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl index ea86656..3598247 100644 --- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl +++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl @@ -38,13 +38,13 @@ RewriteCond /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1} -d RewriteRule ^(.*) /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1}$1 [last] - RewriteCond %{REQUEST_URI} !^/cgi-bin/ + RewriteCond %{REQUEST_URI} !^/cgi-bin/ RewriteCond %{REQUEST_URI} !^/fastcgi-bin/ RewriteCond %{HTTP_HOST} ^(.+)\.{DOM_HOSTNAME}\.?(:80)?$ [novary] RewriteCond /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1} !-d RewriteRule ^(.*) - [redirect=404,last] - - AddType application/x-httpd-php .php .php5 .php4 .php3 + + AddType application/x-httpd-php .php .php5 .php4 .php3 Action application/x-httpd-php /fastcgi-bin/phpstub diff --git a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl index 8db34fc..c6982a4 100644 --- a/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl +++ b/hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl @@ -31,11 +31,11 @@ RewriteCond /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1} -d RewriteRule ^(.*) /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1}$1 [last] - RewriteCond %{HTTP_HOST} ^(.+)\.{DOM_HOSTNAME}\.?(:80)?$ [novary] + RewriteCond %{HTTP_HOST} ^(.+)\.{DOM_HOSTNAME}\.?(:80)?$ [novary] RewriteCond /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1} !-d RewriteRule ^(.*) - [redirect=404,last] - - + + diff --git a/hsarback/test/de/hsadmin/remote/DomainTest.java b/hsarback/test/de/hsadmin/remote/DomainTest.java index 57fe078..f72e591 100644 --- a/hsarback/test/de/hsadmin/remote/DomainTest.java +++ b/hsarback/test/de/hsadmin/remote/DomainTest.java @@ -155,7 +155,7 @@ public class DomainTest { Map setParams = new HashMap(); Map whereParams = new HashMap(); List optionslist = new ArrayList(); - optionslist.add("greylisting"); + optionslist.add("nogreylisting"); setParams.put("domainoptions", optionslist); whereParams.put("name", "example01.org"); Object[] params = new Object[] { user, @@ -176,8 +176,8 @@ public class DomainTest { Map setParams = new HashMap(); Map whereParams = new HashMap(); List optionslist = new ArrayList(); - optionslist.add("htdocsfallback"); - optionslist.add("greylisting"); + optionslist.add("nohtdocsfallback"); + optionslist.add("nogreylisting"); setParams.put("domainoptions", optionslist); whereParams.put("name", "example01.org"); Object[] params = new Object[] { user,