HSAdmin Backend Domains, E-Mail, Datenbanken
Purodha
2013-04-02 e762eb2145f513284a31a5f11326539efa50f7b2
Merge branch 'master' of ssh://hsh04-source@hsh04.hostsharing.net/home/doms/source.hostsharing.net/source/hsadmin.git
7 files modified
1 files added
131 ■■■■ changed files
hsarback/conf/META-INF/prod-context.xml 25 ●●●●● patch | view | raw | blame | history
hsarback/conf/WEB-INF/prod-web.xml 30 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 46 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/htaccess.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-pri-zones.vm 8 ●●●●● patch | view | raw | blame | history
hsarjcli/scripting/package_dump.js 14 ●●●●● patch | view | raw | blame | history
hsarback/conf/META-INF/prod-context.xml
@@ -66,6 +66,16 @@
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h53"
        global="jms/hsadminSystem-h53"
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h54"
        global="jms/hsadminSystem-h54"
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h55"
        global="jms/hsadminSystem-h55"
        type="javax.jms.Queue"/>
@@ -86,6 +96,21 @@
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h59"
        global="jms/hsadminSystem-h59"
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h60"
        global="jms/hsadminSystem-h60"
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-h61"
        global="jms/hsadminSystem-h61"
        type="javax.jms.Queue"/>
    <ResourceLink
        name="jms/hsadminSystem-mail1"
        global="jms/hsadminSystem-mail1"
        type="javax.jms.Queue"/>
hsarback/conf/WEB-INF/prod-web.xml
@@ -230,6 +230,18 @@
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h53</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h54</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h55</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
@@ -254,6 +266,24 @@
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h59</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h60</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-h61</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <res-ref-name>jms/hsadminSystem-dns1</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Container</res-auth>
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/htaccess.vm
@@ -1 +1 @@
Redirect permanent / ${protocol}://www.${domain.name}/
Redirect permanent / ${protocol}://www.${dom.name}/
hsarback/src/de/hsadmin/mods/dom/httpd-vhost.vm
@@ -51,7 +51,7 @@
    RewriteCond %{REQUEST_URI} !^/cgi-bin/
    RewriteCond %{REQUEST_URI} !^/fastcgi-bin/    
    RewriteCond %{HTTP_HOST} ^(.+)\.${dom.name}\.?(:[0-9]+)?\$ [novary]
    RewriteCond %{HTTP_HOST} ^(.+)\.${dom.name}\.?(:[0-9]+)?$ [novary]
    RewriteCond /home/doms/${dom.name}/subs/#[[${tolower:%1} ]]# -d
    RewriteRule ^(.*) /home/doms/${dom.name}/subs/#[[${tolower:%1}$1 ]]# [last]     
    
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
@@ -4,5 +4,5 @@
//
#foreach( $domain in ${domains} )
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetaddr}; }; };
#end
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; };
#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
hsarjcli/scripting/package_dump.js
@@ -29,14 +29,12 @@
            + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump;
    runbash(cmd);
}
function mysqlpasswddump(pac) {
function mysqlaclsdump(pac) {
    var dump = "/home/pacs/" + pac + "/.bak/mysql_passwd.gz";
    var sql = "select concat('update user set Password=\\\'', Password, '\\\' where User=\\\'', User, '\\\';')"
               + " as update_passwd from user where user like '" + pac + "%';";
    var cmd = "( ( echo \"" + sql + "\"|mysql mysql ) ; echo \"flush privileges;\" )"
            + "|sed '1d'|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump;
    var cmd = "mysqldump --no-create-db --skip-opt --no-create-info --replace --where=\"user like '" + pac + "%'\" mysql --tables user > " + dump
        + " && mysqldump --no-create-db --skip-opt --no-create-info --replace --where=\"db like '" + pac + "%'\" mysql --tables db tables_priv proc >>" + dump;
    runbash(cmd);
}
}
function pgsqlpasswddump(pac) {
    var dump = "/home/pacs/" + pac + "/.bak/pgsql_passwd.gz";
    var cmd = "export PGUSER=postgres; pg_dumpall -r | grep ^ALTER | grep " + pac
@@ -129,7 +127,7 @@
            file.write('target: [\n');
            if (addresses[idx]['target']) {
                for (jdx=0; jdx<addresses[idx]['target'].length; jdx++) {
                    file.write('     "' + addresses[idx]['target'][jdx] + '",\n');
                    file.write('     \'' + addresses[idx]['target'][jdx] + '\',\n');
                }
            }
            file.write('  ]\n');
@@ -207,7 +205,7 @@
    }
    file.close();
    shadowdump(pacname);
    mysqlpasswddump(pacname);
    mysqlaclsdump(pacname);
    pgsqlpasswddump(pacname);
} else {
    print('run as pac-owner!\n');