mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 09:31:54 +00:00
Merge pull request #17 from funkemunky/fixing-ip-whitelist
Fixing ip whitelist
This commit is contained in:
@@ -14,7 +14,7 @@ public class BukkitConfig implements VPNConfig {
|
||||
"license", BukkitPlugin.pluginInstance), kickStringDefault =
|
||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
||||
"kickMessage", BukkitPlugin.pluginInstance),
|
||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
||||
defaultDatabaseType = new ConfigDefault<>("H2",
|
||||
"database.type", BukkitPlugin.pluginInstance),
|
||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
||||
"database.database", BukkitPlugin.pluginInstance),
|
||||
|
||||
@@ -12,7 +12,7 @@ public class BungeeConfig implements VPNConfig {
|
||||
"license", BungeePlugin.pluginInstance), kickStringDefault =
|
||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
||||
"kickMessage", BungeePlugin.pluginInstance),
|
||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
||||
defaultDatabaseType = new ConfigDefault<>("H2",
|
||||
"database.type", BungeePlugin.pluginInstance),
|
||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
||||
"database.database", BungeePlugin.pluginInstance),
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
<version>2.1.210</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -53,6 +53,7 @@ public class AntiVPN {
|
||||
|
||||
switch(INSTANCE.config.getDatabaseType().toLowerCase()) {
|
||||
case "mysql":
|
||||
case "h2":
|
||||
case "sql":{
|
||||
AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL...");
|
||||
INSTANCE.database = new MySqlVPN();
|
||||
|
||||
@@ -65,13 +65,16 @@ public class AllowlistCommand extends Command {
|
||||
if(MiscUtils.isIpv4(args[1])) {
|
||||
if(!databaseEnabled) {
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
case "add":
|
||||
case "insert": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(args[1]);
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true);
|
||||
return String.format("&aAdded &6%s &ato the exemption allowlist.", args[1]);
|
||||
}
|
||||
case "remove":
|
||||
case "delete": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(args[1]);
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false);
|
||||
return String.format("&cRemoved &6%s &cfrom the exemption allowlist.", args[1]);
|
||||
}
|
||||
default: {
|
||||
@@ -80,7 +83,8 @@ public class AllowlistCommand extends Command {
|
||||
}
|
||||
} else {
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
case "add":
|
||||
case "insert": {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true);
|
||||
return String.format("&aAdded &6%s &a to the exemption allowlist.", args[1]);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,9 @@ public class MySqlVPN implements VPNDatabase {
|
||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled())
|
||||
return;
|
||||
AntiVPN.getInstance().getExecutor().log("Initializing MySQL...");
|
||||
MySQL.init();
|
||||
if(AntiVPN.getInstance().getConfig().getDatabaseType().contains("sql")) {
|
||||
MySQL.init();
|
||||
} else MySQL.initH2();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package dev.brighten.antivpn.database.sql.utils;
|
||||
|
||||
import org.h2.jdbc.JdbcConnection;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MySQL {
|
||||
private static Connection conn;
|
||||
@@ -35,12 +38,13 @@ public class MySQL {
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void initH2() {
|
||||
public static void initH2() {
|
||||
File dataFolder = new File(AntiVPN.getInstance().getPluginFolder(), "databases" + File.separator + "database");
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
conn = new NonClosableConnection(new JdbcConnection("jdbc:h2:file:" +
|
||||
dataFolder.getAbsolutePath(), new Properties()));
|
||||
conn = new NonClosableConnection(DriverManager.getConnection ("jdbc:h2:file:" +
|
||||
dataFolder.getAbsolutePath(),
|
||||
AntiVPN.getInstance().getConfig().getUsername(),AntiVPN.getInstance().getConfig().getPassword()));
|
||||
conn.setAutoCommit(true);
|
||||
Query.use(conn);
|
||||
AntiVPN.getInstance().getExecutor().log("Connection to SQlLite has been established.");
|
||||
@@ -50,7 +54,7 @@ public class MySQL {
|
||||
} catch (ClassNotFoundException ex) {
|
||||
AntiVPN.getInstance().getExecutor().log("No H2 library found!");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void use() {
|
||||
try {
|
||||
|
||||
@@ -11,9 +11,12 @@ 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 {
|
||||
|
||||
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) {
|
||||
try {
|
||||
for (Closeable closeable : closeables) if (closeable != null) closeable.close();
|
||||
@@ -32,13 +35,6 @@ public class MiscUtils {
|
||||
|
||||
public static boolean isIpv4(String ip)
|
||||
{
|
||||
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(ip);
|
||||
|
||||
return address instanceof Inet4Address;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
return ipv4.matcher(ip).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class VelocityConfig implements VPNConfig {
|
||||
"license", VelocityPlugin.INSTANCE), kickStringDefault =
|
||||
new ConfigDefault<>("Proxies are not allowed on our server",
|
||||
"kickMessage", VelocityPlugin.INSTANCE),
|
||||
defaultDatabaseType = new ConfigDefault<>("MySQL",
|
||||
defaultDatabaseType = new ConfigDefault<>("H2",
|
||||
"database.type", VelocityPlugin.INSTANCE),
|
||||
defaultDatabaseName = new ConfigDefault<>("kaurivpn",
|
||||
"database.database", VelocityPlugin.INSTANCE),
|
||||
|
||||
Reference in New Issue
Block a user