Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 24 bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@
<pattern>org.apache.commons.net</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.apache.commons.net</shadedPattern>
</relocation>
<relocation>
<pattern>club.minnced.discord.webhook</pattern>
<shadedPattern>${project.parent.groupId}.libs.club.minnced.discord.webhook</shadedPattern>
</relocation>
<relocation>
<pattern>kotlin</pattern>
<shadedPattern>${project.parent.groupId}.libs.kotlin</shadedPattern>
</relocation>
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>${project.parent.groupId}.libs.okhttp3</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>${project.parent.groupId}.libs.okio</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.slf4j</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void onEvent(PlayerJoinEvent event) {
this.plugin.getServer().dispatchCommand(
this.plugin.getServer().getConsoleSender(), command);
}

this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
NetworkFilterCommon.getInstance().sendNotify(result, player.getName(), player.getUniqueId());
});
});
});
}
Expand Down
24 changes: 24 additions & 0 deletions 24 bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@
<pattern>org.apache.commons.net</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.apache.commons.net</shadedPattern>
</relocation>
<relocation>
<pattern>club.minnced.discord.webhook</pattern>
<shadedPattern>${project.parent.groupId}.libs.club.minnced.discord.webhook</shadedPattern>
</relocation>
<relocation>
<pattern>kotlin</pattern>
<shadedPattern>${project.parent.groupId}.libs.kotlin</shadedPattern>
</relocation>
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>${project.parent.groupId}.libs.okhttp3</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>${project.parent.groupId}.libs.okio</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.slf4j</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public void onEvent(PostLoginEvent event) {
this.plugin.getProxy().getPluginManager().dispatchCommand(
this.plugin.getProxy().getConsole(), command);
}

NetworkFilterCommon.getInstance().sendNotify(result, player.getName(), player.getUniqueId());
});
}
}
6 changes: 6 additions & 0 deletions 6 common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<artifactId>caffeine</artifactId>
<version>3.1.8</version>
</dependency>

<dependency>
<groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId>
<version>0.8.4</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package ls.ni.networkfilter.common;

import jakarta.validation.constraints.Null;
import club.minnced.discord.webhook.WebhookClient;
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import lombok.Getter;
import ls.ni.networkfilter.common.cache.Cache;
import ls.ni.networkfilter.common.cache.CacheFactory;
import ls.ni.networkfilter.common.config.Config;
import ls.ni.networkfilter.common.config.ConfigManager;
import ls.ni.networkfilter.common.filter.*;
import ls.ni.networkfilter.common.filter.FilterException;
import ls.ni.networkfilter.common.filter.FilterResult;
import ls.ni.networkfilter.common.filter.FilterService;
import ls.ni.networkfilter.common.filter.FilterServiceFactory;
import ls.ni.networkfilter.common.util.PlaceholderUtil;
import org.apache.commons.net.util.SubnetUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.text.MessageFormat;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -120,6 +125,7 @@ public void debug(String pattern, Object... arguments) {
cached.get().block(),
cached.get().asn(),
cached.get().org(),
ip,
true,
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)
);
Expand All @@ -146,6 +152,7 @@ public void debug(String pattern, Object... arguments) {
false,
-1,
"Ignored Network",
ip,
false,
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)
);
Expand Down Expand Up @@ -179,8 +186,30 @@ public void debug(String pattern, Object... arguments) {
filterResult.block(),
filterResult.asn(),
filterResult.org(),
ip,
false,
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)
);
}

public void sendNotify(NetworkFilterResult result, String name, UUID uuid) {
if (this.getConfigManager().getConfig().getNotify().getDiscord().getEnabled()) {
String webhookUrl = this.getConfigManager().getConfig().getNotify().getDiscord().getWebhook();

try (WebhookClient client = WebhookClient.withUrl(webhookUrl)) {
String message = PlaceholderUtil.replace(this.getConfigManager().getConfig().getNotify().getDiscord().getMessage(),
result, name, uuid);

WebhookEmbed embed = new WebhookEmbedBuilder()
.setColor(0xFF0000)
.setDescription(message)
.addField(new WebhookEmbed.EmbedField(true, "ASN", String.valueOf(result.asn())))
.addField(new WebhookEmbed.EmbedField(true, "Organisation", String.valueOf(result.org())))
.addField(new WebhookEmbed.EmbedField(true, "Took", result.tookMs() + "ms"))
.build();

client.send(embed);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ls.ni.networkfilter.common;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

/**
* @param blocked
Expand All @@ -9,6 +10,6 @@
* @param cached
* @param tookMs
*/
public record NetworkFilterResult(boolean blocked, @Nullable Integer asn, @Nullable String org, boolean cached,
public record NetworkFilterResult(boolean blocked, @Nullable Integer asn, @Nullable String org, @NotNull String ip, boolean cached,
long tookMs) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ls.ni.networkfilter.common.config.cache.CacheType;
import ls.ni.networkfilter.common.config.consequence.ConsequenceSettings;
import ls.ni.networkfilter.common.config.ignore.IgnoreSettings;
import ls.ni.networkfilter.common.config.notify.NotifySettings;
import ls.ni.networkfilter.common.config.service.ServiceSettings;
import ls.ni.networkfilter.common.config.service.ServiceType;

Expand Down Expand Up @@ -45,4 +46,8 @@ public class Config {
@Valid
@NotNull
private ConsequenceSettings consequences;

@Valid
@NotNull
private NotifySettings notify;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ls.ni.networkfilter.common.config.notify;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DiscordNotifySettings {

@NotNull
private Boolean enabled;

@NotNull
private String webhook;

@NotNull
private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ls.ni.networkfilter.common.config.notify;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class NotifySettings {

@Valid
@NotNull
private DiscordNotifySettings discord;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PlaceholderUtil {
public static String replace(String message, NetworkFilterResult result, String name, UUID uuid) {
message = message.replace("%asn%", Optional.ofNullable(result.asn()).map(String::valueOf).orElse("-1"));
message = message.replace("%org%", Optional.ofNullable(result.org()).orElse("Unknown"));
message = message.replace("%ip%", result.ip());
message = message.replace("%name%", name);
message = message.replace("%uuid%", uuid.toString());

Expand Down
18 changes: 11 additions & 7 deletions 18 common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ignore:
- "10.0.0.0/8"
- "100.64.0.0/10"
- "127.0.0.0/8"
- "127.0.53.53"
- "127.0.53.53/32"
- "169.254.0.0/16"
- "172.16.0.0/12"
- "192.0.0.0/24"
Expand All @@ -56,13 +56,17 @@ ignore:
permission: "networkfilter.bypass"

consequences:
# Available placeholders for message and commands:
# %asn% - Autonomous System Number
# %org% - Organization
# %name% - Player Name
# %uuid% - Player UUID
kick:
enabled: true
message: "§3§lNetworkFilter §8§l» §7Fehler beim Verbinden. Melde dich beim Support mit der Id §e%asn% (%org%)"
# Placeholders: %asn%, %org%, %name%, %uuid%
message: "§3§lNetworkFilter §8§l» §7Bei dir wurde eine VPN erkannt. Melde dich im Support mit der Id §e%asn% (%org%)"
# Placeholders: %asn%, %org%, %name%, %uuid%
commands:
- ""

notify:
discord:
enabled: false
webhook: ""
# Placeholders: %asn%, %org%, %name%, %uuid%
message: "`%name%` (`%uuid%`) hat eine VPN und wurde gekickt"
24 changes: 24 additions & 0 deletions 24 velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@
<pattern>org.apache.commons.net</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.apache.commons.net</shadedPattern>
</relocation>
<relocation>
<pattern>club.minnced.discord.webhook</pattern>
<shadedPattern>${project.parent.groupId}.libs.club.minnced.discord.webhook</shadedPattern>
</relocation>
<relocation>
<pattern>kotlin</pattern>
<shadedPattern>${project.parent.groupId}.libs.kotlin</shadedPattern>
</relocation>
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>${project.parent.groupId}.libs.okhttp3</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>${project.parent.groupId}.libs.okio</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${project.parent.groupId}.libs.org.slf4j</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void onEvent(PostLoginEvent event) {
this.plugin.getServer().getCommandManager().executeAsync(
this.plugin.getServer().getConsoleCommandSource(), command);
}

NetworkFilterCommon.getInstance().sendNotify(result, player.getUsername(), player.getUniqueId());
}).schedule();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.