diff --git a/src/main/java/net/frozenorb/apiv3/config/MongoConfig.java b/src/main/java/net/frozenorb/apiv3/config/MongoConfig.java index 1109146..b91ac68 100644 --- a/src/main/java/net/frozenorb/apiv3/config/MongoConfig.java +++ b/src/main/java/net/frozenorb/apiv3/config/MongoConfig.java @@ -110,7 +110,8 @@ public class MongoConfig { db.getCollection("users").createIndexes(ImmutableList.of( new IndexModel(new Document("lastUsername", 1)), new IndexModel(new Document("lastUsernameLower", 1)), - new IndexModel(new Document("emailToken", 1)) + new IndexModel(new Document("emailToken", 1)), + new IndexModel(new Document("totpSecret", 1)) ), (a, b) -> {}); db.getCollection("userMeta").createIndexes(ImmutableList.of( new IndexModel(new Document("user", 1).append("serverGroup", 1)) diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index 28762f5..01b044e 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -92,6 +92,10 @@ public final class User { usersCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); } + public static void findAllWithTotpSetup(SingleResultCallback> callback) { + usersCollection.find(new Document("totpSecret", new Document("$exists", true))).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); + } + public static void findById(String id, SingleResultCallback callback) { try { findById(UuidUtils.parseUuid(id), callback); diff --git a/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java b/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java index 8ef8b9b..51656b2 100644 --- a/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java +++ b/src/main/java/net/frozenorb/apiv3/route/GETDumpsType.java @@ -39,6 +39,7 @@ public final class GETDumpsType implements Handler { private final DecimalFormat coordinateFormat = new DecimalFormat("#.#####"); + private List totpCache = ImmutableList.of(); private List banCache = ImmutableList.of(); private List blacklistCache = ImmutableList.of(); private List ipBanCache = ImmutableList.of(); @@ -48,6 +49,21 @@ public final class GETDumpsType implements Handler { // 5 minutes, can't use TimeUnit expression in annotation @Scheduled(fixedRate = 5 * 60 * 1000) public void updateCache() { + User.findAllWithTotpSetup((users, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + List totpCache = new LinkedList<>(); + + for (User user : users) { + totpCache.add(user.getId()); + } + + this.totpCache = totpCache; + }); + Punishment.findByType(ImmutableSet.of( Punishment.PunishmentType.BAN, Punishment.PunishmentType.BLACKLIST @@ -157,6 +173,9 @@ public final class GETDumpsType implements Handler { String dumpType = ctx.request().getParam("dumpType"); switch (dumpType.toLowerCase()) { + case "totp": + APIv3.respondJson(ctx, 200, totpCache); + return; case "ban": APIv3.respondJson(ctx, 200, banCache); return; @@ -246,7 +265,7 @@ public final class GETDumpsType implements Handler { )); return; default: - ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, ipBan, grant, ipIntel, ipIntelFormatted]"); + ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [totp, ban, blacklist, accessDeniable, ipBan, grant, ipIntel, ipIntelFormatted]"); } }