mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 14:37:45 +01:00
Redirect on an invalid server address
This commit is contained in:
parent
aebf6c0b25
commit
d90273da50
@ -60,13 +60,18 @@ public class ServerPageHandler implements PageHandler {
|
||||
|
||||
@Override
|
||||
public Response getResponse(Request request, RequestTarget target) throws WebException {
|
||||
UUID serverUUID = getServerUUID(target);
|
||||
|
||||
checkDBState();
|
||||
if (serverInfo.getServer().isProxy() && serverInfo.getServerUUID().equals(serverUUID)) {
|
||||
return responseFactory.networkPageResponse();
|
||||
Optional<UUID> serverUUID = getServerUUID(target);
|
||||
boolean proxy = serverInfo.getServer().isProxy();
|
||||
if (serverUUID.isPresent()) {
|
||||
checkDBState();
|
||||
if (proxy && serverInfo.getServerUUID().equals(serverUUID.get())) {
|
||||
return responseFactory.networkPageResponse();
|
||||
}
|
||||
return responseFactory.serverPageResponse(serverUUID.get());
|
||||
} else {
|
||||
// Redirect to base server page.
|
||||
return responseFactory.redirectResponse(proxy ? "/network" : "/server");
|
||||
}
|
||||
return responseFactory.serverPageResponse(serverUUID);
|
||||
}
|
||||
|
||||
private void checkDBState() throws ForbiddenException {
|
||||
@ -76,24 +81,18 @@ public class ServerPageHandler implements PageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private UUID getServerUUID(RequestTarget target) {
|
||||
// Default to current server's page
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
|
||||
private Optional<UUID> getServerUUID(RequestTarget target) {
|
||||
if (!target.isEmpty()) {
|
||||
try {
|
||||
String serverName = target.get(0);
|
||||
Optional<UUID> serverUUIDOptional = dbSystem.getDatabase()
|
||||
return dbSystem.getDatabase()
|
||||
.query(ServerQueries.fetchServerMatchingIdentifier(serverName))
|
||||
.map(Server::getUuid);
|
||||
if (serverUUIDOptional.isPresent()) {
|
||||
serverUUID = serverUUIDOptional.get();
|
||||
}
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
/*ignored*/
|
||||
}
|
||||
}
|
||||
return serverUUID;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,6 +134,12 @@ public class ResponseFactory {
|
||||
return new ByteResponse(ResponseType.IMAGE, FileResponse.format(fileName), files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect somewhere
|
||||
*
|
||||
* @param location Starts with '/'
|
||||
* @return Redirection response.
|
||||
*/
|
||||
public Response redirectResponse(String location) {
|
||||
return new RedirectResponse(location);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user