diff --git a/src/main/java/net/frozenorb/apiv3/model/IpBan.java b/src/main/java/net/frozenorb/apiv3/model/IpBan.java index 079c707..3104282 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpBan.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpBan.java @@ -38,6 +38,10 @@ public final class IpBan { @Getter private Instant removedAt; @Getter private String removalReason; + public static void find(SingleResultCallback> callback) { + ipBansCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); + } + public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback> callback) { ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); } diff --git a/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java b/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java index d8caa9b..06ab752 100644 --- a/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java +++ b/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java @@ -7,6 +7,7 @@ import io.vertx.core.Handler; import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.model.Grant; +import net.frozenorb.apiv3.model.IpBan; import net.frozenorb.apiv3.model.Punishment; import net.frozenorb.apiv3.util.ErrorUtils; @@ -17,6 +18,7 @@ public final class GETDumpsType implements Handler { private static List banCache = ImmutableList.of(); private static List blacklistCache = ImmutableList.of(); + private static List ipBanCache = ImmutableList.of(); private static Map> grantCache = ImmutableMap.of(); static { @@ -77,6 +79,25 @@ public final class GETDumpsType implements Handler { GETDumpsType.grantCache = grantCache; }); + + IpBan.find((ipBans, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + List ipBanCache = new LinkedList<>(); + + for (IpBan ipBan : ipBans) { + if (!ipBan.isActive()) { + continue; + } + + ipBanCache.add(ipBan.getUserIp()); + } + + GETDumpsType.ipBanCache = ipBanCache; + }); } public void handle(RoutingContext ctx) { @@ -97,11 +118,14 @@ public final class GETDumpsType implements Handler { APIv3.respondJson(ctx, 200, result); return; + case "ipban": + APIv3.respondJson(ctx, 200, ipBanCache); + return; case "grant": APIv3.respondJson(ctx, 200, grantCache); return; default: - ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, grant]"); + ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, ipBan, grant]"); } }