Add ip ban dumps. Adds #39

This commit is contained in:
Colin McDonald 2016-07-11 23:05:00 -04:00
parent 8e85914d64
commit 38dec65bf9
2 changed files with 29 additions and 1 deletions

View File

@ -38,6 +38,10 @@ public final class IpBan {
@Getter private Instant removedAt; @Getter private Instant removedAt;
@Getter private String removalReason; @Getter private String removalReason;
public static void find(SingleResultCallback<List<IpBan>> callback) {
ipBansCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
}
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<IpBan>> callback) { public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<IpBan>> callback) {
ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }

View File

@ -7,6 +7,7 @@ import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Grant; import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.model.Punishment; import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.util.ErrorUtils; import net.frozenorb.apiv3.util.ErrorUtils;
@ -17,6 +18,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
private static List<UUID> banCache = ImmutableList.of(); private static List<UUID> banCache = ImmutableList.of();
private static List<UUID> blacklistCache = ImmutableList.of(); private static List<UUID> blacklistCache = ImmutableList.of();
private static List<String> ipBanCache = ImmutableList.of();
private static Map<String, List<UUID>> grantCache = ImmutableMap.of(); private static Map<String, List<UUID>> grantCache = ImmutableMap.of();
static { static {
@ -77,6 +79,25 @@ public final class GETDumpsType implements Handler<RoutingContext> {
GETDumpsType.grantCache = grantCache; GETDumpsType.grantCache = grantCache;
}); });
IpBan.find((ipBans, error) -> {
if (error != null) {
error.printStackTrace();
return;
}
List<String> ipBanCache = new LinkedList<>();
for (IpBan ipBan : ipBans) {
if (!ipBan.isActive()) {
continue;
}
ipBanCache.add(ipBan.getUserIp());
}
GETDumpsType.ipBanCache = ipBanCache;
});
} }
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
@ -97,11 +118,14 @@ public final class GETDumpsType implements Handler<RoutingContext> {
APIv3.respondJson(ctx, 200, result); APIv3.respondJson(ctx, 200, result);
return; return;
case "ipban":
APIv3.respondJson(ctx, 200, ipBanCache);
return;
case "grant": case "grant":
APIv3.respondJson(ctx, 200, grantCache); APIv3.respondJson(ctx, 200, grantCache);
return; return;
default: 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]");
} }
} }