From 38d9e8ceb87eda56fdb710e3ce336e5a19c61135 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 29 Aug 2011 14:09:20 +0000 Subject: [PATCH] Release 2.0.1 --- .../de/hsadmin/core/model/AbstractEntity.java | 2 +- .../src/de/hsadmin/mods/cust/Contact.java | 2 +- hsarback/src/de/hsadmin/mods/db/Database.java | 2 +- .../src/de/hsadmin/mods/db/MySqlDatabase.java | 4 ++ .../src/de/hsadmin/mods/db/PgSqlDatabase.java | 7 +- .../de/hsadmin/mods/dom/DomainModuleImpl.java | 2 +- .../mods/dom/DomainProcessorFactory.java | 7 +- .../src/de/hsadmin/mods/dom/zonefile.jtpl | 2 +- .../email/EMailAddressProcessorFactory.java | 67 +++++++++++++------ .../src/de/hsadmin/mods/email/EMailAlias.java | 2 +- .../de/hsadmin/mods/pac/BaseComponent.java | 2 +- hsarback/src/de/hsadmin/mods/pac/Hive.java | 2 +- .../src/de/hsadmin/mods/pac/INetAddress.java | 2 +- 13 files changed, 67 insertions(+), 36 deletions(-) diff --git a/hsarback/src/de/hsadmin/core/model/AbstractEntity.java b/hsarback/src/de/hsadmin/core/model/AbstractEntity.java index fac726d..b93cef6 100644 --- a/hsarback/src/de/hsadmin/core/model/AbstractEntity.java +++ b/hsarback/src/de/hsadmin/core/model/AbstractEntity.java @@ -58,7 +58,7 @@ public abstract class AbstractEntity { * @return jpaQLQuery the matching JPA-QL query */ public static String createQueryFromStringKey(String humanKey) throws HSAdminException { - return "id=" + humanKey; + return "obj.id=" + humanKey; } /** diff --git a/hsarback/src/de/hsadmin/mods/cust/Contact.java b/hsarback/src/de/hsadmin/mods/cust/Contact.java index 275ee46..691419e 100644 --- a/hsarback/src/de/hsadmin/mods/cust/Contact.java +++ b/hsarback/src/de/hsadmin/mods/cust/Contact.java @@ -100,7 +100,7 @@ public class Contact extends AbstractEntity implements Serializable { } public static String createQueryFromStringKey(String humanKey) { - return "name='" + humanKey + "'"; + return "obj.name='" + humanKey + "'"; } @Override diff --git a/hsarback/src/de/hsadmin/mods/db/Database.java b/hsarback/src/de/hsadmin/mods/db/Database.java index 5c62998..86ea204 100644 --- a/hsarback/src/de/hsadmin/mods/db/Database.java +++ b/hsarback/src/de/hsadmin/mods/db/Database.java @@ -103,7 +103,7 @@ public abstract class Database extends AbstractEntity implements Serializable { } public static String createQueryFromStringKey(String humanKey) { - return "name='" + humanKey + "'"; + return "obj.name='" + humanKey + "'"; } @Override diff --git a/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java b/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java index 045b256..f40c7cb 100644 --- a/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java +++ b/hsarback/src/de/hsadmin/mods/db/MySqlDatabase.java @@ -39,6 +39,10 @@ public class MySqlDatabase extends Database implements Serializable { return MySqlUser.class; } + public static String createQueryFromStringKey(String humanKey) { + return "obj.name='" + humanKey + "'"; + } + public static String restriction() { return "obj.instance='mysql' AND ( " + Database.restriction() + " )"; } diff --git a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java index c7f443e..680c8a7 100644 --- a/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java +++ b/hsarback/src/de/hsadmin/mods/db/PgSqlDatabase.java @@ -39,9 +39,10 @@ public class PgSqlDatabase extends Database implements Serializable { 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() + " )"; } diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 9bc06bc..81abc1a 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -84,7 +84,7 @@ public class DomainModuleImpl extends AbstractModuleImpl { 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"); } diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 5b320f0..0ef8e45 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -53,7 +53,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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(); templateVars.put("PAC", pacName); templateVars.put("HIVE", pac.getHiveName()); @@ -88,7 +88,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { 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 @@ public class DomainProcessorFactory implements EntityProcessorFactory { } 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"); diff --git a/hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl b/hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl index 1cc6c6b..b4560a7 100644 --- a/hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl +++ b/hsarback/src/de/hsadmin/mods/dom/zonefile.jtpl @@ -1,5 +1,5 @@ $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) diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java b/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java index 26b54f3..5c33f69 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java @@ -10,15 +10,10 @@ import de.hsadmin.core.qserv.CompoundProcessor; 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 Processor createCreateProcessor(EntityManager em, T entity) { // TODO: combine both keys in a single call (optimization) EMailAddress email = (EMailAddress) entity; @@ -27,29 +22,47 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory { 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 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 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 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory { } 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"); + } + } diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java index 87b60f7..05d8292 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java @@ -91,7 +91,7 @@ public class EMailAlias extends AbstractEntity implements Serializable { } public static String createQueryFromStringKey(String humanKey) { - return "name='" + humanKey + "'"; + return "obj.name='" + humanKey + "'"; } @Override diff --git a/hsarback/src/de/hsadmin/mods/pac/BaseComponent.java b/hsarback/src/de/hsadmin/mods/pac/BaseComponent.java index e08f8c0..fbf5380 100644 --- a/hsarback/src/de/hsadmin/mods/pac/BaseComponent.java +++ b/hsarback/src/de/hsadmin/mods/pac/BaseComponent.java @@ -49,7 +49,7 @@ public class BaseComponent extends de.hsadmin.core.model.AbstractEntity implemen } public static String createQueryFromStringKey(String humanKey) { - return "feature='" + humanKey + "'"; + return "obj.feature='" + humanKey + "'"; } @Override diff --git a/hsarback/src/de/hsadmin/mods/pac/Hive.java b/hsarback/src/de/hsadmin/mods/pac/Hive.java index 268f611..6183d9f 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Hive.java +++ b/hsarback/src/de/hsadmin/mods/pac/Hive.java @@ -63,7 +63,7 @@ public class Hive extends AbstractEntity implements Serializable { } public static String createQueryFromStringKey(String humanKey) { - return "hiveName='" + humanKey + "'"; + return "obj.hiveName='" + humanKey + "'"; } @Override diff --git a/hsarback/src/de/hsadmin/mods/pac/INetAddress.java b/hsarback/src/de/hsadmin/mods/pac/INetAddress.java index 83267f3..6cb784b 100644 --- a/hsarback/src/de/hsadmin/mods/pac/INetAddress.java +++ b/hsarback/src/de/hsadmin/mods/pac/INetAddress.java @@ -46,7 +46,7 @@ public class INetAddress extends AbstractEntity implements Serializable { } public static String createQueryFromStringKey(String humanKey) { - return "inetAddr='" + humanKey + "'"; + return "obj.inetAddr='" + humanKey + "'"; } @Override