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 private static boolean communityCA;
81 public static void init(Properties conf) {
82 securePort = port = "";
83 if ( !conf.getProperty("https.port").equals("443")) {
84 securePort = ":" + conf.getProperty("https.port");
86 if ( !conf.getProperty("http.port").equals("80")) {
87 port = ":" + conf.getProperty("http.port");
89 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
90 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
92 suffix = conf.getProperty("name.suffix", "wpia.local");
93 HashMap<Host, String> hostnames = new HashMap<>();
94 for (Host h : Host.values()) {
95 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
97 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
98 appName = conf.getProperty("appName");
99 if (appName == null) {
100 throw new Error("App name missing");
102 appIdentifier = conf.getProperty("appIdentifier");
103 if (appIdentifier == null) {
104 throw new Error("App identifier missing");
106 mailSupport = conf.getProperty("mail.support", "support@" + suffix);
107 mailBoard = conf.getProperty("mail.board", "board@" + suffix);
108 mailQuiz = conf.getProperty("mail.quiz", "quiz@" + suffix);
109 mailQuizAdmin = conf.getProperty("mail.quizAdmin", "quiz-admin@" + suffix);
110 communityCA = conf.getProperty("communityCA", "false").equalsIgnoreCase("true");
113 public static String getHostName(Host h) {
114 return hostnames.get(h);
117 public static String getHostNamePortSecure(Host h) {
118 return hostnames.get(h) + securePort;
121 public static String getHostNamePort(Host h) {
122 return hostnames.get(h) + port;
125 public static int getSecurePort() {
126 if (secureBindPort != null && !secureBindPort.isEmpty()) {
127 if (secureBindPort.equals("stdin")) {
130 return Integer.parseInt(secureBindPort);
133 if (securePort.isEmpty()) {
136 return Integer.parseInt(securePort.substring(1, securePort.length()));
139 public static int getPort() {
140 if (bindPort != null && !bindPort.isEmpty()) {
141 if (bindPort.equals("stdin")) {
144 return Integer.parseInt(bindPort);
147 if (port.isEmpty()) {
150 return Integer.parseInt(port.substring(1, port.length()));
153 public static String getSuffix() {
157 public static String getSupportMailAddress() {
161 public static String getBoardMailAddress() {
165 public static String getQuizMailAddress() {
169 public static String getQuizAdminMailAddress() {
170 return mailQuizAdmin;
173 public static String getAppName() {
174 if (appName == null) {
175 throw new Error("AppName not initialized.");
180 public static String getAppIdentifier() {
181 if (appIdentifier == null) {
182 throw new Error("AppIdentifier not initialized.");
184 return appIdentifier;
187 public static boolean isCommunityCA() {