mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-28 06:18:28 +00:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a69e49fb9 | |||
| fe6d5a3635 | |||
| b5caf9604d | |||
| 315d4eaa3f | |||
| f98ab77944 | |||
| 0fccd9e296 | |||
| 0db8b93a7c | |||
| ea979cd729 | |||
| ba72ad2a44 | |||
| 8edef241e4 | |||
| 2fbbe5b3c8 | |||
| 325e19dca5 | |||
| 8ad6c3aaa2 | |||
| f8765ff95f | |||
| 619b61fe55 | |||
| a6aac8fce7 | |||
| 2afb31b073 | |||
| 66d193148e | |||
| 58b48dceb4 | |||
| e03deb6ba6 | |||
| 6142ef603d | |||
| 2d82e0c433 | |||
| 3b629f4796 | |||
| 23481bd786 | |||
| 46156c4286 | |||
| 898e32972b | |||
| cd502b6f34 | |||
| 7ee04b74ea | |||
| 206d375bbd | |||
| cba3c2f2d9 | |||
| 5ec4cb98e3 | |||
| e44bd5843d | |||
| a9d356a04a | |||
| 5ba19b42f9 |
@@ -0,0 +1,20 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 17.0.2
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 17.0
|
||||||
|
|
||||||
|
- name: Compile
|
||||||
|
run: mvn -B -Pclean install
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>Assembly</artifactId>
|
<artifactId>Assembly</artifactId>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.4</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -20,6 +20,32 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.yaml.snakeyaml</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.org.yaml.snakeyaml</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mongodb</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mongodb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bson</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.org.bson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mysql</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mysql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.google</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.google</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.moandjiezana</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.moandjiezana</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -35,8 +61,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
+30
-4
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.4</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -30,6 +30,32 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.yaml.snakeyaml</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.org.yaml.snakeyaml</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mongodb</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mongodb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bson</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.org.bson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mysql</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mysql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.google</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.google</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.moandjiezana</pattern>
|
||||||
|
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.moandjiezana</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -46,13 +72,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Velocity</artifactId>
|
||||||
<version>${version}</version>
|
<version>${version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Velocity</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>${version}</version>
|
<version>${version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>Bukkit</artifactId>
|
<artifactId>Bukkit</artifactId>
|
||||||
@@ -56,8 +56,30 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>toml4j</artifactId>
|
||||||
|
<groupId>com.moandjiezana.toml</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.funkemunky.utils</groupId>
|
<groupId>cc.funkemunky.utils</groupId>
|
||||||
@@ -67,8 +89,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
package dev.brighten.antivpn.bukkit;
|
|
||||||
|
|
||||||
import dev.brighten.antivpn.api.VPNConfig;
|
|
||||||
import dev.brighten.antivpn.bukkit.util.ConfigDefault;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BukkitConfig implements VPNConfig {
|
|
||||||
private final ConfigDefault<String> licenseDefault = new ConfigDefault<>("",
|
|
||||||
"license", BukkitPlugin.pluginInstance), kickStringDefault =
|
|
||||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
|
||||||
"kickMessage", BukkitPlugin.pluginInstance),
|
|
||||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
|
||||||
"database.type", BukkitPlugin.pluginInstance),
|
|
||||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
|
||||||
"database.database", BukkitPlugin.pluginInstance),
|
|
||||||
defaultUsername = new ConfigDefault<>("root",
|
|
||||||
"database.username", BukkitPlugin.pluginInstance),
|
|
||||||
defaultPassword = new ConfigDefault<>("password",
|
|
||||||
"database.password", BukkitPlugin.pluginInstance),
|
|
||||||
defaultAuthDatabase = new ConfigDefault<>("admin",
|
|
||||||
"database.auth", BukkitPlugin.pluginInstance),
|
|
||||||
defaultIp = new ConfigDefault<>("localhost", "database.ip", BukkitPlugin.pluginInstance),
|
|
||||||
defaultAlertMsg = new ConfigDefault<>("&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy" +
|
|
||||||
" &8(&f%reason%&8) &7in location &8(&f%city%&7, &f%country%&8)", "alerts.message",
|
|
||||||
BukkitPlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<Boolean> cacheResultsDefault = new ConfigDefault<>(true,
|
|
||||||
"cachedResults", BukkitPlugin.pluginInstance),
|
|
||||||
defaultDatabaseEnabled = new ConfigDefault<>(false, "database.enabled",
|
|
||||||
BukkitPlugin.pluginInstance), defaultCommandsEnable = new ConfigDefault<>(false,
|
|
||||||
"commands.enabled", BukkitPlugin.pluginInstance), defaultKickPlayers
|
|
||||||
= new ConfigDefault<>(true, "kickPlayers", BukkitPlugin.pluginInstance),
|
|
||||||
defaultAlertToStaff = new ConfigDefault<>(true, "alerts.enabled",
|
|
||||||
BukkitPlugin.pluginInstance),
|
|
||||||
defaultMetrics = new ConfigDefault<>(true, "bstats", BukkitPlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<Integer>
|
|
||||||
defaultPort = new ConfigDefault<>(-1, "database.port", BukkitPlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<List<String>> prefixWhitelistsDefault = new ConfigDefault<>(new ArrayList<>(),
|
|
||||||
"prefixWhitelists", BukkitPlugin.pluginInstance), defaultCommands = new ConfigDefault<>(
|
|
||||||
Collections.singletonList("kick %player% VPNs are not allowed on our server!"), "commands.execute",
|
|
||||||
BukkitPlugin.pluginInstance);
|
|
||||||
|
|
||||||
private String license, kickMessage, databaseType, databaseName, username, password, ip, alertMsg;
|
|
||||||
private List<String> prefixWhitelists, commands;
|
|
||||||
private int port;
|
|
||||||
private boolean cacheResults, databaseEnabled, commandsEnabled, kickPlayers, alertToStaff, metrics;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLicense() {
|
|
||||||
return license;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean cachedResults() {
|
|
||||||
return cacheResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKickString() {
|
|
||||||
return kickMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String alertMessage() {
|
|
||||||
return alertMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean alertToStaff() {
|
|
||||||
return alertToStaff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean runCommands() {
|
|
||||||
return commandsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> commands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean kickPlayersOnDetect() {
|
|
||||||
return kickPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getPrefixWhitelists() {
|
|
||||||
return prefixWhitelists;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDatabaseEnabled() {
|
|
||||||
return databaseEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseType() {
|
|
||||||
return databaseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseName() {
|
|
||||||
return databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIp() {
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
if(port == -1) {
|
|
||||||
switch (getDatabaseType().toLowerCase()) {
|
|
||||||
case "mongodb":
|
|
||||||
case "mongo":
|
|
||||||
case "mongod":
|
|
||||||
return 27017;
|
|
||||||
case "sql":
|
|
||||||
case "mysql":
|
|
||||||
return 3306;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean metrics() {
|
|
||||||
return metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
license = licenseDefault.get();
|
|
||||||
kickMessage = kickStringDefault.get();
|
|
||||||
cacheResults = cacheResultsDefault.get();
|
|
||||||
prefixWhitelists = prefixWhitelistsDefault.get();
|
|
||||||
databaseEnabled = defaultDatabaseEnabled.get();
|
|
||||||
databaseType = defaultDatabaseType.get();
|
|
||||||
databaseName = defaultDatabaseName.get();
|
|
||||||
username = defaultUsername.get();
|
|
||||||
password = defaultPassword.get();
|
|
||||||
ip = defaultIp.get();
|
|
||||||
port = defaultPort.get();
|
|
||||||
commandsEnabled = defaultCommandsEnable.get();
|
|
||||||
commands = defaultCommands.get();
|
|
||||||
kickPlayers = defaultKickPlayers.get();
|
|
||||||
alertToStaff = defaultAlertToStaff.get();
|
|
||||||
alertMsg = defaultAlertMsg.get();
|
|
||||||
metrics = defaultMetrics.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,9 @@ import dev.brighten.antivpn.api.APIPlayer;
|
|||||||
import dev.brighten.antivpn.api.VPNExecutor;
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
import dev.brighten.antivpn.message.VpnString;
|
import dev.brighten.antivpn.message.VpnString;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -47,18 +48,23 @@ public class BukkitListener extends VPNExecutor implements Listener {
|
|||||||
if(cacheResetTask != null && !cacheResetTask.isCancelled()) cacheResetTask.cancel();
|
if(cacheResetTask != null && !cacheResetTask.isCancelled()) cacheResetTask.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String log, Object... objects) {
|
||||||
|
Bukkit.getLogger().log(Level.INFO, String.format(log, objects));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(final PlayerJoinEvent event) {
|
public void onJoin(final PlayerJoinEvent event) {
|
||||||
AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId())
|
AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId())
|
||||||
.ifPresent(player -> {
|
.ifPresent(player -> {
|
||||||
AntiVPN.getInstance().getDatabase().alertsState(player.getUuid(), enabled -> {
|
AntiVPN.getInstance().getDatabase().alertsState(player.getUuid(), enabled -> {
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
System.out.println("Enabled");
|
AntiVPN.getInstance().getExecutor().log("Enabled");
|
||||||
player.setAlertsEnabled(true);
|
player.setAlertsEnabled(true);
|
||||||
player.sendMessage(AntiVPN.getInstance().getMessageHandler()
|
player.sendMessage(AntiVPN.getInstance().getMessageHandler()
|
||||||
.getString("command-alerts-toggled")
|
.getString("command-alerts-toggled")
|
||||||
.getFormattedMessage(new VpnString.Var<>("state", true)));
|
.getFormattedMessage(new VpnString.Var<>("state", true)));
|
||||||
} else System.out.println("Not enabled");
|
} else AntiVPN.getInstance().getExecutor().log("Not enabled");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -66,48 +72,88 @@ public class BukkitListener extends VPNExecutor implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onListener(final PlayerLoginEvent event) {
|
public void onListener(final PlayerLoginEvent event) {
|
||||||
//If they're exempt, don't check.
|
//If they're exempt, don't check.
|
||||||
if(AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId())) return;
|
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||||
checkIp(event.getAddress().getHostAddress(), AntiVPN.getInstance().getConfig().cachedResults(), result -> {
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||||
if(result.isSuccess() && result.isProxy()) {
|
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||||
new BukkitRunnable() {
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getAddress().getHostAddress())
|
||||||
public void run() {
|
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||||
Player player = event.getPlayer();
|
.anyMatch(prefix -> event.getPlayer().getName().startsWith(prefix))) return;
|
||||||
|
|
||||||
if(!player.hasPermission("antivpn.bypass") //Has bypass permission
|
final Player player = event.getPlayer();
|
||||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
checkIp(event.getAddress().getHostAddress(),
|
||||||
|| AntiVPN.getInstance().getConfig().getPrefixWhitelists().stream()
|
AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> {
|
||||||
.anyMatch(prefix -> player.getName().startsWith(prefix))) {
|
if(result.isSuccess()) {
|
||||||
if (AntiVPN.getInstance().getConfig().kickPlayersOnDetect())
|
//We need to run on main thread or kicking and running commands will cause errors
|
||||||
player.kickPlayer(ChatColor.translateAlternateColorCodes('&',
|
new BukkitRunnable() {
|
||||||
AntiVPN.getInstance().getConfig().getKickString()));
|
public void run() {
|
||||||
|
// If the countryList() size is zero, no need to check.
|
||||||
|
// Running country check first
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||||
|
// This bit of code will decide whether or not to kick the player
|
||||||
|
// If it contains the code and it is set to whitelist, it will not kick as they are equal
|
||||||
|
// and vise versa. However, if the contains does not match the state, it will kick.
|
||||||
|
&& AntiVPN.getInstance().getVpnConfig().countryList()
|
||||||
|
.contains(result.getCountryCode())
|
||||||
|
!= AntiVPN.getInstance().getVpnConfig().whitelistCountries()) {
|
||||||
|
//Using our built in kicking system if no commands are configured
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().size() == 0) {
|
||||||
|
final String kickReason = AntiVPN.getInstance().getVpnConfig()
|
||||||
|
.countryVanillaKickReason();
|
||||||
|
// Kicking our player
|
||||||
|
event.getPlayer().kickPlayer(ChatColor
|
||||||
|
.translateAlternateColorCodes('&',
|
||||||
|
kickReason
|
||||||
|
.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%code%", result.getCountryCode())));
|
||||||
|
} else {
|
||||||
|
for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) {
|
||||||
|
final String formattedCommand = ChatColor.translateAlternateColorCodes('&',
|
||||||
|
cmd.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%code%", result.getCountryCode()));
|
||||||
|
|
||||||
//Ensuring the user wishes to alert to staff
|
// Runs our command from console
|
||||||
if(AntiVPN.getInstance().getConfig().alertToStaff())
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand);
|
||||||
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
}
|
||||||
.filter(APIPlayer::isAlertsEnabled)
|
}
|
||||||
.forEach(pl -> pl.sendMessage(AntiVPN.getInstance().getConfig()
|
} else if(result.isProxy()) {
|
||||||
.alertMessage().replace("%player%", event.getPlayer().getName())
|
if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect())
|
||||||
.replace("%reason%", result.getMethod())
|
player.kickPlayer(org.bukkit.ChatColor.translateAlternateColorCodes('&',
|
||||||
.replace("%country%", result.getCountryName())
|
AntiVPN.getInstance().getVpnConfig().getKickString()));
|
||||||
.replace("%city%", result.getCity())));
|
Bukkit.getLogger().info(event.getPlayer().getName()
|
||||||
|
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
||||||
|
|
||||||
//In case the user wants to run their own commands instead of using the built in kicking
|
//Ensuring the user wishes to alert to staff
|
||||||
if(AntiVPN.getInstance().getConfig().runCommands())
|
if(AntiVPN.getInstance().getVpnConfig().alertToStaff())
|
||||||
for (String command : AntiVPN.getInstance().getConfig().commands()) {
|
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
.filter(APIPlayer::isAlertsEnabled)
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
.forEach(pl -> pl.sendMessage(AntiVPN.getInstance().getVpnConfig().alertMessage()
|
||||||
command.replace("%player%", event.getPlayer().getName())));
|
.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%reason%", result.getMethod())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%city%", result.getCity())));
|
||||||
|
|
||||||
|
//In case the user wants to run their own commands instead of using the built in kicking
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().runCommands()) {
|
||||||
|
for (String command : AntiVPN.getInstance().getVpnConfig().commands()) {
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
|
ChatColor.translateAlternateColorCodes('&',
|
||||||
|
command.replace("%player%",
|
||||||
|
event.getPlayer().getName())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AntiVPN.getInstance().detections++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getLogger().info(player.getPlayer().getName()
|
}.runTask(BukkitPlugin.pluginInstance);
|
||||||
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
} else {
|
||||||
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING,
|
||||||
|
"The API query was not a success! " +
|
||||||
|
"You may need to upgrade your license on https://funkemunky.cc/shop");
|
||||||
}
|
}
|
||||||
}.runTask(BukkitPlugin.pluginInstance);
|
AntiVPN.getInstance().checked++;
|
||||||
} else if(!result.isSuccess()) {
|
});
|
||||||
Bukkit.getLogger().log(Level.WARNING,
|
|
||||||
"The API query was not a success! " +
|
|
||||||
"You may need to upgrade your license on https://funkemunky.cc/shop");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class BukkitPlayerExecutor implements PlayerExecutor {
|
public class BukkitPlayerExecutor implements PlayerExecutor {
|
||||||
|
|
||||||
private final Map<Player, BukkitPlayer> cachedPlayers = new WeakHashMap<>();
|
private final Map<UUID, BukkitPlayer> cachedPlayers = new WeakHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<APIPlayer> getPlayer(String name) {
|
public Optional<APIPlayer> getPlayer(String name) {
|
||||||
@@ -21,7 +21,7 @@ public class BukkitPlayerExecutor implements PlayerExecutor {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(cachedPlayers.computeIfAbsent(player, BukkitPlayer::new));
|
return Optional.of(cachedPlayers.computeIfAbsent(player.getUniqueId(), k -> new BukkitPlayer(player)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,14 +32,14 @@ public class BukkitPlayerExecutor implements PlayerExecutor {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(cachedPlayers.computeIfAbsent(player, BukkitPlayer::new));
|
return Optional.of(cachedPlayers.computeIfAbsent(player.getUniqueId(), k -> new BukkitPlayer(player)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<APIPlayer> getOnlinePlayers() {
|
public List<APIPlayer> getOnlinePlayers() {
|
||||||
return Bukkit.getOnlinePlayers().stream()
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
.map(pl -> cachedPlayers.computeIfAbsent(pl, BukkitPlayer::new))
|
.map(pl -> cachedPlayers.computeIfAbsent(pl.getUniqueId(), k -> new BukkitPlayer(pl)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package dev.brighten.antivpn.bukkit;
|
package dev.brighten.antivpn.bukkit;
|
||||||
|
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
import dev.brighten.antivpn.bukkit.util.ConfigDefault;
|
|
||||||
import dev.brighten.antivpn.command.Command;
|
import dev.brighten.antivpn.command.Command;
|
||||||
|
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||||
|
import dev.brighten.antivpn.utils.MiscUtils;
|
||||||
|
import dev.brighten.antivpn.utils.config.Configuration;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bstats.charts.MultiLineChart;
|
|
||||||
import org.bstats.charts.SingleLineChart;
|
import org.bstats.charts.SingleLineChart;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -16,6 +17,7 @@ import org.bukkit.plugin.SimplePluginManager;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -35,12 +37,17 @@ public class BukkitPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
//Loading config
|
//Loading config
|
||||||
Bukkit.getLogger().info("Loading config...");
|
Bukkit.getLogger().info("Loading config...");
|
||||||
saveDefaultConfig();
|
Configuration config = new Configuration();
|
||||||
|
File configFile = new File(getDataFolder(), "config.yml");
|
||||||
|
if(!configFile.exists()){
|
||||||
|
configFile.getParentFile().mkdirs();
|
||||||
|
MiscUtils.copy(getResource( "config.yml"), configFile);
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getLogger().info("Starting AntiVPN services...");
|
Bukkit.getLogger().info("Starting AntiVPN services...");
|
||||||
AntiVPN.start(new BukkitConfig(), new BukkitListener(), new BukkitPlayerExecutor());
|
AntiVPN.start(new BukkitListener(), new BukkitPlayerExecutor(), getDataFolder());
|
||||||
|
|
||||||
if(AntiVPN.getInstance().getConfig().metrics()) {
|
if(AntiVPN.getInstance().getVpnConfig().metrics()) {
|
||||||
Bukkit.getLogger().info("Starting bStats metrics...");
|
Bukkit.getLogger().info("Starting bStats metrics...");
|
||||||
Metrics metrics = new Metrics(this, 12615);
|
Metrics metrics = new Metrics(this, 12615);
|
||||||
metrics.addCustomChart(vpnDetections = new SingleLineChart("vpn_detections",
|
metrics.addCustomChart(vpnDetections = new SingleLineChart("vpn_detections",
|
||||||
@@ -128,7 +135,7 @@ public class BukkitPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), BukkitPlugin.pluginInstance)
|
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||||
.get());
|
.get());
|
||||||
//TODO Finish system before implementing on startup
|
//TODO Finish system before implementing on startup
|
||||||
/*Bukkit.getLogger().info("Getting strings...");
|
/*Bukkit.getLogger().info("Getting strings...");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: AntiVPN
|
name: KauriVPN
|
||||||
main: dev.brighten.antivpn.bukkit.BukkitPlugin
|
main: dev.brighten.antivpn.bukkit.BukkitPlugin
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
author: funkemunky
|
author: funkemunky
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>Bungee</artifactId>
|
<artifactId>Bungee</artifactId>
|
||||||
@@ -50,8 +50,30 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>toml4j</artifactId>
|
||||||
|
<groupId>com.moandjiezana.toml</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.github.bungee</groupId>
|
<groupId>org.github.bungee</groupId>
|
||||||
@@ -67,8 +89,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,166 +0,0 @@
|
|||||||
package dev.brighten.antivpn.bungee;
|
|
||||||
|
|
||||||
import dev.brighten.antivpn.api.VPNConfig;
|
|
||||||
import dev.brighten.antivpn.bungee.util.ConfigDefault;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BungeeConfig implements VPNConfig {
|
|
||||||
private final ConfigDefault<String> licenseDefault = new ConfigDefault<>("",
|
|
||||||
"license", BungeePlugin.pluginInstance), kickStringDefault =
|
|
||||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
|
||||||
"kickMessage", BungeePlugin.pluginInstance),
|
|
||||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
|
||||||
"database.type", BungeePlugin.pluginInstance),
|
|
||||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
|
||||||
"database.database", BungeePlugin.pluginInstance),
|
|
||||||
defaultUsername = new ConfigDefault<>("root",
|
|
||||||
"database.username", BungeePlugin.pluginInstance),
|
|
||||||
defaultPassword = new ConfigDefault<>("password",
|
|
||||||
"database.password", BungeePlugin.pluginInstance),
|
|
||||||
defaultAuthDatabase = new ConfigDefault<>("admin",
|
|
||||||
"database.auth", BungeePlugin.pluginInstance),
|
|
||||||
defaultIp = new ConfigDefault<>("localhost", "database.ip", BungeePlugin.pluginInstance),
|
|
||||||
defaultAlertMsg = new ConfigDefault<>("&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy" +
|
|
||||||
" &8(&f%reason%&8) &7in location &8(&f%city%&7, &f%country%&8)", "alerts.message",
|
|
||||||
BungeePlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<Boolean> cacheResultsDefault = new ConfigDefault<>(true,
|
|
||||||
"cachedResults", BungeePlugin.pluginInstance),
|
|
||||||
defaultDatabaseEnabled = new ConfigDefault<>(false, "database.enabled",
|
|
||||||
BungeePlugin.pluginInstance), defaultCommandsEnable = new ConfigDefault<>(false,
|
|
||||||
"commands.enabled", BungeePlugin.pluginInstance), defaultKickPlayers
|
|
||||||
= new ConfigDefault<>(true, "kickPlayers", BungeePlugin.pluginInstance),
|
|
||||||
defaultAlertToStaff = new ConfigDefault<>(true, "alerts.enabled",
|
|
||||||
BungeePlugin.pluginInstance),
|
|
||||||
defaultMetrics = new ConfigDefault<>(true, "bstats", BungeePlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<Integer>
|
|
||||||
defaultPort = new ConfigDefault<>(-1, "database.port", BungeePlugin.pluginInstance);
|
|
||||||
private final ConfigDefault<List<String>> prefixWhitelistsDefault = new ConfigDefault<>(new ArrayList<>(),
|
|
||||||
"prefixWhitelists", BungeePlugin.pluginInstance), defaultCommands = new ConfigDefault<>(
|
|
||||||
Collections.singletonList("kick %player% VPNs are not allowed on our server!"), "commands.execute",
|
|
||||||
BungeePlugin.pluginInstance);
|
|
||||||
|
|
||||||
private String license, kickMessage, databaseType, databaseName, username, password, ip, alertMsg;
|
|
||||||
private List<String> prefixWhitelists, commands;
|
|
||||||
private int port;
|
|
||||||
private boolean cacheResults, databaseEnabled, commandsEnabled, kickPlayers, alertToStaff, metrics;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLicense() {
|
|
||||||
return license;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean cachedResults() {
|
|
||||||
return cacheResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKickString() {
|
|
||||||
return kickMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String alertMessage() {
|
|
||||||
return alertMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean alertToStaff() {
|
|
||||||
return alertToStaff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean runCommands() {
|
|
||||||
return commandsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> commands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean kickPlayersOnDetect() {
|
|
||||||
return kickPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getPrefixWhitelists() {
|
|
||||||
return prefixWhitelists;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDatabaseEnabled() {
|
|
||||||
return databaseEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseType() {
|
|
||||||
return databaseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseName() {
|
|
||||||
return databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIp() {
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
if(port == -1) {
|
|
||||||
switch (getDatabaseType().toLowerCase()) {
|
|
||||||
case "mongodb":
|
|
||||||
case "mongo":
|
|
||||||
case "mongod":
|
|
||||||
return 27017;
|
|
||||||
case "sql":
|
|
||||||
case "mysql":
|
|
||||||
return 3306;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean metrics() {
|
|
||||||
return metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
license = licenseDefault.get();
|
|
||||||
kickMessage = kickStringDefault.get();
|
|
||||||
cacheResults = cacheResultsDefault.get();
|
|
||||||
prefixWhitelists = prefixWhitelistsDefault.get();
|
|
||||||
databaseEnabled = defaultDatabaseEnabled.get();
|
|
||||||
databaseType = defaultDatabaseType.get();
|
|
||||||
databaseName = defaultDatabaseName.get();
|
|
||||||
username = defaultUsername.get();
|
|
||||||
password = defaultPassword.get();
|
|
||||||
ip = defaultIp.get();
|
|
||||||
port = defaultPort.get();
|
|
||||||
commandsEnabled = defaultCommandsEnable.get();
|
|
||||||
commands = defaultCommands.get();
|
|
||||||
kickPlayers = defaultKickPlayers.get();
|
|
||||||
alertToStaff = defaultAlertToStaff.get();
|
|
||||||
alertMsg = defaultAlertMsg.get();
|
|
||||||
metrics = defaultMetrics.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,44 +40,85 @@ public class BungeeListener extends VPNExecutor implements Listener {
|
|||||||
BungeePlugin.pluginInstance.getProxy().getPluginManager().unregisterListener(this);
|
BungeePlugin.pluginInstance.getProxy().getPluginManager().unregisterListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String log, Object... objects) {
|
||||||
|
BungeeCord.getInstance().getLogger().log(Level.INFO, String.format(log, objects));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onListener(final PostLoginEvent event) {
|
public void onListener(final PostLoginEvent event) {
|
||||||
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||||
|| AntiVPN.getInstance().getConfig().getPrefixWhitelists().stream()
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getAddress().getAddress()
|
||||||
|
.getHostAddress())
|
||||||
|
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||||
.anyMatch(prefix -> event.getPlayer().getName().startsWith(prefix))) return;
|
.anyMatch(prefix -> event.getPlayer().getName().startsWith(prefix))) return;
|
||||||
|
|
||||||
checkIp(event.getPlayer().getAddress().getAddress().getHostAddress(),
|
checkIp(event.getPlayer().getAddress().getAddress().getHostAddress(),
|
||||||
AntiVPN.getInstance().getConfig().cachedResults(), result -> {
|
AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> {
|
||||||
if(result.isSuccess() && result.isProxy()) {
|
if(result.isSuccess()) {
|
||||||
if(AntiVPN.getInstance().getConfig().kickPlayersOnDetect())
|
// If the countryList() size is zero, no need to check.
|
||||||
event.getPlayer().disconnect(TextComponent.fromLegacyText(ChatColor
|
// Running country check first
|
||||||
.translateAlternateColorCodes('&',
|
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||||
AntiVPN.getInstance().getConfig().getKickString())));
|
// This bit of code will decide whether or not to kick the player
|
||||||
BungeeCord.getInstance().getLogger().info(event.getPlayer().getName()
|
// If it contains the code and it is set to whitelist, it will not kick as they are equal
|
||||||
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
// and vise versa. However, if the contains does not match the state, it will kick.
|
||||||
|
&& AntiVPN.getInstance().getVpnConfig().countryList()
|
||||||
|
.contains(result.getCountryCode()) != AntiVPN.getInstance().getVpnConfig().whitelistCountries()) {
|
||||||
|
//Using our built in kicking system if no commands are configured
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().size() == 0) {
|
||||||
|
final String kickReason = AntiVPN.getInstance().getVpnConfig()
|
||||||
|
.countryVanillaKickReason();
|
||||||
|
// Kicking our player
|
||||||
|
event.getPlayer().disconnect(TextComponent.fromLegacyText(ChatColor
|
||||||
|
.translateAlternateColorCodes('&',
|
||||||
|
kickReason
|
||||||
|
.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%code%", result.getCountryCode()))));
|
||||||
|
} else {
|
||||||
|
for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) {
|
||||||
|
final String formattedCommand = ChatColor.translateAlternateColorCodes('&',
|
||||||
|
cmd.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%code%", result.getCountryCode()));
|
||||||
|
|
||||||
if(AntiVPN.getInstance().getConfig().alertToStaff()) //Ensuring the user wishes to alert to staff
|
// Runs our command from console
|
||||||
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
BungeeCord.getInstance().getPluginManager().dispatchCommand(
|
||||||
.filter(APIPlayer::isAlertsEnabled)
|
BungeeCord.getInstance().getConsole(), formattedCommand);
|
||||||
.forEach(pl -> pl.sendMessage(AntiVPN.getInstance().getConfig().alertMessage()
|
}
|
||||||
.replace("%player%", event.getPlayer().getName())
|
|
||||||
.replace("%reason%", result.getMethod())
|
|
||||||
.replace("%country%", result.getCountryName())
|
|
||||||
.replace("%city%", result.getCity())));
|
|
||||||
|
|
||||||
//In case the user wants to run their own commands instead of using the built in kicking
|
|
||||||
if(AntiVPN.getInstance().getConfig().runCommands()) {
|
|
||||||
for (String command : AntiVPN.getInstance().getConfig().commands()) {
|
|
||||||
BungeeCord.getInstance().getPluginManager()
|
|
||||||
.dispatchCommand(BungeeCord.getInstance().getConsole(),
|
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
|
||||||
command.replace("%player%", event.getPlayer().getName())));
|
|
||||||
}
|
}
|
||||||
|
} else if(result.isProxy()) {
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect())
|
||||||
|
event.getPlayer().disconnect(TextComponent.fromLegacyText(ChatColor
|
||||||
|
.translateAlternateColorCodes('&',
|
||||||
|
AntiVPN.getInstance().getVpnConfig().getKickString())));
|
||||||
|
BungeeCord.getInstance().getLogger().info(event.getPlayer().getName()
|
||||||
|
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
||||||
|
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().alertToStaff()) //Ensuring the user wishes to alert to staff
|
||||||
|
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||||
|
.filter(APIPlayer::isAlertsEnabled)
|
||||||
|
.forEach(pl -> pl.sendMessage(AntiVPN.getInstance().getVpnConfig().alertMessage()
|
||||||
|
.replace("%player%", event.getPlayer().getName())
|
||||||
|
.replace("%reason%", result.getMethod())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%city%", result.getCity())));
|
||||||
|
|
||||||
|
//In case the user wants to run their own commands instead of using the built in kicking
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().runCommands()) {
|
||||||
|
for (String command : AntiVPN.getInstance().getVpnConfig().commands()) {
|
||||||
|
BungeeCord.getInstance().getPluginManager()
|
||||||
|
.dispatchCommand(BungeeCord.getInstance().getConsole(),
|
||||||
|
ChatColor.translateAlternateColorCodes('&',
|
||||||
|
command.replace("%player%", event.getPlayer().getName())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AntiVPN.getInstance().detections++;
|
||||||
}
|
}
|
||||||
AntiVPN.getInstance().detections++;
|
|
||||||
} else if(!result.isSuccess()) {
|
} else {
|
||||||
BungeeCord.getInstance().getLogger()
|
BungeeCord.getInstance().getLogger()
|
||||||
.log(Level.WARNING,
|
.log(Level.WARNING,
|
||||||
"The API query was not a success! " +
|
"The API query was not a success! " +
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package dev.brighten.antivpn.bungee;
|
package dev.brighten.antivpn.bungee;
|
||||||
|
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
import dev.brighten.antivpn.bungee.util.Config;
|
|
||||||
import dev.brighten.antivpn.bungee.util.ConfigDefault;
|
|
||||||
import dev.brighten.antivpn.command.Command;
|
import dev.brighten.antivpn.command.Command;
|
||||||
import lombok.Getter;
|
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
@@ -24,8 +22,6 @@ public class BungeePlugin extends Plugin {
|
|||||||
|
|
||||||
public static BungeePlugin pluginInstance;
|
public static BungeePlugin pluginInstance;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Config config;
|
|
||||||
private SingleLineChart vpnDetections, ipsChecked;
|
private SingleLineChart vpnDetections, ipsChecked;
|
||||||
|
|
||||||
private static final BaseComponent[] noPermission = new ComponentBuilder("No permission").color(ChatColor.RED)
|
private static final BaseComponent[] noPermission = new ComponentBuilder("No permission").color(ChatColor.RED)
|
||||||
@@ -37,14 +33,13 @@ public class BungeePlugin extends Plugin {
|
|||||||
|
|
||||||
//Setting up config
|
//Setting up config
|
||||||
BungeeCord.getInstance().getLogger().info("Loading config...");
|
BungeeCord.getInstance().getLogger().info("Loading config...");
|
||||||
config = new Config();
|
|
||||||
|
|
||||||
|
|
||||||
//Loading plugin
|
//Loading plugin
|
||||||
BungeeCord.getInstance().getLogger().info("Starting AntiVPN services...");
|
BungeeCord.getInstance().getLogger().info("Starting AntiVPN services...");
|
||||||
AntiVPN.start(new BungeeConfig(), new BungeeListener(), new BungeePlayerExecutor());
|
AntiVPN.start(new BungeeListener(), new BungeePlayerExecutor(), getDataFolder());
|
||||||
|
|
||||||
if(AntiVPN.getInstance().getConfig().metrics()) {
|
if(AntiVPN.getInstance().getVpnConfig().metrics()) {
|
||||||
BungeeCord.getInstance().getLogger().info("Starting bStats metrics...");
|
BungeeCord.getInstance().getLogger().info("Starting bStats metrics...");
|
||||||
Metrics metrics = new Metrics(this, 12616);
|
Metrics metrics = new Metrics(this, 12616);
|
||||||
metrics.addCustomChart(vpnDetections = new SingleLineChart("vpn_detections",
|
metrics.addCustomChart(vpnDetections = new SingleLineChart("vpn_detections",
|
||||||
@@ -103,7 +98,7 @@ public class BungeePlugin extends Plugin {
|
|||||||
|
|
||||||
BungeeCord.getInstance().getLogger().info("Getting strings...");
|
BungeeCord.getInstance().getLogger().info("Getting strings...");
|
||||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), BungeePlugin.pluginInstance)
|
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||||
.get());
|
.get());
|
||||||
//TODO Finish system before implementing on startup
|
//TODO Finish system before implementing on startup
|
||||||
/*BungeeCord.getInstance().getLogger().info("Getting strings...");
|
/*BungeeCord.getInstance().getLogger().info("Getting strings...");
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
package dev.brighten.antivpn.bungee.util;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import dev.brighten.antivpn.bungee.BungeePlugin;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author: nitramleo (Martin)
|
|
||||||
* Date created: 10-Aug-18
|
|
||||||
*/
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
private Configuration configuration;
|
|
||||||
|
|
||||||
public Config() {
|
|
||||||
this.file = new File(BungeePlugin.pluginInstance.getDataFolder(), "config.yml");
|
|
||||||
try {
|
|
||||||
if (!this.file.exists()) {
|
|
||||||
if (!BungeePlugin.pluginInstance.getDataFolder().exists()) {
|
|
||||||
BungeePlugin.pluginInstance.getDataFolder().mkdir();
|
|
||||||
}
|
|
||||||
this.file.createNewFile();
|
|
||||||
try (final InputStream is = BungeePlugin.pluginInstance.getResourceAsStream("config.yml");
|
|
||||||
final OutputStream os = new FileOutputStream(this.file)) {
|
|
||||||
ByteStreams.copy(is, os);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
this.file = new File(BungeePlugin.pluginInstance.getDataFolder(), "config.yml");
|
|
||||||
try {
|
|
||||||
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
try {
|
|
||||||
ConfigurationProvider.getProvider( YamlConfiguration.class).save(this.configuration, this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Configuration getConfiguration() {
|
|
||||||
return this.configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return this.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDouble(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return this.configuration.getDouble(path);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInt(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return this.configuration.getInt(path);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(final String path) {
|
|
||||||
return this.configuration.get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(final String path, final Object object) {
|
|
||||||
configuration.set(path, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean(final String path) {
|
|
||||||
return this.configuration.get(path) != null && this.configuration.getBoolean(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', this.configuration.getString(path));
|
|
||||||
}
|
|
||||||
return "String at path: " + path + " not found!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getStringList(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
final ArrayList<String> strings = new ArrayList<String>();
|
|
||||||
for (final String string : this.configuration.getStringList(path)) {
|
|
||||||
strings.add(ChatColor.translateAlternateColorCodes('&', string));
|
|
||||||
}
|
|
||||||
return strings;
|
|
||||||
}
|
|
||||||
return Arrays.asList("String List at path: " + path + " not found!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package dev.brighten.antivpn.bungee.util;
|
|
||||||
|
|
||||||
import dev.brighten.antivpn.bungee.BungeePlugin;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ConfigDefault<A> {
|
|
||||||
|
|
||||||
private final A defaultValue;
|
|
||||||
private final String path;
|
|
||||||
private final BungeePlugin plugin;
|
|
||||||
|
|
||||||
public A get() {
|
|
||||||
if(plugin.getConfig().get(path) != null)
|
|
||||||
return (A) plugin.getConfig().get(path);
|
|
||||||
else {
|
|
||||||
plugin.getConfig().set(path, defaultValue);
|
|
||||||
plugin.getConfig().save();
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public A set(A value) {
|
|
||||||
plugin.getConfig().set(path, value);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: AntiVPN
|
name: KauriVPN
|
||||||
main: dev.brighten.antivpn.bungee.BungeePlugin
|
main: dev.brighten.antivpn.bungee.BungeePlugin
|
||||||
description: A simple and fast antivpn plugin.
|
description: A simple and fast antivpn plugin.
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
|
|||||||
+43
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>8</source>
|
||||||
<target>8</target>
|
<target>8</target>
|
||||||
@@ -37,4 +37,45 @@
|
|||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>funkemunky-releases</id>
|
||||||
|
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.moandjiezana.toml</groupId>
|
||||||
|
<artifactId>toml4j</artifactId>
|
||||||
|
<version>0.7.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.27</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>2.1.210</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.30</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
<version>3.12.10</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -6,9 +6,14 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
|||||||
import dev.brighten.antivpn.command.Command;
|
import dev.brighten.antivpn.command.Command;
|
||||||
import dev.brighten.antivpn.command.impl.AntiVPNCommand;
|
import dev.brighten.antivpn.command.impl.AntiVPNCommand;
|
||||||
import dev.brighten.antivpn.database.VPNDatabase;
|
import dev.brighten.antivpn.database.VPNDatabase;
|
||||||
|
import dev.brighten.antivpn.database.mongo.MongoVPN;
|
||||||
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
||||||
import dev.brighten.antivpn.message.MessageHandler;
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
|
import dev.brighten.antivpn.utils.MiscUtils;
|
||||||
import dev.brighten.antivpn.utils.VPNResponse;
|
import dev.brighten.antivpn.utils.VPNResponse;
|
||||||
|
import dev.brighten.antivpn.utils.config.Configuration;
|
||||||
|
import dev.brighten.antivpn.utils.config.ConfigurationProvider;
|
||||||
|
import dev.brighten.antivpn.utils.config.YamlConfiguration;
|
||||||
import dev.brighten.antivpn.utils.json.JSONException;
|
import dev.brighten.antivpn.utils.json.JSONException;
|
||||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||||
@@ -16,7 +21,11 @@ import lombok.AccessLevel;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -25,32 +34,48 @@ import java.util.List;
|
|||||||
public class AntiVPN {
|
public class AntiVPN {
|
||||||
|
|
||||||
private static AntiVPN INSTANCE;
|
private static AntiVPN INSTANCE;
|
||||||
private VPNConfig config;
|
private VPNConfig vpnConfig;
|
||||||
private VPNExecutor executor;
|
private VPNExecutor executor;
|
||||||
private PlayerExecutor playerExecutor;
|
private PlayerExecutor playerExecutor;
|
||||||
private VPNDatabase database;
|
private VPNDatabase database;
|
||||||
private MessageHandler messageHandler;
|
private MessageHandler messageHandler;
|
||||||
|
private Configuration config;
|
||||||
private List<Command> commands = new ArrayList<>();
|
private List<Command> commands = new ArrayList<>();
|
||||||
public int detections, checked;
|
public int detections, checked;
|
||||||
|
private File pluginFolder;
|
||||||
|
|
||||||
public static void start(VPNConfig config, VPNExecutor executor, PlayerExecutor playerExecutor) {
|
public static void start(VPNExecutor executor, PlayerExecutor playerExecutor, File pluginFolder) {
|
||||||
//Initializing
|
//Initializing
|
||||||
|
|
||||||
INSTANCE = new AntiVPN();
|
INSTANCE = new AntiVPN();
|
||||||
|
|
||||||
INSTANCE.config = config;
|
INSTANCE.pluginFolder = pluginFolder;
|
||||||
INSTANCE.executor = executor;
|
INSTANCE.executor = executor;
|
||||||
INSTANCE.playerExecutor = playerExecutor;
|
INSTANCE.playerExecutor = playerExecutor;
|
||||||
|
try {
|
||||||
|
File configFile = new File(pluginFolder, "config.yml");
|
||||||
|
if(!configFile.exists()){
|
||||||
|
configFile.getParentFile().mkdirs();
|
||||||
|
MiscUtils.copy(INSTANCE.getResource( "config.yml"), configFile);
|
||||||
|
}
|
||||||
|
INSTANCE.config = ConfigurationProvider.getProvider(YamlConfiguration.class)
|
||||||
|
.load(configFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANCE.vpnConfig = new VPNConfig();
|
||||||
|
|
||||||
INSTANCE.executor.registerListeners();
|
INSTANCE.executor.registerListeners();
|
||||||
INSTANCE.config.update();
|
INSTANCE.vpnConfig.update();
|
||||||
|
|
||||||
INSTANCE.messageHandler = new MessageHandler();
|
INSTANCE.messageHandler = new MessageHandler();
|
||||||
|
|
||||||
switch(INSTANCE.config.getDatabaseType().toLowerCase()) {
|
switch(INSTANCE.vpnConfig.getDatabaseType().toLowerCase()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
|
case "h2":
|
||||||
case "sql":{
|
case "sql":{
|
||||||
System.out.println("Using databaseType MySQL...");
|
AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL...");
|
||||||
INSTANCE.database = new MySqlVPN();
|
INSTANCE.database = new MySqlVPN();
|
||||||
INSTANCE.database.init();
|
INSTANCE.database.init();
|
||||||
break;
|
break;
|
||||||
@@ -58,11 +83,12 @@ public class AntiVPN {
|
|||||||
case "mongo":
|
case "mongo":
|
||||||
case "mongodb":
|
case "mongodb":
|
||||||
case "mongod": {
|
case "mongod": {
|
||||||
System.out.println("We currently do not support Mongo, but this is coming in future updates.");
|
INSTANCE.database = new MongoVPN();
|
||||||
|
INSTANCE.database.init();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
System.out.println("Could not find database type \"" + INSTANCE.config.getDatabaseType() + "\". " +
|
AntiVPN.getInstance().getExecutor().log("Could not find database type \"" + INSTANCE.vpnConfig.getDatabaseType() + "\". " +
|
||||||
"Options: [MySQL]");
|
"Options: [MySQL]");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -82,6 +108,25 @@ public class AntiVPN {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputStream getResource(String filename) {
|
||||||
|
if (filename == null) {
|
||||||
|
throw new IllegalArgumentException("Filename cannot be null");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
URL url = executor.getClass().getClassLoader().getResource(filename);
|
||||||
|
if (url == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
URLConnection connection = url.openConnection();
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
return connection.getInputStream();
|
||||||
|
}
|
||||||
|
} catch (IOException var4) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
if(database != null) database.shutdown();
|
if(database != null) database.shutdown();
|
||||||
@@ -93,6 +138,15 @@ public class AntiVPN {
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveConfig() {
|
||||||
|
try {
|
||||||
|
ConfigurationProvider.getProvider(YamlConfiguration.class)
|
||||||
|
.save(getConfig(), new File(pluginFolder.getPath() + File.separator + "config.yml"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
||||||
throws JSONException, IOException {
|
throws JSONException, IOException {
|
||||||
JSONObject result = JsonReader.readJsonFromUrl(String
|
JSONObject result = JsonReader.readJsonFromUrl(String
|
||||||
|
|||||||
@@ -1,43 +1,291 @@
|
|||||||
package dev.brighten.antivpn.api;
|
package dev.brighten.antivpn.api;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface VPNConfig {
|
public class VPNConfig {
|
||||||
|
private final ConfigDefault<String> licenseDefault = new ConfigDefault<>("",
|
||||||
|
"license", AntiVPN.getInstance()), kickStringDefault =
|
||||||
|
new ConfigDefault<>("Proxies are not allowed on our server",
|
||||||
|
"kickMessage", AntiVPN.getInstance()),
|
||||||
|
defaultDatabaseType = new ConfigDefault<>("H2",
|
||||||
|
"database.type", AntiVPN.getInstance()),
|
||||||
|
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
||||||
|
"database.database", AntiVPN.getInstance()),
|
||||||
|
defaultMongoURL = new ConfigDefault<>("", "database.mongoURL", AntiVPN.getInstance()),
|
||||||
|
defaultUsername = new ConfigDefault<>("root",
|
||||||
|
"database.username", AntiVPN.getInstance()),
|
||||||
|
defaultPassword = new ConfigDefault<>("password",
|
||||||
|
"database.password", AntiVPN.getInstance()),
|
||||||
|
defaultCountryKickReason = new ConfigDefault<>(
|
||||||
|
"&cSorry, but our server does not allow connections from\n&f%country%",
|
||||||
|
"countries.vanillaKickReason", AntiVPN.getInstance()),
|
||||||
|
defaultIp = new ConfigDefault<>("localhost", "database.ip", AntiVPN.getInstance()),
|
||||||
|
defaultAlertMsg = new ConfigDefault<>("&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy" +
|
||||||
|
" &8(&f%reason%&8) &7in location &8(&f%city%&7, &f%country%&8)", "alerts.message",
|
||||||
|
AntiVPN.getInstance());
|
||||||
|
private final ConfigDefault<Boolean> cacheResultsDefault = new ConfigDefault<>(true,
|
||||||
|
"cachedResults", AntiVPN.getInstance()),
|
||||||
|
defaultUseCredentials = new ConfigDefault<>(true,
|
||||||
|
"database.useCredentials", AntiVPN.getInstance()),
|
||||||
|
defaultDatabaseEnabled = new ConfigDefault<>(false, "database.enabled",
|
||||||
|
AntiVPN.getInstance()), defaultCommandsEnable = new ConfigDefault<>(false,
|
||||||
|
"commands.enabled", AntiVPN.getInstance()), defaultKickPlayers
|
||||||
|
= new ConfigDefault<>(true, "kickPlayers", AntiVPN.getInstance()),
|
||||||
|
defaultAlertToStaff = new ConfigDefault<>(true, "alerts.enabled",
|
||||||
|
AntiVPN.getInstance()),
|
||||||
|
defaultWhitelistCountries = new ConfigDefault<>(true, "countries.whitelist",
|
||||||
|
AntiVPN.getInstance()),
|
||||||
|
defaultMetrics = new ConfigDefault<>(true, "bstats", AntiVPN.getInstance());
|
||||||
|
private final ConfigDefault<Integer>
|
||||||
|
defaultPort = new ConfigDefault<>(-1, "database.port", AntiVPN.getInstance());
|
||||||
|
private final ConfigDefault<List<String>> prefixWhitelistsDefault = new ConfigDefault<>(new ArrayList<>(),
|
||||||
|
"prefixWhitelists", AntiVPN.getInstance()), defaultCommands = new ConfigDefault<>(
|
||||||
|
Collections.singletonList("kick %player% VPNs are not allowed on our server!"), "commands.execute",
|
||||||
|
AntiVPN.getInstance()),
|
||||||
|
defCountryKickCommands = new ConfigDefault<>(Collections.emptyList(),
|
||||||
|
"countries.commands", AntiVPN.getInstance()),
|
||||||
|
defCountrylist = new ConfigDefault<>(new ArrayList<>(), "countries.list",
|
||||||
|
AntiVPN.getInstance());
|
||||||
|
|
||||||
String getLicense();
|
private String license, kickMessage, databaseType, databaseName, mongoURL, username, password, ip, alertMsg,
|
||||||
|
countryVanillaKickReason;
|
||||||
|
private List<String> prefixWhitelists, commands, countryList, countryKickCommands;
|
||||||
|
private int port;
|
||||||
|
private boolean cacheResults, databaseEnabled, useCredentials, commandsEnabled, kickPlayers, alertToStaff,
|
||||||
|
metrics, whitelistCountries;
|
||||||
|
|
||||||
boolean cachedResults();
|
/**
|
||||||
|
* License from https://funkemunky.cc/shop to be used for more queries.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getLicense() {
|
||||||
|
return license;
|
||||||
|
}
|
||||||
|
|
||||||
String getKickString();
|
/**
|
||||||
|
* If true, results will be cached to reduce queries to https://funkemunky.cc
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean cachedResults() {
|
||||||
|
return cacheResults;
|
||||||
|
}
|
||||||
|
|
||||||
String alertMessage();
|
/**
|
||||||
|
* Will be used for vanilla kick message when {@link VPNConfig#runCommands()} is true.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getKickString() {
|
||||||
|
return kickMessage;
|
||||||
|
}
|
||||||
|
|
||||||
boolean alertToStaff();
|
/**
|
||||||
|
* Message to send staff on proxy detection.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String alertMessage() {
|
||||||
|
return alertMsg;
|
||||||
|
}
|
||||||
|
|
||||||
boolean runCommands();
|
/**
|
||||||
|
* If true, staff will be alerted on proxy detection.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean alertToStaff() {
|
||||||
|
return alertToStaff;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> commands();
|
/**
|
||||||
|
* If true, will run {@link VPNConfig#commands()} on detect. If not, it will use vanilla kicking methods.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean runCommands() {
|
||||||
|
return commandsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
boolean kickPlayersOnDetect();
|
/**
|
||||||
|
* Commands to run on proxy detection.
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
public List<String> commands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> getPrefixWhitelists();
|
/**
|
||||||
|
* If false, no commands nor kick will be run on proxy detection.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean kickPlayersOnDetect() {
|
||||||
|
return kickPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isDatabaseEnabled();
|
/**
|
||||||
|
* Returns Strings of which are checked against the beginning of player names. Used to
|
||||||
|
* allow Geyser-connected players to join.
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
public List<String> getPrefixWhitelists() {
|
||||||
|
return prefixWhitelists;
|
||||||
|
}
|
||||||
|
|
||||||
String getDatabaseType();
|
/**
|
||||||
|
* Returns true if we want to use a database
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isDatabaseEnabled() {
|
||||||
|
return databaseEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
String getDatabaseName();
|
/**
|
||||||
|
* Whether or not the database we want to connect to requires credentials.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean useDatabaseCreds() {
|
||||||
|
return useCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
String getUsername();
|
/**
|
||||||
|
* Only for Mongo only. URL used for connecting to database. Overrides other fields
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String mongoDatabaseURL() {
|
||||||
|
return mongoURL;
|
||||||
|
}
|
||||||
|
|
||||||
String getPassword();
|
/**
|
||||||
|
* Database type. Either MySQL and Mongo.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getDatabaseType() {
|
||||||
|
return databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
String getIp();
|
/**
|
||||||
|
* Database name
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getDatabaseName() {
|
||||||
|
return databaseName;
|
||||||
|
}
|
||||||
|
|
||||||
int getPort();
|
/**
|
||||||
|
* Database username
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
boolean metrics();
|
/**
|
||||||
|
* Database Password
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
void update();
|
/**
|
||||||
|
* Database IP
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of ISO country codes we need to check.
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
public List<String> countryList() {
|
||||||
|
return countryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, we only allow the {@link VPNConfig#countryKickCommands()}. If false, we blacklist them.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean whitelistCountries() {
|
||||||
|
return whitelistCountries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns our configured commands to run on player country detection.
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
public List<String> countryKickCommands() {
|
||||||
|
return countryKickCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the vanilla kick reason for bad country locations
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String countryVanillaKickReason() {
|
||||||
|
return countryVanillaKickReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the port based on configuration. If {@link VPNConfig#port} is -1, will get default port
|
||||||
|
* based on {@link VPNConfig#getDatabaseType()} lowerCase().
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public int getPort() {
|
||||||
|
if(port == -1) {
|
||||||
|
switch (getDatabaseType().toLowerCase()) {
|
||||||
|
case "mongodb":
|
||||||
|
case "mongo":
|
||||||
|
case "mongod":
|
||||||
|
return 27017;
|
||||||
|
case "sql":
|
||||||
|
case "mysql":
|
||||||
|
return 3306;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, https://bstats.org metrics will be collected to improve KauriVPN.
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean metrics() {
|
||||||
|
return metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs all information from the config.yml
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
license = licenseDefault.get();
|
||||||
|
kickMessage = kickStringDefault.get();
|
||||||
|
cacheResults = cacheResultsDefault.get();
|
||||||
|
prefixWhitelists = prefixWhitelistsDefault.get();
|
||||||
|
databaseEnabled = defaultDatabaseEnabled.get();
|
||||||
|
useCredentials = defaultUseCredentials.get();
|
||||||
|
databaseType = defaultDatabaseType.get();
|
||||||
|
databaseName = defaultDatabaseName.get();
|
||||||
|
mongoURL = defaultMongoURL.get();
|
||||||
|
username = defaultUsername.get();
|
||||||
|
password = defaultPassword.get();
|
||||||
|
ip = defaultIp.get();
|
||||||
|
port = defaultPort.get();
|
||||||
|
commandsEnabled = defaultCommandsEnable.get();
|
||||||
|
commands = defaultCommands.get();
|
||||||
|
kickPlayers = defaultKickPlayers.get();
|
||||||
|
alertToStaff = defaultAlertToStaff.get();
|
||||||
|
alertMsg = defaultAlertMsg.get();
|
||||||
|
metrics = defaultMetrics.get();
|
||||||
|
countryList = defCountrylist.get();
|
||||||
|
whitelistCountries = defaultWhitelistCountries.get();
|
||||||
|
countryKickCommands = defCountryKickCommands.get();
|
||||||
|
countryVanillaKickReason = defaultCountryKickReason.get();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.brighten.antivpn.api;
|
package dev.brighten.antivpn.api;
|
||||||
|
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.utils.EvictingMap;
|
||||||
import dev.brighten.antivpn.utils.VPNResponse;
|
import dev.brighten.antivpn.utils.VPNResponse;
|
||||||
import dev.brighten.antivpn.utils.json.JSONException;
|
import dev.brighten.antivpn.utils.json.JSONException;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -15,9 +16,11 @@ import java.util.function.Consumer;
|
|||||||
public abstract class VPNExecutor {
|
public abstract class VPNExecutor {
|
||||||
public static ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
|
public static ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
private static final Map<String, VPNResponse> responseCache = new HashMap<>();
|
public static final Map<String, VPNResponse> responseCache = new EvictingMap<>(5000);
|
||||||
@Getter
|
@Getter
|
||||||
private final Set<UUID> whitelisted = Collections.synchronizedSet(new HashSet<>());
|
private final Set<UUID> whitelisted = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
@Getter
|
||||||
|
private final Set<String> whitelistedIps = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
public abstract void registerListeners();
|
public abstract void registerListeners();
|
||||||
|
|
||||||
@@ -29,10 +32,16 @@ public abstract class VPNExecutor {
|
|||||||
|
|
||||||
public abstract void shutdown();
|
public abstract void shutdown();
|
||||||
|
|
||||||
|
public abstract void log(String log, Object... objects);
|
||||||
|
|
||||||
public boolean isWhitelisted(UUID uuid) {
|
public boolean isWhitelisted(UUID uuid) {
|
||||||
return whitelisted.contains(uuid);
|
return whitelisted.contains(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWhitelisted(String ip) {
|
||||||
|
return whitelistedIps.contains(ip);
|
||||||
|
}
|
||||||
|
|
||||||
public void checkIp(String ip, boolean cachedResults, Consumer<VPNResponse> result) {
|
public void checkIp(String ip, boolean cachedResults, Consumer<VPNResponse> result) {
|
||||||
threadExecutor.execute(() -> result.accept(responseCache.compute(ip, (key, val) -> {
|
threadExecutor.execute(() -> result.accept(responseCache.compute(ip, (key, val) -> {
|
||||||
if(val == null) {
|
if(val == null) {
|
||||||
@@ -42,17 +51,17 @@ public abstract class VPNExecutor {
|
|||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
VPNResponse response = AntiVPN
|
VPNResponse response = AntiVPN
|
||||||
.getVPNResponse(ip, AntiVPN.getInstance().getConfig().getLicense(), cachedResults);
|
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||||
|
|
||||||
if(response.isSuccess()) {
|
if(response.isSuccess()) {
|
||||||
AntiVPN.getInstance().getDatabase().cacheResponse(response);
|
AntiVPN.getInstance().getDatabase().cacheResponse(response);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
|
log("Query to VPN API failed! Reason: " + response.getFailureReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (JSONException | IOException e) {
|
} catch (JSONException | IOException e) {
|
||||||
System.out.println("Query to VPN API failed! Reason: Java Exception");
|
log("Query to VPN API failed! Reason: Java Exception");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,17 +80,17 @@ public abstract class VPNExecutor {
|
|||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
VPNResponse response = AntiVPN
|
VPNResponse response = AntiVPN
|
||||||
.getVPNResponse(ip, AntiVPN.getInstance().getConfig().getLicense(), cachedResults);
|
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||||
|
|
||||||
if(response.isSuccess()) {
|
if(response.isSuccess()) {
|
||||||
threadExecutor.execute(() -> AntiVPN.getInstance().getDatabase().cacheResponse(response));
|
threadExecutor.execute(() -> AntiVPN.getInstance().getDatabase().cacheResponse(response));
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Query to VPN API failed! Reason: " + response.getFailureReason());
|
log("Query to VPN API failed! Reason: " + response.getFailureReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (JSONException | IOException e) {
|
} catch (JSONException | IOException e) {
|
||||||
System.out.println("Query to VPN API failed! Reason: Java Exception");
|
log("Query to VPN API failed! Reason: Java Exception");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dev.brighten.antivpn.AntiVPN;
|
|||||||
import dev.brighten.antivpn.api.APIPlayer;
|
import dev.brighten.antivpn.api.APIPlayer;
|
||||||
import dev.brighten.antivpn.command.Command;
|
import dev.brighten.antivpn.command.Command;
|
||||||
import dev.brighten.antivpn.command.CommandExecutor;
|
import dev.brighten.antivpn.command.CommandExecutor;
|
||||||
|
import dev.brighten.antivpn.utils.MiscUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -34,7 +35,7 @@ public class AllowlistCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String usage() {
|
public String usage() {
|
||||||
return "<add/remove> <player/uuid>";
|
return "<add/remove> <player/uuid/ip>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,45 +51,97 @@ public class AllowlistCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public String execute(CommandExecutor executor, String[] args) {
|
public String execute(CommandExecutor executor, String[] args) {
|
||||||
if(args.length == 0 || Arrays.stream(secondArgs).noneMatch(arg -> arg.equalsIgnoreCase(args[0]))) {
|
if(args.length == 0 || Arrays.stream(secondArgs).noneMatch(arg -> arg.equalsIgnoreCase(args[0]))) {
|
||||||
return "&cUsage: /antivpn allowlist <add/remove> <player>";
|
return "&cUsage: /antivpn allowlist " + usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.length == 1)
|
if(args.length == 1)
|
||||||
return "&cYou have to provide a player to allow or deny exemption.";
|
return "&cYou have to provide a player to allow or deny exemption.";
|
||||||
|
|
||||||
boolean databaseEnabled = AntiVPN.getInstance().getConfig().isDatabaseEnabled();
|
boolean databaseEnabled = AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled();
|
||||||
|
|
||||||
if(!databaseEnabled) executor.sendMessage("&cThe database is currently not setup, " +
|
if(!databaseEnabled) executor.sendMessage("&cThe database is currently not setup, " +
|
||||||
"so any changes here will disappear after a restart.");
|
"so any changes here will disappear after a restart.");
|
||||||
|
|
||||||
UUID uuid = null;
|
if(MiscUtils.isIpv4(args[1])) {
|
||||||
try {
|
if(!databaseEnabled) {
|
||||||
uuid = UUID.fromString(args[1]);
|
switch(args[0].toLowerCase()) {
|
||||||
} catch(IllegalArgumentException e) {
|
case "add":
|
||||||
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
case "insert": {
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(args[1]);
|
||||||
if(!player.isPresent()) {
|
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true);
|
||||||
return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID.";
|
return String.format("&aAdded &6%s &ato the exemption allowlist.", args[1]);
|
||||||
}
|
}
|
||||||
|
case "remove":
|
||||||
uuid = player.get().getUuid();
|
case "delete": {
|
||||||
}
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(args[1]);
|
||||||
|
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false);
|
||||||
if(!databaseEnabled) {
|
return String.format("&cRemoved &6%s &cfrom the exemption allowlist.", args[1]);
|
||||||
if(args[0].equalsIgnoreCase("add")) {
|
}
|
||||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
default: {
|
||||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
switch(args[0].toLowerCase()) {
|
||||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
case "add":
|
||||||
|
case "insert": {
|
||||||
|
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true);
|
||||||
|
return String.format("&aAdded &6%s &a to the exemption allowlist.", args[1]);
|
||||||
|
}
|
||||||
|
case "remove":
|
||||||
|
case "delete": {
|
||||||
|
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false);
|
||||||
|
return String.format("&cRemoved &6%s &c from the exemption allowlist.", args[1]);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(args[0].equalsIgnoreCase("add")) {
|
UUID uuid = null;
|
||||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, true);
|
try {
|
||||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
uuid = UUID.fromString(args[1]);
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
||||||
|
|
||||||
|
if(!player.isPresent()) {
|
||||||
|
return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID.";
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid = player.get().getUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!databaseEnabled) {
|
||||||
|
switch(args[0].toLowerCase()) {
|
||||||
|
case "add": {
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||||
|
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||||
|
}
|
||||||
|
case "remove":
|
||||||
|
case "delete": {
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||||
|
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, false);
|
switch(args[0].toLowerCase()) {
|
||||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
case "add": {
|
||||||
|
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, true);
|
||||||
|
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||||
|
}
|
||||||
|
case "remove":
|
||||||
|
case "delete": {
|
||||||
|
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, false);
|
||||||
|
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ public class AntiVPNCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command[] children() {
|
public Command[] children() {
|
||||||
return new Command[] {new LookupCommand(), new AllowlistCommand(), new AlertsCommand()};
|
return new Command[] {new LookupCommand(), new AllowlistCommand(), new AlertsCommand(),
|
||||||
|
new ClearCacheCommand()};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package dev.brighten.antivpn.command.impl;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.command.Command;
|
||||||
|
import dev.brighten.antivpn.command.CommandExecutor;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClearCacheCommand extends Command {
|
||||||
|
@Override
|
||||||
|
public String permission() {
|
||||||
|
return "antivpn.command.clearcache";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "clearcache";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] aliases() {
|
||||||
|
return new String[] {"clear", "cc"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Clear the API response cache if you're having problems.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String parent() {
|
||||||
|
return "antivpn";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Command[] children() {
|
||||||
|
return new Command[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(CommandExecutor executor, String[] args) {
|
||||||
|
AntiVPN.getInstance().getDatabase().clearResponses();
|
||||||
|
VPNExecutor.responseCache.clear();
|
||||||
|
return "&aCleared all cached API response information!";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(CommandExecutor executor, String alias, String[] args) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,18 +14,28 @@ public interface VPNDatabase {
|
|||||||
|
|
||||||
boolean isWhitelisted(UUID uuid);
|
boolean isWhitelisted(UUID uuid);
|
||||||
|
|
||||||
|
boolean isWhitelisted(String ip);
|
||||||
|
|
||||||
void setWhitelisted(UUID uuid, boolean whitelisted);
|
void setWhitelisted(UUID uuid, boolean whitelisted);
|
||||||
|
|
||||||
|
void setWhitelisted(String ip, boolean whitelisted);
|
||||||
|
|
||||||
List<UUID> getAllWhitelisted();
|
List<UUID> getAllWhitelisted();
|
||||||
|
|
||||||
|
List<String> getAllWhitelistedIps();
|
||||||
|
|
||||||
void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result);
|
void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result);
|
||||||
|
|
||||||
void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result);
|
void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result);
|
||||||
|
|
||||||
|
void isWhitelistedAsync(String ip, Consumer<Boolean> result);
|
||||||
|
|
||||||
void alertsState(UUID uuid, Consumer<Boolean> result);
|
void alertsState(UUID uuid, Consumer<Boolean> result);
|
||||||
|
|
||||||
void updateAlertsState(UUID uuid, boolean state);
|
void updateAlertsState(UUID uuid, boolean state);
|
||||||
|
|
||||||
|
void clearResponses();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
package dev.brighten.antivpn.database.mongo;
|
||||||
|
|
||||||
|
import com.mongodb.*;
|
||||||
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
import com.mongodb.client.model.Indexes;
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.database.VPNDatabase;
|
||||||
|
import dev.brighten.antivpn.utils.VPNResponse;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class MongoVPN implements VPNDatabase {
|
||||||
|
|
||||||
|
private MongoCollection<Document> settingsDocument, cacheDocument;
|
||||||
|
private MongoClient client;
|
||||||
|
private MongoDatabase antivpnDatabase;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<VPNResponse> getStoredResponse(String ip) {
|
||||||
|
Document rdoc = cacheDocument.find(Filters.eq("ip", ip)).first();
|
||||||
|
|
||||||
|
if(rdoc != null) {
|
||||||
|
return Optional.of(VPNResponse.builder().asn(rdoc.getString("asn")).ip(ip)
|
||||||
|
.countryName(rdoc.getString("countryName"))
|
||||||
|
.countryCode(rdoc.getString("countryCode"))
|
||||||
|
.city(rdoc.getString("city"))
|
||||||
|
.isp(rdoc.getString("isp"))
|
||||||
|
.method(rdoc.getString("method"))
|
||||||
|
.timeZone(rdoc.getString("timeZone"))
|
||||||
|
.proxy(rdoc.getBoolean("proxy"))
|
||||||
|
.cached(rdoc.getBoolean("cached"))
|
||||||
|
.success(true)
|
||||||
|
.latitude(rdoc.getDouble("latitude"))
|
||||||
|
.longitude(rdoc.getDouble("longitude"))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cacheResponse(VPNResponse toCache) {
|
||||||
|
Document rdoc = new Document("ip", toCache.getIp());
|
||||||
|
|
||||||
|
rdoc.put("asn", toCache.getAsn());
|
||||||
|
rdoc.put("countryName", toCache.getCountryName());
|
||||||
|
rdoc.put("countryCode", toCache.getCountryCode());
|
||||||
|
rdoc.put("city", toCache.getCity());
|
||||||
|
rdoc.put("isp", toCache.getIsp());
|
||||||
|
rdoc.put("method", toCache.getMethod());
|
||||||
|
rdoc.put("timeZone", toCache.getTimeZone());
|
||||||
|
rdoc.put("proxy", toCache.isProxy());
|
||||||
|
rdoc.put("cached", toCache.isCached());
|
||||||
|
rdoc.put("success", toCache.isSuccess());
|
||||||
|
rdoc.put("latitude", toCache.getLatitude());
|
||||||
|
rdoc.put("longitude", toCache.getLongitude());
|
||||||
|
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> {
|
||||||
|
cacheDocument.deleteMany(Filters.eq("ip", toCache.getIp()));
|
||||||
|
cacheDocument.insertOne(rdoc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelisted(UUID uuid) {
|
||||||
|
return settingsDocument
|
||||||
|
.find(Filters.and(Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.eq("uuid", uuid.toString()))).first() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelisted(String ip) {
|
||||||
|
return settingsDocument
|
||||||
|
.find(Filters.and(Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.eq("ip", ip))).first() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWhitelisted(UUID uuid, boolean whitelisted) {
|
||||||
|
if(whitelisted) {
|
||||||
|
Document wdoc = new Document("setting", "whitelist");
|
||||||
|
wdoc.put("uuid", uuid.toString());
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> settingsDocument.insertOne(wdoc));
|
||||||
|
} else {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> settingsDocument.deleteMany(Filters
|
||||||
|
.and(
|
||||||
|
Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.eq("uuid", uuid.toString()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWhitelisted(String ip, boolean whitelisted) {
|
||||||
|
if(whitelisted) {
|
||||||
|
Document wdoc = new Document("setting", "whitelist");
|
||||||
|
wdoc.put("ip", ip);
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> settingsDocument.insertOne(wdoc));
|
||||||
|
} else {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> settingsDocument.deleteMany(Filters
|
||||||
|
.and(
|
||||||
|
Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.eq("ip", ip))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UUID> getAllWhitelisted() {
|
||||||
|
List<UUID> uuids = new ArrayList<>();
|
||||||
|
settingsDocument.find(Filters.and(Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.exists("uuid")))
|
||||||
|
.forEach((Consumer<? super Document>) doc -> uuids.add(UUID.fromString(doc.getString("uuid"))));
|
||||||
|
return uuids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAllWhitelistedIps() {
|
||||||
|
List<String> ips = new ArrayList<>();
|
||||||
|
settingsDocument.find(Filters.and(Filters.eq("setting", "whitelist"),
|
||||||
|
Filters.exists("ip")))
|
||||||
|
.forEach((Consumer<? super Document>) doc -> ips.add(doc.getString("ip")));
|
||||||
|
return ips;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result) {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result) {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isWhitelistedAsync(String ip, Consumer<Boolean> result) {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void alertsState(UUID uuid, Consumer<Boolean> result) {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> result.accept(settingsDocument
|
||||||
|
.find(Filters.and(Filters.eq("setting", "alerts"),
|
||||||
|
Filters.eq("uuid", uuid.toString()))).first() != null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAlertsState(UUID uuid, boolean state) {
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> {
|
||||||
|
settingsDocument.deleteMany(Filters.and(Filters.eq("setting", "alerts"),
|
||||||
|
Filters.eq("uuid", uuid.toString())));
|
||||||
|
if(state) {
|
||||||
|
Document adoc = new Document("setting", "alerts");
|
||||||
|
|
||||||
|
adoc.put("uuid", uuid.toString());
|
||||||
|
settingsDocument.insertOne(adoc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearResponses() {
|
||||||
|
cacheDocument.deleteMany(Filters.exists("ip"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().mongoDatabaseURL().length() > 0) { //URL
|
||||||
|
ConnectionString cs = new ConnectionString(AntiVPN.getInstance().getVpnConfig().mongoDatabaseURL());
|
||||||
|
MongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(cs).build();
|
||||||
|
client = MongoClients.create(settings);
|
||||||
|
} else {
|
||||||
|
MongoClientSettings.Builder settingsBld = MongoClientSettings.builder().readPreference(ReadPreference.nearest())
|
||||||
|
.applyToClusterSettings(builder -> {
|
||||||
|
builder.hosts(Collections.singletonList(new ServerAddress(AntiVPN.getInstance().getVpnConfig().getIp(),
|
||||||
|
AntiVPN.getInstance().getVpnConfig().getPort())));
|
||||||
|
});
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().useDatabaseCreds()) {
|
||||||
|
settingsBld = settingsBld.credential(MongoCredential
|
||||||
|
.createCredential(AntiVPN.getInstance().getVpnConfig().getUsername(),
|
||||||
|
AntiVPN.getInstance().getVpnConfig().getDatabaseName(),
|
||||||
|
AntiVPN.getInstance().getVpnConfig().getPassword().toCharArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
client = MongoClients.create(settingsBld.build());
|
||||||
|
}
|
||||||
|
antivpnDatabase = client.getDatabase(AntiVPN.getInstance().getVpnConfig().getDatabaseName());
|
||||||
|
|
||||||
|
settingsDocument = antivpnDatabase.getCollection("settings");
|
||||||
|
if(settingsDocument.listIndexes().first() == null) {
|
||||||
|
AntiVPN.getInstance().getExecutor().log("Created index for settings collection!");
|
||||||
|
settingsDocument.createIndex(Indexes.ascending("ip"));
|
||||||
|
}
|
||||||
|
cacheDocument = antivpnDatabase.getCollection("cache");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
settingsDocument = null;
|
||||||
|
cacheDocument = null;
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,16 +20,19 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
public MySqlVPN() {
|
public MySqlVPN() {
|
||||||
whitelistedThread = new Thread(() -> {
|
whitelistedThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(8));
|
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
// Updating from database
|
// Updating from database
|
||||||
if (AntiVPN.getInstance().getConfig().isDatabaseEnabled()) {
|
if (AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) {
|
||||||
AntiVPN.getInstance().getExecutor().getWhitelisted().clear();
|
AntiVPN.getInstance().getExecutor().getWhitelisted().clear();
|
||||||
AntiVPN.getInstance().getExecutor().getWhitelisted()
|
AntiVPN.getInstance().getExecutor().getWhitelisted()
|
||||||
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelisted());
|
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelisted());
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps().clear();
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps()
|
||||||
|
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelistedIps());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(4));
|
Thread.sleep(TimeUnit.SECONDS.toMillis(4));
|
||||||
@@ -44,7 +47,7 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<VPNResponse> getStoredResponse(String ip) {
|
public Optional<VPNResponse> getStoredResponse(String ip) {
|
||||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip).executeQuery();
|
ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip).executeQuery();
|
||||||
@@ -78,7 +81,7 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void cacheResponse(VPNResponse toCache) {
|
public void cacheResponse(VPNResponse toCache) {
|
||||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
||||||
@@ -93,17 +96,30 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public boolean isWhitelisted(UUID uuid) {
|
public boolean isWhitelisted(UUID uuid) {
|
||||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
return false;
|
return false;
|
||||||
ResultSet set = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1").append(uuid.toString())
|
ResultSet set = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1")
|
||||||
.executeQuery();
|
.append(uuid.toString()).executeQuery();
|
||||||
|
|
||||||
return set != null && set.next() && set.getString("uuid") != null;
|
return set != null && set.next() && set.getString("uuid") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelisted(String ip) {
|
||||||
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
|
return false;
|
||||||
|
ResultSet set = Query.prepare("select `ip` from `whitelisted-ips` where `ip` = ? limit 1")
|
||||||
|
.append(ip).executeQuery();
|
||||||
|
|
||||||
|
|
||||||
|
return set != null && set.next() && set.getString("ip") != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWhitelisted(UUID uuid, boolean whitelisted) {
|
public void setWhitelisted(UUID uuid, boolean whitelisted) {
|
||||||
if(MySQL.isClosed()) return;
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
|
return;
|
||||||
|
|
||||||
if (whitelisted) {
|
if (whitelisted) {
|
||||||
if (!isWhitelisted(uuid)) {
|
if (!isWhitelisted(uuid)) {
|
||||||
@@ -116,24 +132,42 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWhitelisted(String ip, boolean whitelisted) {
|
||||||
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(whitelisted) {
|
||||||
|
if(!isWhitelisted(ip)) {
|
||||||
|
Query.prepare("insert into `whitelisted-ips` (`ip`) values (?)").append(ip).execute();
|
||||||
|
}
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(ip);
|
||||||
|
} else {
|
||||||
|
Query.prepare("delete from `whitelisted-ips` where `ip` = ?").append(ip).execute();
|
||||||
|
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UUID> getAllWhitelisted() {
|
public List<UUID> getAllWhitelisted() {
|
||||||
List<UUID> uuids = new ArrayList<>();
|
List<UUID> uuids = new ArrayList<>();
|
||||||
|
|
||||||
if(MySQL.isClosed()) return uuids;
|
if(!MySQL.isClosed()) Query.prepare("select uuid from `whitelisted`")
|
||||||
|
.execute(set -> uuids.add(UUID.fromString(set.getString("uuid"))));
|
||||||
|
|
||||||
ResultSet set = Query.prepare("select uuid from `whitelisted`").executeQuery();
|
|
||||||
|
|
||||||
try {
|
|
||||||
while (set.next()) {
|
|
||||||
uuids.add(UUID.fromString(set.getString("uuid")));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAllWhitelistedIps() {
|
||||||
|
List<String> ips = new ArrayList<>();
|
||||||
|
|
||||||
|
if(!MySQL.isClosed()) Query.prepare("select `ip` from `whitelisted-ips`")
|
||||||
|
.execute(set -> ips.add(set.getString("ip")));
|
||||||
|
|
||||||
|
return ips;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result) {
|
public void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result) {
|
||||||
if(MySQL.isClosed()) return;
|
if(MySQL.isClosed()) return;
|
||||||
@@ -148,6 +182,13 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid)));
|
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isWhitelistedAsync(String ip, Consumer<Boolean> result) {
|
||||||
|
if(MySQL.isClosed()) return;
|
||||||
|
|
||||||
|
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void alertsState(UUID uuid, Consumer<Boolean> result) {
|
public void alertsState(UUID uuid, Consumer<Boolean> result) {
|
||||||
if(MySQL.isClosed()) return;
|
if(MySQL.isClosed()) return;
|
||||||
@@ -185,74 +226,105 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void clearResponses() {
|
||||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled())
|
if(MySQL.isClosed()) return;
|
||||||
return;
|
|
||||||
System.out.println("Initializing MySQL...");
|
|
||||||
MySQL.init();
|
|
||||||
|
|
||||||
System.out.println("Creating tables...");
|
VPNExecutor.threadExecutor.execute(() -> Query.prepare("delete from `responses`").execute());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||||
|
return;
|
||||||
|
AntiVPN.getInstance().getExecutor().log("Initializing MySQL...");
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().getDatabaseType().contains("sql")) {
|
||||||
|
MySQL.init();
|
||||||
|
} else MySQL.initH2();
|
||||||
|
|
||||||
|
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||||
|
|
||||||
//Running check for old table types to update
|
//Running check for old table types to update
|
||||||
oldTableCheck: {
|
oldTableCheck: {
|
||||||
Query.prepare("select `DATA_TYPE` from INFORMATION_SCHEMA.COLUMNS " +
|
Query.prepare("select `DATA_TYPE` from INFORMATION_SCHEMA.COLUMNS " +
|
||||||
"WHERE table_name = 'responses' AND COLUMN_NAME = 'isp';").execute(set -> {
|
"WHERE table_name = 'responses' AND COLUMN_NAME = 'isp';").execute(set -> {
|
||||||
if(set.getObject("DATA_TYPE").toString().contains("varchar")) {
|
if(set.getObject("DATA_TYPE").toString().contains("varchar")) {
|
||||||
System.out.println("Using old database format for storing responses! " +
|
AntiVPN.getInstance().getExecutor().log("Using old database format for storing responses! " +
|
||||||
"Dropping table and creating a new one...");
|
"Dropping table and creating a new one...");
|
||||||
if(Query.prepare("drop table `responses`").execute() > 0) {
|
if(Query.prepare("drop table `responses`").execute() > 0) {
|
||||||
System.out.println("Successfully dropped table!");
|
AntiVPN.getInstance().getExecutor().log("Successfully dropped table!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Query.prepare("create table if not exists `whitelisted` (`uuid` varchar(36) not null)").execute();
|
Query.prepare("create table if not exists `whitelisted` (`uuid` varchar(36) not null)").execute();
|
||||||
|
Query.prepare("create table if not exists `whitelisted-ips` (`ip` varchar(45) not null)").execute();
|
||||||
Query.prepare("create table if not exists `responses` (`ip` varchar(45) not null, `asn` varchar(12),"
|
Query.prepare("create table if not exists `responses` (`ip` varchar(45) not null, `asn` varchar(12),"
|
||||||
+ "`countryName` text, `countryCode` varchar(10), `city` text, `timeZone` varchar(64), "
|
+ "`countryName` text, `countryCode` varchar(10), `city` text, `timeZone` varchar(64), "
|
||||||
+ "`method` varchar(32), `isp` text, `proxy` boolean, `cached` boolean, `inserted` timestamp,"
|
+ "`method` varchar(32), `isp` text, `proxy` boolean, `cached` boolean, `inserted` timestamp,"
|
||||||
+ "`latitude` double, `longitude` double)").execute();
|
+ "`latitude` double, `longitude` double)").execute();
|
||||||
Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)").execute();
|
Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)").execute();
|
||||||
|
|
||||||
System.out.println("Creating indexes...");
|
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
|
||||||
try {
|
try {
|
||||||
// Ref:
|
// Ref:
|
||||||
// https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
|
// https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
|
||||||
String query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='whitelisted' AND index_name='uuid_1';";
|
|
||||||
|
String query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||||
|
" AND table_name='whitelisted' AND index_name='uuid_1';";
|
||||||
ResultSet rs = Query.prepare(query).executeQuery();
|
ResultSet rs = Query.prepare(query).executeQuery();
|
||||||
int id = 0;
|
int id = 0;
|
||||||
while (rs.next()) {
|
whitelistedIndex: {
|
||||||
id = rs.getInt("IndexExists");
|
while (rs.next()) {
|
||||||
|
id = rs.getInt("IndexExists");
|
||||||
|
}
|
||||||
|
if (id == 0) {
|
||||||
|
Query.prepare("create index `uuid_1` on `whitelisted` (`uuid`)").execute();
|
||||||
|
}
|
||||||
|
id = 0;
|
||||||
}
|
}
|
||||||
if (id == 0) {
|
responsesIndex: {
|
||||||
Query.prepare("create index `uuid_1` on `whitelisted` (`uuid`)").execute();
|
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " +
|
||||||
|
"AND table_name='responses' AND index_name='ip_1';";
|
||||||
|
rs = Query.prepare(query).executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
id = rs.getInt("IndexExists");
|
||||||
|
}
|
||||||
|
if (id == 0) {
|
||||||
|
Query.prepare("create index `ip_1` on `responses` (`ip`)").execute();
|
||||||
|
}
|
||||||
|
id = 0;
|
||||||
|
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " +
|
||||||
|
"AND table_name='responses' AND index_name='proxy_1';";
|
||||||
|
rs = Query.prepare(query).executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
id = rs.getInt("IndexExists");
|
||||||
|
}
|
||||||
|
if (id == 0) {
|
||||||
|
Query.prepare("create index `proxy_1` on `responses` (`proxy`)").execute();
|
||||||
|
}
|
||||||
|
id = 0;
|
||||||
|
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||||
|
" AND table_name='responses' AND index_name='inserted_1';";
|
||||||
|
rs = Query.prepare(query).executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
id = rs.getInt("IndexExists");
|
||||||
|
}
|
||||||
|
if (id == 0) {
|
||||||
|
Query.prepare("create index `inserted_1` on `responses` (`inserted`)").execute();
|
||||||
|
}
|
||||||
|
id = 0;
|
||||||
}
|
}
|
||||||
id = 0;
|
whitelistedIpsIndex: {
|
||||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='ip_1';";
|
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||||
rs = Query.prepare(query).executeQuery();
|
" AND table_name='whitelisted-ips' AND index_name='ip_1';";
|
||||||
while (rs.next()) {
|
rs = Query.prepare(query).executeQuery();
|
||||||
id = rs.getInt("IndexExists");
|
while (rs.next()) {
|
||||||
}
|
id = rs.getInt("IndexExists");
|
||||||
if (id == 0) {
|
}
|
||||||
Query.prepare("create index `ip_1` on `responses` (`ip`)").execute();
|
if (id == 0) {
|
||||||
}
|
Query.prepare("create index `ip_1` on `whitelisted-ips` (`ip`)").execute();
|
||||||
id = 0;
|
}
|
||||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='proxy_1';";
|
|
||||||
rs = Query.prepare(query).executeQuery();
|
|
||||||
while (rs.next()) {
|
|
||||||
id = rs.getInt("IndexExists");
|
|
||||||
}
|
|
||||||
if (id == 0) {
|
|
||||||
Query.prepare("create index `proxy_1` on `responses` (`proxy`)").execute();
|
|
||||||
}
|
|
||||||
id = 0;
|
|
||||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='inserted_1';";
|
|
||||||
rs = Query.prepare(query).executeQuery();
|
|
||||||
while (rs.next()) {
|
|
||||||
id = rs.getInt("IndexExists");
|
|
||||||
}
|
|
||||||
if (id == 0) {
|
|
||||||
Query.prepare("create index `inserted_1` on `responses` (`inserted`)").execute();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("MySQL Excepton created" + e.getMessage());
|
System.err.println("MySQL Excepton created" + e.getMessage());
|
||||||
@@ -261,7 +333,7 @@ public class MySqlVPN implements VPNDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||||
return;
|
return;
|
||||||
MySQL.shutdown();
|
MySQL.shutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package dev.brighten.antivpn.database.sql.utils;
|
package dev.brighten.antivpn.database.sql.utils;
|
||||||
|
|
||||||
|
import org.h2.jdbc.JdbcConnection;
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public class MySQL {
|
public class MySQL {
|
||||||
private static Connection conn;
|
private static Connection conn;
|
||||||
@@ -12,24 +15,47 @@ public class MySQL {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
try {
|
try {
|
||||||
if (conn == null || conn.isClosed()) {
|
if (conn == null || conn.isClosed()) {
|
||||||
conn = DriverManager.getConnection("jdbc:mysql://" + AntiVPN.getInstance().getConfig().getIp()
|
try {
|
||||||
+ ":" + AntiVPN.getInstance().getConfig().getPort()
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
}
|
||||||
|
conn = DriverManager.getConnection("jdbc:mysql://" + AntiVPN.getInstance().getVpnConfig().getIp()
|
||||||
|
+ ":" + AntiVPN.getInstance().getVpnConfig().getPort()
|
||||||
+ "/?useSSL=true&autoReconnect=true",
|
+ "/?useSSL=true&autoReconnect=true",
|
||||||
AntiVPN.getInstance().getConfig().getUsername(),
|
AntiVPN.getInstance().getVpnConfig().getUsername(),
|
||||||
AntiVPN.getInstance().getConfig().getPassword());
|
AntiVPN.getInstance().getVpnConfig().getPassword());
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
Query.use(conn);
|
Query.use(conn);
|
||||||
Query.prepare("CREATE DATABASE IF NOT EXISTS `"
|
Query.prepare("CREATE DATABASE IF NOT EXISTS `"
|
||||||
+ AntiVPN.getInstance().getConfig().getDatabaseName() + "`").execute();
|
+ AntiVPN.getInstance().getVpnConfig().getDatabaseName() + "`").execute();
|
||||||
Query.prepare("USE `" + AntiVPN.getInstance().getConfig().getDatabaseName() + "`").execute();
|
Query.prepare("USE `" + AntiVPN.getInstance().getVpnConfig().getDatabaseName() + "`").execute();
|
||||||
System.out.println("Connection to MySQL has been established.");
|
AntiVPN.getInstance().getExecutor().log("Connection to MySQL has been established.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Failed to load mysql: " + e.getMessage());
|
AntiVPN.getInstance().getExecutor().log("Failed to load mysql: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void initH2() {
|
||||||
|
File dataFolder = new File(AntiVPN.getInstance().getPluginFolder(), "databases" + File.separator + "database");
|
||||||
|
try {
|
||||||
|
Class.forName("org.h2.Driver");
|
||||||
|
conn = new NonClosableConnection(DriverManager.getConnection ("jdbc:h2:file:" +
|
||||||
|
dataFolder.getAbsolutePath(),
|
||||||
|
AntiVPN.getInstance().getVpnConfig().getUsername(),AntiVPN.getInstance().getVpnConfig().getPassword()));
|
||||||
|
conn.setAutoCommit(true);
|
||||||
|
Query.use(conn);
|
||||||
|
AntiVPN.getInstance().getExecutor().log("Connection to SQlLite has been established.");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
AntiVPN.getInstance().getExecutor().log("SQLite exception on initialize");
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
AntiVPN.getInstance().getExecutor().log("No H2 library found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void use() {
|
public static void use() {
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
@@ -41,7 +67,9 @@ public class MySQL {
|
|||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
try {
|
try {
|
||||||
if(conn != null && !conn.isClosed()) {
|
if(conn != null && !conn.isClosed()) {
|
||||||
conn.close();
|
if(conn instanceof NonClosableConnection) {
|
||||||
|
((NonClosableConnection)conn).shutdown();
|
||||||
|
} else conn.close();
|
||||||
conn = null;
|
conn = null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+122
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.brighten.antivpn.database.sql.utils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper around a {@link Connection} which blocks usage of the default {@link #close()} method.
|
||||||
|
*/
|
||||||
|
public class NonClosableConnection implements Connection {
|
||||||
|
private final Connection delegate;
|
||||||
|
|
||||||
|
public NonClosableConnection(Connection delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually {@link #close() closes} the underlying connection.
|
||||||
|
*/
|
||||||
|
public final void shutdown() throws SQLException {
|
||||||
|
this.delegate.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void close() throws SQLException {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||||
|
return iface.isInstance(this.delegate) || this.delegate.isWrapperFor(iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public final <T> T unwrap(Class<T> iface) throws SQLException {
|
||||||
|
if (iface.isInstance(this.delegate)) {
|
||||||
|
return (T) this.delegate;
|
||||||
|
}
|
||||||
|
return this.delegate.unwrap(iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward to the delegate connection
|
||||||
|
@Override public Statement createStatement() throws SQLException { return this.delegate.createStatement(); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql) throws SQLException { return this.delegate.prepareStatement(sql); }
|
||||||
|
@Override public CallableStatement prepareCall(String sql) throws SQLException { return this.delegate.prepareCall(sql); }
|
||||||
|
@Override public String nativeSQL(String sql) throws SQLException { return this.delegate.nativeSQL(sql); }
|
||||||
|
@Override public void setAutoCommit(boolean autoCommit) throws SQLException { this.delegate.setAutoCommit(autoCommit); }
|
||||||
|
@Override public boolean getAutoCommit() throws SQLException { return this.delegate.getAutoCommit(); }
|
||||||
|
@Override public void commit() throws SQLException { this.delegate.commit(); }
|
||||||
|
@Override public void rollback() throws SQLException { this.delegate.rollback(); }
|
||||||
|
@Override public boolean isClosed() throws SQLException { return this.delegate.isClosed(); }
|
||||||
|
@Override public DatabaseMetaData getMetaData() throws SQLException { return this.delegate.getMetaData(); }
|
||||||
|
@Override public void setReadOnly(boolean readOnly) throws SQLException { this.delegate.setReadOnly(readOnly); }
|
||||||
|
@Override public boolean isReadOnly() throws SQLException { return this.delegate.isReadOnly(); }
|
||||||
|
@Override public void setCatalog(String catalog) throws SQLException { this.delegate.setCatalog(catalog); }
|
||||||
|
@Override public String getCatalog() throws SQLException { return this.delegate.getCatalog(); }
|
||||||
|
@Override public void setTransactionIsolation(int level) throws SQLException { this.delegate.setTransactionIsolation(level); }
|
||||||
|
@Override public int getTransactionIsolation() throws SQLException { return this.delegate.getTransactionIsolation(); }
|
||||||
|
@Override public SQLWarning getWarnings() throws SQLException { return this.delegate.getWarnings(); }
|
||||||
|
@Override public void clearWarnings() throws SQLException { this.delegate.clearWarnings(); }
|
||||||
|
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.createStatement(resultSetType, resultSetConcurrency); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.prepareStatement(sql, resultSetType, resultSetConcurrency); }
|
||||||
|
@Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.prepareCall(sql, resultSetType, resultSetConcurrency); }
|
||||||
|
@Override public Map<String, Class<?>> getTypeMap() throws SQLException { return this.delegate.getTypeMap(); }
|
||||||
|
@Override public void setTypeMap(Map<String, Class<?>> map) throws SQLException { this.delegate.setTypeMap(map); }
|
||||||
|
@Override public void setHoldability(int holdability) throws SQLException { this.delegate.setHoldability(holdability); }
|
||||||
|
@Override public int getHoldability() throws SQLException { return this.delegate.getHoldability(); }
|
||||||
|
@Override public Savepoint setSavepoint() throws SQLException { return this.delegate.setSavepoint(); }
|
||||||
|
@Override public Savepoint setSavepoint(String name) throws SQLException { return this.delegate.setSavepoint(name); }
|
||||||
|
@Override public void rollback(Savepoint savepoint) throws SQLException { this.delegate.rollback(savepoint); }
|
||||||
|
@Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { this.delegate.releaseSavepoint(savepoint); }
|
||||||
|
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||||
|
@Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return this.delegate.prepareStatement(sql, autoGeneratedKeys); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { return this.delegate.prepareStatement(sql, columnIndexes); }
|
||||||
|
@Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { return this.delegate.prepareStatement(sql, columnNames); }
|
||||||
|
@Override public Clob createClob() throws SQLException { return this.delegate.createClob(); }
|
||||||
|
@Override public Blob createBlob() throws SQLException { return this.delegate.createBlob(); }
|
||||||
|
@Override public NClob createNClob() throws SQLException { return this.delegate.createNClob(); }
|
||||||
|
@Override public SQLXML createSQLXML() throws SQLException { return this.delegate.createSQLXML(); }
|
||||||
|
@Override public boolean isValid(int timeout) throws SQLException { return this.delegate.isValid(timeout); }
|
||||||
|
@Override public void setClientInfo(String name, String value) throws SQLClientInfoException { this.delegate.setClientInfo(name, value); }
|
||||||
|
@Override public void setClientInfo(Properties properties) throws SQLClientInfoException { this.delegate.setClientInfo(properties); }
|
||||||
|
@Override public String getClientInfo(String name) throws SQLException { return this.delegate.getClientInfo(name); }
|
||||||
|
@Override public Properties getClientInfo() throws SQLException { return this.delegate.getClientInfo(); }
|
||||||
|
@Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return this.delegate.createArrayOf(typeName, elements); }
|
||||||
|
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return this.delegate.createStruct(typeName, attributes); }
|
||||||
|
@Override public void setSchema(String schema) throws SQLException { this.delegate.setSchema(schema); }
|
||||||
|
@Override public String getSchema() throws SQLException { return this.delegate.getSchema(); }
|
||||||
|
@Override public void abort(Executor executor) throws SQLException { this.delegate.abort(executor); }
|
||||||
|
@Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { this.delegate.setNetworkTimeout(executor, milliseconds); }
|
||||||
|
@Override public int getNetworkTimeout() throws SQLException { return this.delegate.getNetworkTimeout(); }
|
||||||
|
|
||||||
|
}
|
||||||
+3
-3
@@ -1,14 +1,14 @@
|
|||||||
package dev.brighten.antivpn.bukkit.util;
|
package dev.brighten.antivpn.utils;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ConfigDefault<A> {
|
public class ConfigDefault<A> {
|
||||||
|
|
||||||
private final A defaultValue;
|
private final A defaultValue;
|
||||||
private final String path;
|
private final String path;
|
||||||
private final Plugin plugin;
|
private final AntiVPN plugin;
|
||||||
|
|
||||||
public A get() {
|
public A get() {
|
||||||
if(plugin.getConfig().get(path) != null)
|
if(plugin.getConfig().get(path) != null)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.brighten.antivpn.utils;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class EvictingMap<K, V> extends LinkedHashMap<K, V> {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int size;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
|
||||||
|
return size() >= size;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,19 @@
|
|||||||
package dev.brighten.antivpn.utils;
|
package dev.brighten.antivpn.utils;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MiscUtils {
|
public class MiscUtils {
|
||||||
|
|
||||||
|
private static final Pattern ipv4 = Pattern.compile("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
|
||||||
|
|
||||||
public static void close(Closeable... closeables) {
|
public static void close(Closeable... closeables) {
|
||||||
try {
|
try {
|
||||||
for (Closeable closeable : closeables) if (closeable != null) closeable.close();
|
for (Closeable closeable : closeables) if (closeable != null) closeable.close();
|
||||||
@@ -20,4 +30,26 @@ public class MiscUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copy(InputStream in, File file) {
|
||||||
|
try {
|
||||||
|
OutputStream out = new FileOutputStream(file);
|
||||||
|
int lenght;
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
|
||||||
|
while ((lenght = in.read(buf)) > 0)
|
||||||
|
{
|
||||||
|
out.write(buf, 0, lenght);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isIpv4(String ip)
|
||||||
|
{
|
||||||
|
return ipv4.matcher(ip).matches();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,13 @@ package dev.brighten.antivpn.utils;
|
|||||||
|
|
||||||
import dev.brighten.antivpn.utils.json.JSONException;
|
import dev.brighten.antivpn.utils.json.JSONException;
|
||||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Builder
|
||||||
public class VPNResponse {
|
public class VPNResponse {
|
||||||
private String asn, ip, countryName, countryCode, city, timeZone, method, isp, failureReason = "N/A";
|
private String asn, ip, countryName, countryCode, city, timeZone, method, isp, failureReason = "N/A";
|
||||||
private boolean proxy, cached;
|
private boolean proxy, cached;
|
||||||
|
|||||||
+101
-8
@@ -1,18 +1,13 @@
|
|||||||
package dev.brighten.antivpn.velocity.config;
|
package dev.brighten.antivpn.utils.config;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class Configuration
|
public final class Configuration
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final char SEPARATOR = '.';
|
private static final char SEPARATOR = '.';
|
||||||
final Map<String, Object> self;
|
final Map<String, Object> self;
|
||||||
|
final Map<String, List<String>> comments;
|
||||||
private final Configuration defaults;
|
private final Configuration defaults;
|
||||||
|
|
||||||
public Configuration()
|
public Configuration()
|
||||||
@@ -29,6 +24,7 @@ public final class Configuration
|
|||||||
{
|
{
|
||||||
this.self = new LinkedHashMap<>();
|
this.self = new LinkedHashMap<>();
|
||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
|
comments = new HashMap<>();
|
||||||
|
|
||||||
for ( Map.Entry<?, ?> entry : map.entrySet() )
|
for ( Map.Entry<?, ?> entry : map.entrySet() )
|
||||||
{
|
{
|
||||||
@@ -44,6 +40,103 @@ public final class Configuration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadFromString(String contents) {
|
||||||
|
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
Collections.addAll(list, contents.split("\n"));
|
||||||
|
|
||||||
|
int currentLayer = 0;
|
||||||
|
String currentPath = "";
|
||||||
|
|
||||||
|
int lineNumber = 0;
|
||||||
|
for(Iterator<String> iterator = list.iterator(); iterator.hasNext(); lineNumber++) {
|
||||||
|
String line = iterator.next();
|
||||||
|
|
||||||
|
String trimmed = line.trim();
|
||||||
|
if(trimmed.startsWith("#") || trimmed.isEmpty()) {
|
||||||
|
addCommentLine(currentPath, line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!line.isEmpty()) {
|
||||||
|
if(line.contains(":")) {
|
||||||
|
|
||||||
|
int layerFromLine = getLayerFromLine(line, lineNumber);
|
||||||
|
|
||||||
|
if(layerFromLine < currentLayer) {
|
||||||
|
currentPath = regressPathBy(currentLayer - layerFromLine, currentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = getKeyFromLine(line);
|
||||||
|
|
||||||
|
if(currentLayer == 0) {
|
||||||
|
currentPath = key;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentPath += "." + key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCommentLine(String currentPath, String line) {
|
||||||
|
|
||||||
|
List<String> list = comments.get(currentPath);
|
||||||
|
if(list == null) {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
list.add(line);
|
||||||
|
|
||||||
|
comments.put(currentPath, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getKeyFromLine(String line) {
|
||||||
|
String key = null;
|
||||||
|
|
||||||
|
for(int i = 0; i < line.length(); i++) {
|
||||||
|
if(line.charAt(i) == ':') {
|
||||||
|
key = line.substring(0, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return key == null ? null : key.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
String regressPathBy(int i, String currentPath) {
|
||||||
|
if(i <= 0) {
|
||||||
|
return currentPath;
|
||||||
|
}
|
||||||
|
String[] split = currentPath.split("\\.");
|
||||||
|
|
||||||
|
String rebuild = "";
|
||||||
|
for(int j = 0; j < split.length - i; j++) {
|
||||||
|
rebuild += split[j];
|
||||||
|
if(j <= (split.length - j)) {
|
||||||
|
rebuild += ".";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rebuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getLayerFromLine(String line, int lineNumber) {
|
||||||
|
|
||||||
|
double d = 0;
|
||||||
|
for(int i = 0; i < line.length(); i++) {
|
||||||
|
if(line.charAt(i) == ' ') {
|
||||||
|
d += 0.5;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) d;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Configuration getSectionFor(String path)
|
private Configuration getSectionFor(String path)
|
||||||
{
|
{
|
||||||
int index = path.indexOf( SEPARATOR );
|
int index = path.indexOf( SEPARATOR );
|
||||||
+4
-15
@@ -1,17 +1,13 @@
|
|||||||
package dev.brighten.antivpn.velocity.config;
|
package dev.brighten.antivpn.utils.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class ConfigurationProvider
|
public abstract class ConfigurationProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Map<Class<? extends ConfigurationProvider>, ConfigurationProvider> providers = new HashMap<>();
|
public static final Map<Class<? extends ConfigurationProvider>, ConfigurationProvider> providers = new HashMap<>();
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@@ -20,16 +16,9 @@ public abstract class ConfigurationProvider
|
|||||||
providers.put( YamlConfiguration.class, new YamlConfiguration() );
|
providers.put( YamlConfiguration.class, new YamlConfiguration() );
|
||||||
} catch ( NoClassDefFoundError ex )
|
} catch ( NoClassDefFoundError ex )
|
||||||
{
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
// Ignore, no SnakeYAML
|
// Ignore, no SnakeYAML
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
providers.put( JsonConfiguration.class, new JsonConfiguration() );
|
|
||||||
} catch ( NoClassDefFoundError ex )
|
|
||||||
{
|
|
||||||
// Ignore, no Gson
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurationProvider getProvider(Class<? extends ConfigurationProvider> provider)
|
public static ConfigurationProvider getProvider(Class<? extends ConfigurationProvider> provider)
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package dev.brighten.antivpn.utils.config;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
import org.yaml.snakeyaml.LoaderOptions;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
||||||
|
public class YamlConfiguration extends ConfigurationProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ThreadLocal<Yaml> yaml = new ThreadLocal<Yaml>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Yaml initialValue()
|
||||||
|
{
|
||||||
|
Representer representer = new Representer()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
representers.put( Configuration.class, data -> represent( ( (Configuration) data ).self ));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DumperOptions options = new DumperOptions();
|
||||||
|
options.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK );
|
||||||
|
representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
return new Yaml( new Constructor(), representer, options );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(Configuration config, File file) throws IOException
|
||||||
|
{
|
||||||
|
try ( Writer writer = new OutputStreamWriter( new FileOutputStream( file ), StandardCharsets.UTF_8 ) )
|
||||||
|
{
|
||||||
|
save( config, writer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(Configuration config, Writer writer)
|
||||||
|
{
|
||||||
|
String contents = this.yaml.get().dump(config.self);
|
||||||
|
if (contents.equals("{}\n")) {
|
||||||
|
contents = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
Collections.addAll(list, contents.split("\n"));
|
||||||
|
|
||||||
|
int currentLayer = 0;
|
||||||
|
StringBuilder currentPath = new StringBuilder();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
int lineNumber = 0;
|
||||||
|
for(Iterator<String> iterator = list.iterator(); iterator.hasNext(); lineNumber++) {
|
||||||
|
String line = iterator.next();
|
||||||
|
sb.append(line);
|
||||||
|
sb.append('\n');
|
||||||
|
|
||||||
|
if (!line.isEmpty()) {
|
||||||
|
if (line.contains(":")) {
|
||||||
|
|
||||||
|
int layerFromLine = config.getLayerFromLine(line, lineNumber);
|
||||||
|
|
||||||
|
if (layerFromLine < currentLayer) {
|
||||||
|
currentPath = new StringBuilder(config.regressPathBy(currentLayer - layerFromLine, currentPath.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = config.getKeyFromLine(line);
|
||||||
|
|
||||||
|
if (currentLayer == 0) {
|
||||||
|
currentPath = new StringBuilder(key);
|
||||||
|
} else {
|
||||||
|
currentPath.append("." + key);
|
||||||
|
}
|
||||||
|
|
||||||
|
String path = currentPath.toString();
|
||||||
|
if (config.comments.containsKey(path)) {
|
||||||
|
config.comments.get(path).forEach(string -> {
|
||||||
|
sb.append(string);
|
||||||
|
sb.append('\n');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
writer.write(sb.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Configuration load(File file) throws IOException
|
||||||
|
{
|
||||||
|
return load( file, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(File file, Configuration defaults) throws IOException
|
||||||
|
{
|
||||||
|
try ( FileInputStream is = new FileInputStream( file ) )
|
||||||
|
{
|
||||||
|
return load( is, defaults );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(Reader reader)
|
||||||
|
{
|
||||||
|
return load( reader, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public Configuration load(Reader reader, Configuration defaults)
|
||||||
|
{
|
||||||
|
BufferedReader input = reader instanceof BufferedReader ? (BufferedReader)reader : new BufferedReader(reader);
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
String line;
|
||||||
|
try {
|
||||||
|
while((line = input.readLine()) != null) {
|
||||||
|
builder.append(line);
|
||||||
|
builder.append('\n');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return load(builder.toString(), defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(InputStream is)
|
||||||
|
{
|
||||||
|
return this.load(new InputStreamReader(is, Charset.defaultCharset()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(InputStream is, Configuration defaults)
|
||||||
|
{
|
||||||
|
return this.load(new InputStreamReader(is, Charset.defaultCharset()), defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(String string)
|
||||||
|
{
|
||||||
|
return load( string, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Configuration load(String contents, Configuration defaults)
|
||||||
|
{
|
||||||
|
Map<String, Object> map;
|
||||||
|
LoaderOptions loaderOptions = new LoaderOptions();
|
||||||
|
loaderOptions.setMaxAliasesForCollections(2147483647);
|
||||||
|
map = this.yaml.get().loadAs(contents, LinkedHashMap.class);
|
||||||
|
|
||||||
|
Configuration config = new Configuration( map, defaults );
|
||||||
|
config.loadFromString(contents);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#####################################################
|
||||||
|
# KauriVPN Config #
|
||||||
|
# by Brighten Development #
|
||||||
|
#####################################################
|
||||||
|
# If you find that you run out of your free 20,000 queries, you may purchase a license on https://funkemunky.cc/shop
|
||||||
|
license: ''
|
||||||
|
# Message only sent with commands disabled below. Supports color codes ('&')
|
||||||
|
kickMessage: Proxies are not allowed on our server
|
||||||
|
# Caching results will lower your query usage, but results may be out of date.
|
||||||
|
cachedResults: true
|
||||||
|
# All players with any of the following characters in the beginning of their name will be whitelisted
|
||||||
|
# This is a useful feature for servers that allow players through Geyser and their IPs are not forwarded, causing
|
||||||
|
# players to be removed falsely for use of proxy.
|
||||||
|
prefixWhitelists: []
|
||||||
|
# Configure your database here.
|
||||||
|
database:
|
||||||
|
# Enable to cache queries and save alerts state beyond restarts
|
||||||
|
enabled: false
|
||||||
|
useCredentials: true
|
||||||
|
#Options Mongo, MySQL, or H2
|
||||||
|
type: H2
|
||||||
|
# The database name you would like to use
|
||||||
|
database: kaurivpn
|
||||||
|
# Can be used if you prefer to authenticate via Mongo URL
|
||||||
|
mongoURL: ''
|
||||||
|
# Your database username
|
||||||
|
username: root
|
||||||
|
# Your database password
|
||||||
|
password: password
|
||||||
|
# The IP of your database goes here
|
||||||
|
ip: localhost
|
||||||
|
# -1 will use default port of databases (MySQL:3306, Mongo:27017). Otherwise, enter alternative ports here.
|
||||||
|
port: -1
|
||||||
|
commands:
|
||||||
|
# Enable this to override the default kick function of the plugin with your own commands
|
||||||
|
enabled: false
|
||||||
|
# List of commands to run when a player is detected to be using a proxy. Supports color codes ('&')
|
||||||
|
execute:
|
||||||
|
- kick %player% VPNs are not allowed on our server!
|
||||||
|
# Enable/disable the default kicking feature of KauriVPN.
|
||||||
|
kickPlayers: true
|
||||||
|
# Configure all alerting functionality
|
||||||
|
alerts:
|
||||||
|
# You may set to 'false' to disable all alerts functionality
|
||||||
|
enabled: true
|
||||||
|
# Message to send to users with alerts enabled
|
||||||
|
# Placeholders: %country% (Country name), %player% (Player name), %reason% (Proxy detection method),
|
||||||
|
# %city% (City name).
|
||||||
|
message: '&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy &8(&f%reason%&8)
|
||||||
|
&7in location &8(&f%city%&7, &f%country%&8)'
|
||||||
|
# Configuration for country gatekeepings
|
||||||
|
countries:
|
||||||
|
# You must use ISO codes for country configuration: https://www.iban.com/country-code
|
||||||
|
# Leave empty to disable this configuration
|
||||||
|
list: []
|
||||||
|
# Set whitelist to true to only allow listed country codes, and false to deny listed country codes.
|
||||||
|
whitelist: true
|
||||||
|
# The commands to be run if the player is not allowed on the server with the above configured conditions
|
||||||
|
# Placeholders: %country% (Country name), %player% (Player name), %code% (Country ISO Code)
|
||||||
|
# Keep this empty with "[]" if you want to use the built in kicking system.
|
||||||
|
commands: []
|
||||||
|
# The kick message that will be used if commands are configured to use the built-in kicking sytem.
|
||||||
|
# PlaceHolders: %country% (Country name), %player% (Player name), %code% (Country ISO Code)
|
||||||
|
vanillaKickReason: "&cSorry, but our server does not allow connections from\n&f%country%"
|
||||||
|
# This will disable any information being sent to https://bstats.org. We recommend you keep this enabled as it helps
|
||||||
|
# us understand our users and put effort where it is needed. All information sent goes under their privacy as seen
|
||||||
|
# here: https://bstats.org/privacy-policy
|
||||||
|
bstats: true
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,166 +0,0 @@
|
|||||||
package dev.brighten.antivpn.velocity;
|
|
||||||
|
|
||||||
import dev.brighten.antivpn.api.VPNConfig;
|
|
||||||
import dev.brighten.antivpn.velocity.util.ConfigDefault;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class VelocityConfig implements VPNConfig {
|
|
||||||
private final ConfigDefault<String> licenseDefault = new ConfigDefault<>("",
|
|
||||||
"license", VelocityPlugin.INSTANCE), kickStringDefault =
|
|
||||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
|
||||||
"kickMessage", VelocityPlugin.INSTANCE),
|
|
||||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
|
||||||
"database.type", VelocityPlugin.INSTANCE),
|
|
||||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
|
||||||
"database.database", VelocityPlugin.INSTANCE),
|
|
||||||
defaultUsername = new ConfigDefault<>("root",
|
|
||||||
"database.username", VelocityPlugin.INSTANCE),
|
|
||||||
defaultPassword = new ConfigDefault<>("password",
|
|
||||||
"database.password", VelocityPlugin.INSTANCE),
|
|
||||||
defaultAuthDatabase = new ConfigDefault<>("admin",
|
|
||||||
"database.auth", VelocityPlugin.INSTANCE),
|
|
||||||
defaultIp = new ConfigDefault<>("localhost", "database.ip", VelocityPlugin.INSTANCE),
|
|
||||||
defaultAlertMsg = new ConfigDefault<>("&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy" +
|
|
||||||
" &8(&f%reason%&8) &7in location &8(&f%city%&7, &f%country%&8)", "alerts.message",
|
|
||||||
VelocityPlugin.INSTANCE);
|
|
||||||
private final ConfigDefault<Boolean> cacheResultsDefault = new ConfigDefault<>(true,
|
|
||||||
"cachedResults", VelocityPlugin.INSTANCE),
|
|
||||||
defaultDatabaseEnabled = new ConfigDefault<>(false, "database.enabled",
|
|
||||||
VelocityPlugin.INSTANCE), defaultCommandsEnable = new ConfigDefault<>(false,
|
|
||||||
"commands.enabled", VelocityPlugin.INSTANCE), defaultKickPlayers
|
|
||||||
= new ConfigDefault<>(true, "kickPlayers", VelocityPlugin.INSTANCE),
|
|
||||||
defaultAlertToStaff = new ConfigDefault<>(true, "alerts.enabled",
|
|
||||||
VelocityPlugin.INSTANCE),
|
|
||||||
defaultMetrics = new ConfigDefault<>(true, "bstats", VelocityPlugin.INSTANCE);
|
|
||||||
private final ConfigDefault<Integer>
|
|
||||||
defaultPort = new ConfigDefault<>(-1, "database.port", VelocityPlugin.INSTANCE);
|
|
||||||
private final ConfigDefault<List<String>> prefixWhitelistsDefault = new ConfigDefault<>(new ArrayList<>(),
|
|
||||||
"prefixWhitelists", VelocityPlugin.INSTANCE), defaultCommands = new ConfigDefault<>(
|
|
||||||
Collections.singletonList("kick %player% VPNs are not allowed on our server!"), "commands.execute",
|
|
||||||
VelocityPlugin.INSTANCE);
|
|
||||||
|
|
||||||
private String license, kickMessage, databaseType, databaseName, username, password, ip, alertMsg;
|
|
||||||
private List<String> prefixWhitelists, commands;
|
|
||||||
private int port;
|
|
||||||
private boolean cacheResults, databaseEnabled, commandsEnabled, kickPlayers, alertToStaff, metrics;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLicense() {
|
|
||||||
return license;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean cachedResults() {
|
|
||||||
return cacheResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKickString() {
|
|
||||||
return kickMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String alertMessage() {
|
|
||||||
return alertMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean alertToStaff() {
|
|
||||||
return alertToStaff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean runCommands() {
|
|
||||||
return commandsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> commands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean kickPlayersOnDetect() {
|
|
||||||
return kickPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getPrefixWhitelists() {
|
|
||||||
return prefixWhitelists;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDatabaseEnabled() {
|
|
||||||
return databaseEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseType() {
|
|
||||||
return databaseType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatabaseName() {
|
|
||||||
return databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIp() {
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
if(port == -1) {
|
|
||||||
switch (getDatabaseType().toLowerCase()) {
|
|
||||||
case "mongodb":
|
|
||||||
case "mongo":
|
|
||||||
case "mongod":
|
|
||||||
return 27017;
|
|
||||||
case "sql":
|
|
||||||
case "mysql":
|
|
||||||
return 3306;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean metrics() {
|
|
||||||
return metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
license = licenseDefault.get();
|
|
||||||
kickMessage = kickStringDefault.get();
|
|
||||||
cacheResults = cacheResultsDefault.get();
|
|
||||||
prefixWhitelists = prefixWhitelistsDefault.get();
|
|
||||||
databaseEnabled = defaultDatabaseEnabled.get();
|
|
||||||
databaseType = defaultDatabaseType.get();
|
|
||||||
databaseName = defaultDatabaseName.get();
|
|
||||||
username = defaultUsername.get();
|
|
||||||
password = defaultPassword.get();
|
|
||||||
ip = defaultIp.get();
|
|
||||||
port = defaultPort.get();
|
|
||||||
commandsEnabled = defaultCommandsEnable.get();
|
|
||||||
commands = defaultCommands.get();
|
|
||||||
kickPlayers = defaultKickPlayers.get();
|
|
||||||
alertToStaff = defaultAlertToStaff.get();
|
|
||||||
alertMsg = defaultAlertMsg.get();
|
|
||||||
metrics = defaultMetrics.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import com.velocitypowered.api.event.connection.LoginEvent;
|
|||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
import dev.brighten.antivpn.api.APIPlayer;
|
import dev.brighten.antivpn.api.APIPlayer;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
import dev.brighten.antivpn.api.VPNExecutor;
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
import dev.brighten.antivpn.velocity.util.StringUtils;
|
import dev.brighten.antivpn.velocity.util.StringUtils;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
@@ -24,46 +25,96 @@ public class VelocityListener extends VPNExecutor {
|
|||||||
event -> {
|
event -> {
|
||||||
if(event.getResult().isAllowed()) {
|
if(event.getResult().isAllowed()) {
|
||||||
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
//Is exempt
|
||||||
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId())
|
||||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||||
|| AntiVPN.getInstance().getConfig().getPrefixWhitelists().stream()
|
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getRemoteAddress()
|
||||||
|
.getAddress().getHostAddress())
|
||||||
|
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||||
.anyMatch(prefix -> event.getPlayer().getUsername().startsWith(prefix))) return;
|
.anyMatch(prefix -> event.getPlayer().getUsername().startsWith(prefix))) return;
|
||||||
|
|
||||||
checkIp(event.getPlayer().getRemoteAddress().getAddress().getHostAddress(),
|
checkIp(event.getPlayer().getRemoteAddress().getAddress().getHostAddress(),
|
||||||
AntiVPN.getInstance().getConfig().cachedResults(), result -> {
|
AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> {
|
||||||
if(result.isSuccess() && result.isProxy()) {
|
if(result.isSuccess()) {
|
||||||
if(AntiVPN.getInstance().getConfig().kickPlayersOnDetect())
|
// If the countryList() size is zero, no need to check.
|
||||||
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
// Running country check first
|
||||||
.build().deserialize(AntiVPN.getInstance().getConfig().getKickString()));
|
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||||
VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername()
|
// This bit of code will decide whether or not to kick the player
|
||||||
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
// If it contains the code and it is set to whitelist, it will not kick
|
||||||
|
// as they are equal and vise versa. However, if the contains does not match
|
||||||
if(AntiVPN.getInstance().getConfig().alertToStaff()) //Ensuring the user wishes to alert to staff
|
// the state, it will kick.
|
||||||
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
&& AntiVPN.getInstance().getVpnConfig().countryList()
|
||||||
.filter(APIPlayer::isAlertsEnabled)
|
.contains(result.getCountryCode())
|
||||||
.forEach(pl -> pl.sendMessage(AntiVPN.getInstance().getConfig().alertMessage()
|
!= AntiVPN.getInstance().getVpnConfig().whitelistCountries()) {
|
||||||
.replace("%player%", event.getPlayer().getUsername())
|
//Using our built in kicking system if no commands are configured
|
||||||
.replace("%reason%", result.getMethod())
|
if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().size() == 0) {
|
||||||
.replace("%country%", result.getCountryName())
|
final String kickReason = AntiVPN.getInstance().getVpnConfig()
|
||||||
.replace("%city%", result.getCity())));
|
.countryVanillaKickReason();
|
||||||
|
// Kicking our player
|
||||||
//In case the user wants to run their own commands instead of using the built in kicking
|
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||||
if(AntiVPN.getInstance().getConfig().runCommands()) {
|
.build().deserialize(kickReason
|
||||||
for (String command : AntiVPN.getInstance().getConfig().commands()) {
|
.replace("%player%", event.getPlayer().getUsername())
|
||||||
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
.replace("%country%", result.getCountryName())
|
||||||
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
.replace("%code%", result.getCountryCode())));
|
||||||
.getConsoleCommandSource(),
|
} else {
|
||||||
StringUtils.translateAlternateColorCodes('&',
|
for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) {
|
||||||
command.replace("%player%",
|
final String formattedCommand = StringUtils
|
||||||
event.getPlayer().getUsername())));
|
.translateAlternateColorCodes('&',
|
||||||
|
cmd.replace("%player%",
|
||||||
|
event.getPlayer().getUsername())
|
||||||
|
.replace("%country%", result.getCountryName())
|
||||||
|
.replace("%code%", result.getCountryCode()));
|
||||||
|
// Running the command from console
|
||||||
|
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||||
|
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||||
|
.getConsoleCommandSource(),
|
||||||
|
StringUtils.translateAlternateColorCodes('&',
|
||||||
|
formattedCommand));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if(result.isProxy()) {
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect())
|
||||||
|
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||||
|
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
||||||
|
.getKickString()));
|
||||||
|
VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername()
|
||||||
|
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
||||||
|
//Ensuring the user wishes to alert to staff
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().alertToStaff())
|
||||||
|
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||||
|
.filter(APIPlayer::isAlertsEnabled)
|
||||||
|
.forEach(pl ->
|
||||||
|
pl.sendMessage(AntiVPN.getInstance().getVpnConfig()
|
||||||
|
.alertMessage()
|
||||||
|
.replace("%player%",
|
||||||
|
event.getPlayer().getUsername())
|
||||||
|
.replace("%reason%",
|
||||||
|
result.getMethod())
|
||||||
|
.replace("%country%",
|
||||||
|
result.getCountryName())
|
||||||
|
.replace("%city%",
|
||||||
|
result.getCity())));
|
||||||
|
|
||||||
|
//In case the user wants to run their own commands instead of using the
|
||||||
|
// built in kicking
|
||||||
|
if(AntiVPN.getInstance().getVpnConfig().runCommands()) {
|
||||||
|
for (String command : AntiVPN.getInstance().getVpnConfig().commands()) {
|
||||||
|
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||||
|
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||||
|
.getConsoleCommandSource(),
|
||||||
|
StringUtils.translateAlternateColorCodes('&',
|
||||||
|
command.replace("%player%",
|
||||||
|
event.getPlayer().getUsername())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AntiVPN.getInstance().detections++;
|
||||||
}
|
}
|
||||||
AntiVPN.getInstance().detections++;
|
} else {
|
||||||
} else if(!result.isSuccess()) {
|
|
||||||
VelocityPlugin.INSTANCE.getLogger()
|
VelocityPlugin.INSTANCE.getLogger()
|
||||||
.log(Level.WARNING,
|
.log(Level.WARNING,
|
||||||
"The API query was not a success! " +
|
"The API query was not a success! " +
|
||||||
"You may need to upgrade your license on https://funkemunky.cc/shop");
|
"You may need to upgrade your license on " +
|
||||||
|
"https://funkemunky.cc/shop");
|
||||||
}
|
}
|
||||||
AntiVPN.getInstance().checked++;
|
AntiVPN.getInstance().checked++;
|
||||||
});
|
});
|
||||||
@@ -88,4 +139,9 @@ public class VelocityListener extends VPNExecutor {
|
|||||||
threadExecutor.shutdown();
|
threadExecutor.shutdown();
|
||||||
VelocityPlugin.INSTANCE.getServer().getEventManager().unregisterListener(VelocityPlugin.INSTANCE, this);
|
VelocityPlugin.INSTANCE.getServer().getEventManager().unregisterListener(VelocityPlugin.INSTANCE, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String log, Object... objects) {
|
||||||
|
VelocityPlugin.INSTANCE.getLogger().log(Level.INFO, String.format(log, objects));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import dev.brighten.antivpn.AntiVPN;
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
import dev.brighten.antivpn.command.Command;
|
import dev.brighten.antivpn.command.Command;
|
||||||
import dev.brighten.antivpn.velocity.util.Config;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -37,8 +36,6 @@ public class VelocityPlugin {
|
|||||||
@DataDirectory
|
@DataDirectory
|
||||||
private Path configDir;
|
private Path configDir;
|
||||||
|
|
||||||
private Config config;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public VelocityPlugin(ProxyServer server, Logger logger, Metrics.Factory metricsFactory) {
|
public VelocityPlugin(ProxyServer server, Logger logger, Metrics.Factory metricsFactory) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@@ -50,13 +47,12 @@ public class VelocityPlugin {
|
|||||||
public void onInit(ProxyInitializeEvent event) {
|
public void onInit(ProxyInitializeEvent event) {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
logger.info("Loading config...");
|
logger.info("Loading config...");
|
||||||
config = new Config();
|
|
||||||
|
|
||||||
//Loading plugin
|
//Loading plugin
|
||||||
logger.info("Starting AntiVPN services...");
|
logger.info("Starting AntiVPN services...");
|
||||||
AntiVPN.start(new VelocityConfig(), new VelocityListener(), new VelocityPlayerExecutor());
|
AntiVPN.start(new VelocityListener(), new VelocityPlayerExecutor(), configDir.toFile());
|
||||||
|
|
||||||
if(AntiVPN.getInstance().getConfig().metrics()) {
|
if(AntiVPN.getInstance().getVpnConfig().metrics()) {
|
||||||
logger.info("Starting metrics...");
|
logger.info("Starting metrics...");
|
||||||
Metrics metrics = metricsFactory.make(this, 12791);
|
Metrics metrics = metricsFactory.make(this, 12791);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
package dev.brighten.antivpn.velocity.config;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonSerializationContext;
|
|
||||||
import com.google.gson.JsonSerializer;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
|
||||||
public class JsonConfiguration extends ConfigurationProvider
|
|
||||||
{
|
|
||||||
|
|
||||||
private final Gson json = new GsonBuilder().serializeNulls().setPrettyPrinting().registerTypeAdapter( Configuration.class, new JsonSerializer<Configuration>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public JsonElement serialize(Configuration src, Type typeOfSrc, JsonSerializationContext context)
|
|
||||||
{
|
|
||||||
return context.serialize( ( (Configuration) src ).self );
|
|
||||||
}
|
|
||||||
} ).create();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(Configuration config, File file) throws IOException
|
|
||||||
{
|
|
||||||
try ( Writer writer = new OutputStreamWriter( new FileOutputStream( file ), Charsets.UTF_8 ) )
|
|
||||||
{
|
|
||||||
save( config, writer );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(Configuration config, Writer writer)
|
|
||||||
{
|
|
||||||
json.toJson( config.self, writer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(File file) throws IOException
|
|
||||||
{
|
|
||||||
return load( file, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(File file, Configuration defaults) throws IOException
|
|
||||||
{
|
|
||||||
try ( FileInputStream is = new FileInputStream( file ) )
|
|
||||||
{
|
|
||||||
return load( is, defaults );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(Reader reader)
|
|
||||||
{
|
|
||||||
return load( reader, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Configuration load(Reader reader, Configuration defaults)
|
|
||||||
{
|
|
||||||
Map<String, Object> map = json.fromJson( reader, LinkedHashMap.class );
|
|
||||||
if ( map == null )
|
|
||||||
{
|
|
||||||
map = new LinkedHashMap<>();
|
|
||||||
}
|
|
||||||
return new Configuration( map, defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(InputStream is)
|
|
||||||
{
|
|
||||||
return load( is, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(InputStream is, Configuration defaults)
|
|
||||||
{
|
|
||||||
return load( new InputStreamReader( is, Charsets.UTF_8 ), defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(String string)
|
|
||||||
{
|
|
||||||
return load( string, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Configuration load(String string, Configuration defaults)
|
|
||||||
{
|
|
||||||
Map<String, Object> map = json.fromJson( string, LinkedHashMap.class );
|
|
||||||
if ( map == null )
|
|
||||||
{
|
|
||||||
map = new LinkedHashMap<>();
|
|
||||||
}
|
|
||||||
return new Configuration( map, defaults );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
package dev.brighten.antivpn.velocity.config;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
|
||||||
import org.yaml.snakeyaml.nodes.Node;
|
|
||||||
import org.yaml.snakeyaml.representer.Represent;
|
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
|
||||||
public class YamlConfiguration extends ConfigurationProvider
|
|
||||||
{
|
|
||||||
|
|
||||||
private final ThreadLocal<Yaml> yaml = new ThreadLocal<Yaml>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Yaml initialValue()
|
|
||||||
{
|
|
||||||
Representer representer = new Representer()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
representers.put( Configuration.class, new Represent()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Node representData(Object data)
|
|
||||||
{
|
|
||||||
return represent( ( (Configuration) data ).self );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DumperOptions options = new DumperOptions();
|
|
||||||
options.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK );
|
|
||||||
|
|
||||||
return new Yaml( new Constructor(), representer, options );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(Configuration config, File file) throws IOException
|
|
||||||
{
|
|
||||||
try ( Writer writer = new OutputStreamWriter( new FileOutputStream( file ), Charsets.UTF_8 ) )
|
|
||||||
{
|
|
||||||
save( config, writer );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(Configuration config, Writer writer)
|
|
||||||
{
|
|
||||||
yaml.get().dump( config.self, writer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(File file) throws IOException
|
|
||||||
{
|
|
||||||
return load( file, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(File file, Configuration defaults) throws IOException
|
|
||||||
{
|
|
||||||
try ( FileInputStream is = new FileInputStream( file ) )
|
|
||||||
{
|
|
||||||
return load( is, defaults );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(Reader reader)
|
|
||||||
{
|
|
||||||
return load( reader, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Configuration load(Reader reader, Configuration defaults)
|
|
||||||
{
|
|
||||||
Map<String, Object> map = yaml.get().loadAs( reader, LinkedHashMap.class );
|
|
||||||
if ( map == null )
|
|
||||||
{
|
|
||||||
map = new LinkedHashMap<>();
|
|
||||||
}
|
|
||||||
return new Configuration( map, defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(InputStream is)
|
|
||||||
{
|
|
||||||
return load( is, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Configuration load(InputStream is, Configuration defaults)
|
|
||||||
{
|
|
||||||
Map<String, Object> map = yaml.get().loadAs( is, LinkedHashMap.class );
|
|
||||||
if ( map == null )
|
|
||||||
{
|
|
||||||
map = new LinkedHashMap<>();
|
|
||||||
}
|
|
||||||
return new Configuration( map, defaults );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Configuration load(String string)
|
|
||||||
{
|
|
||||||
return load( string, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Configuration load(String string, Configuration defaults)
|
|
||||||
{
|
|
||||||
Map<String, Object> map = yaml.get().loadAs( string, LinkedHashMap.class );
|
|
||||||
if ( map == null )
|
|
||||||
{
|
|
||||||
map = new LinkedHashMap<>();
|
|
||||||
}
|
|
||||||
return new Configuration( map, defaults );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
package dev.brighten.antivpn.velocity.util;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import dev.brighten.antivpn.velocity.VelocityPlugin;
|
|
||||||
import dev.brighten.antivpn.velocity.config.Configuration;
|
|
||||||
import dev.brighten.antivpn.velocity.config.ConfigurationProvider;
|
|
||||||
import dev.brighten.antivpn.velocity.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author: nitramleo (Martin)
|
|
||||||
* Date created: 10-Aug-18
|
|
||||||
*/
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
private Configuration configuration;
|
|
||||||
|
|
||||||
public Config() {
|
|
||||||
File dataFolder = VelocityPlugin.INSTANCE.getConfigDir().toFile();
|
|
||||||
this.file = new File(dataFolder, "config.yml");
|
|
||||||
try {
|
|
||||||
if (!this.file.exists()) {
|
|
||||||
if (!dataFolder.exists()) {
|
|
||||||
dataFolder.mkdir();
|
|
||||||
}
|
|
||||||
this.file.createNewFile();
|
|
||||||
try (final InputStream is =VelocityPlugin.INSTANCE.getClass().getResourceAsStream("config.yml");
|
|
||||||
final OutputStream os = new FileOutputStream(this.file)) {
|
|
||||||
ByteStreams.copy(is, os);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
File dataFolder = VelocityPlugin.INSTANCE.getConfigDir().toFile();
|
|
||||||
this.file = new File(dataFolder, "config.yml");
|
|
||||||
try {
|
|
||||||
this.configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
try {
|
|
||||||
ConfigurationProvider.getProvider( YamlConfiguration.class).save(this.configuration, this.file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Configuration getConfiguration() {
|
|
||||||
return this.configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return this.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDouble(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return this.configuration.getDouble(path);
|
|
||||||
}
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInt(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return this.configuration.getInt(path);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object get(final String path) {
|
|
||||||
return this.configuration.get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(final String path, final Object object) {
|
|
||||||
configuration.set(path, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean(final String path) {
|
|
||||||
return this.configuration.get(path) != null && this.configuration.getBoolean(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
return StringUtils.translateAlternateColorCodes('&', this.configuration.getString(path));
|
|
||||||
}
|
|
||||||
return "String at path: " + path + " not found!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getStringList(final String path) {
|
|
||||||
if (this.configuration.get(path) != null) {
|
|
||||||
final ArrayList<String> strings = new ArrayList<String>();
|
|
||||||
for (final String string : this.configuration.getStringList(path)) {
|
|
||||||
strings.add(StringUtils.translateAlternateColorCodes('&', string));
|
|
||||||
}
|
|
||||||
return strings;
|
|
||||||
}
|
|
||||||
return Arrays.asList("String List at path: " + path + " not found!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package dev.brighten.antivpn.velocity.util;
|
|
||||||
|
|
||||||
import dev.brighten.antivpn.velocity.VelocityPlugin;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ConfigDefault<A> {
|
|
||||||
|
|
||||||
private final A defaultValue;
|
|
||||||
private final String path;
|
|
||||||
private final VelocityPlugin plugin;
|
|
||||||
|
|
||||||
public A get() {
|
|
||||||
if(plugin.getConfig().get(path) != null)
|
|
||||||
return (A) plugin.getConfig().get(path);
|
|
||||||
else {
|
|
||||||
plugin.getConfig().set(path, defaultValue);
|
|
||||||
plugin.getConfig().save();
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public A set(A value) {
|
|
||||||
plugin.getConfig().set(path, value);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"id":"kaurivpn","name":"KauriVPN","version":"${project.version}","authors":["funkemunky"],"dependencies":[],"main":"dev.brighten.antivpn.velocity.VelocityPlugin"}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<groupId>dev.brighten.antivpn</groupId>
|
<groupId>dev.brighten.antivpn</groupId>
|
||||||
<artifactId>AntiVPN</artifactId>
|
<artifactId>AntiVPN</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.5.0</version>
|
<version>1.7</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>Common</module>
|
<module>Common</module>
|
||||||
@@ -32,6 +32,14 @@
|
|||||||
<source>8</source>
|
<source>8</source>
|
||||||
<target>8</target>
|
<target>8</target>
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
||||||
|
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.20</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
Reference in New Issue
Block a user