Adding branch with trial stuff for domain options to hsarweb

+ possibly applying recent changes of Peter Hormanns to
DomainProcessorfactory.
This commit is contained in:
Purodha Blissenbach 2012-12-18 13:26:16 +01:00
parent da4bee4361
commit 5767f4ff1e
5 changed files with 183 additions and 63 deletions

View File

@ -53,13 +53,13 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
templateVars.put("DOM_IPNUMBEREX", getOldIPAddress(pac)); templateVars.put("DOM_IPNUMBEREX", getOldIPAddress(pac));
WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(domName, templateVars)); WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(createHiveDNSSetupProcessor(domName, templateVars));
mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, domName), "Setup EMail"); mainProcessor.appendProcessor(hiveName, createHiveEMailSetupProcessor(em, domName), "Setup EMail");
String pacInetAddr = pac.getCurINetAddr().getInetAddr(); String hiveInetAddr = pac.getHive().getInetAddr().getInetAddr();
Config config = Config.getInstance(); Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.dns").split(",")) { for (String queueName : config.getProperty("queues.dns").split(",")) {
mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, pacInetAddr), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createDNSServerSetupProcessor(domName, hiveInetAddr), queueName + ".hostsharing.net");
} }
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, domName, pac), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
} }
templateVars = new HashMap<String, String>(); templateVars = new HashMap<String, String>();
templateVars.put("PAC", pacName); templateVars.put("PAC", pacName);
@ -71,10 +71,8 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
templateVars.put("DOM_IPNUMBEREX", getOldIPAddress(pac)); templateVars.put("DOM_IPNUMBEREX", getOldIPAddress(pac));
templateVars.put("DOMAIN", domName); templateVars.put("DOMAIN", domName);
templateVars.put("USER_NAME", domUser.getComment()); templateVars.put("USER_NAME", domUser.getComment());
mainProcessor.appendProcessor(hiveName, createDomainDirectoriesProcessor(dom, templateVars), "Setup Domain Directories");
mainProcessor.appendProcessor(hiveName, createApacheVHostSetupProcessor(em, 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");
}
return mainProcessor; return mainProcessor;
} }
@ -97,7 +95,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
WaitingTasksProcessor processor = new WaitingTasksProcessor(createApacheVHostSetupProcessor(em, dom, templateVars)); WaitingTasksProcessor processor = new WaitingTasksProcessor(createApacheVHostSetupProcessor(em, dom, templateVars));
Config config = Config.getInstance(); Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
processor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net"); processor.appendProcessor(queueName, createMailinSetupProcessor(em, dom, pac), queueName + ".hostsharing.net");
} }
return processor; return processor;
} }
@ -113,8 +111,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createDNSServerRemoveProcessor(domName), queueName + ".hostsharing.net");
} }
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
mainProcessor.appendProcessor(queueName, createMailinDeleteProcessor(domName), queueName + ".hostsharing.net"); mainProcessor.appendProcessor(queueName, createMailinUnsetupProcessor(em, dom), queueName + ".hostsharing.net");
mainProcessor.appendProcessor(queueName, createPostgreyConfiguration(em), queueName + ".hostsharing.net");
} }
mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost"); mainProcessor.appendProcessor(dom.getHiveName(), createApacheVHostDeleteProcessor(dom), "remove apache vhost");
return mainProcessor; return mainProcessor;
@ -160,10 +157,10 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
return emailAdrProcessor; return emailAdrProcessor;
} }
private Processor createDNSServerSetupProcessor(String domName, String pacInetAddr) { private Processor createDNSServerSetupProcessor(String domName, String hiveInetAddr) {
Processor seczonesFileProcessor; Processor seczonesFileProcessor;
seczonesFileProcessor = seczonesFileProcessor =
new ShellProcessor("echo 'zone \"" + domName + "\" { type slave; file \"sec." + domName + "\"; masters { " + pacInetAddr + "; }; };' >>/etc/bind/named-hsh.conf" + new ShellProcessor("echo 'zone \"" + domName + "\" { type slave; file \"sec." + domName + "\"; masters { " + hiveInetAddr + "; }; };' >>/etc/bind/named-hsh.conf" +
" && sort /etc/bind/named-hsh.conf | uniq >/etc/bind/named-hsh.conf.tmp" + " && sort /etc/bind/named-hsh.conf | uniq >/etc/bind/named-hsh.conf.tmp" +
" && mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf" + " && mv /etc/bind/named-hsh.conf.tmp /etc/bind/named-hsh.conf" +
" && invoke-rc.d bind9 reload"); " && invoke-rc.d bind9 reload");
@ -178,17 +175,30 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
" && invoke-rc.d bind9 reload"); " && invoke-rc.d bind9 reload");
} }
private Processor createMailinSetupProcessor(EntityManager em, String domName, Pac pac) throws ProcessorException { private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
String inetAddr = pac.getCurINetAddr().getInetAddr(); String inetAddr = pac.getCurINetAddr().getInetAddr();
return new CompoundProcessor( CompoundProcessor cp = new CompoundProcessor(
createPostgreyConfiguration(em), createPostgreyConfiguration(em),
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains",
domName + " anything\n" + dom.getName() + " anything\n" +
"." + domName + " anything\n"), "." + dom.getName() + " anything\n"));
Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
query.setParameter("domname", dom.getName());
query.setParameter("option", "backupmxforexternalmx");
if (query.getResultList().isEmpty()) {
cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport", new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport",
domName + " smtp:" + inetAddr + ":225\n" + dom.getName() + " smtp:" + inetAddr + ":225\n" +
"." + domName + " smtp:" + inetAddr + ":225\n") "." + dom.getName() + " smtp:" + inetAddr + ":225\n")
); );
} else {
cp.appendProcessor(
new ShellProcessor(
"postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport")
);
}
return cp;
} }
private Processor createPostgreyConfiguration(EntityManager em) throws ProcessorException { private Processor createPostgreyConfiguration(EntityManager em) throws ProcessorException {
@ -215,12 +225,14 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
); );
} }
private Processor createMailinDeleteProcessor(String domName) { private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
Processor mailQueueProcessor = new ShellProcessor( Processor mailQueueProcessor = new CompoundProcessor(
"postmap -d '" + domName + "' /etc/postfix-mailin/relaydomains && " + createPostgreyConfiguration(em),
"postmap -d '" + domName + "' /etc/postfix-mailin/transport && " + new ShellProcessor(
"postmap -d '." + domName + "' /etc/postfix-mailin/relaydomains && " + "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
"postmap -d '." + domName + "' /etc/postfix-mailin/transport"); "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
"postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport"));
return mailQueueProcessor; return mailQueueProcessor;
} }
@ -343,7 +355,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
} }
Processor domSetupProcessor = new CompoundProcessor( Processor domSetupProcessor = new CompoundProcessor(
createDomainDirectoriesProcessor(dom, templateVars),
new CreateFileProcessor(selectVHostTemplate(dom), templateVars, "/etc/apache2/sites-available/" + domName + ".tmp", "root", "root", "644", true), new CreateFileProcessor(selectVHostTemplate(dom), templateVars, "/etc/apache2/sites-available/" + domName + ".tmp", "root", "root", "644", true),
new ShellProcessor("ls /etc/apache2/pems/" + pac + ".pem >/dev/null 2>&1" + new ShellProcessor("ls /etc/apache2/pems/" + pac + ".pem >/dev/null 2>&1" +
" && sed -i '/SSLCertificate.*default/d' " + "/etc/apache2/sites-available/" + domName + ".tmp" + " && sed -i '/SSLCertificate.*default/d' " + "/etc/apache2/sites-available/" + domName + ".tmp" +
@ -372,43 +383,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
return vhostDelProcessor; return vhostDelProcessor;
} }
private Processor createMovePacDomainContent(EntityManager em, Domain dom) {
Pac pac = dom.getUser().getPac();
String pacName = pac.getName();
String pacDir = "/home/pacs/" + pacName;
String domDir = pacDir + "/doms/" + pacName + ".hostsharing.net";
String[] sourceDirs = new String[] { "web", "web-ssl", "cgi", "cgi-ssl", "fastcgi", "fastcgi-ssl" } ;
String[] targetDirs = new String[] { "htdocs", "htdocs-ssl", "cgi", "cgi-ssl", "fastcgi", "fastcgi-ssl" } ;
CompoundProcessor processor = new CompoundProcessor();
for (int idx = 0; idx < targetDirs.length; idx++) {
processor.appendProcessor(
new ShellProcessor("rm -rf " + domDir + "/" + targetDirs[idx]));
}
for (int idx = 0; idx < sourceDirs.length; idx++) {
processor.appendProcessor(
new ShellProcessor("shopt -s dotglob && ls " + pacDir + "/" + sourceDirs[idx] + " >/dev/null 2>&1" +
" && mv " + pacDir + "/" + sourceDirs[idx] + " " + domDir + "/" + targetDirs[idx] +
" || echo 'directory " + pacDir + "/" + sourceDirs[idx] + " not found'"));
}
processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs" +
" && test $( stat -c '%N' " + domDir + "/htdocs |sed -e\"s/[\\`']//g\" |cut -d ' ' -f 3 ) = web-ssl " +
" && cd " + domDir +
" && rm " + domDir + "/htdocs" +
" && ln -sf htdocs-ssl htdocs" +
" && chown -h " + pacName + ":" + pacName + " " + domDir + "/htdocs" +
" || echo 'link htdocs not found'"));
processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs-ssl" +
" && test $( stat -c '%N' " + domDir + "/htdocs-ssl |sed -e\"s/[\\`']//g\" |cut -d ' ' -f 3 ) = web " +
" && cd " + domDir +
" && rm " + domDir + "/htdocs-ssl" +
" && ln -sf htdocs htdocs-ssl" +
" && chown -h " + pacName + ":" + pacName + " " + domDir + "/htdocs-ssl" +
" || echo 'link htdocs-ssl not found'"));
return processor;
}
private String selectVHostTemplate(Domain dom) { private String selectVHostTemplate(Domain dom) {
String domName = dom.getName(); String domName = dom.getName();
UnixUser user = dom.getUser(); UnixUser user = dom.getUser();

View File

@ -0,0 +1,5 @@
package de.hsadmin.web;
public class AbstractProperty {
}

View File

@ -0,0 +1,15 @@
package de.hsadmin.web;
import java.util.List;
public class ListOfStringsProperty extends AbstractProperty {
public List<String> properties;
public ListOfStringsProperty(){
// ?? this.properties = new List<String>();
}
public boolean Add(String string){
return properties.add(string);
}
}

View File

@ -0,0 +1,10 @@
package de.hsadmin.web;
public class StringProperty extends AbstractProperty {
public String property ;
public StringProperty(String property) {
this.property = property;
}
}

View File

@ -0,0 +1,116 @@
/**
*
*/
package de.hsadmin.web.vaadin;
import java.util.HashMap;
import java.util.Map;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout;
import de.hsadmin.web.AbstractProperty;
import de.hsadmin.web.HsarwebException;
import de.hsadmin.web.ListOfStringsProperty;
import de.hsadmin.web.config.PropertyConfig;
import de.hsadmin.web.config.PropertyFieldFactory;
/**
* @author pblissenbach
*
*/
public class DomainOptionsPropertyFieldFactory implements PropertyFieldFactory {
private Map<String,AbstractProperty> optionTypes ; // TODO: auf Vorrat hier
private ListOfStringsProperty setOptions ;
private boolean readOnly = false;
private boolean writeOnce = false;
private VerticalLayout layout;
public DomainOptionsPropertyFieldFactory() {
// TODO: besorge Options und ihre Typen aus der DB
optionTypes = new HashMap<String,AbstractProperty>() ;
optionTypes.put("backupmxforexternalmx", null);
optionTypes.put("greylisting", null);
optionTypes.put("htdocsfallback", null);
optionTypes.put("includes", null);
optionTypes.put("indexes", null);
optionTypes.put("multiviews", null);
optionTypes.put("nonexistiondomainoptionfortesting", null); // TESTCASE
optionTypes.put("php", null);
// TODO: besorge Options .... Ende
// setOptions = null ;
setOptions = new ListOfStringsProperty() ;
// TODO Auto-generated constructor stub
}
@Override
public Object createFieldComponent(PropertyConfig prop, Object value) {
// TODO Auto-generated method stub
return null;
}
@Override
public AbstractProperty getValue(PropertyConfig prop, Object component)
throws HsarwebException {
return setOptions;
}
@Override
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
@Override
public boolean isReadOnly() {
return readOnly;
}
@Override
public void setWriteOnce(boolean writeOnce) {
this.writeOnce = writeOnce;
}
@Override
public boolean isWriteOnce() {
return writeOnce;
}
class SingleDomainOption {
private HorizontalLayout targetLine;
private HorizontalLayout leftPart;
private HorizontalLayout rightPart;
private int index;
private String optionName;
private DomainOptionsPropertyFieldFactory owner;
protected SingleDomainOption(DomainOptionsPropertyFieldFactory owner, int key, String optionName, Object optionValue) {
this.owner = owner;
this.index = key;
this.optionName = optionName;
targetLine = new HorizontalLayout();
targetLine.setWidth(480.0f, Sizeable.UNITS_PIXELS);
leftPart = new HorizontalLayout();
leftPart.setWidth(100.0f, Sizeable.UNITS_PIXELS);
leftPart.setCaption(optionName);
rightPart = new HorizontalLayout();
rightPart.setWidth(380.0f, Sizeable.UNITS_PIXELS);
// ToDO: Fallunterscheidungen nach Optionsart. Z.Z. nur Boolean.
}
public String getValue() {
String value = null;
if (rightPart.getComponentCount() > 0) {
Object object = ((AbstractField) rightPart.getComponent(0)).getValue();
if (object != null && object instanceof String) {
value = ((String) object).trim();
}
}
return value;
}
}
}