From 898561481245ca43e2416c8ec645ee2269df7369 Mon Sep 17 00:00:00 2001
From: peter <peter.hormanns@jalin.de>
Date: Sat, 20 Oct 2012 19:09:17 +0200
Subject: [PATCH] Merge branch 'master' of ssh://hsh04-source@hsh04.hostsharing.net/home/doms/source.hostsharing.net/source/hsadmin.git

---
 hsarback/database/database_update.sql                        |    2 
 hsarweb/src/de/hsadmin/web/vaadin/TableComponentFactory.java |    1 
 hsarweb/build.xml                                            |    6 ++
 hsarweb/conf/WEB-INF/web.xml                                 |   20 +++---
 hsarweb/src/de/hsadmin/web/MainApplication.java              |   29 +++++++++
 hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java    |   27 ++++++--
 hsarweb/src/de/hsadmin/web/Config.java                       |   57 +++++++++++++++++++
 hsarback/src/de/hsadmin/remote/EMailAddressRemote.java       |    4 +
 hsarback/src/de/hsadmin/mods/pac/httpd-virtual.jtpl          |    4 
 hsarback/src/de/hsadmin/mods/dom/Domain.java                 |    1 
 hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java |   19 +++--
 hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java          |    6 +-
 12 files changed, 142 insertions(+), 34 deletions(-)

diff --git a/hsarback/database/database_update.sql b/hsarback/database/database_update.sql
index 3f3f5dd..dd855d7 100644
--- a/hsarback/database/database_update.sql
+++ b/hsarback/database/database_update.sql
@@ -59,7 +59,7 @@
 	WHERE domain_option.domain_option_name = 'greylisting' ;
 INSERT INTO domain__domain_option SELECT domain_option_id, domain_id
 	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
 	FROM domain, domain_option
 	WHERE domain_option.domain_option_name = 'includes' ;
diff --git a/hsarback/src/de/hsadmin/mods/dom/Domain.java b/hsarback/src/de/hsadmin/mods/dom/Domain.java
index 0a0c112..07d2c32 100644
--- a/hsarback/src/de/hsadmin/mods/dom/Domain.java
+++ b/hsarback/src/de/hsadmin/mods/dom/Domain.java
@@ -6,7 +6,6 @@
 import java.util.Date;
 import java.util.Set;
 
-import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EntityManager;
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
index b09d7d3..3a320a3 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -374,35 +374,38 @@
 
 	private Processor createMovePacDomainContent(EntityManager em, Domain dom) {
 		Pac pac = dom.getUser().getPac();
-		String pacDir = "/home/pacs/" + pac.getName();
-		String domDir = pacDir + "/doms/" + pac.getName() + ".hostsharing.net"; 
+		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]));
+					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] +
+						" && mv " + pacDir + "/" + sourceDirs[idx] + " " + domDir + "/" + targetDirs[idx] +
 						" || echo 'directory " + pacDir + "/" + sourceDirs[idx] + " not found'"));
 		}		
 		processor.appendProcessor(
 				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 +
 						" && rm " + domDir + "/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(
 				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 +
 						" && rm " + domDir + "/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;		
 	}
 
diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
index 32ae06f..1ed2d7d 100644
--- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -113,10 +113,10 @@
 	public AbstractEntity update(AbstractEntity entity)
 			throws HSAdminException {
 		UnixUser loginUser = getTransaction().getLoginUser();
-		if (entity instanceof Pac) {
-			Pac pac = (Pac) entity;
-		} else {
+		if (!(entity instanceof Pac)) {
 			throw new AuthorisationException(loginUser, "update", entity);
+//		} else {
+//			Pac pac = (Pac) entity;
 		}
 		needsWriteAccessOn(entity, "update");
 		return super.update(entity);
diff --git a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
index f764792..b0013fb 100644
--- a/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
+++ b/hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
@@ -57,14 +57,25 @@
 	private Processor createHttpdVirtualProc(
 			String pacName, List<Map<String, String>> pacValuesList) throws ProcessorException {
 		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 ShellProcessor("ls /etc/apache2/pems/" + pacName + ".pem >/dev/null 2>&1 " + "&& sed -i '/SSLCertificate.*default/d' " + "/etc/apache2/apache.conf.tmp"
-								+ " && (ls /etc/apache2/pems/" + pacName + ".chain.pem >/dev/null 2>&1"
-								+ " || sed -i '/SSLCertificateChain.*" + pacName + "/d' " + "/etc/apache2/virtual.conf.tmp)"
-								+ " || sed -i '/SSLCertificate.*" + pacName + "/d' " + "/etc/apache2/virtual.conf.tmp"),
-				new ShellProcessor("(diff -q /etc/apache2/apache.conf.tmp /etc/apache2/apache.conf"
-								+ " && rm /etc/apache2/apache.conf.tmp)"
-								+ " || invoke-rc.d apache2 reload >/dev/null 2>&1"));
+				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 ShellProcessor("for PEM in $( cat /etc/apache2/virtual.conf.tmp | grep SSLCertificateFile | cut -c24- ); do " +
+						"ls $PEM >/dev/null 2>&1 || ( " +
+						" sed -i \"/SSLCertificateFile.*${PEM:18}/c \\\n" +
+						"\\ \\ \\ \\ SSLCertificateFile \\/etc\\/apache2\\/pems\\/default.pem\" /etc/apache2/virtual.conf.tmp && " +
+						" 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;
 	}
 
diff --git a/hsarback/src/de/hsadmin/mods/pac/httpd-virtual.jtpl b/hsarback/src/de/hsadmin/mods/pac/httpd-virtual.jtpl
index 719f1db..1361e90 100644
--- a/hsarback/src/de/hsadmin/mods/pac/httpd-virtual.jtpl
+++ b/hsarback/src/de/hsadmin/mods/pac/httpd-virtual.jtpl
@@ -4,6 +4,7 @@
 #
 
 <!-- BEGIN: iterate -->
+
 NameVirtualHost {PAC_IP}:80
 NameVirtualHost {PAC_IP}:443
 
@@ -16,13 +17,12 @@
 <VirtualHost {PAC_IP}:443>
 
     SSLEngine On
-    SSLCertificateFile /etc/apache2/pems/default.pem
-    SSLCertificateChainFile /etc/apache2/pems/default.chain.pem
     SSLCertificateFile /etc/apache2/pems/{PAC}.pem
     SSLCertificateChainFile /etc/apache2/pems/{PAC}.chain.pem
 
     Redirect 404 /
     
 </VirtualHost>
+
 <!-- END: iterate -->
 <!-- END: main -->
\ No newline at end of file
diff --git a/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java b/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java
index 1982382..05bff40 100644
--- a/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java
+++ b/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java
@@ -65,6 +65,10 @@
 				}
 			}
 			adr.setTarget(tBuff.toString());
+		} else {
+			if (l != null && l instanceof String) {
+				adr.setTarget((String) l);
+			}
 		}
 		String domain = (String) map.get("domain");
 		if (assertNotNull(domain)) {
diff --git a/hsarweb/build.xml b/hsarweb/build.xml
index 530142d..eaad198 100644
--- a/hsarweb/build.xml
+++ b/hsarweb/build.xml
@@ -21,6 +21,7 @@
 				<filter token="CONFIG_PORT" value="${hsar.https.port}"/>
 				<filter token="ADMIN_HOST" value="${hsarweb.domain.name}"/>
 				<filter token="ADMIN_PORT" value="${hsarweb.https.port}"/>
+				<filter token="HTTPS" value="${hsar.https}"/>
 			</filterset>
 		</copy>
         <war destfile="build/hsarweb.war" basedir="WebContent">
@@ -38,4 +39,9 @@
 		/>    
     </target>
 
+    <target name="clean">
+    	<delete dir="build"/>
+    	<delete file="WebContent/WEB-INF/web.xml"/>
+    </target>
+
 </project>
diff --git a/hsarweb/conf/WEB-INF/web.xml b/hsarweb/conf/WEB-INF/web.xml
index efabea9..e9a46ec 100644
--- a/hsarweb/conf/WEB-INF/web.xml
+++ b/hsarweb/conf/WEB-INF/web.xml
@@ -7,15 +7,15 @@
 
 	<context-param>
 		<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>
 		<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>
 		<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>
 		<description>Vaadin production mode</description>
@@ -28,11 +28,11 @@
 		<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
 		<init-param>
 			<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>
 			<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>
 	</filter>
 
@@ -41,7 +41,7 @@
 		<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
 		<init-param>
 			<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>
         	<param-name>proxyReceptorUrl</param-name>
@@ -49,11 +49,11 @@
         </init-param>
         <init-param>
         	<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>
 			<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>
 	</filter>
 	
@@ -66,13 +66,13 @@
         <filter-name>CAS Authentication Filter</filter-name>
 		<url-pattern>/*</url-pattern>
     </filter-mapping>
-
+		 
 	<servlet>
 		<servlet-name>Logout Servlet</servlet-name>
 		<servlet-class>de.hsadmin.logout.LogoutServlet</servlet-class>
 		<init-param>
 			<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>
 	</servlet>
 	
diff --git a/hsarweb/src/de/hsadmin/web/Config.java b/hsarweb/src/de/hsadmin/web/Config.java
new file mode 100644
index 0000000..83ef15d
--- /dev/null
+++ b/hsarweb/src/de/hsadmin/web/Config.java
@@ -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();
+	}
+	
+}
diff --git a/hsarweb/src/de/hsadmin/web/MainApplication.java b/hsarweb/src/de/hsadmin/web/MainApplication.java
index 5f256a2..9d87716 100644
--- a/hsarweb/src/de/hsadmin/web/MainApplication.java
+++ b/hsarweb/src/de/hsadmin/web/MainApplication.java
@@ -32,6 +32,14 @@
 public class MainApplication extends Application implements HttpServletRequestListener, TabSheet.SelectedTabChangeListener {
 
 	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 ServletContext servletContext;
@@ -138,7 +146,26 @@
 		requestLocale = request.getLocale();
 		httpSession = request.getSession();
 		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
diff --git a/hsarweb/src/de/hsadmin/web/vaadin/TableComponentFactory.java b/hsarweb/src/de/hsadmin/web/vaadin/TableComponentFactory.java
index 59cd903..fd98b01 100644
--- a/hsarweb/src/de/hsadmin/web/vaadin/TableComponentFactory.java
+++ b/hsarweb/src/de/hsadmin/web/vaadin/TableComponentFactory.java
@@ -162,6 +162,7 @@
 								}
 								if (valueObject != null && valueObject instanceof Map) {
 									StringBuffer buf = new StringBuffer();
+									@SuppressWarnings("rawtypes")
 									Map valueMap = (Map) valueObject;
 									for (Object o : valueMap.keySet()) {
 										if (o instanceof String) {

--
Gitblit v1.9.0-SNAPSHOT