Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +01:00
Simplify IP censoring in dumps (#3330)
Dieser Commit ist enthalten in:
Ursprung
87f8cf9cea
Commit
592b48dbf5
@ -29,7 +29,6 @@ import lombok.Getter;
|
|||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||||
import org.geysermc.geyser.text.AsteriskSerializer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -52,15 +51,17 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo {
|
|||||||
this.plugins = new ArrayList<>();
|
this.plugins = new ArrayList<>();
|
||||||
|
|
||||||
for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) {
|
for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) {
|
||||||
String hostname = listener.getHost().getHostString();
|
this.listeners.add(new ListenerInfo(listener.getHost().getHostString(), listener.getHost().getPort()));
|
||||||
if (!AsteriskSerializer.showSensitive && !(hostname.equals("") || hostname.equals("0.0.0.0"))) {
|
|
||||||
hostname = "***";
|
|
||||||
}
|
|
||||||
this.listeners.add(new ListenerInfo(hostname, listener.getHost().getPort()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Plugin plugin : proxy.getPluginManager().getPlugins()) {
|
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 {
|
plugins {
|
||||||
id("fabric-loom") version "1.0-SNAPSHOT"
|
id("fabric-loom") version "1.0-SNAPSHOT"
|
||||||
id("maven-publish")
|
|
||||||
id("com.github.johnrengelman.shadow")
|
|
||||||
id("java")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -25,65 +25,58 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.platform.fabric;
|
package org.geysermc.geyser.platform.fabric;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
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 net.minecraft.server.MinecraftServer;
|
||||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||||
import org.geysermc.geyser.text.AsteriskSerializer;
|
import org.geysermc.geyser.text.AsteriskSerializer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 {
|
public class GeyserFabricDumpInfo extends BootstrapDumpInfo {
|
||||||
|
|
||||||
private String platformVersion = null;
|
private String platformVersion = null;
|
||||||
private final EnvType environmentType;
|
private final EnvType environmentType;
|
||||||
|
|
||||||
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private final String serverIP;
|
private final String serverIP;
|
||||||
private final int serverPort;
|
private final int serverPort;
|
||||||
private final List<ModInfo> mods;
|
private final List<ModInfo> mods;
|
||||||
|
|
||||||
public GeyserFabricDumpInfo(MinecraftServer server) {
|
public GeyserFabricDumpInfo(MinecraftServer server) {
|
||||||
super();
|
FabricLoader.getInstance().getModContainer("fabricloader").ifPresent(mod ->
|
||||||
for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
|
this.platformVersion = mod.getMetadata().getVersion().getFriendlyString());
|
||||||
if (modContainer.getMetadata().getId().equals("fabricloader")) {
|
|
||||||
this.platformVersion = modContainer.getMetadata().getVersion().getFriendlyString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.environmentType = FabricLoader.getInstance().getEnvironmentType();
|
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() == null ? "unknown" : server.getLocalIp();
|
||||||
this.serverIP = server.getLocalIp();
|
|
||||||
} else {
|
|
||||||
this.serverIP = "***";
|
|
||||||
}
|
|
||||||
this.serverPort = server.getPort();
|
this.serverPort = server.getPort();
|
||||||
this.mods = new ArrayList<>();
|
this.mods = new ArrayList<>();
|
||||||
|
|
||||||
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
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() {
|
@Getter
|
||||||
return platformVersion;
|
@AllArgsConstructor
|
||||||
}
|
public static class ModInfo {
|
||||||
|
public boolean enabled;
|
||||||
public EnvType getEnvironmentType() {
|
public String name;
|
||||||
return environmentType;
|
public String version;
|
||||||
}
|
public List<String> authors;
|
||||||
|
|
||||||
public String getServerIP() {
|
|
||||||
return this.serverIP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getServerPort() {
|
|
||||||
return this.serverPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ModInfo> getMods() {
|
|
||||||
return this.mods;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,10 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
|||||||
@Override
|
@Override
|
||||||
public InputStream getResourceOrNull(String resource) {
|
public InputStream getResourceOrNull(String resource) {
|
||||||
// We need to handle this differently, because Fabric shares the classloader across multiple mods
|
// 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 {
|
try {
|
||||||
return path.getFileSystem()
|
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 platformVersion;
|
||||||
private final String platformAPIVersion;
|
private final String platformAPIVersion;
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
|
|
||||||
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private final String serverIP;
|
private final String serverIP;
|
||||||
private final int serverPort;
|
private final int serverPort;
|
||||||
private final List<PluginInfo> plugins;
|
private final List<PluginInfo> plugins;
|
||||||
@ -51,12 +53,7 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo {
|
|||||||
this.platformVersion = Bukkit.getVersion();
|
this.platformVersion = Bukkit.getVersion();
|
||||||
this.platformAPIVersion = Bukkit.getBukkitVersion();
|
this.platformAPIVersion = Bukkit.getBukkitVersion();
|
||||||
this.onlineMode = Bukkit.getOnlineMode();
|
this.onlineMode = Bukkit.getOnlineMode();
|
||||||
String ip = Bukkit.getIp();
|
this.serverIP = Bukkit.getIp();
|
||||||
if (AsteriskSerializer.showSensitive || (ip.equals("") || ip.equals("0.0.0.0"))) {
|
|
||||||
this.serverIP = ip;
|
|
||||||
} else {
|
|
||||||
this.serverIP = "***";
|
|
||||||
}
|
|
||||||
this.serverPort = Bukkit.getPort();
|
this.serverPort = Bukkit.getPort();
|
||||||
this.plugins = new ArrayList<>();
|
this.plugins = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo {
|
|||||||
private final String platformName;
|
private final String platformName;
|
||||||
private final String platformVersion;
|
private final String platformVersion;
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
|
|
||||||
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private final String serverIP;
|
private final String serverIP;
|
||||||
private final int serverPort;
|
private final int serverPort;
|
||||||
private final List<PluginInfo> plugins;
|
private final List<PluginInfo> plugins;
|
||||||
@ -56,12 +58,7 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo {
|
|||||||
this.platformVersion = platformMeta.version().getQualifier();
|
this.platformVersion = platformMeta.version().getQualifier();
|
||||||
this.onlineMode = Sponge.server().isOnlineModeEnabled();
|
this.onlineMode = Sponge.server().isOnlineModeEnabled();
|
||||||
Optional<InetSocketAddress> socketAddress = Sponge.server().boundAddress();
|
Optional<InetSocketAddress> socketAddress = Sponge.server().boundAddress();
|
||||||
String hostString = socketAddress.map(InetSocketAddress::getHostString).orElse("unknown");
|
this.serverIP = 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.serverPort = socketAddress.map(InetSocketAddress::getPort).orElse(-1);
|
this.serverPort = socketAddress.map(InetSocketAddress::getPort).orElse(-1);
|
||||||
this.plugins = new ArrayList<>();
|
this.plugins = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo {
|
|||||||
private final String platformVersion;
|
private final String platformVersion;
|
||||||
private final String platformVendor;
|
private final String platformVendor;
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
|
|
||||||
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private final String serverIP;
|
private final String serverIP;
|
||||||
private final int serverPort;
|
private final int serverPort;
|
||||||
private final List<PluginInfo> plugins;
|
private final List<PluginInfo> plugins;
|
||||||
@ -51,12 +53,7 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo {
|
|||||||
this.platformVersion = proxy.getVersion().getVersion();
|
this.platformVersion = proxy.getVersion().getVersion();
|
||||||
this.platformVendor = proxy.getVersion().getVendor();
|
this.platformVendor = proxy.getVersion().getVendor();
|
||||||
this.onlineMode = proxy.getConfiguration().isOnlineMode();
|
this.onlineMode = proxy.getConfiguration().isOnlineMode();
|
||||||
String hostString = proxy.getBoundAddress().getHostString();
|
this.serverIP = proxy.getBoundAddress().getHostString();
|
||||||
if (AsteriskSerializer.showSensitive || (hostString.equals("") || hostString.equals("0.0.0.0"))) {
|
|
||||||
this.serverIP = hostString;
|
|
||||||
} else {
|
|
||||||
this.serverIP = "***";
|
|
||||||
}
|
|
||||||
this.serverPort = proxy.getBoundAddress().getPort();
|
this.serverPort = proxy.getBoundAddress().getPort();
|
||||||
this.plugins = new ArrayList<>();
|
this.plugins = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
|
import org.geysermc.geyser.text.AsteriskSerializer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -53,6 +54,8 @@ public class BootstrapDumpInfo {
|
|||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class ListenerInfo {
|
public static class ListenerInfo {
|
||||||
|
|
||||||
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
public String ip;
|
public String ip;
|
||||||
public int port;
|
public int port;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class AsteriskSerializer extends StdSerializer<Object> implements ContextualSerializer {
|
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;
|
public static boolean showSensitive = false;
|
||||||
|
|
||||||
@Target({ElementType.FIELD})
|
@Target({ElementType.FIELD})
|
||||||
@ -91,11 +93,11 @@ public class AsteriskSerializer extends StdSerializer<Object> implements Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSensitiveIp(String ip) {
|
private boolean isSensitiveIp(String ip) {
|
||||||
if (ip.equalsIgnoreCase("localhost") || ip.equalsIgnoreCase("auto")) {
|
for (String address : NON_SENSITIVE_ADDRESSES) {
|
||||||
// `auto` should not be shown unless there is an obscure issue with setting the localhost address
|
if (address.equalsIgnoreCase(ip)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return !ip.isEmpty() && !ip.equals("0.0.0.0") && !ip.equals("127.0.0.1");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren