mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 14:34:59 +01:00
Simplify IP censoring in dumps (#3330)
This commit is contained in:
parent
87f8cf9cea
commit
592b48dbf5
10 changed files with 56 additions and 132 deletions
|
@ -29,7 +29,6 @@ import lombok.Getter;
|
|||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||
import org.geysermc.geyser.text.AsteriskSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -52,15 +51,17 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo {
|
|||
this.plugins = new ArrayList<>();
|
||||
|
||||
for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) {
|
||||
String hostname = listener.getHost().getHostString();
|
||||
if (!AsteriskSerializer.showSensitive && !(hostname.equals("") || hostname.equals("0.0.0.0"))) {
|
||||
hostname = "***";
|
||||
}
|
||||
this.listeners.add(new ListenerInfo(hostname, listener.getHost().getPort()));
|
||||
this.listeners.add(new ListenerInfo(listener.getHost().getHostString(), listener.getHost().getPort()));
|
||||
}
|
||||
|
||||
for (Plugin plugin : proxy.getPluginManager().getPlugins()) {
|
||||
this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Collections.singletonList(plugin.getDescription().getAuthor())));
|
||||
this.plugins.add(new PluginInfo(
|
||||
true,
|
||||
plugin.getDescription().getName(),
|
||||
plugin.getDescription().getVersion(),
|
||||
plugin.getDescription().getMain(),
|
||||
Collections.singletonList(plugin.getDescription().getAuthor()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
plugins {
|
||||
id("fabric-loom") version "1.0-SNAPSHOT"
|
||||
id("maven-publish")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("java")
|
||||
}
|
||||
|
||||
java {
|
||||
|
|
|
@ -25,65 +25,58 @@
|
|||
|
||||
package org.geysermc.geyser.platform.fabric;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
import net.fabricmc.loader.api.metadata.Person;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||
import org.geysermc.geyser.text.AsteriskSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unused") // The way that the dump renders makes them used
|
||||
@Getter
|
||||
public class GeyserFabricDumpInfo extends BootstrapDumpInfo {
|
||||
|
||||
private String platformVersion = null;
|
||||
private final EnvType environmentType;
|
||||
|
||||
@AsteriskSerializer.Asterisk(isIp = true)
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<ModInfo> mods;
|
||||
|
||||
public GeyserFabricDumpInfo(MinecraftServer server) {
|
||||
super();
|
||||
for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
|
||||
if (modContainer.getMetadata().getId().equals("fabricloader")) {
|
||||
this.platformVersion = modContainer.getMetadata().getVersion().getFriendlyString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
FabricLoader.getInstance().getModContainer("fabricloader").ifPresent(mod ->
|
||||
this.platformVersion = mod.getMetadata().getVersion().getFriendlyString());
|
||||
|
||||
this.environmentType = FabricLoader.getInstance().getEnvironmentType();
|
||||
if (AsteriskSerializer.showSensitive || (server.getLocalIp() == null || server.getLocalIp().equals("") || server.getLocalIp().equals("0.0.0.0"))) {
|
||||
this.serverIP = server.getLocalIp();
|
||||
} else {
|
||||
this.serverIP = "***";
|
||||
}
|
||||
this.serverIP = server.getLocalIp() == null ? "unknown" : server.getLocalIp();
|
||||
this.serverPort = server.getPort();
|
||||
this.mods = new ArrayList<>();
|
||||
|
||||
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
||||
this.mods.add(new ModInfo(mod));
|
||||
ModMetadata meta = mod.getMetadata();
|
||||
this.mods.add(new ModInfo(
|
||||
FabricLoader.getInstance().isModLoaded(meta.getId()),
|
||||
meta.getId(),
|
||||
meta.getVersion().getFriendlyString(),
|
||||
meta.getAuthors().stream().map(Person::getName).collect(Collectors.toList()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPlatformVersion() {
|
||||
return platformVersion;
|
||||
}
|
||||
|
||||
public EnvType getEnvironmentType() {
|
||||
return environmentType;
|
||||
}
|
||||
|
||||
public String getServerIP() {
|
||||
return this.serverIP;
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
return this.serverPort;
|
||||
}
|
||||
|
||||
public List<ModInfo> getMods() {
|
||||
return this.mods;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class ModInfo {
|
||||
public boolean enabled;
|
||||
public String name;
|
||||
public String version;
|
||||
public List<String> authors;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,7 +246,10 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
|||
@Override
|
||||
public InputStream getResourceOrNull(String resource) {
|
||||
// We need to handle this differently, because Fabric shares the classloader across multiple mods
|
||||
Path path = this.mod.getPath(resource);
|
||||
Path path = this.mod.findPath(resource).orElse(null);
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return path.getFileSystem()
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.platform.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A wrapper for Fabric mod information to be presented in a Geyser dump
|
||||
*/
|
||||
public class ModInfo {
|
||||
|
||||
private final String name;
|
||||
private final String id;
|
||||
private final String version;
|
||||
private final List<String> authors;
|
||||
|
||||
public ModInfo(ModContainer mod) {
|
||||
this.name = mod.getMetadata().getName();
|
||||
this.id = mod.getMetadata().getId();
|
||||
this.authors = new ArrayList<>();
|
||||
mod.getMetadata().getAuthors().forEach((person) -> this.authors.add(person.getName()));
|
||||
this.version = mod.getMetadata().getVersion().getFriendlyString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public List<String> getAuthors() {
|
||||
return this.authors;
|
||||
}
|
||||
}
|
|
@ -41,6 +41,8 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo {
|
|||
private final String platformVersion;
|
||||
private final String platformAPIVersion;
|
||||
private final boolean onlineMode;
|
||||
|
||||
@AsteriskSerializer.Asterisk(isIp = true)
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
@ -51,12 +53,7 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo {
|
|||
this.platformVersion = Bukkit.getVersion();
|
||||
this.platformAPIVersion = Bukkit.getBukkitVersion();
|
||||
this.onlineMode = Bukkit.getOnlineMode();
|
||||
String ip = Bukkit.getIp();
|
||||
if (AsteriskSerializer.showSensitive || (ip.equals("") || ip.equals("0.0.0.0"))) {
|
||||
this.serverIP = ip;
|
||||
} else {
|
||||
this.serverIP = "***";
|
||||
}
|
||||
this.serverIP = Bukkit.getIp();
|
||||
this.serverPort = Bukkit.getPort();
|
||||
this.plugins = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo {
|
|||
private final String platformName;
|
||||
private final String platformVersion;
|
||||
private final boolean onlineMode;
|
||||
|
||||
@AsteriskSerializer.Asterisk(isIp = true)
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
@ -56,12 +58,7 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo {
|
|||
this.platformVersion = platformMeta.version().getQualifier();
|
||||
this.onlineMode = Sponge.server().isOnlineModeEnabled();
|
||||
Optional<InetSocketAddress> socketAddress = Sponge.server().boundAddress();
|
||||
String hostString = socketAddress.map(InetSocketAddress::getHostString).orElse("unknown");
|
||||
if (AsteriskSerializer.showSensitive || (hostString.equals("") || hostString.equals("0.0.0.0") || hostString.equals("unknown"))) {
|
||||
this.serverIP = hostString;
|
||||
} else {
|
||||
this.serverIP = "***";
|
||||
}
|
||||
this.serverIP = socketAddress.map(InetSocketAddress::getHostString).orElse("unknown");
|
||||
this.serverPort = socketAddress.map(InetSocketAddress::getPort).orElse(-1);
|
||||
this.plugins = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo {
|
|||
private final String platformVersion;
|
||||
private final String platformVendor;
|
||||
private final boolean onlineMode;
|
||||
|
||||
@AsteriskSerializer.Asterisk(isIp = true)
|
||||
private final String serverIP;
|
||||
private final int serverPort;
|
||||
private final List<PluginInfo> plugins;
|
||||
|
@ -51,12 +53,7 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo {
|
|||
this.platformVersion = proxy.getVersion().getVersion();
|
||||
this.platformVendor = proxy.getVersion().getVendor();
|
||||
this.onlineMode = proxy.getConfiguration().isOnlineMode();
|
||||
String hostString = proxy.getBoundAddress().getHostString();
|
||||
if (AsteriskSerializer.showSensitive || (hostString.equals("") || hostString.equals("0.0.0.0"))) {
|
||||
this.serverIP = hostString;
|
||||
} else {
|
||||
this.serverIP = "***";
|
||||
}
|
||||
this.serverIP = proxy.getBoundAddress().getHostString();
|
||||
this.serverPort = proxy.getBoundAddress().getPort();
|
||||
this.plugins = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Getter;
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.text.AsteriskSerializer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -53,6 +54,8 @@ public class BootstrapDumpInfo {
|
|||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class ListenerInfo {
|
||||
|
||||
@AsteriskSerializer.Asterisk(isIp = true)
|
||||
public String ip;
|
||||
public int port;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ import java.util.Optional;
|
|||
|
||||
public class AsteriskSerializer extends StdSerializer<Object> implements ContextualSerializer {
|
||||
|
||||
public static final String[] NON_SENSITIVE_ADDRESSES = {"", "0.0.0.0", "localhost", "127.0.0.1", "auto", "unknown"};
|
||||
|
||||
public static boolean showSensitive = false;
|
||||
|
||||
@Target({ElementType.FIELD})
|
||||
|
@ -91,11 +93,11 @@ public class AsteriskSerializer extends StdSerializer<Object> implements Context
|
|||
}
|
||||
|
||||
private boolean isSensitiveIp(String ip) {
|
||||
if (ip.equalsIgnoreCase("localhost") || ip.equalsIgnoreCase("auto")) {
|
||||
// `auto` should not be shown unless there is an obscure issue with setting the localhost address
|
||||
return false;
|
||||
for (String address : NON_SENSITIVE_ADDRESSES) {
|
||||
if (address.equalsIgnoreCase(ip)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !ip.isEmpty() && !ip.equals("0.0.0.0") && !ip.equals("127.0.0.1");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue