HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2011-08-29 38d9e8ceb87eda56fdb710e3ce336e5a19c61135
Release 2.0.1
13 files modified
103 ■■■■■ changed files
hsarback/src/de/hsadmin/core/model/AbstractEntity.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/cust/Contact.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/Database.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java 67 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAlias.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/BaseComponent.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/Hive.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/INetAddress.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/AbstractEntity.java
@@ -58,7 +58,7 @@
     * @return jpaQLQuery the matching JPA-QL query
     */
    public static String createQueryFromStringKey(String humanKey) throws HSAdminException {
        return "id=" + humanKey;
        return "obj.id=" + humanKey;
    }
    /**
hsarback/src/de/hsadmin/mods/cust/Contact.java
@@ -100,7 +100,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "name='" + humanKey + "'";
        return "obj.name='" + humanKey + "'";
    }
    @Override
hsarback/src/de/hsadmin/mods/db/Database.java
@@ -103,7 +103,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "name='" + humanKey + "'";
        return "obj.name='" + humanKey + "'";
    }
    @Override
hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java
@@ -39,6 +39,10 @@
        return MySqlUser.class;
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "obj.name='" + humanKey + "'";
    }
    public static String restriction() {
        return "obj.instance='mysql' AND ( " + Database.restriction() + " )";
    }
hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java
@@ -39,9 +39,10 @@
        return getEncoding();
    }
    /**
     *  query restriction for access control
     */
    public static String createQueryFromStringKey(String humanKey) {
        return "obj.name='" + humanKey + "'";
    }
    public static String restriction() {
        return "obj.instance='pgsql' AND ( " + Database.restriction() + " )";
    }
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -84,7 +84,7 @@
        dom.setFiled(now);
        dom.setStatus(Status.SELF);
        dom.setStatusChanged(now);
        dom.setDnsMaster("dns1.hostsharing.net");
        dom.setDnsMaster("dns.hostsharing.net");
        if (dom.getName() == null || dom.getName().length() == 0) {
            throw new HSAdminException("domain name required");
        }
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -53,7 +53,7 @@
        for (String queueName : new String[] { "mail1", "mail2", "mail3" }) {
            mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pac), queueName + ".hostsharing.net");
        }
        mainProcessor.appendProcessor("backupmx", createBackupMXSetupProcessor(domName), "backupmx.hostsharing.net");
//        mainProcessor.appendProcessor("backupmx", createBackupMXSetupProcessor(domName), "backupmx.hostsharing.net");
        templateVars = new HashMap<String, String>();
        templateVars.put("PAC", pacName);
        templateVars.put("HIVE", pac.getHiveName());
@@ -88,7 +88,7 @@
            mainProcessor.appendProcessor(queueName, createMailinDeleteProcessor(domName), queueName + ".hostsharing.net");
        }
        mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost");
        mainProcessor.appendProcessor("backupmx", createBackupMXDeleteProcessor(domName), "backupmx.hostsharing.net");
//        mainProcessor.appendProcessor("backupmx", createBackupMXDeleteProcessor(domName), "backupmx.hostsharing.net");
        return mainProcessor;
    }
@@ -167,7 +167,8 @@
    }
    private Processor createMailinDeleteProcessor(String domName) {
        Processor mailQueueProcessor = new ShellProcessor("postmap -d '" + domName + "' /etc/postfix-mailin/relaydomains && " +
        Processor mailQueueProcessor = new ShellProcessor(
                "postmap -d '" + domName + "' /etc/postfix-mailin/relaydomains && " +
                "postmap -d '" + domName + "' /etc/postfix-mailin/transport && " +
                "postmap -d '." + domName + "' /etc/postfix-mailin/relaydomains && " +
                "postmap -d '." + domName + "' /etc/postfix-mailin/transport");
hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl
@@ -1,5 +1,5 @@
<!-- BEGIN: main -->$TTL 6H
{DOM_HOSTNAME}. IN SOA dns1.hostsharing.net. hostmaster.hostsharing.net. (
{DOM_HOSTNAME}. IN SOA dns.hostsharing.net. hostmaster.hostsharing.net. (
                {SIO}    ; serial secs since Jan 1 1970 
                6H        ; refresh (>=10000)
                1H        ; retry (>=1800)
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java
@@ -10,15 +10,10 @@
import de.hsadmin.core.qserv.EntityProcessorFactory;
import de.hsadmin.core.qserv.Processor;
import de.hsadmin.core.qserv.ShellProcessor;
import de.hsadmin.core.qserv.WaitingTasksProcessor;
/**
 * System level implementation for EMailAdress module.
 */
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
    
    /**
     * @return a Processor which creates an email address
     */
    public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
        // TODO: combine both keys in a single call (optimization)
        EMailAddress email = (EMailAddress) entity;
@@ -27,29 +22,47 @@
                email.getFullDomain() + " -" ) );
        cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix/virtual",
                email.getEMailAddress() + " " + email.getTarget() ) );
        return cp;
        if (emailAddressCount(em, email) < 2) {
            WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
            String pacName = email.getDomain().getUser().getPac().getName();
            String domName = email.getDomain().getName();
            for (String queueName : new String[] { "mail1", "mail2", "mail3" }) {
                waitingTasksProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pacName), queueName + ".hostsharing.net");
            }
            return waitingTasksProcessor;
        } else {
            return cp;
        }
    }
    
    /**
     * @return a Processor which updates an email address
     */
    public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
        // TODO: if update is specified by primary-key or DB query instead of OID,
        //     a  postmap -d might be neccessary 
        return createCreateProcessor(em, entity);
    }
    
    /**
     * @return a Processor which deletes an email address
     */
    public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
        // TODO: combine both keys in a single call (optimization)
        // remove the entry itself
        CompoundProcessor cp = new CompoundProcessor();
        EMailAddress email = (EMailAddress) entity;
        cp.appendProcessor( 
                new ShellProcessor( "postmap -d '" + email.getEMailAddress() + "' /etc/postfix/virtual" ) );
        // any other email addresses for this domain?
        int emailAddressCount = emailAddressCount(em, email);
        if (emailAddressCount == 0) {
            // remove the domain from virtual.db
            cp.appendProcessor(
                    new ShellProcessor( "postmap -d '" + email.getFullDomain() + "' /etc/postfix/virtual" ) );
            WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
            String domName = email.getDomain().getName();
            for (String queueName : new String[] { "mail1", "mail2", "mail3" }) {
                waitingTasksProcessor.appendProcessor(queueName, createMailinDeleteProcessor(domName), queueName + ".hostsharing.net");
            }
            return waitingTasksProcessor;
        } else {
            return cp;
        }
    }
    private int emailAddressCount(EntityManager em, EMailAddress email) {
        Query query;
        if ( email.getSubdomain() != null ) {
            query = em.createQuery("SELECT e FROM EMailAddresses e WHERE e.subdomain=:subdomain AND e.domain=:domain");
@@ -60,11 +73,23 @@
        }
        query.setParameter("domain", email.getDomain());
        List<?> result = query.getResultList();
        if ( result == null || result.size() == 0 ) {
            // remove the domain from virtual.db
            cp.appendProcessor(
                    new ShellProcessor( "postmap -d '" + email.getFullDomain() + "' /etc/postfix/virtual" ) );
        if (result == null) {
            return 0;
        }
        return cp;
        return result.size();
    }
    private Processor createMailinSetupProcessor(String domName, String pacName) {
        return
            new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport",
                        domName + " smtp:[" + pacName + ".hostsharing.net]\n" +
                        "." + domName + " smtp:[" + pacName + ".hostsharing.net]\n");
    }
    private Processor createMailinDeleteProcessor(String domName) {
        return new ShellProcessor(
                "postmap -d '" + domName + "' /etc/postfix-mailin/transport && " +
                "postmap -d '." + domName + "' /etc/postfix-mailin/transport");
    }
}
hsarback/src/de/hsadmin/mods/email/EMailAlias.java
@@ -91,7 +91,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "name='" + humanKey + "'";
        return "obj.name='" + humanKey + "'";
    }
    @Override
hsarback/src/de/hsadmin/mods/pac/BaseComponent.java
@@ -49,7 +49,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "feature='" + humanKey + "'";
        return "obj.feature='" + humanKey + "'";
    }
    @Override
hsarback/src/de/hsadmin/mods/pac/Hive.java
@@ -63,7 +63,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "hiveName='" + humanKey + "'";
        return "obj.hiveName='" + humanKey + "'";
    }
    @Override
hsarback/src/de/hsadmin/mods/pac/INetAddress.java
@@ -46,7 +46,7 @@
    }
    public static String createQueryFromStringKey(String humanKey) {
        return "inetAddr='" + humanKey + "'";
        return "obj.inetAddr='" + humanKey + "'";
    }
    @Override