mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-01 17:52:16 +00:00
Using regex to check ipv4 and fixing allowlist ips
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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("[1-9]{1,3}\\.[1-9]{1,3}\\.[1-9]{1,3}.[1-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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user