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 public static void init(Properties conf) {
62 securePort = port = "";
63 if ( !conf.getProperty("https.port").equals("443")) {
64 securePort = ":" + conf.getProperty("https.port");
66 if ( !conf.getProperty("http.port").equals("80")) {
67 port = ":" + conf.getProperty("http.port");
69 secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
70 bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
72 suffix = conf.getProperty("name.suffix", conf.getProperty("name.www", "www.wpia.local").substring(4));
73 HashMap<Host, String> hostnames = new HashMap<>();
74 for (Host h : Host.values()) {
75 hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
77 ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
80 public static String getHostName(Host h) {
81 return hostnames.get(h);
84 public static String getHostNamePortSecure(Host h) {
85 return hostnames.get(h) + securePort;
88 public static String getHostNamePort(Host h) {
89 return hostnames.get(h) + port;
92 public static int getSecurePort() {
93 if (secureBindPort != null && !secureBindPort.isEmpty()) {
94 if (secureBindPort.equals("stdin")) {
97 return Integer.parseInt(secureBindPort);
100 if (securePort.isEmpty()) {
103 return Integer.parseInt(securePort.substring(1, securePort.length()));
106 public static int getPort() {
107 if (bindPort != null && !bindPort.isEmpty()) {
108 if (bindPort.equals("stdin")) {
111 return Integer.parseInt(bindPort);
114 if (port.isEmpty()) {
117 return Integer.parseInt(port.substring(1, port.length()));
120 public static String getSuffix() {
124 public static String getSupportMailAddress() {
125 return "support@" + getSuffix();
128 public static String getBoardMailAddress() {
129 return "board@" + getSuffix();
132 public static String getQuizMailAddress() {
133 return "quiz@" + getSuffix();
136 public static String getQuizAdminMailAddress() {
137 return "quiz-admin@" + getSuffix();