1 package club.wpia.gigi.util;
3 import java.util.Collections;
4 import java.util.HashMap;
6 import java.util.Properties;
8 public class ServerConstants {
12 * Serves the main application. Both via HTTP and HTTPS.
16 * Serves static resource like css, js, for modal dialogs on
17 * delete-operations and similar things.
21 * Serves the same content as {@link #WWW}, but requires
22 * authentification via client certificate.
26 * Serves the API for issuing certificates, receiving Quiz results.
30 * Hosts a link-redirector (not served by Gigi) for external links from
35 * Hosts the certificate repository for the certificates generated
36 * during NRE. Also not served by Gigi.
40 private final String value;
42 private Host(String value) {
46 public String getConfigName() {
50 public String getHostDefaultPrefix() {
55 private static Map<Host, String> hostnames;
57 private static String securePort, port, secureBindPort, bindPort;
59 private static String suffix = "wpia.local";
61 private static String appName = null;
63 private static String appIdentifier = null;
65 public static void init(Properties conf) {
66 securePort = port = "";
67 if ( !conf.getProperty("https.port").equals("443")) {
68 securePort = ":" + conf.getProperty("https.port");
70 if ( !conf.getProperty("http.port").equals("80")) {
71 port = ":" + conf.getProperty("http.port");
73 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
74 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
76 suffix = conf.getProperty("name.suffix", conf.getProperty("name.www", "www.wpia.local").substring(4));
77 HashMap<Host, String> hostnames = new HashMap<>();
78 for (Host h : Host.values()) {
79 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
81 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
82 appName = conf.getProperty("appName");
83 if (appName == null) {
84 throw new Error("App name missing");
86 appIdentifier = conf.getProperty("appIdentifier");
87 if (appIdentifier == null) {
88 throw new Error("App identifier missing");
92 public static String getHostName(Host h) {
93 return hostnames.get(h);
96 public static String getHostNamePortSecure(Host h) {
97 return hostnames.get(h) + securePort;
100 public static String getHostNamePort(Host h) {
101 return hostnames.get(h) + port;
104 public static int getSecurePort() {
105 if (secureBindPort != null && !secureBindPort.isEmpty()) {
106 if (secureBindPort.equals("stdin")) {
109 return Integer.parseInt(secureBindPort);
112 if (securePort.isEmpty()) {
115 return Integer.parseInt(securePort.substring(1, securePort.length()));
118 public static int getPort() {
119 if (bindPort != null && !bindPort.isEmpty()) {
120 if (bindPort.equals("stdin")) {
123 return Integer.parseInt(bindPort);
126 if (port.isEmpty()) {
129 return Integer.parseInt(port.substring(1, port.length()));
132 public static String getSuffix() {
136 public static String getSupportMailAddress() {
137 return "support@" + getSuffix();
140 public static String getBoardMailAddress() {
141 return "board@" + getSuffix();
144 public static String getQuizMailAddress() {
145 return "quiz@" + getSuffix();
148 public static String getQuizAdminMailAddress() {
149 return "quiz-admin@" + getSuffix();
152 public static String getAppName() {
153 if (appName == null) {
154 throw new Error("AppName not initialized.");
159 public static String getAppIdentifier() {
160 if (appIdentifier == null) {
161 throw new Error("AppIdentifier not initialized.");
163 return appIdentifier;