HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2012-08-16 b9f140d19d20d0ae4972dc675e1dfe09c3156250
Domain createprocessor works with domainoptions
1 files added
6 files modified
65 ■■■■ changed files
hsarback/.classpath 2 ●●●●● patch | view | raw | blame | history
hsarback/.gitignore 2 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/qserv/CreateFileProcessor.java 15 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 28 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/httpd-vhost-dynamic.jtpl 6 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/httpd-vhost-static.jtpl 6 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/DomainTest.java 6 ●●●● patch | view | raw | blame | history
hsarback/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="test"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="lib/activemq-core-5.4.2.jar"/>
    <classpathentry kind="lib" path="lib/commons-beanutils-1.8.3.jar"/>
@@ -26,5 +27,6 @@
    <classpathentry kind="lib" path="lib/xmlrpc-client-3.1.3.jar"/>
    <classpathentry kind="lib" path="lib/xmlrpc-common-3.1.3.jar"/>
    <classpathentry kind="lib" path="lib/xmlrpc-server-3.1.3.jar"/>
    <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    <classpathentry kind="output" path="bin"/>
</classpath>
hsarback/.gitignore
New file
@@ -0,0 +1,2 @@
/build
/webapp
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<String, String> 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<String, String> templateValues, Iterator<Map<String, String>> 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
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -66,7 +66,7 @@
        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 @@
        ArrayList<Map<String, String>> domsMaps = new ArrayList<Map<String, String>>();
        Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option");
        query.setParameter("option", "nogreylisting");
        List<Domain> result = query.getResultList();
        for (Domain dom : result) {
            HashMap<String, String> hashMap = new HashMap<String, String>();
            domsMaps.add(hashMap);
        List<?> result = query.getResultList();
        for (Object dom : result) {
            if (dom instanceof Domain) {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                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<String, String>(),
                        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 @@
        return domDirsProcessor;
    }
    private Processor createApacheVHostSetupProcessor(Domain dom, Map<String, String> templateVars)
    private Processor createApacheVHostSetupProcessor(EntityManager em, Domain dom, Map<String, String> 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<Map<String, String>> iterateMaps = new ArrayList<Map<String, String>>();
        if (!result.isEmpty()) {
            iterateMaps.add(new HashMap<String, String>());
        }
        Processor domSetupProcessor = new CompoundProcessor(
            createDomainDirectoriesProcessor(dom, templateVars),
            new CreateFileProcessor(selectVHostTemplate(dom), templateVars, "/etc/apache2/sites-available/" + domName, "root", "root", "644", true),
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]
<!-- BEGIN: nosubdomainfallbackforhttp -->    RewriteCond %{REQUEST_URI} !^/cgi-bin/
<!-- BEGIN: iterate -->    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]
<!-- END: nosubdomainfallbackforhttp -->    AddType application/x-httpd-php .php .php5 .php4 .php3
<!-- END: iterate -->
    AddType application/x-httpd-php .php .php5 .php4 .php3
    Action application/x-httpd-php /fastcgi-bin/phpstub
</VirtualHost>
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]
<!-- BEGIN: nosubdomainfallbackforhttp -->    RewriteCond %{HTTP_HOST} ^(.+)\.{DOM_HOSTNAME}\.?(:80)?$ [novary]
<!-- BEGIN: iterate -->    RewriteCond %{HTTP_HOST} ^(.+)\.{DOM_HOSTNAME}\.?(:80)?$ [novary]
    RewriteCond /home/doms/{DOM_HOSTNAME}/subs/${tolower:%1} !-d
    RewriteRule ^(.*) - [redirect=404,last]
<!-- END: nosubdomainfallbackforhttp --></VirtualHost>
<!-- END: iterate -->
</VirtualHost>
<VirtualHost {DOM_IPNUMBER}:443 {DOM_IPNUMBEREX}:443>
hsarback/test/de/hsadmin/remote/DomainTest.java
@@ -155,7 +155,7 @@
        Map<String, Object> setParams = new HashMap<String, Object>();
        Map<String, String> whereParams = new HashMap<String, String>();
        List<String> optionslist = new ArrayList<String>();
        optionslist.add("greylisting");
        optionslist.add("nogreylisting");
        setParams.put("domainoptions", optionslist);
        whereParams.put("name", "example01.org");
        Object[] params = new Object[] { user, 
@@ -176,8 +176,8 @@
        Map<String, Object> setParams = new HashMap<String, Object>();
        Map<String, String> whereParams = new HashMap<String, String>();
        List<String> optionslist = new ArrayList<String>();
        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,