From 1b2342fe11c9f8d83cd8155ce2f42364a006b191 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 9 Nov 2019 17:52:29 +0200 Subject: [PATCH] Changed redirection of root page Changed Redirects From / -> "/server/" to /server/ServerName From /server/Unexisting -> "/server/" to "/server/ServerName" Affects issues: - Close 1210 --- .../com/djrapitops/plan/delivery/rendering/html/Html.java | 6 +++++- .../plan/delivery/webserver/pages/RootPageHandler.java | 6 ++++-- .../plan/delivery/webserver/pages/ServerPageHandler.java | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Html.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Html.java index 1ea493109..3ccf59882 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Html.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Html.java @@ -16,6 +16,7 @@ */ package com.djrapitops.plan.delivery.rendering.html; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringSubstitutor; import org.apache.commons.text.TextStringBuilder; @@ -174,7 +175,10 @@ public enum Html { public static String encodeToURL(String string) { try { - return URLEncoder.encode(string, "UTF-8"); + return StringUtils.replace( + URLEncoder.encode(string, "UTF-8"), + "+", "%20" // Encoding replaces spaces with + + ); } catch (UnsupportedEncodingException e) { return string; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageHandler.java index 71aae2d06..ca7f5ac23 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageHandler.java @@ -25,6 +25,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; import com.djrapitops.plan.exceptions.connection.WebException; +import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.ServerInfo; import java.util.Optional; @@ -50,8 +51,9 @@ public class RootPageHandler implements PageHandler { @Override public Response getResponse(Request request, RequestTarget target) throws WebException { + Server server = serverInfo.getServer(); if (!webServer.isAuthRequired()) { - return responseFactory.redirectResponse(serverInfo.getServer().isProxy() ? "network" : "server"); + return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName())); } Optional auth = request.getAuth(); @@ -64,7 +66,7 @@ public class RootPageHandler implements PageHandler { int permLevel = webUser.getPermLevel(); switch (permLevel) { case 0: - return responseFactory.redirectResponse(serverInfo.getServer().isProxy() ? "network" : "server"); + return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName())); case 1: return responseFactory.redirectResponse("players"); case 2: diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageHandler.java index e6eeaa420..af15e780c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageHandler.java @@ -16,6 +16,7 @@ */ package com.djrapitops.plan.delivery.webserver.pages; +import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.WebServer; @@ -75,7 +76,8 @@ public class ServerPageHandler implements PageHandler { return responseFactory.serverPageResponse(serverUUID.get()); } else { // Redirect to base server page. - return responseFactory.redirectResponse(webServer.get().getAccessAddress() + (proxy ? "/network" : "/server")); + String directTo = proxy ? "/network" : "/server/" + Html.encodeToURL(serverInfo.getServer().getIdentifiableName()); + return responseFactory.redirectResponse(webServer.get().getAccessAddress() + directTo); } }