mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 17:31:55 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ff25c75055 | |||
| 733e797a17 | |||
| 0c903794e5 | |||
| bddf26359d | |||
| 4424b2b9a5 |
@@ -13,6 +13,9 @@ local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
*.iml
|
||||
|
||||
.idea/
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Assembly</artifactId>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Bukkit</artifactId>
|
||||
@@ -56,7 +56,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -16,8 +16,9 @@ public class BukkitCommandExecutor implements CommandExecutor {
|
||||
private final CommandSender sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
String.format(message, objects)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,9 +71,6 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
commandMap.register(pluginInstance.getName(), newCommand);
|
||||
}
|
||||
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
//TODO Finish system before implementing on startup
|
||||
/*Bukkit.getLogger().info("Getting strings...");
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Bungee</artifactId>
|
||||
@@ -50,7 +50,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -49,12 +49,6 @@ public class BungeePlugin extends Plugin {
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
//TODO Finish system before implementing on startup
|
||||
/*BungeeCord.getInstance().getLogger().info("Getting strings...");
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), BungeePlugin.pluginInstance)
|
||||
.get());
|
||||
AntiVPN.getInstance().getMessageHandler().reloadStrings();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,9 +17,9 @@ public class BungeeCommandExecutor implements CommandExecutor {
|
||||
private final CommandSender sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(TextComponent.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&', message)));
|
||||
.translateAlternateColorCodes('&', String.format(message, objects))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,17 +6,15 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.impl.AntiVPNCommand;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.local.H2VPN;
|
||||
import dev.brighten.antivpn.database.mongo.MongoVPN;
|
||||
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
||||
import dev.brighten.antivpn.message.MessageHandler;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import dev.brighten.antivpn.utils.MiscUtils;
|
||||
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.JSONObject;
|
||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -72,8 +70,15 @@ public class AntiVPN {
|
||||
INSTANCE.messageHandler = new MessageHandler();
|
||||
|
||||
switch(INSTANCE.vpnConfig.getDatabaseType().toLowerCase()) {
|
||||
case "mysql":
|
||||
case "h2":
|
||||
case "local":
|
||||
case "flatfile": {
|
||||
AntiVPN.getInstance().getExecutor().log("Using databaseType H2...");
|
||||
INSTANCE.database = new H2VPN();
|
||||
INSTANCE.database.init();
|
||||
break;
|
||||
}
|
||||
case "mysql":
|
||||
case "sql":{
|
||||
AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL...");
|
||||
INSTANCE.database = new MySqlVPN();
|
||||
@@ -106,6 +111,10 @@ public class AntiVPN {
|
||||
INSTANCE.database.alertsState(player.getUuid(), player::setAlertsEnabled);
|
||||
}
|
||||
});
|
||||
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
}
|
||||
|
||||
public InputStream getResource(String filename) {
|
||||
@@ -147,15 +156,6 @@ public class AntiVPN {
|
||||
}
|
||||
}
|
||||
|
||||
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
||||
throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl(String
|
||||
.format("https://funkemunky.cc/vpn?ip=%s&license=%s&cache=%s",
|
||||
ip, license.length() == 0 ? "none" : license, cachedResults));
|
||||
|
||||
return VPNResponse.fromJson(result);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
commands.add(new AntiVPNCommand());
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package dev.brighten.antivpn.api;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.EvictingMap;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.web.FunkemunkyAPI;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -49,7 +50,7 @@ public abstract class VPNExecutor {
|
||||
if(cachedRes.isPresent()) return cachedRes.get();
|
||||
else {
|
||||
try {
|
||||
VPNResponse response = AntiVPN
|
||||
VPNResponse response = FunkemunkyAPI
|
||||
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||
|
||||
if(response.isSuccess()) {
|
||||
@@ -78,7 +79,7 @@ public abstract class VPNExecutor {
|
||||
if(cachedRes.isPresent()) return cachedRes.get();
|
||||
else {
|
||||
try {
|
||||
VPNResponse response = AntiVPN
|
||||
VPNResponse response = FunkemunkyAPI
|
||||
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||
|
||||
if(response.isSuccess()) {
|
||||
|
||||
@@ -2,11 +2,12 @@ package dev.brighten.antivpn.command;
|
||||
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CommandExecutor {
|
||||
|
||||
void sendMessage(String message);
|
||||
void sendMessage(String message, Object... objects);
|
||||
boolean hasPermission(String permission);
|
||||
Optional<APIPlayer> getPlayer();
|
||||
boolean isPlayer();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class AntiVPNCommand extends Command {
|
||||
@Override
|
||||
public Command[] children() {
|
||||
return new Command[] {new LookupCommand(), new AllowlistCommand(), new AlertsCommand(),
|
||||
new ClearCacheCommand()};
|
||||
new ClearCacheCommand(), new PlanCommand()};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,13 +67,13 @@ public class LookupCommand extends Command {
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
executor.sendMessage("&6&l" + player.get().getName() + "&7&l's Connection Information");
|
||||
executor.sendMessage("");
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Proxy", result.isProxy()
|
||||
? "&a" + result.getMethod() : "&cNo"));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "ISP", result.getIsp()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Country", result.getCountryName()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "City", result.getCity()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Coordinates", result.getLatitude()
|
||||
+ "&7/&f" + result.getLongitude()));
|
||||
executor.sendMessage("&e%s&8: &f%s", "Proxy", result.isProxy()
|
||||
? "&a" + result.getMethod() : "&cNo");
|
||||
executor.sendMessage("&e%s&8: &f%s", "ISP", result.getIsp());
|
||||
executor.sendMessage("&e%s&8: &f%s", "Country", result.getCountryName());
|
||||
executor.sendMessage("&e%s&8: &f%s", "City", result.getCity());
|
||||
executor.sendMessage("&e%s&8: &f%s", "Coordinates", result.getLatitude()
|
||||
+ "&7/&f" + result.getLongitude());
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
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 dev.brighten.antivpn.utils.StringUtil;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.web.FunkemunkyAPI;
|
||||
import dev.brighten.antivpn.web.objects.QueryResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class PlanCommand extends Command {
|
||||
@Override
|
||||
public String permission() {
|
||||
return "antivpn.command.plan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "plan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[] {"queries", "query"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Info related to KauriVPN Plan";
|
||||
}
|
||||
|
||||
@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) {
|
||||
VPNExecutor.threadExecutor.execute(() -> {
|
||||
QueryResponse result;
|
||||
try {
|
||||
if(AntiVPN.getInstance().getVpnConfig().getLicense().equals("")) {
|
||||
result = FunkemunkyAPI.getQueryResponse();
|
||||
} else {
|
||||
result = FunkemunkyAPI.getQueryResponse(AntiVPN.getInstance().getVpnConfig().getLicense());
|
||||
|
||||
if(!result.isValidPlan()) {
|
||||
executor.sendMessage("&cThe license &f%s &cis not a valid license, " +
|
||||
"checking your Free plan information...",
|
||||
AntiVPN.getInstance().getVpnConfig().getLicense());
|
||||
|
||||
result = FunkemunkyAPI.getQueryResponse();
|
||||
}
|
||||
}
|
||||
|
||||
String plan = result.getPlanType();
|
||||
if(plan.equals("IP")) plan+= " (Free)";
|
||||
|
||||
String queryMax = result.getQueriesMax() == Long.MAX_VALUE
|
||||
? "Unlimited" : String.valueOf(result.getQueriesMax());
|
||||
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
executor.sendMessage("&6&lKauriVPN Plan Information");
|
||||
executor.sendMessage("");
|
||||
executor.sendMessage("&e%s&8: &f%s", "Plan", plan);
|
||||
executor.sendMessage("&e%s&8: &f%s&7/&f%s", "Queries Used",
|
||||
result.getQueries(), queryMax);
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
executor.sendMessage("&cThere was a JSONException thrown while looking up your query " +
|
||||
"information. Check console for more details.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
executor.sendMessage("&cThere was a IOException thrown while looking up your query " +
|
||||
"information. Check console for more details.");
|
||||
}
|
||||
});
|
||||
return "&7Looking up your query information...";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandExecutor executor, String alias, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.brighten.antivpn.database;
|
||||
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
package dev.brighten.antivpn.database.local;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.sql.utils.MySQL;
|
||||
import dev.brighten.antivpn.database.sql.utils.Query;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class H2VPN implements VPNDatabase {
|
||||
|
||||
private Thread whitelistedThread;
|
||||
|
||||
public H2VPN() {
|
||||
whitelistedThread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (true) {
|
||||
// Updating from database
|
||||
if (AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().clear();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted()
|
||||
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelisted());
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().clear();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps()
|
||||
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelistedIps());
|
||||
}
|
||||
try {
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(4));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
whitelistedThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VPNResponse> getStoredResponse(String ip) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
||||
return Optional.empty();
|
||||
|
||||
ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip).executeQuery();
|
||||
|
||||
try {
|
||||
if (rs != null && rs.next()) {
|
||||
VPNResponse response = new VPNResponse(rs.getString("asn"), rs.getString("ip"),
|
||||
rs.getString("countryName"), rs.getString("countryCode"),
|
||||
rs.getString("city"), rs.getString("timeZone"),
|
||||
rs.getString("method"), rs.getString("isp"), "N/A",
|
||||
rs.getBoolean("proxy"), rs.getBoolean("cached"), true,
|
||||
rs.getDouble("latitude"), rs.getDouble("longitude"),
|
||||
System.currentTimeMillis(), -1);
|
||||
return Optional.of(response);
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/*
|
||||
* Query.
|
||||
* prepare("create table if not exists `responses` (`ip` varchar(45) not null, "
|
||||
* +
|
||||
* "`countryName` varchar(64), `countryCode` varchar(10), `city` varchar(64), `timeZone` varchar(64), "
|
||||
* +
|
||||
* "`method` varchar(32), `isp` varchar(32), `proxy` boolean, `cached` boolean "
|
||||
* + "`latitude` double, `longitude` double)");
|
||||
*/
|
||||
@Override
|
||||
public void cacheResponse(VPNResponse toCache) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
||||
+ "`method`,`isp`,`proxy`,`cached`,`inserted`,`latitude`,`longitude`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
.append(toCache.getIp()).append(toCache.getAsn()).append(toCache.getCountryName())
|
||||
.append(toCache.getCountryCode()).append(toCache.getCity()).append(toCache.getTimeZone())
|
||||
.append(toCache.getMethod()).append(toCache.getIsp()).append(toCache.isProxy())
|
||||
.append(toCache.isCached()).append(new Timestamp(System.currentTimeMillis()))
|
||||
.append(toCache.getLatitude()).append(toCache.getLongitude()).execute();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public boolean isWhitelisted(UUID uuid) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return false;
|
||||
ResultSet set = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1")
|
||||
.append(uuid.toString()).executeQuery();
|
||||
|
||||
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
|
||||
public void setWhitelisted(UUID uuid, boolean whitelisted) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
if (whitelisted) {
|
||||
if (!isWhitelisted(uuid)) {
|
||||
Query.prepare("insert into `whitelisted` (`uuid`) values (?)").append(uuid.toString()).execute();
|
||||
}
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||
} else {
|
||||
Query.prepare("delete from `whitelisted` where `uuid` = ?").append(uuid.toString()).execute();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
public List<UUID> getAllWhitelisted() {
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
|
||||
if(!MySQL.isClosed()) Query.prepare("select uuid from `whitelisted`")
|
||||
.execute(set -> uuids.add(UUID.fromString(set.getString("uuid"))));
|
||||
|
||||
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
|
||||
public void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
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
|
||||
public void alertsState(UUID uuid, Consumer<Boolean> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> {
|
||||
ResultSet set = Query.prepare("select * from `alerts` where `uuid` = ? limit 1")
|
||||
.append(uuid.toString()).executeQuery();
|
||||
|
||||
try {
|
||||
result.accept(set != null && set.next() && set.getString("uuid") != null);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.accept(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAlertsState(UUID uuid, boolean enabled) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
if(enabled) {
|
||||
//We want to make sure there isn't already a uuid inserted to prevent double insertions
|
||||
alertsState(uuid, alreadyEnabled -> { //No need to make another thread execute, already async
|
||||
if(!alreadyEnabled) {
|
||||
Query.prepare("insert into `alerts` (`uuid`) values (?)").append(uuid.toString())
|
||||
.execute();
|
||||
} //No need to insert again of already enabled
|
||||
});
|
||||
//Removing any uuid from the alerts table will disable alerts globally.
|
||||
} else VPNExecutor.threadExecutor.execute(() ->
|
||||
Query.prepare("delete from `alerts` where `uuid` = ?")
|
||||
.append(uuid.toString())
|
||||
.execute());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearResponses() {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> Query.prepare("delete from `responses`").execute());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
AntiVPN.getInstance().getExecutor().log("Initializing H2...");
|
||||
MySQL.initH2();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||
|
||||
//Running check for old table types to update
|
||||
|
||||
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),"
|
||||
+ "`countryName` text, `countryCode` varchar(10), `city` text, `timeZone` varchar(64), "
|
||||
+ "`method` varchar(32), `isp` text, `proxy` boolean, `cached` boolean, `inserted` timestamp,"
|
||||
+ "`latitude` double, `longitude` double)").execute();
|
||||
Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)").execute();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
|
||||
try {
|
||||
Query.prepare("create index `uuid_1` if not exists on `whitelisted` (`uuid`)").execute();
|
||||
Query.prepare("create index `ip_1` if not exists on `responses` (`ip`)").execute();
|
||||
Query.prepare("create index `proxy_1` if not exists on `responses` (`proxy`)").execute();
|
||||
Query.prepare("create index `inserted_1` if not exists on `responses` (`inserted`)").execute();
|
||||
Query.prepare("create index `ip_1` if not exists on `whitelisted-ips` (`ip`)").execute();
|
||||
} catch (Exception e) {
|
||||
System.err.println("MySQL Excepton created" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
MySQL.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ 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 dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.sql.utils.MySQL;
|
||||
import dev.brighten.antivpn.database.sql.utils.Query;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
@@ -242,9 +242,7 @@ public class MySqlVPN implements VPNDatabase {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
AntiVPN.getInstance().getExecutor().log("Initializing MySQL...");
|
||||
if(AntiVPN.getInstance().getVpnConfig().getDatabaseType().contains("sql")) {
|
||||
MySQL.init();
|
||||
} else MySQL.initH2();
|
||||
MySQL.init();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package dev.brighten.antivpn.web;
|
||||
|
||||
import dev.brighten.antivpn.web.objects.QueryResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FunkemunkyAPI {
|
||||
|
||||
/**
|
||||
*
|
||||
* Queries https://funkemunky.cc/vpn API and returns information on the IP
|
||||
*
|
||||
* @param ip String
|
||||
* @param license String
|
||||
* @param cachedResults boolean
|
||||
* @return VPNResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
||||
throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl(String
|
||||
.format("https://funkemunky.cc/vpn?ip=%s&license=%s&cache=%s",
|
||||
ip, license.length() == 0 ? "none" : license, cachedResults));
|
||||
|
||||
return VPNResponse.fromJson(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds into {@link FunkemunkyAPI#getQueryResponse(String)} using "none" as argument
|
||||
* to grab query information based on the connecting IP address.
|
||||
*
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static QueryResponse getQueryResponse() throws JSONException, IOException {
|
||||
return getQueryResponse("none");
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries https://funkemunky.cc/vpn/queryCheck and returns information based on the
|
||||
* provided licence input.
|
||||
*
|
||||
* @param license String
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static QueryResponse getQueryResponse(String license) throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl("https://funkemunky.cc/vpn/queryCheck?license=" + license);
|
||||
|
||||
return QueryResponse.fromJson(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.brighten.antivpn.web.objects;
|
||||
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* Used to format the JSON response from https://funkemunky.cc/vpn/queryCheck into an object for project use.
|
||||
*/
|
||||
@Data
|
||||
@Builder(toBuilder = true)
|
||||
public class QueryResponse {
|
||||
|
||||
private boolean validPlan;
|
||||
private String planType;
|
||||
private long queries;
|
||||
private long queriesMax;
|
||||
|
||||
/**
|
||||
* Takes a JSON String and feeds it into {@link QueryResponse#fromJson(JSONObject)}
|
||||
*
|
||||
* @param jsonString String (formatted in JSON)
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static QueryResponse fromJson(String jsonString) throws JSONException {
|
||||
return fromJson(new JSONObject(jsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats response from https://funkemunky.cc/vpn/queryCheck into {@link QueryResponse} for project use.
|
||||
*
|
||||
* @param object JSONObject
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static QueryResponse fromJson(JSONObject object) throws JSONException {
|
||||
boolean validPlan = object.getBoolean("validPlan");
|
||||
|
||||
if(!validPlan) { // Nothing else will be returned from API if validPlan is false.
|
||||
return QueryResponse.builder().validPlan(false).build();
|
||||
}
|
||||
|
||||
return QueryResponse.builder().validPlan(object.getBoolean("validPlan"))
|
||||
.planType(object.getString("planType"))
|
||||
.queries(object.getLong("queries"))
|
||||
.queriesMax(object.getLong("queryLimit")).build();
|
||||
}
|
||||
}
|
||||
+20
-28
@@ -1,13 +1,11 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
package dev.brighten.antivpn.web.objects;
|
||||
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class VPNResponse {
|
||||
private String asn, ip, countryName, countryCode, city, timeZone, method, isp, failureReason = "N/A";
|
||||
@@ -29,34 +27,31 @@ public class VPNResponse {
|
||||
json.put("proxy", proxy);
|
||||
json.put("success", success);
|
||||
json.put("timeZone", timeZone);
|
||||
json.put("success", true);
|
||||
json.put("queriesLeft", queriesLeft);
|
||||
json.put("cached", cached);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds into {@link VPNResponse#fromJson(JSONObject)} formatting the JSON {@link String} into
|
||||
* a {@link JSONObject}
|
||||
*
|
||||
* @param json String
|
||||
* @return VPNResponse
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static VPNResponse fromJson(String json) throws JSONException {
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
if(jsonObject.getBoolean("success")) {
|
||||
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
|
||||
jsonObject.getString("countryName"), jsonObject.getString("countryCode"),
|
||||
jsonObject.getString("city"), jsonObject.getString("timeZone"),
|
||||
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
|
||||
jsonObject.getString("isp"), "N/A", jsonObject.getBoolean("proxy"),
|
||||
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"),
|
||||
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
|
||||
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
|
||||
} else {
|
||||
VPNResponse response = new VPNResponse(false);
|
||||
|
||||
response.failureReason = jsonObject.getString("failureReason");
|
||||
|
||||
return response;
|
||||
}
|
||||
return fromJson(new JSONObject(json));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats response from https://funkemunky.cc/vpn into {@link VPNResponse} for project use.
|
||||
*
|
||||
* @param jsonObject JSONObject
|
||||
* @return VPNResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static VPNResponse fromJson(JSONObject jsonObject) throws JSONException {
|
||||
if(jsonObject.getBoolean("success")) {
|
||||
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
|
||||
@@ -68,11 +63,8 @@ public class VPNResponse {
|
||||
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
|
||||
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
|
||||
} else {
|
||||
VPNResponse response = new VPNResponse(false);
|
||||
|
||||
response.failureReason = jsonObject.getString("failureReason");
|
||||
|
||||
return response;
|
||||
return VPNResponse.builder().success(false)
|
||||
.failureReason(jsonObject.getString("failureReason")).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import dev.brighten.antivpn.velocity.command.VelocityCommand;
|
||||
import lombok.Getter;
|
||||
import org.bstats.velocity.Metrics;
|
||||
|
||||
+3
-2
@@ -16,8 +16,9 @@ public class VelocityCommandExecutor implements CommandExecutor {
|
||||
private final CommandSource sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(message));
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(String.format(message, objects)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user