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 public static void init(Properties conf) {
64 securePort = port = "";
65 if ( !conf.getProperty("https.port").equals("443")) {
66 securePort = ":" + conf.getProperty("https.port");
68 if ( !conf.getProperty("http.port").equals("80")) {
69 port = ":" + conf.getProperty("http.port");
71 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
72 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
74 suffix = conf.getProperty("name.suffix", conf.getProperty("name.www", "www.wpia.local").substring(4));
75 HashMap<Host, String> hostnames = new HashMap<>();
76 for (Host h : Host.values()) {
77 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
79 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
80 appName = conf.getProperty("appName");
81 if (appName == null) {
82 throw new Error("App name missing");
86 public static String getHostName(Host h) {
87 return hostnames.get(h);
90 public static String getHostNamePortSecure(Host h) {
91 return hostnames.get(h) + securePort;
94 public static String getHostNamePort(Host h) {
95 return hostnames.get(h) + port;
98 public static int getSecurePort() {
99 if (secureBindPort != null && !secureBindPort.isEmpty()) {
100 if (secureBindPort.equals("stdin")) {
103 return Integer.parseInt(secureBindPort);
106 if (securePort.isEmpty()) {
109 return Integer.parseInt(securePort.substring(1, securePort.length()));
112 public static int getPort() {
113 if (bindPort != null && !bindPort.isEmpty()) {
114 if (bindPort.equals("stdin")) {
117 return Integer.parseInt(bindPort);
120 if (port.isEmpty()) {
123 return Integer.parseInt(port.substring(1, port.length()));
126 public static String getSuffix() {
130 public static String getSupportMailAddress() {
131 return "support@" + getSuffix();
134 public static String getBoardMailAddress() {
135 return "board@" + getSuffix();
138 public static String getQuizMailAddress() {
139 return "quiz@" + getSuffix();
142 public static String getQuizAdminMailAddress() {
143 return "quiz-admin@" + getSuffix();
146 public static String getAppName() {
147 if (appName == null) {
148 throw new Error("AppName not initialized.");