Add ip ban dumps. Adds #39
This commit is contained in:
parent
8e85914d64
commit
38dec65bf9
@ -38,6 +38,10 @@ public final class IpBan {
|
||||
@Getter private Instant removedAt;
|
||||
@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) {
|
||||
ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
@ -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<RoutingContext> {
|
||||
|
||||
private static List<UUID> banCache = 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();
|
||||
|
||||
static {
|
||||
@ -77,6 +79,25 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
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) {
|
||||
@ -97,11 +118,14 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
||||
|
||||
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]");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user