1 package club.wpia.gigi.util;
3 import java.util.Collections;
4 import java.util.HashMap;
6 import java.util.Properties;
8 import club.wpia.gigi.ocsp.OCSPResponder;
10 public class ServerConstants {
14 * Serves the main application. Both via HTTP and HTTPS.
18 * Serves static resource like css, js, for modal dialogs on
19 * delete-operations and similar things.
23 * Serves the same content as {@link #WWW}, but requires
24 * authentification via client certificate.
28 * Serves the API for issuing certificates, receiving Quiz results.
32 * Hosts a link-redirector (not served by Gigi) for external links from
37 * Hosts the certificate repository for the certificates generated
38 * during NRE. Also not served by Gigi.
42 * Hosts the {@link OCSPResponder}.
44 OCSP_RESPONDER("g2.ocsp");
46 private final String value;
48 private Host(String value) {
52 public String getConfigName() {
56 public String getHostDefaultPrefix() {
61 private static Map<Host, String> hostnames;
63 private static String securePort, port, secureBindPort, bindPort;
65 private static String suffix = "wpia.local";
67 private static String appName = null;
69 private static String appIdentifier = null;
71 private static String mailSupport;
73 private static String mailBoard;
75 private static String mailQuiz;
77 private static String mailQuizAdmin;
79 public static void init(Properties conf) {
80 securePort = port = "";
81 if ( !conf.getProperty("https.port").equals("443")) {
82 securePort = ":" + conf.getProperty("https.port");
84 if ( !conf.getProperty("http.port").equals("80")) {
85 port = ":" + conf.getProperty("http.port");
87 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
88 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
90 suffix = conf.getProperty("name.suffix", "wpia.local");
91 HashMap<Host, String> hostnames = new HashMap<>();
92 for (Host h : Host.values()) {
93 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
95 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
96 appName = conf.getProperty("appName");
97 if (appName == null) {
98 throw new Error("App name missing");
100 appIdentifier = conf.getProperty("appIdentifier");
101 if (appIdentifier == null) {
102 throw new Error("App identifier missing");
104 mailSupport = conf.getProperty("mail.support", "support@" + suffix);
105 mailBoard = conf.getProperty("mail.board", "board@" + suffix);
106 mailQuiz = conf.getProperty("mail.quiz", "quiz@" + suffix);
107 mailQuizAdmin = conf.getProperty("mail.quizAdmin", "quiz-admin@" + suffix);
110 public static String getHostName(Host h) {
111 return hostnames.get(h);
114 public static String getHostNamePortSecure(Host h) {
115 return hostnames.get(h) + securePort;
118 public static String getHostNamePort(Host h) {
119 return hostnames.get(h) + port;
122 public static int getSecurePort() {
123 if (secureBindPort != null && !secureBindPort.isEmpty()) {
124 if (secureBindPort.equals("stdin")) {
127 return Integer.parseInt(secureBindPort);
130 if (securePort.isEmpty()) {
133 return Integer.parseInt(securePort.substring(1, securePort.length()));
136 public static int getPort() {
137 if (bindPort != null && !bindPort.isEmpty()) {
138 if (bindPort.equals("stdin")) {
141 return Integer.parseInt(bindPort);
144 if (port.isEmpty()) {
147 return Integer.parseInt(port.substring(1, port.length()));
150 public static String getSuffix() {
154 public static String getSupportMailAddress() {
158 public static String getBoardMailAddress() {
162 public static String getQuizMailAddress() {
166 public static String getQuizAdminMailAddress() {
167 return mailQuizAdmin;
170 public static String getAppName() {
171 if (appName == null) {
172 throw new Error("AppName not initialized.");
177 public static String getAppIdentifier() {
178 if (appIdentifier == null) {
179 throw new Error("AppIdentifier not initialized.");
181 return appIdentifier;