mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-21 15:41:24 +01:00
Made redirection subdirectory friendly
Redirection from the root page / was pointed towards address like /server leading to reverse-proxies using subdirectories to misbehave Fixed by changing all known redirections: - / now uses relative redirects - /server/wrong_name now redirects to [Configured address]/server Configured address takes Alternative IP settings into account. Affects issues: - Fixed #1207
This commit is contained in:
parent
d0b2559598
commit
a8ed36b051
@ -22,7 +22,6 @@ import com.djrapitops.plan.delivery.webserver.Request;
|
||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||
import com.djrapitops.plan.delivery.webserver.response.RedirectResponse;
|
||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
||||
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||
@ -52,7 +51,7 @@ public class RootPageHandler implements PageHandler {
|
||||
@Override
|
||||
public Response getResponse(Request request, RequestTarget target) throws WebException {
|
||||
if (!webServer.isAuthRequired()) {
|
||||
return responseFactory.redirectResponse(serverInfo.getServer().isProxy() ? "/network" : "/server");
|
||||
return responseFactory.redirectResponse(serverInfo.getServer().isProxy() ? "network" : "server");
|
||||
}
|
||||
|
||||
Optional<Authentication> auth = request.getAuth();
|
||||
@ -65,11 +64,11 @@ public class RootPageHandler implements PageHandler {
|
||||
int permLevel = webUser.getPermLevel();
|
||||
switch (permLevel) {
|
||||
case 0:
|
||||
return new RedirectResponse(serverInfo.getServer().isProxy() ? "/network" : "/server");
|
||||
return responseFactory.redirectResponse(serverInfo.getServer().isProxy() ? "network" : "server");
|
||||
case 1:
|
||||
return new RedirectResponse("/players");
|
||||
return responseFactory.redirectResponse("players");
|
||||
case 2:
|
||||
return new RedirectResponse("/player/" + Html.encodeToURL(webUser.getName()));
|
||||
return responseFactory.redirectResponse("player/" + Html.encodeToURL(webUser.getName()));
|
||||
default:
|
||||
return responseFactory.forbidden403();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.delivery.webserver.pages;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.Request;
|
||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
||||
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
||||
@ -29,6 +30,7 @@ import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -46,16 +48,19 @@ public class ServerPageHandler implements PageHandler {
|
||||
private final ResponseFactory responseFactory;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Lazy<WebServer> webServer;
|
||||
|
||||
@Inject
|
||||
public ServerPageHandler(
|
||||
ResponseFactory responseFactory,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo
|
||||
ServerInfo serverInfo,
|
||||
Lazy<WebServer> webServer
|
||||
) {
|
||||
this.responseFactory = responseFactory;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,7 +75,7 @@ public class ServerPageHandler implements PageHandler {
|
||||
return responseFactory.serverPageResponse(serverUUID.get());
|
||||
} else {
|
||||
// Redirect to base server page.
|
||||
return responseFactory.redirectResponse(proxy ? "/network" : "/server");
|
||||
return responseFactory.redirectResponse(webServer.get().getAccessAddress() + (proxy ? "/network" : "/server"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user