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 public static void init(Properties conf) {
72 securePort = port = "";
73 if ( !conf.getProperty("https.port").equals("443")) {
74 securePort = ":" + conf.getProperty("https.port");
76 if ( !conf.getProperty("http.port").equals("80")) {
77 port = ":" + conf.getProperty("http.port");
79 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
80 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
82 suffix = conf.getProperty("name.suffix", "wpia.local");
83 HashMap<Host, String> hostnames = new HashMap<>();
84 for (Host h : Host.values()) {
85 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
87 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
88 appName = conf.getProperty("appName");
89 if (appName == null) {
90 throw new Error("App name missing");
92 appIdentifier = conf.getProperty("appIdentifier");
93 if (appIdentifier == null) {
94 throw new Error("App identifier missing");
98 public static String getHostName(Host h) {
99 return hostnames.get(h);
102 public static String getHostNamePortSecure(Host h) {
103 return hostnames.get(h) + securePort;
106 public static String getHostNamePort(Host h) {
107 return hostnames.get(h) + port;
110 public static int getSecurePort() {
111 if (secureBindPort != null && !secureBindPort.isEmpty()) {
112 if (secureBindPort.equals("stdin")) {
115 return Integer.parseInt(secureBindPort);
118 if (securePort.isEmpty()) {
121 return Integer.parseInt(securePort.substring(1, securePort.length()));
124 public static int getPort() {
125 if (bindPort != null && !bindPort.isEmpty()) {
126 if (bindPort.equals("stdin")) {
129 return Integer.parseInt(bindPort);
132 if (port.isEmpty()) {
135 return Integer.parseInt(port.substring(1, port.length()));
138 public static String getSuffix() {
142 public static String getSupportMailAddress() {
143 return "support@" + getSuffix();
146 public static String getBoardMailAddress() {
147 return "board@" + getSuffix();
150 public static String getQuizMailAddress() {
151 return "quiz@" + getSuffix();
154 public static String getQuizAdminMailAddress() {
155 return "quiz-admin@" + getSuffix();
158 public static String getAppName() {
159 if (appName == null) {
160 throw new Error("AppName not initialized.");
165 public static String getAppIdentifier() {
166 if (appIdentifier == null) {
167 throw new Error("AppIdentifier not initialized.");
169 return appIdentifier;