Encoded player & server names in URLs

This commit is contained in:
Rsl1122 2019-09-30 15:53:43 +03:00
parent 56dae4c829
commit de33cb1b4f
10 changed files with 26 additions and 9 deletions

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.api;
import com.djrapitops.plan.api.data.PlayerContainer; import com.djrapitops.plan.api.data.PlayerContainer;
import com.djrapitops.plan.api.data.ServerContainer; import com.djrapitops.plan.api.data.ServerContainer;
import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.delivery.rendering.html.Html;
import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.exceptions.database.DBOpException;
import com.djrapitops.plan.identification.UUIDUtility; import com.djrapitops.plan.identification.UUIDUtility;
import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.DBSystem;
@ -80,7 +81,7 @@ public class CommonAPI implements PlanAPI {
@Override @Override
public String getPlayerInspectPageLink(String playerName) { public String getPlayerInspectPageLink(String playerName) {
return "../player/" + playerName; return "../player/" + Html.encodeToURL(playerName);
} }
@Override @Override

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.commands.subcommands;
import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.delivery.export.Exporter; import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.delivery.rendering.html.Html;
import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.WebServer;
import com.djrapitops.plan.exceptions.ExportException; import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.exceptions.database.DBOpException;
@ -108,7 +109,7 @@ public class AnalyzeCommand extends CommandNode {
} }
private void sendLink(Server server, Sender sender) { private void sendLink(Server server, Sender sender) {
String target = "/server/" + server.getName(); String target = "/server/" + Html.encodeToURL(server.getName());
String address = PlanSystem.getMainAddress(webServer, dbSystem); String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + target; String url = address + target;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);

View File

@ -17,6 +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.rendering.html.Html;
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.identification.UUIDUtility; import com.djrapitops.plan.identification.UUIDUtility;
@ -132,7 +133,7 @@ public class InspectCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName)); sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
String address = PlanSystem.getMainAddress(webServer, dbSystem); String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/player/" + playerName; String url = address + "/player/" + Html.encodeToURL(playerName);
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.commands.subcommands.manage; package com.djrapitops.plan.commands.subcommands.manage;
import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.PlanSystem;
import com.djrapitops.plan.delivery.rendering.html.Html;
import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.WebServer;
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;
@ -69,7 +70,7 @@ public class ManageRawDataCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName)); sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
// Link // Link
String address = PlanSystem.getMainAddress(webServer, dbSystem); String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/player/" + playerName + "/raw"; String url = address + "/player/" + Html.encodeToURL(playerName) + "/raw";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -283,7 +283,9 @@ public class SessionsMutator {
return sessions.stream().map(session -> { return sessions.stream().map(session -> {
Map<String, Object> sessionMap = new HashMap<>(); Map<String, Object> sessionMap = new HashMap<>();
sessionMap.put("player_name", session.getValue(SessionKeys.NAME).orElse(session.getUnsafe(SessionKeys.UUID).toString())); sessionMap.put("player_name", session.getValue(SessionKeys.NAME).orElse(session.getUnsafe(SessionKeys.UUID).toString()));
sessionMap.put("player_uuid", session.getUnsafe(SessionKeys.UUID).toString());
sessionMap.put("server_name", session.getValue(SessionKeys.SERVER_NAME).orElse(session.getUnsafe(SessionKeys.SERVER_UUID).toString())); sessionMap.put("server_name", session.getValue(SessionKeys.SERVER_NAME).orElse(session.getUnsafe(SessionKeys.SERVER_UUID).toString()));
sessionMap.put("server_uuid", session.getUnsafe(SessionKeys.SERVER_UUID).toString());
sessionMap.put("name", nameFunction.apply(sessionMap)); sessionMap.put("name", nameFunction.apply(sessionMap));
sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") + sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") +
(session.supports(SessionKeys.END) ? "" : " (Online)")); (session.supports(SessionKeys.END) ? "" : " (Online)"));

View File

@ -20,6 +20,8 @@ import org.apache.commons.text.StringSubstitutor;
import org.apache.commons.text.TextStringBuilder; import org.apache.commons.text.TextStringBuilder;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -169,4 +171,12 @@ public enum Html {
sub.setEnableSubstitutionInVariables(false); sub.setEnableSubstitutionInVariables(false);
return sub.replace(html); return sub.replace(html);
} }
public static String encodeToURL(String string) {
try {
return URLEncoder.encode(string, "UTF-8");
} catch (UnsupportedEncodingException e) {
return string;
}
}
} }

View File

@ -125,7 +125,7 @@ public class PlayersTableJSONParser {
private void appendPlayerData(StringBuilder dataJSON, TablePlayer player) { private void appendPlayerData(StringBuilder dataJSON, TablePlayer player) {
String name = player.getName().orElse(player.getPlayerUUID().toString()); String name = player.getName().orElse(player.getPlayerUUID().toString());
String url = "../player/" + name; String url = "../player/" + Html.encodeToURL(name);
int loginTimes = player.getSessionCount().orElse(0); int loginTimes = player.getSessionCount().orElse(0);
long playtime = player.getPlaytime().orElse(-1L); long playtime = player.getPlaytime().orElse(-1L);

View File

@ -17,6 +17,7 @@
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;
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;
@ -68,7 +69,7 @@ public class RootPageHandler implements PageHandler {
case 1: case 1:
return new RedirectResponse("/players"); return new RedirectResponse("/players");
case 2: case 2:
return new RedirectResponse("/player/" + webUser.getName()); return new RedirectResponse("/player/" + Html.encodeToURL(webUser.getName()));
default: default:
return responseFactory.forbidden403(); return responseFactory.forbidden403();
} }

View File

@ -41,7 +41,7 @@ public class ExtensionStringData implements DescribedExtensionData {
public String getFormattedValue() { public String getFormattedValue() {
String withColors = Html.swapColorCodesToSpan(value); String withColors = Html.swapColorCodesToSpan(value);
return !playerName ? withColors : Html.LINK.parse("../player/" + value, withColors); return !playerName ? withColors : Html.LINK.parse("../player/" + Html.encodeToURL(value), withColors);
} }
ExtensionStringData concatenate(ExtensionStringData other) { ExtensionStringData concatenate(ExtensionStringData other) {

View File

@ -88,8 +88,8 @@ function createAccordionBody(i, session) {
createKillsTable(session.player_kills) + createKillsTable(session.player_kills) +
'</div><div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">' + '</div><div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">' +
'<div id="worldpie_' + i + '" class="chart-pie"></div>' + '<div id="worldpie_' + i + '" class="chart-pie"></div>' +
'<a href="/player/' + session.player_name + '" class="float-right btn bg-blue"><i class="fa fa-user"></i><span> Player Page</span></a>' + '<a href="/player/' + session.player_uuid + '" class="float-right btn bg-blue"><i class="fa fa-user"></i><span> Player Page</span></a>' +
(session.network_server ? '<a href="/server/' + session.server_name + '" class="float-right btn bg-light-green mr-2"><i class="fa fa-server"></i><span> Server Analysis</span></a>' : '') + (session.network_server ? '<a href="/server/' + session.server_uuid + '" class="float-right btn bg-light-green mr-2"><i class="fa fa-server"></i><span> Server Analysis</span></a>' : '') +
'</div>' + '</div>' +
'</div></td></tr>' '</div></td></tr>'
} }