mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 14:37:45 +01:00
Refactored /debug page to use ResolverService
Some issues that were identified: - Going to /debug/ makes the style requests return the debug page content because the /debug resolver is used - In the future when / is to be resolved it might override a bunch of requests. - Use of RequestTarget as incompatible with URIPath for some reason which lead to infinite redirect, so the attempted change was reverted before this commit. - Some Responses are using PlanFiles to obtain a html file (SRP violation) Rest of the pages still use the old resolution that is now deprecated.
This commit is contained in:
parent
9c74c40f72
commit
2736ba042a
@ -23,7 +23,7 @@ import java.util.Optional;
|
|||||||
/**
|
/**
|
||||||
* Utility Resolver for organizing resolution in a tree-like structure.
|
* Utility Resolver for organizing resolution in a tree-like structure.
|
||||||
* <p>
|
* <p>
|
||||||
* CompositeResolver removes first part of the target with {@link URLTarget#omitFirst()}
|
* CompositeResolver removes first part of the target with {@link URIPath#omitFirst()}
|
||||||
* before calling the child Resolvers.
|
* before calling the child Resolvers.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -42,7 +42,7 @@ public final class CompositeResolver implements Resolver {
|
|||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Resolver> getResolver(URLTarget target) {
|
private Optional<Resolver> getResolver(URIPath target) {
|
||||||
return target.getPart(0).flatMap(this::find);
|
return target.getPart(0).flatMap(this::find);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,16 +63,16 @@ public final class CompositeResolver implements Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAccess(WebUser permissions, URLTarget target, Parameters parameters) {
|
public boolean canAccess(WebUser permissions, URIPath target, URIQuery query) {
|
||||||
return getResolver(target)
|
return getResolver(target)
|
||||||
.map(resolver -> resolver.canAccess(permissions, target.omitFirst(), parameters))
|
.map(resolver -> resolver.canAccess(permissions, target.omitFirst(), query))
|
||||||
.orElse(true);
|
.orElse(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Response> resolve(URLTarget target, Parameters parameters) {
|
public Optional<Response> resolve(URIPath target, URIQuery query) {
|
||||||
return getResolver(target)
|
return getResolver(target)
|
||||||
.flatMap(resolver -> resolver.resolve(target.omitFirst(), parameters));
|
.flatMap(resolver -> resolver.resolve(target.omitFirst(), query));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
@ -86,7 +86,7 @@ public final class CompositeResolver implements Resolver {
|
|||||||
* Add a new resolver to the CompositeResolver.
|
* Add a new resolver to the CompositeResolver.
|
||||||
*
|
*
|
||||||
* @param prefix Start of the target (first part of the target string, eg "example" in "/example/target/", or "" in "/")
|
* @param prefix Start of the target (first part of the target string, eg "example" in "/example/target/", or "" in "/")
|
||||||
* @param resolver Resolver to call for this target, {@link URLTarget#omitFirst()} will be called for Resolver method calls.
|
* @param resolver Resolver to call for this target, {@link URIPath#omitFirst()} will be called for Resolver method calls.
|
||||||
* @return this builder.
|
* @return this builder.
|
||||||
*/
|
*/
|
||||||
public Builder add(String prefix, Resolver resolver) {
|
public Builder add(String prefix, Resolver resolver) {
|
||||||
|
@ -27,23 +27,35 @@ public interface Resolver {
|
|||||||
*
|
*
|
||||||
* @param permissions WebUser that is accessing this page.
|
* @param permissions WebUser that is accessing this page.
|
||||||
* @param target Target that is being accessed, /example/target
|
* @param target Target that is being accessed, /example/target
|
||||||
* @param parameters Parameters in the URL, ?param=value etc.
|
* @param query Parameters in the URL, ?param=value etc.
|
||||||
* @return true if allowed or invalid target, false if response should be 403 (forbidden)
|
* @return true if allowed or invalid target, false if response should be 403 (forbidden)
|
||||||
*/
|
*/
|
||||||
boolean canAccess(WebUser permissions, URLTarget target, Parameters parameters);
|
boolean canAccess(WebUser permissions, URIPath target, URIQuery query);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement request resolution.
|
* Implement request resolution.
|
||||||
*
|
*
|
||||||
* @param target Target that is being accessed, /example/target
|
* @param target Target that is being accessed, /example/target
|
||||||
* @param parameters Parameters in the URL, ?param=value etc.
|
* @param query Parameters in the URL, ?param=value etc.
|
||||||
* @return Response or empty if the response should be 404 (not found).
|
* @return Response or empty if the response should be 404 (not found).
|
||||||
* @see Response for return value
|
* @see Response for return value
|
||||||
*/
|
*/
|
||||||
Optional<Response> resolve(URLTarget target, Parameters parameters);
|
Optional<Response> resolve(URIPath target, URIQuery query);
|
||||||
|
|
||||||
default ResponseBuilder newResponseBuilder() {
|
default ResponseBuilder newResponseBuilder() {
|
||||||
return new ResponseBuilder();
|
return Response.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override this method with false to always allow using this resolver.
|
||||||
|
* <p>
|
||||||
|
* Use this when content/style is needed for displaying pages where authentication is not available/needed.
|
||||||
|
*
|
||||||
|
* @param target Target that is being accessed, /example/target
|
||||||
|
* @param query Parameters in the URL, ?param=value etc.
|
||||||
|
* @return true by default. If false is returned {@link #canAccess(WebUser, URIPath, URIQuery)} will not be called.
|
||||||
|
*/
|
||||||
|
default boolean requiresAuth(URIPath target, URIQuery query) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,10 @@ public final class Response {
|
|||||||
headers = new HashMap<>();
|
headers = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResponseBuilder builder() {
|
||||||
|
return new ResponseBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
@ -54,4 +58,8 @@ public final class Response {
|
|||||||
return Optional.ofNullable(charset);
|
return Optional.ofNullable(charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isErrorResponse() {
|
||||||
|
return code >= 400;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,20 @@ package com.djrapitops.plan.delivery.web.resolver;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class URLTarget {
|
public final class URIPath {
|
||||||
|
|
||||||
private final String full;
|
private final String path;
|
||||||
|
|
||||||
public URLTarget(String target) {
|
public URIPath(String path) {
|
||||||
full = target;
|
this.path = path;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtain the full target.
|
|
||||||
*
|
|
||||||
* @return Example: "/target/path/in/url"
|
|
||||||
*/
|
|
||||||
public String asString() {
|
|
||||||
return full;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes parts of the URL before an index.
|
* Removes parts of the URL before an index.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: /example/target, 0 returns /example/target
|
* Example: /example/path, 0 returns /example/path
|
||||||
* Example: /example/target, 1 returns /target
|
* Example: /example/path, 1 returns /path
|
||||||
* Example: /example/target, 2 returns ''
|
* Example: /example/path, 2 returns ''
|
||||||
* Example: /, 0 returns /
|
* Example: /, 0 returns /
|
||||||
* Example: /, 1 returns ''
|
* Example: /, 1 returns ''
|
||||||
*
|
*
|
||||||
@ -67,26 +58,35 @@ public final class URLTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain part of the target by index of slashes in the URL.
|
* Obtain the full path.
|
||||||
|
*
|
||||||
|
* @return Example: "/target/path/in/url"
|
||||||
|
*/
|
||||||
|
public String asString() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain part of the path by index of slashes in the URL.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: "/example/target", 0 returns "example"
|
* Example: "/example/path", 0 returns "example"
|
||||||
* Example: "/example/target", 1 returns "target"
|
* Example: "/example/path", 1 returns "path"
|
||||||
* Example: "/example/target", 2 returns empty optional
|
* Example: "/example/path", 2 returns empty optional
|
||||||
* Example: "/example/target/", 2 returns ""
|
* Example: "/example/path/", 2 returns ""
|
||||||
* Example: "/", 0 returns ""
|
* Example: "/", 0 returns ""
|
||||||
* Example: "/", 1 returns empty optional
|
* Example: "/", 1 returns empty optional
|
||||||
*
|
*
|
||||||
* @param index Index from root, eg. /0/1/2/3 etc
|
* @param index Index from root, eg. /0/1/2/3 etc
|
||||||
* @return part after a '/' in the target,
|
* @return part after a '/' in the path,
|
||||||
*/
|
*/
|
||||||
public Optional<String> getPart(int index) {
|
public Optional<String> getPart(int index) {
|
||||||
String leftover = removePartsBefore(full, index);
|
String leftover = removePartsBefore(path, index);
|
||||||
if (leftover.isEmpty()) return Optional.empty();
|
if (leftover.isEmpty()) return Optional.empty();
|
||||||
|
|
||||||
// Remove the leading slash to find ending slash
|
// Remove the leading slash to find ending slash
|
||||||
leftover = leftover.substring(1);
|
leftover = leftover.substring(1);
|
||||||
|
|
||||||
// Remove rest of the target (Ends in the next slash)
|
// Remove rest of the path (Ends in the next slash)
|
||||||
int nextSlash = leftover.indexOf('/');
|
int nextSlash = leftover.indexOf('/');
|
||||||
if (nextSlash == -1) {
|
if (nextSlash == -1) {
|
||||||
return Optional.of(leftover);
|
return Optional.of(leftover);
|
||||||
@ -96,19 +96,27 @@ public final class URLTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean endsWith(String suffix) {
|
public boolean endsWith(String suffix) {
|
||||||
return full.endsWith(suffix);
|
return path.endsWith(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable modification, removes first part of the target string.
|
* Immutable modification, removes first part of the path string.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: URLTarget "/example/target" return value of omitFirst URLTarget is "/target"
|
* Example: URIPath "/example/path" return value of omitFirst URIPath is "/path"
|
||||||
* Example: URLTarget "/example" return value of omitFirst URLTarget is "/"
|
* Example: URIPath "/example" return value of omitFirst URIPath is "/"
|
||||||
* Example: URLTarget "/" return value of omitFirst URLTarget is ""
|
* Example: URIPath "/" return value of omitFirst URIPath is ""
|
||||||
*
|
*
|
||||||
* @return new URLTarget with first part removed.
|
* @return new URIPath with first part removed.
|
||||||
*/
|
*/
|
||||||
public URLTarget omitFirst() {
|
public URIPath omitFirst() {
|
||||||
return new URLTarget(removePartsBefore(full, 1));
|
return new URIPath(removePartsBefore(path, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int length() {
|
||||||
|
int count = 0;
|
||||||
|
for (char c : path.toCharArray()) {
|
||||||
|
if (c == '/') count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.web.resolver;
|
package com.djrapitops.plan.delivery.web.resolver;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -24,14 +28,37 @@ import java.util.Optional;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public final class Parameters {
|
public final class URIQuery {
|
||||||
|
|
||||||
private final Map<String, String> byKey;
|
private final Map<String, String> byKey;
|
||||||
|
|
||||||
public Parameters(Map<String, String> byKey) {
|
public URIQuery(Map<String, String> byKey) {
|
||||||
this.byKey = byKey;
|
this.byKey = byKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URIQuery(String fromURI) {
|
||||||
|
this.byKey = parseParameters(fromURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> parseParameters(String fromURI) {
|
||||||
|
if (fromURI == null || fromURI.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> parameters = new HashMap<>();
|
||||||
|
String[] keysAndValues = StringUtils.split(fromURI, '&');
|
||||||
|
for (String kv : keysAndValues) {
|
||||||
|
if (kv.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] keyAndValue = StringUtils.split(kv, "=", 2);
|
||||||
|
if (keyAndValue.length >= 2) {
|
||||||
|
parameters.put(keyAndValue[0], keyAndValue[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain an URI parameter by key.
|
* Obtain an URI parameter by key.
|
||||||
*
|
*
|
@ -33,7 +33,7 @@ import java.util.function.Supplier;
|
|||||||
public interface SettingsService {
|
public interface SettingsService {
|
||||||
|
|
||||||
static SettingsService getInstance() {
|
static SettingsService getInstance() {
|
||||||
return Optional.ofNullable(SettingsServiceHolder.service)
|
return Optional.ofNullable(Holder.service)
|
||||||
.orElseThrow(() -> new IllegalStateException("SettingsService has not been initialised yet."));
|
.orElseThrow(() -> new IllegalStateException("SettingsService has not been initialised yet."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,15 +64,15 @@ public interface SettingsService {
|
|||||||
*/
|
*/
|
||||||
List<String> getStringList(String path, Supplier<List<String>> defaultValue);
|
List<String> getStringList(String path, Supplier<List<String>> defaultValue);
|
||||||
|
|
||||||
class SettingsServiceHolder {
|
class Holder {
|
||||||
static SettingsService service;
|
static SettingsService service;
|
||||||
|
|
||||||
private SettingsServiceHolder() {
|
private Holder() {
|
||||||
/* Static variable holder */
|
/* Static variable holder */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set(SettingsService service) {
|
static void set(SettingsService service) {
|
||||||
SettingsServiceHolder.service = service;
|
Holder.service = service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,16 +25,16 @@ import java.util.Optional;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link URLTarget} behavior.
|
* Tests for {@link URIPath} behavior.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnitPlatform.class)
|
@RunWith(JUnitPlatform.class)
|
||||||
class URLTargetTest {
|
class URIPathTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void firstPartEmptyForRoot() {
|
void firstPartEmptyForRoot() {
|
||||||
URLTarget target = new URLTarget("/");
|
URIPath target = new URIPath("/");
|
||||||
Optional<String> expected = Optional.of("");
|
Optional<String> expected = Optional.of("");
|
||||||
Optional<String> result = target.getPart(0);
|
Optional<String> result = target.getPart(0);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -42,7 +42,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fullTargetForRoot() {
|
void fullTargetForRoot() {
|
||||||
URLTarget target = new URLTarget("/");
|
URIPath target = new URIPath("/");
|
||||||
String expected = "/";
|
String expected = "/";
|
||||||
String result = target.asString();
|
String result = target.asString();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -50,7 +50,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void firstPart() {
|
void firstPart() {
|
||||||
URLTarget target = new URLTarget("/example/target");
|
URIPath target = new URIPath("/example/target");
|
||||||
Optional<String> expected = Optional.of("example");
|
Optional<String> expected = Optional.of("example");
|
||||||
Optional<String> result = target.getPart(0);
|
Optional<String> result = target.getPart(0);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -58,7 +58,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fullTarget() {
|
void fullTarget() {
|
||||||
URLTarget target = new URLTarget("/example/target");
|
URIPath target = new URIPath("/example/target");
|
||||||
String expected = "/example/target";
|
String expected = "/example/target";
|
||||||
String result = target.asString();
|
String result = target.asString();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -66,7 +66,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void secondPart() {
|
void secondPart() {
|
||||||
URLTarget target = new URLTarget("/example/target");
|
URIPath target = new URIPath("/example/target");
|
||||||
Optional<String> expected = Optional.of("target");
|
Optional<String> expected = Optional.of("target");
|
||||||
Optional<String> result = target.getPart(1);
|
Optional<String> result = target.getPart(1);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -74,7 +74,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noPart() {
|
void noPart() {
|
||||||
URLTarget target = new URLTarget("/example/target");
|
URIPath target = new URIPath("/example/target");
|
||||||
Optional<String> expected = Optional.empty();
|
Optional<String> expected = Optional.empty();
|
||||||
Optional<String> result = target.getPart(2);
|
Optional<String> result = target.getPart(2);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -82,7 +82,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void emptyLastPart() {
|
void emptyLastPart() {
|
||||||
URLTarget target = new URLTarget("/example/target/");
|
URIPath target = new URIPath("/example/target/");
|
||||||
Optional<String> expected = Optional.of("");
|
Optional<String> expected = Optional.of("");
|
||||||
Optional<String> result = target.getPart(2);
|
Optional<String> result = target.getPart(2);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -90,7 +90,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void omitRoot() {
|
void omitRoot() {
|
||||||
URLTarget target = new URLTarget("/").omitFirst();
|
URIPath target = new URIPath("/").omitFirst();
|
||||||
String expected = "";
|
String expected = "";
|
||||||
String result = target.asString();
|
String result = target.asString();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -98,7 +98,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void omitRootPart() {
|
void omitRootPart() {
|
||||||
URLTarget target = new URLTarget("/").omitFirst();
|
URIPath target = new URIPath("/").omitFirst();
|
||||||
Optional<String> expected = Optional.empty();
|
Optional<String> expected = Optional.empty();
|
||||||
Optional<String> result = target.getPart(0);
|
Optional<String> result = target.getPart(0);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -106,7 +106,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void omitFirstPart() {
|
void omitFirstPart() {
|
||||||
URLTarget target = new URLTarget("/example/target").omitFirst();
|
URIPath target = new URIPath("/example/target").omitFirst();
|
||||||
Optional<String> expected = Optional.of("target");
|
Optional<String> expected = Optional.of("target");
|
||||||
Optional<String> result = target.getPart(0);
|
Optional<String> result = target.getPart(0);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -114,7 +114,7 @@ class URLTargetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void omitFirstFullTarget() {
|
void omitFirstFullTarget() {
|
||||||
URLTarget target = new URLTarget("/example/target").omitFirst();
|
URIPath target = new URIPath("/example/target").omitFirst();
|
||||||
String expected = "/target";
|
String expected = "/target";
|
||||||
String result = target.asString();
|
String result = target.asString();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
@ -124,7 +124,7 @@ class URLTargetTest {
|
|||||||
void partsAreRemoved() {
|
void partsAreRemoved() {
|
||||||
String test = "/example/target";
|
String test = "/example/target";
|
||||||
String expected = "/target";
|
String expected = "/target";
|
||||||
String result = URLTarget.removePartsBefore(test, 1);
|
String result = URIPath.removePartsBefore(test, 1);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class URLTargetTest {
|
|||||||
void partsAreRemoved2() {
|
void partsAreRemoved2() {
|
||||||
String test = "/example/target/";
|
String test = "/example/target/";
|
||||||
String expected = "/";
|
String expected = "/";
|
||||||
String result = URLTarget.removePartsBefore(test, 2);
|
String result = URIPath.removePartsBefore(test, 2);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ class URLTargetTest {
|
|||||||
void partsAreRemoved3() {
|
void partsAreRemoved3() {
|
||||||
String test = "/example/target";
|
String test = "/example/target";
|
||||||
String expected = "";
|
String expected = "";
|
||||||
String result = URLTarget.removePartsBefore(test, 2);
|
String result = URIPath.removePartsBefore(test, 2);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class URLTargetTest {
|
|||||||
void partsAreRemoved4() {
|
void partsAreRemoved4() {
|
||||||
String test = "/example/target";
|
String test = "/example/target";
|
||||||
String expected = "/example/target";
|
String expected = "/example/target";
|
||||||
String result = URLTarget.removePartsBefore(test, 0);
|
String result = URIPath.removePartsBefore(test, 0);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ class URLTargetTest {
|
|||||||
void partsAreRemoved5() {
|
void partsAreRemoved5() {
|
||||||
String test = "/example/target/";
|
String test = "/example/target/";
|
||||||
String expected = "/";
|
String expected = "/";
|
||||||
String result = URLTarget.removePartsBefore(test, 2);
|
String result = URIPath.removePartsBefore(test, 2);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class URLTargetTest {
|
|||||||
void noPartsToRemove() {
|
void noPartsToRemove() {
|
||||||
String test = "";
|
String test = "";
|
||||||
String expected = "";
|
String expected = "";
|
||||||
String result = URLTarget.removePartsBefore(test, 1);
|
String result = URIPath.removePartsBefore(test, 1);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +20,7 @@ import com.djrapitops.plan.api.PlanAPI;
|
|||||||
import com.djrapitops.plan.capability.CapabilitySvc;
|
import com.djrapitops.plan.capability.CapabilitySvc;
|
||||||
import com.djrapitops.plan.delivery.DeliveryUtilities;
|
import com.djrapitops.plan.delivery.DeliveryUtilities;
|
||||||
import com.djrapitops.plan.delivery.export.ExportSystem;
|
import com.djrapitops.plan.delivery.export.ExportSystem;
|
||||||
|
import com.djrapitops.plan.delivery.web.ResolverSvc;
|
||||||
import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker;
|
import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker;
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServerSystem;
|
import com.djrapitops.plan.delivery.webserver.WebServerSystem;
|
||||||
@ -77,6 +78,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
private final ImportSystem importSystem;
|
private final ImportSystem importSystem;
|
||||||
private final ExportSystem exportSystem;
|
private final ExportSystem exportSystem;
|
||||||
private final DeliveryUtilities deliveryUtilities;
|
private final DeliveryUtilities deliveryUtilities;
|
||||||
|
private final ResolverSvc resolverService;
|
||||||
private final ExtensionSvc extensionService;
|
private final ExtensionSvc extensionService;
|
||||||
private final QuerySvc queryService;
|
private final QuerySvc queryService;
|
||||||
private final SettingsSvc settingsService;
|
private final SettingsSvc settingsService;
|
||||||
@ -100,6 +102,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
ImportSystem importSystem,
|
ImportSystem importSystem,
|
||||||
ExportSystem exportSystem,
|
ExportSystem exportSystem,
|
||||||
DeliveryUtilities deliveryUtilities,
|
DeliveryUtilities deliveryUtilities,
|
||||||
|
ResolverSvc resolverService,
|
||||||
ExtensionSvc extensionService,
|
ExtensionSvc extensionService,
|
||||||
QuerySvc queryService,
|
QuerySvc queryService,
|
||||||
SettingsSvc settingsService,
|
SettingsSvc settingsService,
|
||||||
@ -122,6 +125,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
this.importSystem = importSystem;
|
this.importSystem = importSystem;
|
||||||
this.exportSystem = exportSystem;
|
this.exportSystem = exportSystem;
|
||||||
this.deliveryUtilities = deliveryUtilities;
|
this.deliveryUtilities = deliveryUtilities;
|
||||||
|
this.resolverService = resolverService;
|
||||||
this.extensionService = extensionService;
|
this.extensionService = extensionService;
|
||||||
this.queryService = queryService;
|
this.queryService = queryService;
|
||||||
this.settingsService = settingsService;
|
this.settingsService = settingsService;
|
||||||
@ -153,6 +157,11 @@ public class PlanSystem implements SubSystem {
|
|||||||
public void enable() throws EnableException {
|
public void enable() throws EnableException {
|
||||||
CapabilitySvc.initialize();
|
CapabilitySvc.initialize();
|
||||||
|
|
||||||
|
extensionService.register();
|
||||||
|
resolverService.register();
|
||||||
|
settingsService.register();
|
||||||
|
queryService.register();
|
||||||
|
|
||||||
enableSystems(
|
enableSystems(
|
||||||
files,
|
files,
|
||||||
configSystem,
|
configSystem,
|
||||||
@ -176,9 +185,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsService.register();
|
extensionService.registerExtensions();
|
||||||
queryService.register();
|
|
||||||
extensionService.register();
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.commands.subcommands;
|
package com.djrapitops.plan.commands.subcommands;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||||
import com.djrapitops.plan.processing.Processing;
|
import com.djrapitops.plan.processing.Processing;
|
||||||
@ -129,7 +129,7 @@ public class RegisterCommand extends CommandNode {
|
|||||||
Verify.isTrue(userName.length() <= 100, () -> new IllegalArgumentException("Username can only be 100 characters long."));
|
Verify.isTrue(userName.length() <= 100, () -> new IllegalArgumentException("Username can only be 100 characters long."));
|
||||||
int permLevel = Integer.parseInt(args[2]);
|
int permLevel = Integer.parseInt(args[2]);
|
||||||
String passHash = PassEncryptUtil.createHash(args[0]);
|
String passHash = PassEncryptUtil.createHash(args[0]);
|
||||||
registerUser(new WebUser(userName, passHash, permLevel), sender);
|
registerUser(new WebUser_old(userName, passHash, permLevel), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playerRegister(String[] args, Sender sender) throws PassEncryptUtil.CannotPerformOperationException {
|
private void playerRegister(String[] args, Sender sender) throws PassEncryptUtil.CannotPerformOperationException {
|
||||||
@ -138,7 +138,7 @@ public class RegisterCommand extends CommandNode {
|
|||||||
String user = sender.getName();
|
String user = sender.getName();
|
||||||
String pass = PassEncryptUtil.createHash(args[0]);
|
String pass = PassEncryptUtil.createHash(args[0]);
|
||||||
int permLvl = getPermissionLevel(sender);
|
int permLvl = getPermissionLevel(sender);
|
||||||
registerUser(new WebUser(user, pass, permLvl), sender);
|
registerUser(new WebUser_old(user, pass, permLvl), sender);
|
||||||
} else if (sender.hasPermission(Permissions.MANAGE_WEB.getPermission())) {
|
} else if (sender.hasPermission(Permissions.MANAGE_WEB.getPermission())) {
|
||||||
consoleRegister(args, sender, notEnoughArgsMsg);
|
consoleRegister(args, sender, notEnoughArgsMsg);
|
||||||
} else {
|
} else {
|
||||||
@ -162,7 +162,7 @@ public class RegisterCommand extends CommandNode {
|
|||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerUser(WebUser webUser, Sender sender) {
|
private void registerUser(WebUser_old webUser, Sender sender) {
|
||||||
processing.submitCritical(() -> {
|
processing.submitCritical(() -> {
|
||||||
String userName = webUser.getName();
|
String userName = webUser.getName();
|
||||||
try {
|
try {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands.webuser;
|
package com.djrapitops.plan.commands.subcommands.webuser;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.processing.Processing;
|
import com.djrapitops.plan.processing.Processing;
|
||||||
import com.djrapitops.plan.settings.Permissions;
|
import com.djrapitops.plan.settings.Permissions;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
@ -85,12 +85,12 @@ public class WebCheckCommand extends CommandNode {
|
|||||||
processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
Database db = dbSystem.getDatabase();
|
Database db = dbSystem.getDatabase();
|
||||||
Optional<WebUser> found = db.query(WebUserQueries.fetchWebUser(user));
|
Optional<WebUser_old> found = db.query(WebUserQueries.fetchWebUser(user));
|
||||||
if (!found.isPresent()) {
|
if (!found.isPresent()) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WebUser info = found.get();
|
WebUser_old info = found.get();
|
||||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
|
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands.webuser;
|
package com.djrapitops.plan.commands.subcommands.webuser;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.processing.Processing;
|
import com.djrapitops.plan.processing.Processing;
|
||||||
import com.djrapitops.plan.settings.Permissions;
|
import com.djrapitops.plan.settings.Permissions;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
@ -86,7 +86,7 @@ public class WebDeleteCommand extends CommandNode {
|
|||||||
processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
Database db = dbSystem.getDatabase();
|
Database db = dbSystem.getDatabase();
|
||||||
Optional<WebUser> found = db.query(WebUserQueries.fetchWebUser(user));
|
Optional<WebUser_old> found = db.query(WebUserQueries.fetchWebUser(user));
|
||||||
if (!found.isPresent()) {
|
if (!found.isPresent()) {
|
||||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||||
return;
|
return;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.commands.subcommands.webuser;
|
package com.djrapitops.plan.commands.subcommands.webuser;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.processing.Processing;
|
import com.djrapitops.plan.processing.Processing;
|
||||||
import com.djrapitops.plan.settings.Permissions;
|
import com.djrapitops.plan.settings.Permissions;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
@ -76,9 +76,9 @@ public class WebListUsersCommand extends CommandNode {
|
|||||||
|
|
||||||
processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
List<WebUser> users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers());
|
List<WebUser_old> users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers());
|
||||||
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size()));
|
||||||
for (WebUser user : users) {
|
for (WebUser_old user : users) {
|
||||||
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
|
sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel()));
|
||||||
}
|
}
|
||||||
sender.sendMessage(">");
|
sender.sendMessage(">");
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.domain;
|
package com.djrapitops.plan.delivery.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,13 +25,14 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class WebUser {
|
@Deprecated
|
||||||
|
public class WebUser_old {
|
||||||
|
|
||||||
private final String user;
|
private final String user;
|
||||||
private final String saltedPassHash;
|
private final String saltedPassHash;
|
||||||
private final int permLevel;
|
private final int permLevel;
|
||||||
|
|
||||||
public WebUser(String user, String saltedPassHash, int permLevel) {
|
public WebUser_old(String user, String saltedPassHash, int permLevel) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.saltedPassHash = saltedPassHash;
|
this.saltedPassHash = saltedPassHash;
|
||||||
this.permLevel = permLevel;
|
this.permLevel = permLevel;
|
||||||
@ -51,7 +54,7 @@ public class WebUser {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
WebUser webUser = (WebUser) o;
|
WebUser_old webUser = (WebUser_old) o;
|
||||||
return permLevel == webUser.permLevel &&
|
return permLevel == webUser.permLevel &&
|
||||||
Objects.equals(user, webUser.user) &&
|
Objects.equals(user, webUser.user) &&
|
||||||
Objects.equals(saltedPassHash, webUser.saltedPassHash);
|
Objects.equals(saltedPassHash, webUser.saltedPassHash);
|
||||||
@ -61,4 +64,24 @@ public class WebUser {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(user, saltedPassHash, permLevel);
|
return Objects.hash(user, saltedPassHash, permLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public com.djrapitops.plan.delivery.web.resolver.WebUser toNewWebUser() {
|
||||||
|
List<String> permissions = new ArrayList<>();
|
||||||
|
if (permLevel <= 0) {
|
||||||
|
permissions.add("page.network");
|
||||||
|
permissions.add("page.server");
|
||||||
|
permissions.add("page.debug");
|
||||||
|
// TODO Add JSON Permissions
|
||||||
|
}
|
||||||
|
if (permLevel <= 1) {
|
||||||
|
permissions.add("page.players");
|
||||||
|
permissions.add("page.player.other");
|
||||||
|
}
|
||||||
|
if (permLevel <= 2) {
|
||||||
|
permissions.add("page.player.self");
|
||||||
|
}
|
||||||
|
return new com.djrapitops.plan.delivery.web.resolver.WebUser(
|
||||||
|
user, permissions.toArray(new String[0])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,7 +17,6 @@
|
|||||||
package com.djrapitops.plan.delivery.export;
|
package com.djrapitops.plan.delivery.export;
|
||||||
|
|
||||||
import com.djrapitops.plan.exceptions.ExportException;
|
import com.djrapitops.plan.exceptions.ExportException;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
@ -86,7 +85,7 @@ public class Exporter extends FileExporter {
|
|||||||
serverPageExporter.export(toDirectory, server);
|
serverPageExporter.export(toDirectory, server);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException | NotFoundException | GenerationException e) {
|
} catch (IOException | NotFoundException e) {
|
||||||
failedServers.add(serverUUID);
|
failedServers.add(serverUUID);
|
||||||
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e);
|
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e);
|
||||||
}
|
}
|
||||||
@ -125,7 +124,7 @@ public class Exporter extends FileExporter {
|
|||||||
try {
|
try {
|
||||||
playerPageExporter.export(toDirectory, playerUUID, playerName);
|
playerPageExporter.export(toDirectory, playerUUID, playerName);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException | NotFoundException | GenerationException e) {
|
} catch (IOException | NotFoundException e) {
|
||||||
throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
|
throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +136,7 @@ public class Exporter extends FileExporter {
|
|||||||
try {
|
try {
|
||||||
playersPageExporter.export(toDirectory);
|
playersPageExporter.export(toDirectory);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException | NotFoundException | GenerationException e) {
|
} catch (IOException | NotFoundException e) {
|
||||||
throw new ExportException("Failed to export players page, " + e.toString(), e);
|
throw new ExportException("Failed to export players page, " + e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page;
|
|||||||
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
@ -76,7 +75,7 @@ public class NetworkPageExporter extends FileExporter {
|
|||||||
exportPaths = new ExportPaths();
|
exportPaths = new ExportPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException {
|
public void export(Path toDirectory, Server server) throws IOException, NotFoundException {
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ public class NetworkPageExporter extends FileExporter {
|
|||||||
exportPaths.clear();
|
exportPaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportHtml(Path toDirectory) throws IOException, GenerationException {
|
private void exportHtml(Path toDirectory) throws IOException {
|
||||||
Path to = toDirectory
|
Path to = toDirectory
|
||||||
.resolve("network")
|
.resolve("network")
|
||||||
.resolve("index.html");
|
.resolve("index.html");
|
||||||
@ -122,7 +121,7 @@ public class NetworkPageExporter extends FileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException {
|
private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException {
|
||||||
Response found = getJSONResponse(resource);
|
Response_old found = getJSONResponse(resource);
|
||||||
if (found instanceof ErrorResponse) {
|
if (found instanceof ErrorResponse) {
|
||||||
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
||||||
}
|
}
|
||||||
@ -140,7 +139,7 @@ public class NetworkPageExporter extends FileExporter {
|
|||||||
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getJSONResponse(String resource) {
|
private Response_old getJSONResponse(String resource) {
|
||||||
try {
|
try {
|
||||||
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
|
@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page;
|
|||||||
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
@ -73,7 +72,7 @@ public class PlayerPageExporter extends FileExporter {
|
|||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException, GenerationException {
|
public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException {
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
||||||
if (!dbSystem.getDatabase().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))) return;
|
if (!dbSystem.getDatabase().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))) return;
|
||||||
@ -89,7 +88,7 @@ public class PlayerPageExporter extends FileExporter {
|
|||||||
exportPaths.clear();
|
exportPaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportHtml(ExportPaths exportPaths, Path playerDirectory, UUID playerUUID) throws IOException, GenerationException, NotFoundException {
|
private void exportHtml(ExportPaths exportPaths, Path playerDirectory, UUID playerUUID) throws IOException, NotFoundException {
|
||||||
Path to = playerDirectory.resolve("index.html");
|
Path to = playerDirectory.resolve("index.html");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -105,7 +104,7 @@ public class PlayerPageExporter extends FileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportJSON(ExportPaths exportPaths, Path toDirectory, String resource, String playerName) throws NotFoundException, IOException {
|
private void exportJSON(ExportPaths exportPaths, Path toDirectory, String resource, String playerName) throws NotFoundException, IOException {
|
||||||
Response found = getJSONResponse(resource);
|
Response_old found = getJSONResponse(resource);
|
||||||
if (found instanceof ErrorResponse) {
|
if (found instanceof ErrorResponse) {
|
||||||
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
||||||
}
|
}
|
||||||
@ -120,7 +119,7 @@ public class PlayerPageExporter extends FileExporter {
|
|||||||
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "player="}, new String[]{"-", "_", "", ""});
|
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "player="}, new String[]{"-", "_", "", ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getJSONResponse(String resource) {
|
private Response_old getJSONResponse(String resource) {
|
||||||
try {
|
try {
|
||||||
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
|
@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page;
|
|||||||
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
@ -79,7 +78,7 @@ public class PlayersPageExporter extends FileExporter {
|
|||||||
exportPaths = new ExportPaths();
|
exportPaths = new ExportPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(Path toDirectory) throws IOException, NotFoundException, GenerationException {
|
public void export(Path toDirectory) throws IOException, NotFoundException {
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ public class PlayersPageExporter extends FileExporter {
|
|||||||
exportPaths.clear();
|
exportPaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportHtml(Path toDirectory) throws IOException, GenerationException {
|
private void exportHtml(Path toDirectory) throws IOException {
|
||||||
Path to = toDirectory
|
Path to = toDirectory
|
||||||
.resolve("players")
|
.resolve("players")
|
||||||
.resolve("index.html");
|
.resolve("index.html");
|
||||||
@ -100,7 +99,7 @@ public class PlayersPageExporter extends FileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportJSON(Path toDirectory) throws NotFoundException, IOException {
|
private void exportJSON(Path toDirectory) throws NotFoundException, IOException {
|
||||||
Response found = getJSONResponse("players");
|
Response_old found = getJSONResponse("players");
|
||||||
if (found instanceof ErrorResponse) {
|
if (found instanceof ErrorResponse) {
|
||||||
throw new NotFoundException("players page was not properly exported: " + found.getContent());
|
throw new NotFoundException("players page was not properly exported: " + found.getContent());
|
||||||
}
|
}
|
||||||
@ -118,7 +117,7 @@ public class PlayersPageExporter extends FileExporter {
|
|||||||
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getJSONResponse(String resource) {
|
private Response_old getJSONResponse(String resource) {
|
||||||
try {
|
try {
|
||||||
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
|
@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page;
|
|||||||
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
@ -81,7 +80,7 @@ public class ServerPageExporter extends FileExporter {
|
|||||||
exportPaths = new ExportPaths();
|
exportPaths = new ExportPaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void export(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException {
|
public void export(Path toDirectory, Server server) throws IOException, NotFoundException {
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ public class ServerPageExporter extends FileExporter {
|
|||||||
exportPaths.clear();
|
exportPaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException {
|
private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException {
|
||||||
UUID serverUUID = server.getUuid();
|
UUID serverUUID = server.getUuid();
|
||||||
Path to = toDirectory
|
Path to = toDirectory
|
||||||
.resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server")
|
.resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server")
|
||||||
@ -134,7 +133,7 @@ public class ServerPageExporter extends FileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException {
|
private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException {
|
||||||
Response found = getJSONResponse(resource);
|
Response_old found = getJSONResponse(resource);
|
||||||
if (found instanceof ErrorResponse) {
|
if (found instanceof ErrorResponse) {
|
||||||
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
throw new NotFoundException(resource + " was not properly exported: " + found.getContent());
|
||||||
}
|
}
|
||||||
@ -152,7 +151,7 @@ public class ServerPageExporter extends FileExporter {
|
|||||||
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response getJSONResponse(String resource) {
|
private Response_old getJSONResponse(String resource) {
|
||||||
try {
|
try {
|
||||||
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
return jsonHandler.resolve(null, new RequestTarget(URI.create(resource)));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
|
@ -19,6 +19,8 @@ package com.djrapitops.plan.delivery.rendering.pages;
|
|||||||
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.delivery.formatting.Formatter;
|
import com.djrapitops.plan.delivery.formatting.Formatter;
|
||||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
import com.djrapitops.plan.delivery.formatting.Formatters;
|
||||||
|
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||||
|
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.icon.Icon;
|
import com.djrapitops.plan.delivery.rendering.html.icon.Icon;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.structure.TabsElement;
|
import com.djrapitops.plan.delivery.rendering.html.structure.TabsElement;
|
||||||
@ -52,6 +54,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class DebugPage implements Page {
|
public class DebugPage implements Page {
|
||||||
|
|
||||||
|
private final String template;
|
||||||
private final Database database;
|
private final Database database;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
@ -62,6 +65,8 @@ public class DebugPage implements Page {
|
|||||||
private final Formatter<Long> yearFormatter;
|
private final Formatter<Long> yearFormatter;
|
||||||
|
|
||||||
DebugPage(
|
DebugPage(
|
||||||
|
String htmlTemplate,
|
||||||
|
|
||||||
Database database,
|
Database database,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters,
|
Formatters formatters,
|
||||||
@ -70,6 +75,8 @@ public class DebugPage implements Page {
|
|||||||
Timings timings,
|
Timings timings,
|
||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
|
this.template = htmlTemplate;
|
||||||
|
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
@ -82,6 +89,17 @@ public class DebugPage implements Page {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toHtml() {
|
public String toHtml() {
|
||||||
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
|
placeholders.put("title", Icon.called("bug") + " Debug Information");
|
||||||
|
placeholders.put("titleText", "Debug Information");
|
||||||
|
placeholders.put("paragraph", createContent());
|
||||||
|
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||||
|
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||||
|
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||||
|
return placeholders.apply(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createContent() {
|
||||||
StringBuilder preContent = new StringBuilder();
|
StringBuilder preContent = new StringBuilder();
|
||||||
|
|
||||||
String issueLink = Html.LINK_EXTERNAL.create("https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new", "Create new issue on Github");
|
String issueLink = Html.LINK_EXTERNAL.create("https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new", "Create new issue on Github");
|
||||||
|
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.delivery.rendering.pages;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||||
|
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
||||||
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
|
import com.djrapitops.plan.delivery.rendering.html.icon.Icon;
|
||||||
|
import com.djrapitops.plan.version.VersionCheckSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page to display error stacktrace.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class InternalErrorPage implements Page {
|
||||||
|
|
||||||
|
private final String template;
|
||||||
|
private final String errorMsg;
|
||||||
|
private final Throwable error;
|
||||||
|
|
||||||
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
|
|
||||||
|
public InternalErrorPage(
|
||||||
|
String template, String errorMsg, Throwable error,
|
||||||
|
VersionCheckSystem versionCheckSystem
|
||||||
|
) {
|
||||||
|
this.template = template;
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
|
this.error = error;
|
||||||
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toHtml() {
|
||||||
|
|
||||||
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
|
placeholders.put("title", Icon.called("bug") + " 500 Internal Error occurred");
|
||||||
|
placeholders.put("titleText", "500 Internal Error occurred");
|
||||||
|
placeholders.put("paragraph", createContent());
|
||||||
|
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||||
|
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||||
|
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||||
|
return placeholders.apply(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createContent() {
|
||||||
|
StringBuilder paragraph = new StringBuilder();
|
||||||
|
paragraph.append("Please report this issue here: ");
|
||||||
|
paragraph.append(Html.LINK.create("https://github.com/Rsl1122/Plan-PlayerAnalytics/issues", "Issues"));
|
||||||
|
paragraph.append("<br><br><pre>");
|
||||||
|
paragraph.append(error).append(" | ").append(errorMsg);
|
||||||
|
|
||||||
|
for (StackTraceElement element : error.getStackTrace()) {
|
||||||
|
paragraph.append("<br>");
|
||||||
|
paragraph.append(" ").append(element);
|
||||||
|
}
|
||||||
|
if (error.getCause() != null) {
|
||||||
|
appendCause(error.getCause(), paragraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
paragraph.append("</pre>");
|
||||||
|
|
||||||
|
return paragraph.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendCause(Throwable cause, StringBuilder paragraph) {
|
||||||
|
paragraph.append("<br>Caused by: ").append(cause);
|
||||||
|
for (StackTraceElement element : cause.getStackTrace()) {
|
||||||
|
paragraph.append("<br>");
|
||||||
|
paragraph.append(" ").append(element);
|
||||||
|
}
|
||||||
|
if (cause.getCause() != null) {
|
||||||
|
appendCause(cause.getCause(), paragraph);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,6 @@ import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
|||||||
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
@ -31,7 +30,6 @@ import com.djrapitops.plan.settings.config.paths.ProxySettings;
|
|||||||
import com.djrapitops.plan.settings.theme.Theme;
|
import com.djrapitops.plan.settings.theme.Theme;
|
||||||
import com.djrapitops.plan.settings.theme.ThemeVal;
|
import com.djrapitops.plan.settings.theme.ThemeVal;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
|
||||||
import com.djrapitops.plan.version.VersionCheckSystem;
|
import com.djrapitops.plan.version.VersionCheckSystem;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@ -45,27 +43,28 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class NetworkPage implements Page {
|
public class NetworkPage implements Page {
|
||||||
|
|
||||||
|
private final String templateHtml;
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
|
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
private final PlanFiles files;
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final Theme theme;
|
private final Theme theme;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
private final Formatters formatters;
|
private final Formatters formatters;
|
||||||
|
|
||||||
NetworkPage(
|
NetworkPage(
|
||||||
|
String templateHtml,
|
||||||
|
|
||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
VersionCheckSystem versionCheckSystem,
|
VersionCheckSystem versionCheckSystem,
|
||||||
PlanFiles files,
|
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
Theme theme,
|
Theme theme,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
Formatters formatters
|
||||||
) {
|
) {
|
||||||
|
this.templateHtml = templateHtml;
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
this.files = files;
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
@ -73,42 +72,38 @@ public class NetworkPage implements Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toHtml() throws GenerationException {
|
public String toHtml() {
|
||||||
try {
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
|
||||||
|
|
||||||
UUID serverUUID = serverInfo.getServerUUID();
|
UUID serverUUID = serverInfo.getServerUUID();
|
||||||
placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
|
placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
|
||||||
placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
|
placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
|
||||||
placeholders.put("serverUUID", serverUUID.toString());
|
placeholders.put("serverUUID", serverUUID.toString());
|
||||||
|
|
||||||
placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
|
placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
|
||||||
placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
|
||||||
placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW));
|
||||||
placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH));
|
||||||
placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING));
|
placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING));
|
||||||
placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING));
|
placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING));
|
||||||
placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING));
|
placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING));
|
||||||
placeholders.put("timeZone", config.getTimeZoneOffsetHours());
|
placeholders.put("timeZone", config.getTimeZoneOffsetHours());
|
||||||
|
|
||||||
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||||
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||||
placeholders.put("contributors", Contributors.generateContributorHtml());
|
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||||
|
|
||||||
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
||||||
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
|
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
|
||||||
return new ServerPluginTabs(extensionData, formatters);
|
return new ServerPluginTabs(extensionData, formatters);
|
||||||
});
|
});
|
||||||
|
|
||||||
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
|
String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav());
|
||||||
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
|
String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs());
|
||||||
|
|
||||||
placeholders.put("navPluginsTabs", nav);
|
placeholders.put("navPluginsTabs", nav);
|
||||||
placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
|
placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
|
||||||
|
|
||||||
return placeholders.apply(files.getCustomizableResourceOrDefault("web/network.html").asString());
|
return placeholders.apply(templateHtml);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new GenerationException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,14 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.rendering.pages;
|
package com.djrapitops.plan.delivery.rendering.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for generating page HTML String.
|
* Interface for generating page HTML String.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public interface Page {
|
public interface Page {
|
||||||
|
String toHtml();
|
||||||
String toHtml() throws GenerationException;
|
|
||||||
}
|
}
|
@ -38,6 +38,7 @@ import dagger.Lazy;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +50,7 @@ import java.util.*;
|
|||||||
public class PageFactory {
|
public class PageFactory {
|
||||||
|
|
||||||
private final Lazy<VersionCheckSystem> versionCheckSystem;
|
private final Lazy<VersionCheckSystem> versionCheckSystem;
|
||||||
private final Lazy<PlanFiles> fileSystem;
|
private final Lazy<PlanFiles> files;
|
||||||
private final Lazy<PlanConfig> config;
|
private final Lazy<PlanConfig> config;
|
||||||
private final Lazy<Theme> theme;
|
private final Lazy<Theme> theme;
|
||||||
private final Lazy<DBSystem> dbSystem;
|
private final Lazy<DBSystem> dbSystem;
|
||||||
@ -62,7 +63,7 @@ public class PageFactory {
|
|||||||
@Inject
|
@Inject
|
||||||
public PageFactory(
|
public PageFactory(
|
||||||
Lazy<VersionCheckSystem> versionCheckSystem,
|
Lazy<VersionCheckSystem> versionCheckSystem,
|
||||||
Lazy<PlanFiles> fileSystem,
|
Lazy<PlanFiles> files,
|
||||||
Lazy<PlanConfig> config,
|
Lazy<PlanConfig> config,
|
||||||
Lazy<Theme> theme,
|
Lazy<Theme> theme,
|
||||||
Lazy<DBSystem> dbSystem,
|
Lazy<DBSystem> dbSystem,
|
||||||
@ -73,7 +74,7 @@ public class PageFactory {
|
|||||||
Lazy<ErrorHandler> errorHandler
|
Lazy<ErrorHandler> errorHandler
|
||||||
) {
|
) {
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
this.fileSystem = fileSystem;
|
this.files = files;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
@ -84,38 +85,40 @@ public class PageFactory {
|
|||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DebugPage debugPage() {
|
public DebugPage debugPage() throws IOException {
|
||||||
return new DebugPage(
|
return new DebugPage(
|
||||||
|
getResource("web/error.html"),
|
||||||
dbSystem.get().getDatabase(), serverInfo.get(), formatters.get(), versionCheckSystem.get(),
|
dbSystem.get().getDatabase(), serverInfo.get(), formatters.get(), versionCheckSystem.get(),
|
||||||
debugLogger.get(), timings.get(), errorHandler.get()
|
debugLogger.get(), timings.get(), errorHandler.get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayersPage playersPage() {
|
public PlayersPage playersPage() throws IOException {
|
||||||
return new PlayersPage(versionCheckSystem.get(), fileSystem.get(), config.get(), serverInfo.get());
|
return new PlayersPage(getResource("web/players.html"), versionCheckSystem.get(), config.get(), serverInfo.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerPage serverPage(UUID serverUUID) throws NotFoundException {
|
public ServerPage serverPage(UUID serverUUID) throws NotFoundException, IOException {
|
||||||
return dbSystem.get().getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID))
|
Server server = dbSystem.get().getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID))
|
||||||
.map(server -> new ServerPage(
|
.orElseThrow(() -> new NotFoundException("Server not found in the database"));
|
||||||
server,
|
return new ServerPage(
|
||||||
config.get(),
|
getResource("web/server.html"),
|
||||||
theme.get(),
|
server,
|
||||||
versionCheckSystem.get(),
|
config.get(),
|
||||||
fileSystem.get(),
|
theme.get(),
|
||||||
dbSystem.get(),
|
versionCheckSystem.get(),
|
||||||
serverInfo.get(),
|
dbSystem.get(),
|
||||||
formatters.get()
|
serverInfo.get(),
|
||||||
)).orElseThrow(() -> new NotFoundException("Server not found in the database"));
|
formatters.get()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerPage playerPage(UUID playerUUID) {
|
public PlayerPage playerPage(UUID playerUUID) throws IOException {
|
||||||
Database db = dbSystem.get().getDatabase();
|
Database db = dbSystem.get().getDatabase();
|
||||||
PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
|
PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
|
||||||
return new PlayerPage(
|
return new PlayerPage(
|
||||||
player,
|
getResource("web/player.html"), player,
|
||||||
versionCheckSystem.get(),
|
versionCheckSystem.get(),
|
||||||
fileSystem.get(), config.get(), this, theme.get(),
|
config.get(), this, theme.get(),
|
||||||
formatters.get(), serverInfo.get()
|
formatters.get(), serverInfo.get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -153,8 +156,25 @@ public class PageFactory {
|
|||||||
return new PlayerPluginTab(navs.toString(), tabs.toString());
|
return new PlayerPluginTab(navs.toString(), tabs.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkPage networkPage() {
|
public NetworkPage networkPage() throws IOException {
|
||||||
return new NetworkPage(dbSystem.get(),
|
return new NetworkPage(getResource("web/network.html"),
|
||||||
versionCheckSystem.get(), fileSystem.get(), config.get(), theme.get(), serverInfo.get(), formatters.get());
|
dbSystem.get(),
|
||||||
|
versionCheckSystem.get(), config.get(), theme.get(), serverInfo.get(), formatters.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page internalErrorPage(String message, Throwable error) {
|
||||||
|
try {
|
||||||
|
return new InternalErrorPage(
|
||||||
|
getResource("web/error.html"), message, error,
|
||||||
|
versionCheckSystem.get());
|
||||||
|
} catch (IOException noParse) {
|
||||||
|
return () -> "Error occurred: " + error.toString() +
|
||||||
|
", additional error occurred when attempting to render error page to user: " +
|
||||||
|
noParse.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResource(String name) throws IOException {
|
||||||
|
return files.get().getCustomizableResourceOrDefault(name).asString();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,15 +23,12 @@ import com.djrapitops.plan.delivery.formatting.Formatters;
|
|||||||
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.theme.Theme;
|
import com.djrapitops.plan.settings.theme.Theme;
|
||||||
import com.djrapitops.plan.settings.theme.ThemeVal;
|
import com.djrapitops.plan.settings.theme.ThemeVal;
|
||||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
|
||||||
import com.djrapitops.plan.version.VersionCheckSystem;
|
import com.djrapitops.plan.version.VersionCheckSystem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,11 +38,11 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class PlayerPage implements Page {
|
public class PlayerPage implements Page {
|
||||||
|
|
||||||
|
private final String templateHtml;
|
||||||
private final PlayerContainer player;
|
private final PlayerContainer player;
|
||||||
|
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
|
|
||||||
private final PlanFiles files;
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final PageFactory pageFactory;
|
private final PageFactory pageFactory;
|
||||||
private final Theme theme;
|
private final Theme theme;
|
||||||
@ -55,18 +52,18 @@ public class PlayerPage implements Page {
|
|||||||
private final Formatter<Long> secondLongFormatter;
|
private final Formatter<Long> secondLongFormatter;
|
||||||
|
|
||||||
PlayerPage(
|
PlayerPage(
|
||||||
|
String templateHtml,
|
||||||
PlayerContainer player,
|
PlayerContainer player,
|
||||||
VersionCheckSystem versionCheckSystem,
|
VersionCheckSystem versionCheckSystem,
|
||||||
PlanFiles files,
|
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
PageFactory pageFactory,
|
PageFactory pageFactory,
|
||||||
Theme theme,
|
Theme theme,
|
||||||
Formatters formatters,
|
Formatters formatters,
|
||||||
ServerInfo serverInfo
|
ServerInfo serverInfo
|
||||||
) {
|
) {
|
||||||
|
this.templateHtml = templateHtml;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
this.files = files;
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
@ -77,18 +74,14 @@ public class PlayerPage implements Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toHtml() throws GenerationException {
|
public String toHtml() {
|
||||||
if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) {
|
if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) {
|
||||||
throw new IllegalStateException("Player is not registered");
|
throw new IllegalStateException("Player is not registered");
|
||||||
}
|
}
|
||||||
try {
|
return createFor(player);
|
||||||
return createFor(player);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new GenerationException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createFor(PlayerContainer player) throws IOException {
|
public String createFor(PlayerContainer player) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
UUID playerUUID = player.getUnsafe(PlayerKeys.UUID);
|
UUID playerUUID = player.getUnsafe(PlayerKeys.UUID);
|
||||||
|
|
||||||
@ -116,6 +109,6 @@ public class PlayerPage implements Page {
|
|||||||
placeholders.put("navPluginsTabs", pluginTabs.getNav());
|
placeholders.put("navPluginsTabs", pluginTabs.getNav());
|
||||||
placeholders.put("pluginsTabs", pluginTabs.getTab());
|
placeholders.put("pluginsTabs", pluginTabs.getTab());
|
||||||
|
|
||||||
return placeholders.apply(files.getCustomizableResourceOrDefault("web/player.html").asString());
|
return placeholders.apply(templateHtml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,10 @@ package com.djrapitops.plan.delivery.rendering.pages;
|
|||||||
|
|
||||||
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||||
import com.djrapitops.plan.settings.config.paths.ProxySettings;
|
import com.djrapitops.plan.settings.config.paths.ProxySettings;
|
||||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
|
||||||
import com.djrapitops.plan.version.VersionCheckSystem;
|
import com.djrapitops.plan.version.VersionCheckSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,40 +31,36 @@ import com.djrapitops.plan.version.VersionCheckSystem;
|
|||||||
*/
|
*/
|
||||||
public class PlayersPage implements Page {
|
public class PlayersPage implements Page {
|
||||||
|
|
||||||
|
private final String templateHtml;
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
private final PlanFiles files;
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
|
||||||
PlayersPage(
|
PlayersPage(
|
||||||
|
String templateHtml,
|
||||||
VersionCheckSystem versionCheckSystem,
|
VersionCheckSystem versionCheckSystem,
|
||||||
PlanFiles files,
|
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
ServerInfo serverInfo
|
ServerInfo serverInfo
|
||||||
) {
|
) {
|
||||||
|
this.templateHtml = templateHtml;
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
this.files = files;
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toHtml() throws GenerationException {
|
public String toHtml() {
|
||||||
try {
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
|
||||||
|
|
||||||
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));
|
||||||
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
placeholders.put("updateModal", versionCheckSystem.getUpdateModal());
|
||||||
placeholders.put("contributors", Contributors.generateContributorHtml());
|
placeholders.put("contributors", Contributors.generateContributorHtml());
|
||||||
if (serverInfo.getServer().isProxy()) {
|
if (serverInfo.getServer().isProxy()) {
|
||||||
placeholders.put("networkName", config.get(ProxySettings.NETWORK_NAME));
|
placeholders.put("networkName", config.get(ProxySettings.NETWORK_NAME));
|
||||||
} else {
|
} else {
|
||||||
placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME));
|
placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME));
|
||||||
}
|
|
||||||
|
|
||||||
return placeholders.apply(files.getCustomizableResourceOrDefault("web/players.html").asString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new GenerationException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return placeholders.apply(templateHtml);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,7 +26,6 @@ import com.djrapitops.plan.delivery.rendering.html.Contributors;
|
|||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
import com.djrapitops.plan.extension.implementation.results.ExtensionData;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
@ -36,10 +35,8 @@ import com.djrapitops.plan.settings.config.paths.DisplaySettings;
|
|||||||
import com.djrapitops.plan.settings.theme.Theme;
|
import com.djrapitops.plan.settings.theme.Theme;
|
||||||
import com.djrapitops.plan.settings.theme.ThemeVal;
|
import com.djrapitops.plan.settings.theme.ThemeVal;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
|
||||||
import com.djrapitops.plan.version.VersionCheckSystem;
|
import com.djrapitops.plan.version.VersionCheckSystem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -52,37 +49,36 @@ import static com.djrapitops.plan.delivery.domain.keys.AnalysisKeys.*;
|
|||||||
*/
|
*/
|
||||||
public class ServerPage implements Page {
|
public class ServerPage implements Page {
|
||||||
|
|
||||||
|
private final String templateHtml;
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final Theme theme;
|
private final Theme theme;
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
private final PlanFiles files;
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
private final Formatters formatters;
|
private final Formatters formatters;
|
||||||
|
|
||||||
ServerPage(
|
ServerPage(
|
||||||
Server server,
|
String templateHtml, Server server,
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
Theme theme,
|
Theme theme,
|
||||||
VersionCheckSystem versionCheckSystem,
|
VersionCheckSystem versionCheckSystem,
|
||||||
PlanFiles files,
|
|
||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
Formatters formatters
|
Formatters formatters
|
||||||
) {
|
) {
|
||||||
|
this.templateHtml = templateHtml;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
this.versionCheckSystem = versionCheckSystem;
|
this.versionCheckSystem = versionCheckSystem;
|
||||||
this.files = files;
|
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
this.formatters = formatters;
|
this.formatters = formatters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toHtml() throws GenerationException {
|
public String toHtml() {
|
||||||
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
PlaceholderReplacer placeholders = new PlaceholderReplacer();
|
||||||
|
|
||||||
UUID serverUUID = server.getUuid();
|
UUID serverUUID = server.getUuid();
|
||||||
@ -139,10 +135,6 @@ public class ServerPage implements Page {
|
|||||||
placeholders.put("navPluginsTabs", nav);
|
placeholders.put("navPluginsTabs", nav);
|
||||||
placeholders.put("tabsPlugins", tabs);
|
placeholders.put("tabsPlugins", tabs);
|
||||||
|
|
||||||
try {
|
return placeholders.apply(templateHtml);
|
||||||
return placeholders.apply(files.getCustomizableResourceOrDefault("web/server.html").asString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new GenerationException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.delivery.web;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ResolverService Implementation.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ResolverSvc implements ResolverService {
|
||||||
|
|
||||||
|
private final Collection<Container> basicResolvers;
|
||||||
|
private final Collection<Container> regexResolvers;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ResolverSvc() {
|
||||||
|
basicResolvers = new ArrayList<>();
|
||||||
|
regexResolvers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register() {
|
||||||
|
ResolverService.Holder.set(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerResolver(String pluginName, String start, Resolver resolver) {
|
||||||
|
basicResolvers.add(new Container(pluginName, checking -> checking.startsWith(start), resolver));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerResolverForMatches(String pluginName, Pattern pattern, Resolver resolver) {
|
||||||
|
regexResolvers.add(new Container(pluginName, pattern.asPredicate(), resolver));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Resolver> getResolver(String target) {
|
||||||
|
for (Container container : basicResolvers) {
|
||||||
|
if (container.matcher.test(target)) return Optional.of(container.resolver);
|
||||||
|
}
|
||||||
|
for (Container container : regexResolvers) {
|
||||||
|
if (container.matcher.test(target)) return Optional.of(container.resolver);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getPluginInChargeOf(String target) {
|
||||||
|
for (Container container : basicResolvers) {
|
||||||
|
if (container.matcher.test(target)) return Optional.of(container.plugin);
|
||||||
|
}
|
||||||
|
for (Container container : regexResolvers) {
|
||||||
|
if (container.matcher.test(target)) return Optional.of(container.plugin);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Container {
|
||||||
|
final String plugin;
|
||||||
|
final Predicate<String> matcher;
|
||||||
|
final Resolver resolver;
|
||||||
|
|
||||||
|
public Container(String plugin, Predicate<String> matcher, Resolver resolver) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.matcher = matcher;
|
||||||
|
this.resolver = resolver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver;
|
package com.djrapitops.plan.delivery.webserver;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.URIPath;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.URIQuery;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
@ -68,8 +70,12 @@ public class Request {
|
|||||||
return requestURI.getPath() + '?' + requestURI.getQuery();
|
return requestURI.getPath() + '?' + requestURI.getQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestTarget getTarget() {
|
public URIPath getPath() {
|
||||||
return new RequestTarget(requestURI);
|
return new URIPath(requestURI.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public URIQuery getQuery() {
|
||||||
|
return new URIQuery(requestURI.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getRequestBody() {
|
public InputStream getRequestBody() {
|
||||||
@ -88,4 +94,9 @@ public class Request {
|
|||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public RequestTarget getRequestTarget() {
|
||||||
|
return new RequestTarget(requestURI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver;
|
|||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.BasicAuthentication;
|
import com.djrapitops.plan.delivery.webserver.auth.BasicAuthentication;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.PromptAuthorizationResponse;
|
import com.djrapitops.plan.delivery.webserver.response.PromptAuthorizationResponse;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.ForbiddenResponse;
|
import com.djrapitops.plan.delivery.webserver.response.errors.ForbiddenResponse;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||||
@ -96,11 +96,11 @@ public class RequestHandler implements HttpHandler {
|
|||||||
request.setAuth(getAuthorization(requestHeaders));
|
request.setAuth(getAuthorization(requestHeaders));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Response response = shouldPreventRequest(request.getRemoteAddress()) // Forbidden response (Optional)
|
Response_old response = shouldPreventRequest(request.getRemoteAddress()) // Forbidden response (Optional)
|
||||||
.orElseGet(() -> responseResolver.getResponse(request)); // Or the actual requested response
|
.orElseGet(() -> responseResolver.getResponse(request)); // Or the actual requested response
|
||||||
|
|
||||||
// Increase attempt count and block if too high
|
// Increase attempt count and block if too high
|
||||||
Optional<Response> forbid = handlePasswordBruteForceAttempts(request, response);
|
Optional<Response_old> forbid = handlePasswordBruteForceAttempts(request, response);
|
||||||
if (forbid.isPresent()) {
|
if (forbid.isPresent()) {
|
||||||
response = forbid.get();
|
response = forbid.get();
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ public class RequestHandler implements HttpHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Response> shouldPreventRequest(String accessor) {
|
private Optional<Response_old> shouldPreventRequest(String accessor) {
|
||||||
Integer attempts = failedLoginAttempts.getIfPresent(accessor);
|
Integer attempts = failedLoginAttempts.getIfPresent(accessor);
|
||||||
if (attempts == null) {
|
if (attempts == null) {
|
||||||
attempts = 0;
|
attempts = 0;
|
||||||
@ -137,7 +137,7 @@ public class RequestHandler implements HttpHandler {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Response> handlePasswordBruteForceAttempts(Request request, Response response) {
|
private Optional<Response_old> handlePasswordBruteForceAttempts(Request request, Response_old response) {
|
||||||
if (request.getAuth().isPresent() && response instanceof PromptAuthorizationResponse) {
|
if (request.getAuth().isPresent() && response instanceof PromptAuthorizationResponse) {
|
||||||
// Authentication was attempted, but failed so new attempt is going to be given if not forbidden
|
// Authentication was attempted, but failed so new attempt is going to be given if not forbidden
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ public class RequestHandler implements HttpHandler {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Response> createForbiddenResponse() {
|
private Optional<Response_old> createForbiddenResponse() {
|
||||||
return Optional.of(responseFactory.forbidden403("You have too many failed login attempts. Please wait 2 minutes until attempting again."));
|
return Optional.of(responseFactory.forbidden403("You have too many failed login attempts. Please wait 2 minutes until attempting again."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import java.util.stream.Collectors;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class RequestTarget {
|
public class RequestTarget {
|
||||||
|
|
||||||
private final String resourceString;
|
private final String resourceString;
|
||||||
|
@ -16,12 +16,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver;
|
package com.djrapitops.plan.delivery.webserver;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.web.ResolverService;
|
||||||
|
import com.djrapitops.plan.delivery.web.ResolverSvc;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.Resolver;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.URIPath;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.URIQuery;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.*;
|
import com.djrapitops.plan.delivery.webserver.pages.*;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.OptionsResponse;
|
import com.djrapitops.plan.delivery.webserver.response.OptionsResponse;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||||
@ -55,10 +60,12 @@ public class ResponseResolver extends CompositePageResolver {
|
|||||||
private final ErrorHandler errorHandler;
|
private final ErrorHandler errorHandler;
|
||||||
|
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
|
private final ResolverService resolverService;
|
||||||
private final Lazy<WebServer> webServer;
|
private final Lazy<WebServer> webServer;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ResponseResolver(
|
public ResponseResolver(
|
||||||
|
ResolverSvc resolverService,
|
||||||
ResponseFactory responseFactory,
|
ResponseFactory responseFactory,
|
||||||
Lazy<WebServer> webServer,
|
Lazy<WebServer> webServer,
|
||||||
ServerInfo serverInfo,
|
ServerInfo serverInfo,
|
||||||
@ -72,6 +79,7 @@ public class ResponseResolver extends CompositePageResolver {
|
|||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
super(responseFactory);
|
super(responseFactory);
|
||||||
|
this.resolverService = resolverService;
|
||||||
this.webServer = webServer;
|
this.webServer = webServer;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
this.debugPageResolver = debugPageResolver;
|
this.debugPageResolver = debugPageResolver;
|
||||||
@ -83,19 +91,20 @@ public class ResponseResolver extends CompositePageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerPages() {
|
public void registerPages() {
|
||||||
registerPage("debug", debugPageResolver);
|
resolverService.registerResolver("Plan", "/debug", debugPageResolver);
|
||||||
registerPage("players", playersPageResolver);
|
registerPage("players", playersPageResolver);
|
||||||
registerPage("player", playerPageResolver);
|
registerPage("player", playerPageResolver);
|
||||||
|
|
||||||
registerPage("network", serverPageResolver);
|
registerPage("network", serverPageResolver);
|
||||||
registerPage("server", serverPageResolver);
|
registerPage("server", serverPageResolver);
|
||||||
|
|
||||||
|
// TODO Figure out how to deal with stuff like this
|
||||||
registerPage("", new RootPageResolver(responseFactory, webServer.get(), serverInfo));
|
registerPage("", new RootPageResolver(responseFactory, webServer.get(), serverInfo));
|
||||||
|
|
||||||
registerPage("v1", rootJSONResolver);
|
registerPage("v1", rootJSONResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response getResponse(Request request) {
|
public Response_old getResponse(Request request) {
|
||||||
try {
|
try {
|
||||||
return tryToGetResponse(request);
|
return tryToGetResponse(request);
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
@ -112,15 +121,47 @@ public class ResponseResolver extends CompositePageResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response tryToGetResponse(Request request) throws WebException {
|
private Response_old tryToGetResponse(Request request) throws WebException {
|
||||||
Optional<Authentication> authentication = request.getAuth();
|
|
||||||
RequestTarget target = request.getTarget();
|
|
||||||
String resource = target.getResourceString();
|
|
||||||
|
|
||||||
if ("OPTIONS".equalsIgnoreCase(request.getRequestMethod())) {
|
if ("OPTIONS".equalsIgnoreCase(request.getRequestMethod())) {
|
||||||
return new OptionsResponse();
|
return new OptionsResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<Authentication> authentication = request.getAuth();
|
||||||
|
|
||||||
|
URIPath target = request.getPath();
|
||||||
|
URIQuery query = request.getQuery();
|
||||||
|
|
||||||
|
Optional<Resolver> foundResolver = resolverService.getResolver(target.asString());
|
||||||
|
if (!foundResolver.isPresent()) return tryToGetResponse_old(request); // TODO Replace with 404 after refactoring
|
||||||
|
|
||||||
|
Resolver resolver = foundResolver.get();
|
||||||
|
|
||||||
|
if (resolver.requiresAuth(target, query)) {
|
||||||
|
// Get required auth
|
||||||
|
boolean isAuthRequired = webServer.get().isAuthRequired();
|
||||||
|
if (isAuthRequired && !authentication.isPresent()) {
|
||||||
|
if (webServer.get().isUsingHTTPS()) {
|
||||||
|
return responseFactory.basicAuth();
|
||||||
|
} else {
|
||||||
|
return responseFactory.forbidden403();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAuthRequired || resolver.canAccess(authentication.get().getWebUser().toNewWebUser(), target, query)) {
|
||||||
|
return resolver.resolve(target, query).map(Response_old::from).orElseGet(responseFactory::pageNotFound404);
|
||||||
|
} else {
|
||||||
|
return responseFactory.forbidden403();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resolver.resolve(target, query).map(Response_old::from).orElseGet(responseFactory::pageNotFound404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response_old tryToGetResponse_old(Request request) throws WebException {
|
||||||
|
RequestTarget target = request.getRequestTarget();
|
||||||
|
Optional<Authentication> authentication = request.getAuth();
|
||||||
|
String resource = target.getResourceString();
|
||||||
|
// TODO Turn into resolvers
|
||||||
if (target.endsWith(".css")) {
|
if (target.endsWith(".css")) {
|
||||||
return responseFactory.cssResponse(resource);
|
return responseFactory.cssResponse(resource);
|
||||||
}
|
}
|
||||||
@ -136,7 +177,6 @@ public class ResponseResolver extends CompositePageResolver {
|
|||||||
if (target.endsWithAny(".woff", ".woff2", ".eot", ".ttf")) {
|
if (target.endsWithAny(".woff", ".woff2", ".eot", ".ttf")) {
|
||||||
return responseFactory.fontResponse(resource);
|
return responseFactory.fontResponse(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAuthRequired = webServer.get().isAuthRequired();
|
boolean isAuthRequired = webServer.get().isAuthRequired();
|
||||||
if (isAuthRequired && !authentication.isPresent()) {
|
if (isAuthRequired && !authentication.isPresent()) {
|
||||||
if (webServer.get().isUsingHTTPS()) {
|
if (webServer.get().isUsingHTTPS()) {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.auth;
|
package com.djrapitops.plan.delivery.webserver.auth;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,6 +26,6 @@ import com.djrapitops.plan.exceptions.WebUserAuthException;
|
|||||||
*/
|
*/
|
||||||
public interface Authentication {
|
public interface Authentication {
|
||||||
|
|
||||||
WebUser getWebUser() throws WebUserAuthException;
|
WebUser_old getWebUser() throws WebUserAuthException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.auth;
|
package com.djrapitops.plan.delivery.webserver.auth;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.exceptions.PassEncryptException;
|
import com.djrapitops.plan.exceptions.PassEncryptException;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||||
@ -45,7 +45,7 @@ public class BasicAuthentication implements Authentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebUser getWebUser() throws WebUserAuthException {
|
public WebUser_old getWebUser() throws WebUserAuthException {
|
||||||
String decoded = Base64Util.decode(authenticationString);
|
String decoded = Base64Util.decode(authenticationString);
|
||||||
|
|
||||||
String[] userInfo = StringUtils.split(decoded, ':');
|
String[] userInfo = StringUtils.split(decoded, ':');
|
||||||
@ -62,7 +62,7 @@ public class BasicAuthentication implements Authentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WebUser webUser = database.query(WebUserQueries.fetchWebUser(user))
|
WebUser_old webUser = database.query(WebUserQueries.fetchWebUser(user))
|
||||||
.orElseThrow(() -> new WebUserAuthException(FailReason.USER_DOES_NOT_EXIST, user));
|
.orElseThrow(() -> new WebUserAuthException(FailReason.USER_DOES_NOT_EXIST, user));
|
||||||
|
|
||||||
boolean correctPass = PassEncryptUtil.verifyPassword(passwordRaw, webUser.getSaltedPassHash());
|
boolean correctPass = PassEncryptUtil.verifyPassword(passwordRaw, webUser.getSaltedPassHash());
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver.cache;
|
package com.djrapitops.plan.delivery.webserver.cache;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.storage.file.ResourceCache;
|
import com.djrapitops.plan.storage.file.ResourceCache;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.task.AbsRunnable;
|
||||||
@ -47,7 +47,7 @@ public class JSONCache {
|
|||||||
// Static class
|
// Static class
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Response getOrCache(String identifier, Supplier<JSONResponse> jsonResponseSupplier) {
|
public static Response_old getOrCache(String identifier, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||||
String found = cache.getIfPresent(identifier);
|
String found = cache.getIfPresent(identifier);
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
JSONResponse response = jsonResponseSupplier.get();
|
JSONResponse response = jsonResponseSupplier.get();
|
||||||
@ -68,11 +68,11 @@ public class JSONCache {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Response getOrCache(DataID dataID, Supplier<JSONResponse> jsonResponseSupplier) {
|
public static Response_old getOrCache(DataID dataID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||||
return getOrCache(dataID.name(), jsonResponseSupplier);
|
return getOrCache(dataID.name(), jsonResponseSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Response getOrCache(DataID dataID, UUID serverUUID, Supplier<JSONResponse> jsonResponseSupplier) {
|
public static Response_old getOrCache(DataID dataID, UUID serverUUID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||||
return getOrCache(dataID.of(serverUUID), jsonResponseSupplier);
|
return getOrCache(dataID.of(serverUUID), jsonResponseSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver.pages;
|
|||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract class CompositePageResolver implements PageResolver {
|
public abstract class CompositePageResolver implements PageResolver {
|
||||||
|
|
||||||
protected final ResponseFactory responseFactory;
|
protected final ResponseFactory responseFactory;
|
||||||
@ -48,14 +49,16 @@ public abstract class CompositePageResolver implements PageResolver {
|
|||||||
pages = new HashMap<>();
|
pages = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void registerPage(String targetPage, PageResolver resolver) {
|
public void registerPage(String targetPage, PageResolver resolver) {
|
||||||
pages.put(targetPage, resolver);
|
pages.put(targetPage, resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void registerPage(String targetPage, PageResolver resolver, int requiredPerm) {
|
public void registerPage(String targetPage, PageResolver resolver, int requiredPerm) {
|
||||||
pages.put(targetPage, new PageResolver() {
|
pages.put(targetPage, new PageResolver() {
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
return resolver.resolve(request, target);
|
return resolver.resolve(request, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,10 +69,11 @@ public abstract class CompositePageResolver implements PageResolver {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPage(String targetPage, Response response, int requiredPerm) {
|
@Deprecated
|
||||||
|
public void registerPage(String targetPage, Response_old response, int requiredPerm) {
|
||||||
pages.put(targetPage, new PageResolver() {
|
pages.put(targetPage, new PageResolver() {
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) {
|
public Response_old resolve(Request request, RequestTarget target) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,13 +85,15 @@ public abstract class CompositePageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
@Deprecated
|
||||||
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
PageResolver pageResolver = getPageResolver(target);
|
PageResolver pageResolver = getPageResolver(target);
|
||||||
return pageResolver != null
|
return pageResolver != null
|
||||||
? pageResolver.resolve(request, target)
|
? pageResolver.resolve(request, target)
|
||||||
: responseFactory.pageNotFound404();
|
: responseFactory.pageNotFound404();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public PageResolver getPageResolver(RequestTarget target) {
|
public PageResolver getPageResolver(RequestTarget target) {
|
||||||
if (target.isEmpty()) {
|
if (target.isEmpty()) {
|
||||||
return pages.get("");
|
return pages.get("");
|
||||||
@ -97,6 +103,7 @@ public abstract class CompositePageResolver implements PageResolver {
|
|||||||
return pages.get(targetPage);
|
return pages.get(targetPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public PageResolver getPageResolver(String targetPage) {
|
public PageResolver getPageResolver(String targetPage) {
|
||||||
return pages.get(targetPage);
|
return pages.get(targetPage);
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.pages;
|
package com.djrapitops.plan.delivery.webserver.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.*;
|
||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves /debug URL.
|
* Resolves /debug URL.
|
||||||
@ -33,7 +35,7 @@ import javax.inject.Singleton;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DebugPageResolver implements PageResolver {
|
public class DebugPageResolver implements PageResolver, Resolver {
|
||||||
|
|
||||||
private final ResponseFactory responseFactory;
|
private final ResponseFactory responseFactory;
|
||||||
|
|
||||||
@ -43,13 +45,23 @@ public class DebugPageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) {
|
public boolean canAccess(WebUser permissions, URIPath target, URIQuery query) {
|
||||||
return responseFactory.debugPageResponse();
|
return permissions.hasPermission("page.debug");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Response> resolve(URIPath target, URIQuery query) {
|
||||||
|
return Optional.of(responseFactory.debugPageResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response_old resolve(Request request, RequestTarget target) {
|
||||||
|
return responseFactory.debugPageResponse_old();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
||||||
WebUser webUser = auth.getWebUser();
|
WebUser_old webUser = auth.getWebUser();
|
||||||
return webUser.getPermLevel() <= 0;
|
return webUser.getPermLevel() <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package com.djrapitops.plan.delivery.webserver.pages;
|
|||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ import com.djrapitops.plan.exceptions.connection.WebException;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @see CompositePageResolver for larger depth resolution than 1.
|
* @see CompositePageResolver for larger depth resolution than 1.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface PageResolver {
|
public interface PageResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +39,7 @@ public interface PageResolver {
|
|||||||
* @param target Rest of the target coordinates after this page has been solved.
|
* @param target Rest of the target coordinates after this page has been solved.
|
||||||
* @return Appropriate response.
|
* @return Appropriate response.
|
||||||
*/
|
*/
|
||||||
Response resolve(Request request, RequestTarget target) throws WebException;
|
Response_old resolve(Request request, RequestTarget target) throws WebException;
|
||||||
|
|
||||||
default boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
default boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
||||||
return true;
|
return true;
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.pages;
|
package com.djrapitops.plan.delivery.webserver.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -57,7 +57,7 @@ public class PlayerPageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
if (target.isEmpty()) {
|
if (target.isEmpty()) {
|
||||||
return responseFactory.pageNotFound404();
|
return responseFactory.pageNotFound404();
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class PlayerPageResolver implements PageResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
||||||
WebUser webUser = auth.getWebUser();
|
WebUser_old webUser = auth.getWebUser();
|
||||||
return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1));
|
return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver.pages;
|
|||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -51,7 +51,7 @@ public class PlayersPageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
Database.State dbState = dbSystem.getDatabase().getState();
|
Database.State dbState = dbSystem.getDatabase().getState();
|
||||||
if (dbState != Database.State.OPEN) {
|
if (dbState != Database.State.OPEN) {
|
||||||
throw new ForbiddenException("Database is " + dbState.name() + " - Please try again later. You can check database status with /plan info");
|
throw new ForbiddenException("Database is " + dbState.name() + " - Please try again later. You can check database status with /plan info");
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.pages;
|
package com.djrapitops.plan.delivery.webserver.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
import com.djrapitops.plan.identification.ServerInfo;
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
@ -48,7 +48,7 @@ public class RootPageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
Server server = serverInfo.getServer();
|
Server server = serverInfo.getServer();
|
||||||
if (!webServer.isAuthRequired()) {
|
if (!webServer.isAuthRequired()) {
|
||||||
return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName()));
|
return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName()));
|
||||||
@ -59,7 +59,7 @@ public class RootPageResolver implements PageResolver {
|
|||||||
return responseFactory.basicAuth();
|
return responseFactory.basicAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebUser webUser = auth.get().getWebUser();
|
WebUser_old webUser = auth.get().getWebUser();
|
||||||
|
|
||||||
int permLevel = webUser.getPermLevel();
|
int permLevel = webUser.getPermLevel();
|
||||||
switch (permLevel) {
|
switch (permLevel) {
|
||||||
|
@ -21,8 +21,8 @@ import com.djrapitops.plan.delivery.webserver.Request;
|
|||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
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.delivery.webserver.response.ResponseFactory;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
import com.djrapitops.plan.exceptions.connection.ForbiddenException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -65,7 +65,7 @@ public class ServerPageResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
Optional<UUID> serverUUID = getServerUUID(target);
|
Optional<UUID> serverUUID = getServerUUID(target);
|
||||||
boolean proxy = serverInfo.getServer().isProxy();
|
boolean proxy = serverInfo.getServer().isProxy();
|
||||||
if (serverUUID.isPresent()) {
|
if (serverUUID.isPresent()) {
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
import com.djrapitops.plan.exceptions.connection.BadRequestException;
|
||||||
@ -56,7 +56,7 @@ public class GraphsJSONResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
String type = target.getParameter("type")
|
String type = target.getParameter("type")
|
||||||
.orElseThrow(() -> new BadRequestException("'type' parameter was not defined."));
|
.orElseThrow(() -> new BadRequestException("'type' parameter was not defined."));
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public class NetworkTabJSONResolver<T> implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) {
|
public Response_old resolve(Request request, RequestTarget target) {
|
||||||
return JSONCache.getOrCache(dataID, () -> new JSONResponse(jsonCreator.get()));
|
return JSONCache.getOrCache(dataID, () -> new JSONResponse(jsonCreator.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.pages.json;
|
package com.djrapitops.plan.delivery.webserver.pages.json;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.rendering.json.PlayerJSONCreator;
|
import com.djrapitops.plan.delivery.rendering.json.PlayerJSONCreator;
|
||||||
import com.djrapitops.plan.delivery.webserver.Request;
|
import com.djrapitops.plan.delivery.webserver.Request;
|
||||||
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
import com.djrapitops.plan.delivery.webserver.RequestTarget;
|
||||||
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -45,14 +45,14 @@ public class PlayerJSONResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
UUID playerUUID = identifiers.getPlayerUUID(target); // Can throw BadRequestException
|
UUID playerUUID = identifiers.getPlayerUUID(target); // Can throw BadRequestException
|
||||||
return new JSONResponse(jsonCreator.createJSONAsMap(playerUUID));
|
return new JSONResponse(jsonCreator.createJSONAsMap(playerUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException {
|
||||||
WebUser webUser = auth.getWebUser();
|
WebUser_old webUser = auth.getWebUser();
|
||||||
return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1));
|
return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -55,7 +55,7 @@ public class PlayerKillsJSONResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
UUID serverUUID = identifiers.getServerUUID(target);
|
UUID serverUUID = identifiers.getServerUUID(target);
|
||||||
return JSONCache.getOrCache(DataID.KILLS, serverUUID, () ->
|
return JSONCache.getOrCache(DataID.KILLS, serverUUID, () ->
|
||||||
new JSONResponse(Collections.singletonMap("player_kills", jsonFactory.serverPlayerKillsAsJSONMap(serverUUID)))
|
new JSONResponse(Collections.singletonMap("player_kills", jsonFactory.serverPlayerKillsAsJSONMap(serverUUID)))
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -54,7 +54,7 @@ public class PlayersTableJSONResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
if (target.getParameter("server").isPresent()) {
|
if (target.getParameter("server").isPresent()) {
|
||||||
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
||||||
return JSONCache.getOrCache(DataID.PLAYERS, serverUUID, () -> new JSONResponse(jsonFactory.serverPlayersTableJSON(serverUUID)));
|
return JSONCache.getOrCache(DataID.PLAYERS, serverUUID, () -> new JSONResponse(jsonFactory.serverPlayersTableJSON(serverUUID)));
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -54,7 +54,7 @@ public class ServerTabJSONResolver<T> implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException
|
||||||
return JSONCache.getOrCache(dataID, serverUUID, () -> new JSONResponse(jsonCreator.apply(serverUUID)));
|
return JSONCache.getOrCache(dataID, serverUUID, () -> new JSONResponse(jsonCreator.apply(serverUUID)));
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||||
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
import com.djrapitops.plan.delivery.webserver.pages.PageResolver;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse;
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.WebException;
|
import com.djrapitops.plan.exceptions.connection.WebException;
|
||||||
@ -55,7 +55,7 @@ public class SessionsJSONResolver implements PageResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response resolve(Request request, RequestTarget target) throws WebException {
|
public Response_old resolve(Request request, RequestTarget target) throws WebException {
|
||||||
if (target.getParameter("server").isPresent()) {
|
if (target.getParameter("server").isPresent()) {
|
||||||
UUID serverUUID = identifiers.getServerUUID(target);
|
UUID serverUUID = identifiers.getServerUUID(target);
|
||||||
return JSONCache.getOrCache(DataID.SESSIONS, serverUUID, () ->
|
return JSONCache.getOrCache(DataID.SESSIONS, serverUUID, () ->
|
||||||
|
@ -26,11 +26,11 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Response} for raw bytes.
|
* {@link Response_old} for raw bytes.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class ByteResponse extends Response {
|
public class ByteResponse extends Response_old {
|
||||||
|
|
||||||
private final PlanFiles files;
|
private final PlanFiles files;
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
|
@ -29,7 +29,7 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class FileResponse extends Response {
|
public class FileResponse extends Response_old {
|
||||||
|
|
||||||
public FileResponse(String fileName, PlanFiles files) throws IOException {
|
public FileResponse(String fileName, PlanFiles files) throws IOException {
|
||||||
super.setHeader("HTTP/1.1 200 OK");
|
super.setHeader("HTTP/1.1 200 OK");
|
||||||
|
@ -22,7 +22,7 @@ package com.djrapitops.plan.delivery.webserver.response;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class OptionsResponse extends Response {
|
public class OptionsResponse extends Response_old {
|
||||||
|
|
||||||
public OptionsResponse() {
|
public OptionsResponse() {
|
||||||
setHeader("HTTP/1.1 204 No Content");
|
setHeader("HTTP/1.1 204 No Content");
|
||||||
|
@ -25,7 +25,7 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class RedirectResponse extends Response {
|
public class RedirectResponse extends Response_old {
|
||||||
|
|
||||||
private final String direct;
|
private final String direct;
|
||||||
|
|
||||||
|
@ -16,10 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.response;
|
package com.djrapitops.plan.delivery.webserver.response;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.rendering.pages.Page;
|
||||||
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
import com.djrapitops.plan.delivery.rendering.pages.PageFactory;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.MimeType;
|
||||||
|
import com.djrapitops.plan.delivery.web.resolver.Response;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.errors.*;
|
import com.djrapitops.plan.delivery.webserver.response.errors.*;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.pages.*;
|
import com.djrapitops.plan.delivery.webserver.response.pages.*;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.exceptions.WebUserAuthException;
|
||||||
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
@ -35,7 +37,7 @@ import java.io.IOException;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for creating different {@link Response} objects.
|
* Factory for creating different {@link Response_old} objects.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@ -64,6 +66,28 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response debugPageResponse() {
|
public Response debugPageResponse() {
|
||||||
|
try {
|
||||||
|
return forPage(pageFactory.debugPage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
return forInternalError("Failed to generate debug page", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response forPage(Page page) throws IOException {
|
||||||
|
return Response.builder().setContent(page.toHtml())
|
||||||
|
.setMimeType(MimeType.HTML)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Response forInternalError(String cause, Throwable error) {
|
||||||
|
return Response.builder().setContent(pageFactory.internalErrorPage(cause, error).toHtml())
|
||||||
|
.setMimeType(MimeType.HTML)
|
||||||
|
.setStatus(500)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public Response_old debugPageResponse_old() {
|
||||||
try {
|
try {
|
||||||
return new DebugPageResponse(pageFactory.debugPage(), versionCheckSystem, files);
|
return new DebugPageResponse(pageFactory.debugPage(), versionCheckSystem, files);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -71,10 +95,10 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response playersPageResponse() {
|
public Response_old playersPageResponse() {
|
||||||
try {
|
try {
|
||||||
return new PlayersPageResponse(pageFactory.playersPage());
|
return new PlayersPageResponse(pageFactory.playersPage());
|
||||||
} catch (GenerationException e) {
|
} catch (IOException e) {
|
||||||
return internalErrorResponse(e, "Failed to generate players page");
|
return internalErrorResponse(e, "Failed to generate players page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,18 +115,18 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response networkPageResponse() {
|
public Response_old networkPageResponse() {
|
||||||
try {
|
try {
|
||||||
return new PageResponse(pageFactory.networkPage());
|
return new PageResponse(pageFactory.networkPage());
|
||||||
} catch (GenerationException e) {
|
} catch (IOException e) {
|
||||||
return internalErrorResponse(e, "Failed to generate network page");
|
return internalErrorResponse(e, "Failed to generate network page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response serverPageResponse(UUID serverUUID) throws NotFoundException {
|
public Response_old serverPageResponse(UUID serverUUID) throws NotFoundException {
|
||||||
try {
|
try {
|
||||||
return new PageResponse(pageFactory.serverPage(serverUUID));
|
return new PageResponse(pageFactory.serverPage(serverUUID));
|
||||||
} catch (GenerationException e) {
|
} catch (IOException e) {
|
||||||
return internalErrorResponse(e, "Failed to generate server page");
|
return internalErrorResponse(e, "Failed to generate server page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +135,7 @@ public class ResponseFactory {
|
|||||||
return new RawPlayerDataResponse(dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid)));
|
return new RawPlayerDataResponse(dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response javaScriptResponse(String fileName) {
|
public Response_old javaScriptResponse(String fileName) {
|
||||||
try {
|
try {
|
||||||
return new JavaScriptResponse(fileName, files, locale);
|
return new JavaScriptResponse(fileName, files, locale);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -119,7 +143,7 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response cssResponse(String fileName) {
|
public Response_old cssResponse(String fileName) {
|
||||||
try {
|
try {
|
||||||
return new CSSResponse(fileName, files);
|
return new CSSResponse(fileName, files);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -127,11 +151,11 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response imageResponse(String fileName) {
|
public Response_old imageResponse(String fileName) {
|
||||||
return new ByteResponse(ResponseType.IMAGE, FileResponse.format(fileName), files);
|
return new ByteResponse(ResponseType.IMAGE, FileResponse.format(fileName), files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response fontResponse(String fileName) {
|
public Response_old fontResponse(String fileName) {
|
||||||
ResponseType type = ResponseType.FONT_BYTESTREAM;
|
ResponseType type = ResponseType.FONT_BYTESTREAM;
|
||||||
if (fileName.endsWith(".woff")) {
|
if (fileName.endsWith(".woff")) {
|
||||||
type = ResponseType.FONT_WOFF;
|
type = ResponseType.FONT_WOFF;
|
||||||
@ -151,11 +175,11 @@ public class ResponseFactory {
|
|||||||
* @param location Starts with '/'
|
* @param location Starts with '/'
|
||||||
* @return Redirection response.
|
* @return Redirection response.
|
||||||
*/
|
*/
|
||||||
public Response redirectResponse(String location) {
|
public Response_old redirectResponse(String location) {
|
||||||
return new RedirectResponse(location);
|
return new RedirectResponse(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response faviconResponse() {
|
public Response_old faviconResponse() {
|
||||||
return new ByteResponse(ResponseType.X_ICON, "web/favicon.ico", files);
|
return new ByteResponse(ResponseType.X_ICON, "web/favicon.ico", files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,12 +236,12 @@ public class ResponseFactory {
|
|||||||
return new BadRequestResponse(errorMessage + " (when requesting '" + target + "')");
|
return new BadRequestResponse(errorMessage + " (when requesting '" + target + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response playerPageResponse(UUID playerUUID) {
|
public Response_old playerPageResponse(UUID playerUUID) {
|
||||||
try {
|
try {
|
||||||
return new PageResponse(pageFactory.playerPage(playerUUID));
|
return new PageResponse(pageFactory.playerPage(playerUUID));
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
return playerNotFound404();
|
return playerNotFound404();
|
||||||
} catch (GenerationException e) {
|
} catch (IOException e) {
|
||||||
return internalErrorResponse(e, "Failed to generate player page");
|
return internalErrorResponse(e, "Failed to generate player page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -33,7 +34,8 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public abstract class Response {
|
@Deprecated
|
||||||
|
public abstract class Response_old {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
private String header;
|
private String header;
|
||||||
@ -41,14 +43,14 @@ public abstract class Response {
|
|||||||
|
|
||||||
protected Headers responseHeaders;
|
protected Headers responseHeaders;
|
||||||
|
|
||||||
public Response(ResponseType type) {
|
public Response_old(ResponseType type) {
|
||||||
this.type = type.get();
|
this.type = type.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Response constructor that defaults ResponseType to HTML.
|
* Default Response constructor that defaults ResponseType to HTML.
|
||||||
*/
|
*/
|
||||||
public Response() {
|
public Response_old() {
|
||||||
this(ResponseType.HTML);
|
this(ResponseType.HTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,13 +96,16 @@ public abstract class Response {
|
|||||||
return getHeader(null).map(h -> Integer.parseInt(StringUtils.split(h, ' ')[1])).orElse(500);
|
return getHeader(null).map(h -> Integer.parseInt(StringUtils.split(h, ' ')[1])).orElse(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Deprecated
|
||||||
public boolean equals(Object o) {
|
public static Response_old from(com.djrapitops.plan.delivery.web.resolver.Response apiResponse) {
|
||||||
if (this == o) return true;
|
Response_old response = new Response_old() {};
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
response.setContent(apiResponse.getCharset().map(charset -> new String(apiResponse.getBytes(), charset))
|
||||||
Response response = (Response) o;
|
.orElse(new String(apiResponse.getBytes())));
|
||||||
return Objects.equals(header, response.header) &&
|
response.setHeader("HTTP/1.1 " + apiResponse.getCode() + " ");
|
||||||
Objects.equals(content, response.content);
|
for (Map.Entry<String, String> header : apiResponse.getHeaders().entrySet()) {
|
||||||
|
response.header += header.getKey() + ": " + header.getValue() + ";\r\n";
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -145,4 +150,13 @@ public abstract class Response {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return header + " | " + getResponse();
|
return header + " | " + getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Response_old response = (Response_old) o;
|
||||||
|
return Objects.equals(header, response.header) &&
|
||||||
|
Objects.equals(content, response.content);
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ package com.djrapitops.plan.delivery.webserver.response;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class TextResponse extends Response {
|
public class TextResponse extends Response_old {
|
||||||
|
|
||||||
public TextResponse(String content) {
|
public TextResponse(String content) {
|
||||||
setHeader("HTTP/1.1 200 OK");
|
setHeader("HTTP/1.1 200 OK");
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.response.data;
|
package com.djrapitops.plan.delivery.webserver.response.data;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.ResponseType;
|
import com.djrapitops.plan.delivery.webserver.response.ResponseType;
|
||||||
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ import com.google.gson.JsonElement;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class JSONResponse extends Response {
|
public class JSONResponse extends Response_old {
|
||||||
|
|
||||||
public JSONResponse(Object object) {
|
public JSONResponse(Object object) {
|
||||||
this(new Gson().toJson(object));
|
this(new Gson().toJson(object));
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.webserver.response.errors;
|
package com.djrapitops.plan.delivery.webserver.response.errors;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fuzzlemann
|
* @author Fuzzlemann
|
||||||
*/
|
*/
|
||||||
public class BadRequestResponse extends Response {
|
public class BadRequestResponse extends Response_old {
|
||||||
|
|
||||||
public BadRequestResponse(String error) {
|
public BadRequestResponse(String error) {
|
||||||
super.setHeader("HTTP/1.1 400 Bad Request " + error);
|
super.setHeader("HTTP/1.1 400 Bad Request " + error);
|
||||||
|
@ -17,9 +17,8 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver.response.pages;
|
package com.djrapitops.plan.delivery.webserver.response.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.rendering.pages.Page;
|
import com.djrapitops.plan.delivery.rendering.pages.Page;
|
||||||
import com.djrapitops.plan.delivery.webserver.response.Response;
|
|
||||||
import com.djrapitops.plan.delivery.webserver.response.ResponseType;
|
import com.djrapitops.plan.delivery.webserver.response.ResponseType;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
import com.djrapitops.plan.delivery.webserver.response.Response_old;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
import com.djrapitops.plan.settings.theme.Theme;
|
import com.djrapitops.plan.settings.theme.Theme;
|
||||||
import com.googlecode.htmlcompressor.compressor.HtmlCompressor;
|
import com.googlecode.htmlcompressor.compressor.HtmlCompressor;
|
||||||
@ -32,7 +31,7 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PageResponse extends Response {
|
public class PageResponse extends Response_old {
|
||||||
|
|
||||||
private static final HtmlCompressor HTML_COMPRESSOR = new HtmlCompressor();
|
private static final HtmlCompressor HTML_COMPRESSOR = new HtmlCompressor();
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ public class PageResponse extends Response {
|
|||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageResponse(Page page) throws GenerationException {
|
public PageResponse(Page page) {
|
||||||
this(ResponseType.HTML);
|
this(ResponseType.HTML);
|
||||||
super.setHeader("HTTP/1.1 200 OK");
|
super.setHeader("HTTP/1.1 200 OK");
|
||||||
setContent(page.toHtml());
|
setContent(page.toHtml());
|
||||||
|
@ -17,14 +17,13 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver.response.pages;
|
package com.djrapitops.plan.delivery.webserver.response.pages;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.rendering.pages.PlayersPage;
|
import com.djrapitops.plan.delivery.rendering.pages.PlayersPage;
|
||||||
import com.djrapitops.plan.exceptions.GenerationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PlayersPageResponse extends PageResponse {
|
public class PlayersPageResponse extends PageResponse {
|
||||||
|
|
||||||
public PlayersPageResponse(PlayersPage playersPage) throws GenerationException {
|
public PlayersPageResponse(PlayersPage playersPage) {
|
||||||
setHeader("HTTP/1.1 200 OK");
|
setHeader("HTTP/1.1 200 OK");
|
||||||
setContent(playersPage.toHtml());
|
setContent(playersPage.toHtml());
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Player Analytics (Plan).
|
|
||||||
*
|
|
||||||
* Plan is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Plan is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.djrapitops.plan.exceptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when Page encounters an Exception.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class GenerationException extends Exception {
|
|
||||||
|
|
||||||
public GenerationException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
@ -78,11 +78,13 @@ public class ExtensionSvc implements ExtensionService {
|
|||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
|
|
||||||
extensionGatherers = new HashMap<>();
|
extensionGatherers = new HashMap<>();
|
||||||
|
|
||||||
Holder.set(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
|
Holder.set(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerExtensions() {
|
||||||
try {
|
try {
|
||||||
extensionRegister.registerBuiltInExtensions(config.getExtensionSettings().getDisabled());
|
extensionRegister.registerBuiltInExtensions(config.getExtensionSettings().getDisabled());
|
||||||
} catch (IllegalStateException failedToRegisterOne) {
|
} catch (IllegalStateException failedToRegisterOne) {
|
||||||
|
@ -49,7 +49,7 @@ public class SettingsSvc implements SettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
SettingsService.SettingsServiceHolder.set(this);
|
Holder.set(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.storage.database.queries;
|
package com.djrapitops.plan.storage.database.queries;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.Nickname;
|
import com.djrapitops.plan.delivery.domain.Nickname;
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.gathering.domain.*;
|
import com.djrapitops.plan.gathering.domain.*;
|
||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
@ -119,7 +119,7 @@ public class LargeStoreQueries {
|
|||||||
* @param users Collection of Plan WebUsers.
|
* @param users Collection of Plan WebUsers.
|
||||||
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
|
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
|
||||||
*/
|
*/
|
||||||
public static Executable storeAllPlanWebUsers(Collection<WebUser> users) {
|
public static Executable storeAllPlanWebUsers(Collection<WebUser_old> users) {
|
||||||
if (Verify.isEmpty(users)) {
|
if (Verify.isEmpty(users)) {
|
||||||
return Executable.empty();
|
return Executable.empty();
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ public class LargeStoreQueries {
|
|||||||
return new ExecBatchStatement(SecurityTable.INSERT_STATEMENT) {
|
return new ExecBatchStatement(SecurityTable.INSERT_STATEMENT) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
for (WebUser user : users) {
|
for (WebUser_old user : users) {
|
||||||
String userName = user.getName();
|
String userName = user.getName();
|
||||||
String pass = user.getSaltedPassHash();
|
String pass = user.getSaltedPassHash();
|
||||||
int permLvl = user.getPermLevel();
|
int permLvl = user.getPermLevel();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.queries.objects;
|
package com.djrapitops.plan.storage.database.queries.objects;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.gathering.domain.Ping;
|
import com.djrapitops.plan.gathering.domain.Ping;
|
||||||
import com.djrapitops.plan.storage.database.queries.Query;
|
import com.djrapitops.plan.storage.database.queries.Query;
|
||||||
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
||||||
@ -33,7 +33,7 @@ import java.util.*;
|
|||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries for {@link WebUser} objects.
|
* Queries for {@link WebUser_old} objects.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.queries.objects;
|
package com.djrapitops.plan.storage.database.queries.objects;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.storage.database.queries.Query;
|
import com.djrapitops.plan.storage.database.queries.Query;
|
||||||
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
||||||
import com.djrapitops.plan.storage.database.queries.QueryStatement;
|
import com.djrapitops.plan.storage.database.queries.QueryStatement;
|
||||||
@ -32,7 +32,7 @@ import java.util.Optional;
|
|||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries for {@link WebUser} objects.
|
* Queries for {@link WebUser_old} objects.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
@ -47,18 +47,18 @@ public class WebUserQueries {
|
|||||||
*
|
*
|
||||||
* @return List of Plan WebUsers.
|
* @return List of Plan WebUsers.
|
||||||
*/
|
*/
|
||||||
public static Query<List<WebUser>> fetchAllPlanWebUsers() {
|
public static Query<List<WebUser_old>> fetchAllPlanWebUsers() {
|
||||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + ORDER_BY + SecurityTable.PERMISSION_LEVEL + " ASC";
|
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + ORDER_BY + SecurityTable.PERMISSION_LEVEL + " ASC";
|
||||||
|
|
||||||
return new QueryAllStatement<List<WebUser>>(sql, 5000) {
|
return new QueryAllStatement<List<WebUser_old>>(sql, 5000) {
|
||||||
@Override
|
@Override
|
||||||
public List<WebUser> processResults(ResultSet set) throws SQLException {
|
public List<WebUser_old> processResults(ResultSet set) throws SQLException {
|
||||||
List<WebUser> list = new ArrayList<>();
|
List<WebUser_old> list = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String user = set.getString(SecurityTable.USERNAME);
|
String user = set.getString(SecurityTable.USERNAME);
|
||||||
String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
|
String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
|
||||||
int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
|
int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
|
||||||
WebUser info = new WebUser(user, saltedPassHash, permissionLevel);
|
WebUser_old info = new WebUser_old(user, saltedPassHash, permissionLevel);
|
||||||
list.add(info);
|
list.add(info);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@ -66,21 +66,21 @@ public class WebUserQueries {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query<Optional<WebUser>> fetchWebUser(String called) {
|
public static Query<Optional<WebUser_old>> fetchWebUser(String called) {
|
||||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME +
|
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME +
|
||||||
WHERE + SecurityTable.USERNAME + "=? LIMIT 1";
|
WHERE + SecurityTable.USERNAME + "=? LIMIT 1";
|
||||||
return new QueryStatement<Optional<WebUser>>(sql) {
|
return new QueryStatement<Optional<WebUser_old>>(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, called);
|
statement.setString(1, called);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<WebUser> processResults(ResultSet set) throws SQLException {
|
public Optional<WebUser_old> processResults(ResultSet set) throws SQLException {
|
||||||
if (set.next()) {
|
if (set.next()) {
|
||||||
String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
|
String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
|
||||||
int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
|
int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
|
||||||
return Optional.of(new WebUser(called, saltedPassHash, permissionLevel));
|
return Optional.of(new WebUser_old(called, saltedPassHash, permissionLevel));
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.transactions.commands;
|
package com.djrapitops.plan.storage.database.transactions.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.SecurityTable;
|
import com.djrapitops.plan.storage.database.sql.tables.SecurityTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||||
@ -25,15 +25,15 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction to save a new Plan {@link WebUser} to the database.
|
* Transaction to save a new Plan {@link WebUser_old} to the database.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class RegisterWebUserTransaction extends Transaction {
|
public class RegisterWebUserTransaction extends Transaction {
|
||||||
|
|
||||||
private final WebUser webUser;
|
private final WebUser_old webUser;
|
||||||
|
|
||||||
public RegisterWebUserTransaction(WebUser webUser) {
|
public RegisterWebUserTransaction(WebUser_old webUser) {
|
||||||
this.webUser = webUser;
|
this.webUser = webUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.transactions.commands;
|
package com.djrapitops.plan.storage.database.transactions.commands;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.SecurityTable;
|
import com.djrapitops.plan.storage.database.sql.tables.SecurityTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||||
@ -28,7 +28,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.DELETE_FROM;
|
|||||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction to remove a Plan {@link WebUser} from the database.
|
* Transaction to remove a Plan {@link WebUser_old} from the database.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.comparators;
|
package com.djrapitops.plan.utilities.comparators;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
@ -25,10 +25,10 @@ import java.util.Comparator;
|
|||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class WebUserComparator implements Comparator<WebUser> {
|
public class WebUserComparator implements Comparator<WebUser_old> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(WebUser o1, WebUser o2) {
|
public int compare(WebUser_old o1, WebUser_old o2) {
|
||||||
return Integer.compare(o2.getPermLevel(), o1.getPermLevel());
|
return Integer.compare(o2.getPermLevel(), o1.getPermLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver;
|
package com.djrapitops.plan.delivery.webserver;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||||
import com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction;
|
import com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction;
|
||||||
@ -61,7 +61,7 @@ class JksHttpsServerTest implements HttpsServerTest {
|
|||||||
|
|
||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
WebUser webUser = new WebUser("test", PassEncryptUtil.createHash("testPass"), 0);
|
WebUser_old webUser = new WebUser_old("test", PassEncryptUtil.createHash("testPass"), 0);
|
||||||
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.delivery.webserver;
|
package com.djrapitops.plan.delivery.webserver;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.changes.ConfigUpdater;
|
import com.djrapitops.plan.settings.config.changes.ConfigUpdater;
|
||||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||||
@ -66,7 +66,7 @@ class Pkcs12HttpsServerTest implements HttpsServerTest {
|
|||||||
|
|
||||||
system.enable();
|
system.enable();
|
||||||
|
|
||||||
WebUser webUser = new WebUser("test", PassEncryptUtil.createHash("testPass"), 0);
|
WebUser_old webUser = new WebUser_old("test", PassEncryptUtil.createHash("testPass"), 0);
|
||||||
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import com.djrapitops.plan.data.element.TableContainer;
|
|||||||
import com.djrapitops.plan.delivery.domain.DateObj;
|
import com.djrapitops.plan.delivery.domain.DateObj;
|
||||||
import com.djrapitops.plan.delivery.domain.Nickname;
|
import com.djrapitops.plan.delivery.domain.Nickname;
|
||||||
import com.djrapitops.plan.delivery.domain.TablePlayer;
|
import com.djrapitops.plan.delivery.domain.TablePlayer;
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
|
import com.djrapitops.plan.delivery.domain.container.PlayerContainer;
|
||||||
import com.djrapitops.plan.delivery.domain.container.ServerContainer;
|
import com.djrapitops.plan.delivery.domain.container.ServerContainer;
|
||||||
import com.djrapitops.plan.delivery.domain.keys.Key;
|
import com.djrapitops.plan.delivery.domain.keys.Key;
|
||||||
@ -208,11 +208,11 @@ public interface DatabaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
default void webUserIsRegistered() {
|
default void webUserIsRegistered() {
|
||||||
WebUser expected = new WebUser(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0);
|
WebUser_old expected = new WebUser_old(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0);
|
||||||
db().executeTransaction(new RegisterWebUserTransaction(expected));
|
db().executeTransaction(new RegisterWebUserTransaction(expected));
|
||||||
commitTest();
|
commitTest();
|
||||||
|
|
||||||
Optional<WebUser> found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME));
|
Optional<WebUser_old> found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME));
|
||||||
assertTrue(found.isPresent());
|
assertTrue(found.isPresent());
|
||||||
assertEquals(expected, found.get());
|
assertEquals(expected, found.get());
|
||||||
}
|
}
|
||||||
@ -500,7 +500,7 @@ public interface DatabaseTest {
|
|||||||
Collections.singletonList(new DateObj<>(System.currentTimeMillis(), r.nextInt())))
|
Collections.singletonList(new DateObj<>(System.currentTimeMillis(), r.nextInt())))
|
||||||
);
|
);
|
||||||
|
|
||||||
WebUser webUser = new WebUser(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0);
|
WebUser_old webUser = new WebUser_old(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0);
|
||||||
db().executeTransaction(new RegisterWebUserTransaction(webUser));
|
db().executeTransaction(new RegisterWebUserTransaction(webUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.utilities.comparators;
|
package com.djrapitops.plan.utilities.comparators;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
import com.djrapitops.plan.delivery.domain.keys.SessionKeys;
|
||||||
import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point;
|
import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point;
|
||||||
import com.djrapitops.plan.gathering.domain.GeoInfo;
|
import com.djrapitops.plan.gathering.domain.GeoInfo;
|
||||||
@ -83,14 +83,14 @@ class ComparatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||||
List<WebUser> webUsers = RandomData.randomWebUsers();
|
List<WebUser_old> webUsers = RandomData.randomWebUsers();
|
||||||
|
|
||||||
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
List<Integer> expected = webUsers.stream().map(WebUser_old::getPermLevel)
|
||||||
.sorted(Integer::compare).collect(Collectors.toList());
|
.sorted(Integer::compare).collect(Collectors.toList());
|
||||||
Collections.reverse(expected);
|
Collections.reverse(expected);
|
||||||
|
|
||||||
webUsers.sort(new WebUserComparator());
|
webUsers.sort(new WebUserComparator());
|
||||||
List<Integer> result = Lists.map(webUsers, WebUser::getPermLevel);
|
List<Integer> result = Lists.map(webUsers, WebUser_old::getPermLevel);
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package utilities;
|
package utilities;
|
||||||
|
|
||||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
import com.djrapitops.plan.delivery.domain.WebUser_old;
|
||||||
import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point;
|
import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point;
|
||||||
import com.djrapitops.plan.gathering.domain.GeoInfo;
|
import com.djrapitops.plan.gathering.domain.GeoInfo;
|
||||||
import com.djrapitops.plan.gathering.domain.Session;
|
import com.djrapitops.plan.gathering.domain.Session;
|
||||||
@ -51,10 +51,10 @@ public class RandomData {
|
|||||||
return RandomStringUtils.randomAlphanumeric(size);
|
return RandomStringUtils.randomAlphanumeric(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<WebUser> randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException {
|
public static List<WebUser_old> randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException {
|
||||||
List<WebUser> test = new ArrayList<>();
|
List<WebUser_old> test = new ArrayList<>();
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
test.add(new WebUser(randomString(5), PassEncryptUtil.createHash(randomString(7)), r.nextInt()));
|
test.add(new WebUser_old(randomString(5), PassEncryptUtil.createHash(randomString(7)), r.nextInt()));
|
||||||
}
|
}
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user