From 38dec65bf9233efbf6372b8754953f07033b97c9 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Mon, 11 Jul 2016 23:05:00 -0400 Subject: [PATCH] Add ip ban dumps. Adds #39 --- .../java/net/frozenorb/apiv3/model/IpBan.java | 4 +++ .../frozenorb/apiv3/route/GETDumpsType.java | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) 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]"); } }