Merge branch 'master' of ssh://hsh04-source@hsh04.hostsharing.net/home/doms/source.hostsharing.net/source/hsadmin.git

This commit is contained in:
peter 2012-10-20 19:09:17 +02:00
commit 8985614812
12 changed files with 142 additions and 34 deletions

View File

@ -59,7 +59,7 @@ INSERT INTO domain__domain_option SELECT domain_option_id, domain_id
WHERE domain_option.domain_option_name = 'greylisting' ; WHERE domain_option.domain_option_name = 'greylisting' ;
INSERT INTO domain__domain_option SELECT domain_option_id, domain_id INSERT INTO domain__domain_option SELECT domain_option_id, domain_id
FROM domain, domain_option FROM domain, domain_option
WHERE domain_option.domain_option_name = 'htdocsfalback' ; WHERE domain_option.domain_option_name = 'htdocsfallback' ;
INSERT INTO domain__domain_option SELECT domain_option_id, domain_id INSERT INTO domain__domain_option SELECT domain_option_id, domain_id
FROM domain, domain_option FROM domain, domain_option
WHERE domain_option.domain_option_name = 'includes' ; WHERE domain_option.domain_option_name = 'includes' ;

View File

@ -6,7 +6,6 @@ import static javax.persistence.GenerationType.SEQUENCE;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;

View File

@ -374,35 +374,38 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
private Processor createMovePacDomainContent(EntityManager em, Domain dom) { private Processor createMovePacDomainContent(EntityManager em, Domain dom) {
Pac pac = dom.getUser().getPac(); Pac pac = dom.getUser().getPac();
String pacDir = "/home/pacs/" + pac.getName(); String pacName = pac.getName();
String domDir = pacDir + "/doms/" + pac.getName() + ".hostsharing.net"; 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[] 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" } ; String[] targetDirs = new String[] { "htdocs", "htdocs-ssl", "cgi", "cgi-ssl", "fastcgi", "fastcgi-ssl" } ;
CompoundProcessor processor = new CompoundProcessor(); CompoundProcessor processor = new CompoundProcessor();
for (int idx = 0; idx < targetDirs.length; idx++) { for (int idx = 0; idx < targetDirs.length; idx++) {
processor.appendProcessor( processor.appendProcessor(
new ShellProcessor("rm -rf " + domDir + targetDirs[idx])); new ShellProcessor("rm -rf " + domDir + "/" + targetDirs[idx]));
} }
for (int idx = 0; idx < sourceDirs.length; idx++) { for (int idx = 0; idx < sourceDirs.length; idx++) {
processor.appendProcessor( processor.appendProcessor(
new ShellProcessor("shopt -s dotglob && ls " + pacDir + "/" + sourceDirs[idx] + " >/dev/null 2>&1" + new ShellProcessor("shopt -s dotglob && ls " + pacDir + "/" + sourceDirs[idx] + " >/dev/null 2>&1" +
" && mv " + pacDir + "/" + sourceDirs[idx] + domDir + "/" + targetDirs[idx] + " && mv " + pacDir + "/" + sourceDirs[idx] + " " + domDir + "/" + targetDirs[idx] +
" || echo 'directory " + pacDir + "/" + sourceDirs[idx] + " not found'")); " || echo 'directory " + pacDir + "/" + sourceDirs[idx] + " not found'"));
} }
processor.appendProcessor( processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs" + new ShellProcessor("test -L " + domDir + "/htdocs" +
" && `stat -c '%N' " + domDir + "/htdocs |sed -e's/^.*`//' -e\"s/'$//\"` = web-ssl " + " && test $( stat -c '%N' " + domDir + "/htdocs |sed -e\"s/[\\`']//g\" |cut -d ' ' -f 3 ) = web-ssl " +
" && cd " + domDir + " && cd " + domDir +
" && rm " + domDir + "/htdocs" + " && rm " + domDir + "/htdocs" +
" && ln -sf htdocs-ssl htdocs" + " && ln -sf htdocs-ssl htdocs" +
" && chown -h " + pac + ":" + pac + " " + domDir + "/htdocs")); " && chown -h " + pacName + ":" + pacName + " " + domDir + "/htdocs" +
" || echo 'link htdocs not found'"));
processor.appendProcessor( processor.appendProcessor(
new ShellProcessor("test -L " + domDir + "/htdocs-ssl" + new ShellProcessor("test -L " + domDir + "/htdocs-ssl" +
" && `stat -c '%N' " + domDir + "/htdocs-ssl |sed -e's/^.*`//' -e\"s/'$//\"` = web " + " && test $( stat -c '%N' " + domDir + "/htdocs-ssl |sed -e\"s/[\\`']//g\" |cut -d ' ' -f 3 ) = web " +
" && cd " + domDir + " && cd " + domDir +
" && rm " + domDir + "/htdocs-ssl" + " && rm " + domDir + "/htdocs-ssl" +
" && ln -sf htdocs htdocs-ssl" + " && ln -sf htdocs htdocs-ssl" +
" && chown -h " + pac + ":" + pac + " " + domDir + "/htdocs-ssl")); " && chown -h " + pacName + ":" + pacName + " " + domDir + "/htdocs-ssl" +
" || echo 'link htdocs-ssl not found'"));
return processor; return processor;
} }

View File

@ -113,10 +113,10 @@ public class PacModuleImpl extends AbstractModuleImpl {
public AbstractEntity update(AbstractEntity entity) public AbstractEntity update(AbstractEntity entity)
throws HSAdminException { throws HSAdminException {
UnixUser loginUser = getTransaction().getLoginUser(); UnixUser loginUser = getTransaction().getLoginUser();
if (entity instanceof Pac) { if (!(entity instanceof Pac)) {
Pac pac = (Pac) entity;
} else {
throw new AuthorisationException(loginUser, "update", entity); throw new AuthorisationException(loginUser, "update", entity);
// } else {
// Pac pac = (Pac) entity;
} }
needsWriteAccessOn(entity, "update"); needsWriteAccessOn(entity, "update");
return super.update(entity); return super.update(entity);

View File

@ -57,14 +57,25 @@ public class PacProcessorFactory implements EntityProcessorFactory {
private Processor createHttpdVirtualProc( private Processor createHttpdVirtualProc(
String pacName, List<Map<String, String>> pacValuesList) throws ProcessorException { String pacName, List<Map<String, String>> pacValuesList) throws ProcessorException {
Processor domSetupProcessor = new CompoundProcessor( Processor domSetupProcessor = new CompoundProcessor(
new CreateFileProcessor("/de/hsadmin/mods/pac/httpd-virtual.jtpl", new HashMap<String, String>(), pacValuesList.iterator(), "/etc/apache2/virtual.conf.tmp", "root", "root", "644", true), new CreateFileProcessor("/de/hsadmin/mods/pac/httpd-virtual.jtpl",
new ShellProcessor("ls /etc/apache2/pems/" + pacName + ".pem >/dev/null 2>&1 " + "&& sed -i '/SSLCertificate.*default/d' " + "/etc/apache2/apache.conf.tmp" new HashMap<String, String>(), pacValuesList.iterator(),
+ " && (ls /etc/apache2/pems/" + pacName + ".chain.pem >/dev/null 2>&1" "/etc/apache2/virtual.conf.tmp", "root", "root", "644", true),
+ " || sed -i '/SSLCertificateChain.*" + pacName + "/d' " + "/etc/apache2/virtual.conf.tmp)" new ShellProcessor("for PEM in $( cat /etc/apache2/virtual.conf.tmp | grep SSLCertificateFile | cut -c24- ); do " +
+ " || sed -i '/SSLCertificate.*" + pacName + "/d' " + "/etc/apache2/virtual.conf.tmp"), "ls $PEM >/dev/null 2>&1 || ( " +
new ShellProcessor("(diff -q /etc/apache2/apache.conf.tmp /etc/apache2/apache.conf" " sed -i \"/SSLCertificateFile.*${PEM:18}/c \\\n" +
+ " && rm /etc/apache2/apache.conf.tmp)" "\\ \\ \\ \\ SSLCertificateFile \\/etc\\/apache2\\/pems\\/default.pem\" /etc/apache2/virtual.conf.tmp && " +
+ " || invoke-rc.d apache2 reload >/dev/null 2>&1")); " sed -i \"/SSLCertificateChainFile.*${PEM:18:5}.chain.pem/c \\\n" +
"\\ \\ \\ \\ SSLCertificateChainFile \\/etc\\/apache2\\/pems\\/default.chain.pem\" /etc/apache2/virtual.conf.tmp " +
"); " +
"done"),
new ShellProcessor("for PEM in $( cat /etc/apache2/virtual.conf.tmp | grep SSLCertificateChainFile | cut -c29- ); do " +
"ls $PEM >/dev/null 2>&1 || " +
" sed -i \"/SSLCertificateChainFile.*${PEM:18:5}.chain.pem/d \" /etc/apache2/virtual.conf.tmp ; " +
"done"),
new ShellProcessor("(diff -q /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf"
+ " && rm /etc/apache2/virtual.conf.tmp )"
+ " || ( mv /etc/apache2/virtual.conf.tmp /etc/apache2/virtual.conf "
+ " && invoke-rc.d apache2 reload >/dev/null 2>&1 ) "));
return domSetupProcessor; return domSetupProcessor;
} }

View File

@ -4,6 +4,7 @@
# #
<!-- BEGIN: iterate --> <!-- BEGIN: iterate -->
NameVirtualHost {PAC_IP}:80 NameVirtualHost {PAC_IP}:80
NameVirtualHost {PAC_IP}:443 NameVirtualHost {PAC_IP}:443
@ -16,13 +17,12 @@ NameVirtualHost {PAC_IP}:443
<VirtualHost {PAC_IP}:443> <VirtualHost {PAC_IP}:443>
SSLEngine On SSLEngine On
SSLCertificateFile /etc/apache2/pems/default.pem
SSLCertificateChainFile /etc/apache2/pems/default.chain.pem
SSLCertificateFile /etc/apache2/pems/{PAC}.pem SSLCertificateFile /etc/apache2/pems/{PAC}.pem
SSLCertificateChainFile /etc/apache2/pems/{PAC}.chain.pem SSLCertificateChainFile /etc/apache2/pems/{PAC}.chain.pem
Redirect 404 / Redirect 404 /
</VirtualHost> </VirtualHost>
<!-- END: iterate --> <!-- END: iterate -->
<!-- END: main --> <!-- END: main -->

View File

@ -65,6 +65,10 @@ public class EMailAddressRemote extends AbstractRemote {
} }
} }
adr.setTarget(tBuff.toString()); adr.setTarget(tBuff.toString());
} else {
if (l != null && l instanceof String) {
adr.setTarget((String) l);
}
} }
String domain = (String) map.get("domain"); String domain = (String) map.get("domain");
if (assertNotNull(domain)) { if (assertNotNull(domain)) {

View File

@ -21,6 +21,7 @@
<filter token="CONFIG_PORT" value="${hsar.https.port}"/> <filter token="CONFIG_PORT" value="${hsar.https.port}"/>
<filter token="ADMIN_HOST" value="${hsarweb.domain.name}"/> <filter token="ADMIN_HOST" value="${hsarweb.domain.name}"/>
<filter token="ADMIN_PORT" value="${hsarweb.https.port}"/> <filter token="ADMIN_PORT" value="${hsarweb.https.port}"/>
<filter token="HTTPS" value="${hsar.https}"/>
</filterset> </filterset>
</copy> </copy>
<war destfile="build/hsarweb.war" basedir="WebContent"> <war destfile="build/hsarweb.war" basedir="WebContent">
@ -38,4 +39,9 @@
/> />
</target> </target>
<target name="clean">
<delete dir="build"/>
<delete file="WebContent/WEB-INF/web.xml"/>
</target>
</project> </project>

View File

@ -7,15 +7,15 @@
<context-param> <context-param>
<param-name>serverName</param-name> <param-name>serverName</param-name>
<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@</param-value> <param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@</param-value>
</context-param> </context-param>
<context-param> <context-param>
<param-name>backendURL</param-name> <param-name>backendURL</param-name>
<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value> <param-value>@HTTPS@://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value>
</context-param> </context-param>
<context-param> <context-param>
<param-name>xmlrpcURL</param-name> <param-name>xmlrpcURL</param-name>
<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/xmlrpc/hsadmin</param-value> <param-value>@HTTPS@://@CONFIG_HOST@:@CONFIG_PORT@/hsar/xmlrpc/hsadmin</param-value>
</context-param> </context-param>
<context-param> <context-param>
<description>Vaadin production mode</description> <description>Vaadin production mode</description>
@ -28,11 +28,11 @@
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param> <init-param>
<param-name>casServerLoginUrl</param-name> <param-name>casServerLoginUrl</param-name>
<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/login</param-value> <param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas/login</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>service</param-name> <param-name>service</param-name>
<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value> <param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
</init-param> </init-param>
</filter> </filter>
@ -41,7 +41,7 @@
<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
<init-param> <init-param>
<param-name>casServerUrlPrefix</param-name> <param-name>casServerUrlPrefix</param-name>
<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas</param-value> <param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>proxyReceptorUrl</param-name> <param-name>proxyReceptorUrl</param-name>
@ -49,11 +49,11 @@
</init-param> </init-param>
<init-param> <init-param>
<param-name>proxyCallbackUrl</param-name> <param-name>proxyCallbackUrl</param-name>
<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb/proxyCallback</param-value> <param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb/proxyCallback</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>service</param-name> <param-name>service</param-name>
<param-value>https://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value> <param-value>@HTTPS@://@ADMIN_HOST@:@ADMIN_PORT@/hsarweb</param-value>
</init-param> </init-param>
</filter> </filter>
@ -72,7 +72,7 @@
<servlet-class>de.hsadmin.logout.LogoutServlet</servlet-class> <servlet-class>de.hsadmin.logout.LogoutServlet</servlet-class>
<init-param> <init-param>
<param-name>redirect</param-name> <param-name>redirect</param-name>
<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/logout</param-value> <param-value>@HTTPS@://@LOGIN_HOST@:@LOGIN_PORT@/cas/logout</param-value>
</init-param> </init-param>
</servlet> </servlet>

View File

@ -0,0 +1,57 @@
package de.hsadmin.web;
import java.io.File;
import java.io.FileReader;
import java.util.Properties;
public class Config {
private static Config instance;
private Properties props;
private Config() {
props = new Properties();
File file = new File(System.getProperty("user.dir") + "/hsadmin.properties");
if (!file.canRead()) {
file = new File(System.getProperty("user.dir") + "/conf/hsadmin.properties");
}
if (!file.canRead()) {
file = new File(System.getProperty("user.home") + "/.hsadmin.properties");
}
if (!file.canRead()) {
file = new File("/etc/hsadmin.properties");
}
if (!file.canRead()) {
file = new File("/etc/hsadmin/hsadmin.properties");
}
if (file.canRead()) {
try {
props.load(new FileReader(file));
} catch (Exception e) {
// should not happen
e.printStackTrace();
}
}
}
public static Config getInstance() {
if (instance == null) {
instance = new Config();
}
return instance;
}
public String getProperty(String propertyName) {
String property = props.getProperty(propertyName);
if (property == null) {
return null;
}
return property.trim();
}
public String getProperty(String propertyName, String defaultValue) {
return props.getProperty(propertyName, defaultValue).trim();
}
}

View File

@ -32,6 +32,14 @@ import de.hsadmin.web.config.ModuleConfig;
public class MainApplication extends Application implements HttpServletRequestListener, TabSheet.SelectedTabChangeListener { public class MainApplication extends Application implements HttpServletRequestListener, TabSheet.SelectedTabChangeListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets";
private static boolean isTestEnvironment = false;
static {
Config config = Config.getInstance();
Object loginURL = config.getProperty("loginURL", LOGIN_URL);
isTestEnvironment = "TestUmgebung".equals(loginURL);
}
private HttpSession httpSession; private HttpSession httpSession;
private ServletContext servletContext; private ServletContext servletContext;
@ -138,7 +146,26 @@ public class MainApplication extends Application implements HttpServletRequestLi
requestLocale = request.getLocale(); requestLocale = request.getLocale();
httpSession = request.getSession(); httpSession = request.getSession();
servletContext = httpSession.getServletContext(); servletContext = httpSession.getServletContext();
userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal(); if (isTestEnvironment) {
userPrincipal = new AttributePrincipal() {
private static final long serialVersionUID = 1L;
@Override
public String getName() {
return "ad";
}
@Override
public String getProxyTicketFor(String arg0) {
return "user:ad";
}
@SuppressWarnings("rawtypes")
@Override
public Map getAttributes() {
return new HashMap();
}
};
} else {
userPrincipal = ((Assertion) httpSession.getAttribute(AuthenticationFilter.CONST_CAS_ASSERTION)).getPrincipal();
}
} }
@Override @Override

View File

@ -162,6 +162,7 @@ public class TableComponentFactory implements ComponentFactory, Serializable {
} }
if (valueObject != null && valueObject instanceof Map) { if (valueObject != null && valueObject instanceof Map) {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
@SuppressWarnings("rawtypes")
Map valueMap = (Map) valueObject; Map valueMap = (Map) valueObject;
for (Object o : valueMap.keySet()) { for (Object o : valueMap.keySet()) {
if (o instanceof String) { if (o instanceof String) {