package info.elexis.server.core;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Host {

	private static Logger log = LoggerFactory.getLogger(Host.class);

	public static String HOSTNAME = null;
	public static int HTTP_PORT = 8380;
	public static int HTTPS_PORT = 8480;
	public static String BASE_URL;
	public static String BASE_URL_SECURE;

	static {
		try {
			InetAddress myHost = InetAddress.getLocalHost();
			HOSTNAME = myHost.getCanonicalHostName();

			String httpPort = System.getProperty("jetty.http.port");
			if (StringUtils.isNumeric(httpPort)) {
				HTTP_PORT = Integer.parseInt(httpPort);
			}

			if (HTTP_PORT != 80) {
				BASE_URL = "http://" + HOSTNAME + ":" + HTTP_PORT + "/";
			} else {
				BASE_URL = "http://" + HOSTNAME + "/";
			}

			String httpsPort = System.getProperty("jetty.ssl.port");
			if (StringUtils.isNumeric(httpsPort)) {
				HTTPS_PORT = Integer.parseInt(httpsPort);
			}

			if (HTTPS_PORT != 443) {
				BASE_URL_SECURE = "https://" + HOSTNAME + ":" + HTTPS_PORT + "/";
			} else {
				BASE_URL_SECURE = "https://" + HOSTNAME + "/";
			}

		} catch (UnknownHostException e) {
			log.error("Could not resolve hostname", e);
		}
		log.info("Hostname is [{}]", HOSTNAME);
	}

	public static String getOpenIDBaseUrl() {
		return BASE_URL + "openid/";
	}

	public static String getOpenIDBaseUrlSecure() {
		return BASE_URL_SECURE + "openid/";
	}

	public static String getLocalhostBaseUrl() {
		return "http://localhost:" + HTTP_PORT + "/";
	}

}

@@ -249,46 +249,8 @@
  log
- = LoggerFactory.getLogger(Host.class)
 ;%0A%0A%09
@@ -259,24 +259,30 @@
 blic static 
+final 
 String HOSTN
@@ -288,15 +288,8 @@
 NAME
- = null
 ;%0A%09p
@@ -293,32 +293,38 @@
 %0A%09public static 
+final 
 int HTTP_PORT = 
@@ -324,15 +324,8 @@
 PORT
- = 8380
 ;%0A%09p
@@ -337,16 +337,22 @@
  static 
+final 
 int HTTP
@@ -361,15 +361,8 @@
 PORT
- = 8480
 ;%0A%09p
@@ -366,32 +366,38 @@
 %0A%09public static 
+final 
 String BASE_URL;
@@ -408,24 +408,30 @@
 blic static 
+final 
 String BASE_
@@ -459,79 +459,249 @@
 %7B%0A%09%09
-try %7B%0A%09%09%09InetAddress myHost = InetAddress.getLocalHost();%0A%09%09%09HOSTNAME =
+log = LoggerFactory.getLogger(Host.class);%0A%0A%09%09InetAddress myHost = null;%0A%09%09try %7B%0A%09%09%09myHost = InetAddress.getLocalHost();%0A%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09log.error(%22Could not resolve hostname%22, e);%0A%09%09%7D%0A%0A%09%09HOSTNAME = (myHost != null) ?
  myH
@@ -726,20 +726,26 @@
 stName()
+ : null
 ;%0A%0A
-%09
 %09%09String
@@ -789,33 +789,32 @@
 .http.port%22);%0A%09%09
-%09
 if (StringUtils.
@@ -832,25 +832,24 @@
 ttpPort)) %7B%0A
-%09
 %09%09%09HTTP_PORT
@@ -872,38 +872,68 @@
 Int(httpPort);%0A%09
+%09%7D else %7B%0A%09%09%09HTTP_PORT = 8380;%0A
 %09%09%7D%0A%0A
-%09
 %09%09if (HTTP_PORT 
@@ -937,25 +937,24 @@
 RT != 80) %7B%0A
-%09
 %09%09%09BASE_URL 
@@ -995,33 +995,32 @@
 P_PORT + %22/%22;%0A%09%09
-%09
 %7D else %7B%0A%09%09%09%09BAS
@@ -1004,33 +1004,32 @@
 %22/%22;%0A%09%09%7D else %7B%0A
-%09
 %09%09%09BASE_URL = %22h
@@ -1056,21 +1056,19 @@
  %22/%22;%0A%09%09
-%09
 %7D%0A%0A
-%09
 %09%09String
@@ -1120,17 +1120,16 @@
 rt%22);%0A%09%09
-%09
 if (Stri
@@ -1160,17 +1160,16 @@
 ort)) %7B%0A
-%09
 %09%09%09HTTPS
@@ -1206,22 +1206,53 @@
 Port);%0A%09
+%09%7D else %7B%0A%09%09%09HTTPS_PORT = 8480;%0A
 %09%09%7D%0A%0A
-%09
 %09%09if (HT
@@ -1270,17 +1270,16 @@
  443) %7B%0A
-%09
 %09%09%09BASE_
@@ -1341,17 +1341,16 @@
  %22/%22;%0A%09%09
-%09
 %7D else %7B
@@ -1350,17 +1350,16 @@
  else %7B%0A
-%09
 %09%09%09BASE_
@@ -1404,102 +1404,13 @@
 /%22;%0A
-%09
 %09%09%7D%0A%0A
-%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09log.error(%22Could not resolve hostname%22, e);%0A%09%09%7D%0A
 %09%09lo

Handle Vulnerabilities identified in Host