Test IntelliJ reformatting
This commit is contained in:
parent
3ea54fdfcd
commit
07e2906d0e
@ -121,21 +121,21 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class APIv3 extends AbstractVerticle {
|
public final class APIv3 extends AbstractVerticle {
|
||||||
|
|
||||||
@Getter private static Vertx vertxInstance;
|
@Getter private static Vertx vertxInstance;
|
||||||
@Getter private static MongoDatabase database;
|
@Getter private static MongoDatabase database;
|
||||||
@Getter private static final Properties config = new Properties();
|
@Getter private static final Properties config = new Properties();
|
||||||
private static final Gson gson = new GsonBuilder()
|
private static final Gson gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
|
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
|
||||||
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
|
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
vertxInstance = vertx;
|
vertxInstance = vertx;
|
||||||
setupConfig();
|
setupConfig();
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
setupMetrics();
|
setupMetrics();
|
||||||
setupHttpServer();
|
setupHttpServer();
|
||||||
|
|
||||||
/*V2Importer converter = new V2Importer("mongodb://158.69.126.126", "minehq");
|
/*V2Importer converter = new V2Importer("mongodb://158.69.126.126", "minehq");
|
||||||
|
|
||||||
@ -146,260 +146,267 @@ public final class APIv3 extends AbstractVerticle {
|
|||||||
log.info("Finished conversion!");
|
log.info("Finished conversion!");
|
||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupConfig() {
|
private void setupConfig() {
|
||||||
try (InputStream in = new FileInputStream("apiv3.properties")) {
|
try (InputStream in = new FileInputStream("apiv3.properties")) {
|
||||||
config.load(in);
|
config.load(in);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDatabase() {
|
private void setupDatabase() {
|
||||||
List<MongoCredential> credentials = ImmutableList.of();
|
List<MongoCredential> credentials = ImmutableList.of();
|
||||||
|
|
||||||
if (!config.getProperty("mongo.username").isEmpty()) {
|
if (!config.getProperty("mongo.username").isEmpty()) {
|
||||||
credentials = ImmutableList.of(
|
credentials = ImmutableList.of(
|
||||||
MongoCredential.createCredential(
|
MongoCredential.createCredential(
|
||||||
config.getProperty("mongo.username"),
|
config.getProperty("mongo.username"),
|
||||||
config.getProperty("mongo.database"),
|
config.getProperty("mongo.database"),
|
||||||
config.getProperty("mongo.password").toCharArray()
|
config.getProperty("mongo.password").toCharArray()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionString connectionString = new ConnectionString("mongodb://" + config.getProperty("mongo.address") + ":" + config.getProperty("mongo.port"));
|
ConnectionString connectionString = new ConnectionString("mongodb://" + config.getProperty("mongo.address") + ":" + config.getProperty("mongo.port"));
|
||||||
|
|
||||||
MongoClient mongoClient = MongoClients.create(MongoClientSettings
|
MongoClient mongoClient = MongoClients.create(MongoClientSettings
|
||||||
.builder()
|
.builder()
|
||||||
.codecRegistry(CodecRegistries.fromProviders(ImmutableList.of(
|
.codecRegistry(CodecRegistries.fromProviders(ImmutableList.of(
|
||||||
new UuidCodecProvider(), // MHQ, fixes uuid serialization
|
new UuidCodecProvider(), // MHQ, fixes uuid serialization
|
||||||
new ValueCodecProvider(),
|
new ValueCodecProvider(),
|
||||||
new DocumentCodecProvider(),
|
new DocumentCodecProvider(),
|
||||||
new BsonValueCodecProvider(),
|
new BsonValueCodecProvider(),
|
||||||
new JacksonCodecProvider(createMongoJacksonMapper()) // Jackson codec, provides serialization/deserialization
|
new JacksonCodecProvider(createMongoJacksonMapper()) // Jackson codec, provides serialization/deserialization
|
||||||
)))
|
)))
|
||||||
.credentialList(credentials)
|
.credentialList(credentials)
|
||||||
.clusterSettings(ClusterSettings.builder()
|
.clusterSettings(ClusterSettings.builder()
|
||||||
.applyConnectionString(connectionString)
|
.applyConnectionString(connectionString)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
database = mongoClient.getDatabase(config.getProperty("mongo.database"));
|
database = mongoClient.getDatabase(config.getProperty("mongo.database"));
|
||||||
database.getCollection("auditLog").createIndexes(ImmutableList.of(
|
database.getCollection("auditLog").createIndexes(ImmutableList.of(
|
||||||
new IndexModel(new Document("user", 1)),
|
new IndexModel(new Document("user", 1)),
|
||||||
new IndexModel(new Document("performedAt", 1)),
|
new IndexModel(new Document("performedAt", 1)),
|
||||||
new IndexModel(new Document("type", 1))
|
new IndexModel(new Document("type", 1))
|
||||||
), (a, b) -> {});
|
), (a, b) -> {
|
||||||
database.getCollection("grants").createIndexes(ImmutableList.of(
|
});
|
||||||
new IndexModel(new Document("user", 1)),
|
database.getCollection("grants").createIndexes(ImmutableList.of(
|
||||||
new IndexModel(new Document("rank", 1)),
|
new IndexModel(new Document("user", 1)),
|
||||||
new IndexModel(new Document("addedAt", 1))
|
new IndexModel(new Document("rank", 1)),
|
||||||
), (a, b) -> {});
|
new IndexModel(new Document("addedAt", 1))
|
||||||
database.getCollection("ipLog").createIndexes(ImmutableList.of(
|
), (a, b) -> {
|
||||||
new IndexModel(new Document("user", 1)),
|
});
|
||||||
new IndexModel(new Document("user", 1).append("userIp", 1))
|
database.getCollection("ipLog").createIndexes(ImmutableList.of(
|
||||||
), (a, b) -> {});
|
new IndexModel(new Document("user", 1)),
|
||||||
database.getCollection("ipBans").createIndexes(ImmutableList.of(
|
new IndexModel(new Document("user", 1).append("userIp", 1))
|
||||||
new IndexModel(new Document("userIp", 1))
|
), (a, b) -> {
|
||||||
), (a, b) -> {});
|
});
|
||||||
database.getCollection("punishments").createIndexes(ImmutableList.of(
|
database.getCollection("ipBans").createIndexes(ImmutableList.of(
|
||||||
new IndexModel(new Document("user", 1)),
|
new IndexModel(new Document("userIp", 1))
|
||||||
new IndexModel(new Document("type", 1)),
|
), (a, b) -> {
|
||||||
new IndexModel(new Document("addedAt", 1)),
|
});
|
||||||
new IndexModel(new Document("addedBy", 1)),
|
database.getCollection("punishments").createIndexes(ImmutableList.of(
|
||||||
new IndexModel(new Document("linkedIpBanId", 1))
|
new IndexModel(new Document("user", 1)),
|
||||||
), (a, b) -> {});
|
new IndexModel(new Document("type", 1)),
|
||||||
database.getCollection("users").createIndexes(ImmutableList.of(
|
new IndexModel(new Document("addedAt", 1)),
|
||||||
new IndexModel(new Document("lastUsername", 1)),
|
new IndexModel(new Document("addedBy", 1)),
|
||||||
new IndexModel(new Document("emailToken", 1))
|
new IndexModel(new Document("linkedIpBanId", 1))
|
||||||
), (a, b) -> {});
|
), (a, b) -> {
|
||||||
database.getCollection("userMeta").createIndexes(ImmutableList.of(
|
});
|
||||||
new IndexModel(new Document("user", 1).append("serverGroup", 1))
|
database.getCollection("users").createIndexes(ImmutableList.of(
|
||||||
), (a, b) -> {});
|
new IndexModel(new Document("lastUsername", 1)),
|
||||||
|
new IndexModel(new Document("emailToken", 1))
|
||||||
|
), (a, b) -> {
|
||||||
|
});
|
||||||
|
database.getCollection("userMeta").createIndexes(ImmutableList.of(
|
||||||
|
new IndexModel(new Document("user", 1).append("serverGroup", 1))
|
||||||
|
), (a, b) -> {
|
||||||
|
});
|
||||||
|
|
||||||
BannedAsn.updateCache();
|
BannedAsn.updateCache();
|
||||||
BannedCellCarrier.updateCache();
|
BannedCellCarrier.updateCache();
|
||||||
Rank.updateCache();
|
Rank.updateCache();
|
||||||
Server.updateCache();
|
Server.updateCache();
|
||||||
ServerGroup.updateCache();
|
ServerGroup.updateCache();
|
||||||
EmailUtils.updateBannedEmailDomains();
|
EmailUtils.updateBannedEmailDomains();
|
||||||
GETDumpsType.updateCache();
|
GETDumpsType.updateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectMapper createMongoJacksonMapper() {
|
private ObjectMapper createMongoJacksonMapper() {
|
||||||
ObjectMapper mongoJacksonMapper = ObjectMapperFactory.createObjectMapper();
|
ObjectMapper mongoJacksonMapper = ObjectMapperFactory.createObjectMapper();
|
||||||
SimpleModule module = new SimpleModule();
|
SimpleModule module = new SimpleModule();
|
||||||
|
|
||||||
module.addSerializer(Instant.class, new InstantJsonSerializer());
|
module.addSerializer(Instant.class, new InstantJsonSerializer());
|
||||||
module.addDeserializer(Instant.class, new InstantJsonDeserializer());
|
module.addDeserializer(Instant.class, new InstantJsonDeserializer());
|
||||||
module.addSerializer(UUID.class, new UuidJsonSerializer());
|
module.addSerializer(UUID.class, new UuidJsonSerializer());
|
||||||
module.addDeserializer(UUID.class, new UuidJsonDeserializer());
|
module.addDeserializer(UUID.class, new UuidJsonDeserializer());
|
||||||
|
|
||||||
mongoJacksonMapper.registerModule(module);
|
mongoJacksonMapper.registerModule(module);
|
||||||
mongoJacksonMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
|
mongoJacksonMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
|
||||||
mongoJacksonMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
mongoJacksonMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
||||||
mongoJacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mongoJacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
|
||||||
return mongoJacksonMapper;
|
return mongoJacksonMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMetrics() {
|
private void setupMetrics() {
|
||||||
MetricRegistry registry = SharedMetricRegistries.getOrCreate("apiv3-registry");
|
MetricRegistry registry = SharedMetricRegistries.getOrCreate("apiv3-registry");
|
||||||
|
|
||||||
LibratoReporter.enable(
|
LibratoReporter.enable(
|
||||||
LibratoReporter.builder(
|
LibratoReporter.builder(
|
||||||
registry,
|
registry,
|
||||||
config.getProperty("librato.email"),
|
config.getProperty("librato.email"),
|
||||||
config.getProperty("librato.apiToken"),
|
config.getProperty("librato.apiToken"),
|
||||||
config.getProperty("librato.sourceIdentifier")),
|
config.getProperty("librato.sourceIdentifier")),
|
||||||
10,
|
10,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupHttpServer() {
|
private void setupHttpServer() {
|
||||||
HttpServerOptions httpServerOptions = new HttpServerOptions();
|
HttpServerOptions httpServerOptions = new HttpServerOptions();
|
||||||
httpServerOptions.setCompressionSupported(true);
|
httpServerOptions.setCompressionSupported(true);
|
||||||
|
|
||||||
if (!config.getProperty("http.keystoreFile").isEmpty()) {
|
if (!config.getProperty("http.keystoreFile").isEmpty()) {
|
||||||
httpServerOptions.setSsl(true);
|
httpServerOptions.setSsl(true);
|
||||||
httpServerOptions.setKeyStoreOptions(
|
httpServerOptions.setKeyStoreOptions(
|
||||||
new JksOptions()
|
new JksOptions()
|
||||||
.setPassword(config.getProperty("http.keystorePassword"))
|
.setPassword(config.getProperty("http.keystorePassword"))
|
||||||
.setPath(config.getProperty("http.keystoreFile"))
|
.setPath(config.getProperty("http.keystoreFile"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
|
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
|
||||||
Router http = Router.router(vertx); // we just name this http to make the route declarations easier to read
|
Router http = Router.router(vertx); // we just name this http to make the route declarations easier to read
|
||||||
|
|
||||||
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
|
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
|
||||||
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
|
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
|
||||||
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
||||||
http.route().handler(new ActorAttributeHandler());
|
http.route().handler(new ActorAttributeHandler());
|
||||||
http.route().handler(new MetricsHandler());
|
http.route().handler(new MetricsHandler());
|
||||||
http.route().handler(new WebsiteUserSessionHandler());
|
http.route().handler(new WebsiteUserSessionHandler());
|
||||||
http.route().handler(new AuthorizationHandler());
|
http.route().handler(new AuthorizationHandler());
|
||||||
http.exceptionHandler(Throwable::printStackTrace);
|
http.exceptionHandler(Throwable::printStackTrace);
|
||||||
|
|
||||||
// TODO: The commented out routes
|
// TODO: The commented out routes
|
||||||
|
|
||||||
http.get("/accessTokens/:accessToken").blockingHandler(new GETAccessTokensId());
|
http.get("/accessTokens/:accessToken").blockingHandler(new GETAccessTokensId());
|
||||||
http.get("/accessTokens").blockingHandler(new GETAccessTokens());
|
http.get("/accessTokens").blockingHandler(new GETAccessTokens());
|
||||||
http.post("/accessTokens").blockingHandler(new POSTAccessTokens(), false);
|
http.post("/accessTokens").blockingHandler(new POSTAccessTokens(), false);
|
||||||
//http.put("/accessTokens/:accessToken").blockingHandler(new PUTAccessTokensId(), false);
|
//http.put("/accessTokens/:accessToken").blockingHandler(new PUTAccessTokensId(), false);
|
||||||
http.delete("/accessTokens/:accessToken").blockingHandler(new DELETEAccessTokensId(), false);
|
http.delete("/accessTokens/:accessToken").blockingHandler(new DELETEAccessTokensId(), false);
|
||||||
|
|
||||||
http.get("/auditLog").handler(new GETAuditLog());
|
http.get("/auditLog").handler(new GETAuditLog());
|
||||||
http.post("/auditLog").handler(new POSTAuditLog());
|
http.post("/auditLog").handler(new POSTAuditLog());
|
||||||
http.delete("/auditLog/:auditLogEntryId").blockingHandler(new DELETEAuditLogId());
|
http.delete("/auditLog/:auditLogEntryId").blockingHandler(new DELETEAuditLogId());
|
||||||
|
|
||||||
http.get("/bannedAsns/:bannedAsn").handler(new GETBannedAsnsId());
|
http.get("/bannedAsns/:bannedAsn").handler(new GETBannedAsnsId());
|
||||||
http.get("/bannedAsns").handler(new GETBannedAsns());
|
http.get("/bannedAsns").handler(new GETBannedAsns());
|
||||||
http.post("/bannedAsns").blockingHandler(new POSTBannedAsns(), false);
|
http.post("/bannedAsns").blockingHandler(new POSTBannedAsns(), false);
|
||||||
//http.put("/bannedAsns/:bannedAsn").blockingHandler(new PUTBannedAsnsId(), false);
|
//http.put("/bannedAsns/:bannedAsn").blockingHandler(new PUTBannedAsnsId(), false);
|
||||||
http.delete("/bannedAsns/:bannedAsn").blockingHandler(new DELETEBannedAsnsId(), false);
|
http.delete("/bannedAsns/:bannedAsn").blockingHandler(new DELETEBannedAsnsId(), false);
|
||||||
|
|
||||||
http.get("/bannedCellCarriers/:bannedCellCarrier").handler(new GETBannedCellCarriersId());
|
http.get("/bannedCellCarriers/:bannedCellCarrier").handler(new GETBannedCellCarriersId());
|
||||||
http.get("/bannedCellCarriers").handler(new GETBannedCellCarriers());
|
http.get("/bannedCellCarriers").handler(new GETBannedCellCarriers());
|
||||||
http.post("/bannedCellCarriers").blockingHandler(new POSTBannedCellCarriers(), false);
|
http.post("/bannedCellCarriers").blockingHandler(new POSTBannedCellCarriers(), false);
|
||||||
//http.put("/bannedCellCarriers/:bannedCellCarrier").blockingHandler(new PUTBannedCellCarriersId(), false);
|
//http.put("/bannedCellCarriers/:bannedCellCarrier").blockingHandler(new PUTBannedCellCarriersId(), false);
|
||||||
http.delete("/bannedCellCarriers/:bannedCellCarrier").blockingHandler(new DELETEBannedCellCarriersId(), false);
|
http.delete("/bannedCellCarriers/:bannedCellCarrier").blockingHandler(new DELETEBannedCellCarriersId(), false);
|
||||||
|
|
||||||
http.get("/chatFilter/:chatFilterEntryId").handler(new GETChatFilterId());
|
http.get("/chatFilter/:chatFilterEntryId").handler(new GETChatFilterId());
|
||||||
http.get("/chatFilter").handler(new GETChatFilter());
|
http.get("/chatFilter").handler(new GETChatFilter());
|
||||||
http.post("/chatFilter").blockingHandler(new POSTChatFilter(), false);
|
http.post("/chatFilter").blockingHandler(new POSTChatFilter(), false);
|
||||||
//http.put("/chatFilter/:chatFilterEntryId").blockingHandler(new PUTChatFilterId(), false);
|
//http.put("/chatFilter/:chatFilterEntryId").blockingHandler(new PUTChatFilterId(), false);
|
||||||
http.delete("/chatFilter/:chatFilterEntryId").blockingHandler(new DELETEChatFilterId(), false);
|
http.delete("/chatFilter/:chatFilterEntryId").blockingHandler(new DELETEChatFilterId(), false);
|
||||||
|
|
||||||
http.post("/disposableLoginTokens").blockingHandler(new POSTDisposableLoginTokens(), false);
|
http.post("/disposableLoginTokens").blockingHandler(new POSTDisposableLoginTokens(), false);
|
||||||
http.post("/disposableLoginTokens/:disposableLoginToken/use").blockingHandler(new POSTDisposableLoginTokensIdUse(), false);
|
http.post("/disposableLoginTokens/:disposableLoginToken/use").blockingHandler(new POSTDisposableLoginTokensIdUse(), false);
|
||||||
|
|
||||||
http.get("/emailTokens/:emailToken/owner").blockingHandler(new GETEmailTokensIdOwner(), false);
|
http.get("/emailTokens/:emailToken/owner").blockingHandler(new GETEmailTokensIdOwner(), false);
|
||||||
http.post("/emailTokens/:emailToken/confirm").blockingHandler(new POSTEmailTokensIdConfirm(), false);
|
http.post("/emailTokens/:emailToken/confirm").blockingHandler(new POSTEmailTokensIdConfirm(), false);
|
||||||
|
|
||||||
http.get("/grants/:grantId").handler(new GETGrantsId());
|
http.get("/grants/:grantId").handler(new GETGrantsId());
|
||||||
http.get("/grants").handler(new GETGrants());
|
http.get("/grants").handler(new GETGrants());
|
||||||
http.post("/grants").blockingHandler(new POSTGrants(), false);
|
http.post("/grants").blockingHandler(new POSTGrants(), false);
|
||||||
//http.put("/grants/:grantId").blockingHandler(new PUTGrantsId(), false);
|
//http.put("/grants/:grantId").blockingHandler(new PUTGrantsId(), false);
|
||||||
http.delete("/grants/:grantId").blockingHandler(new DELETEGrantsId(), false);
|
http.delete("/grants/:grantId").blockingHandler(new DELETEGrantsId(), false);
|
||||||
|
|
||||||
http.get("/ipBans/:ipBanId").handler(new GETIpBansId());
|
http.get("/ipBans/:ipBanId").handler(new GETIpBansId());
|
||||||
http.get("/ipBans").handler(new GETIpBans());
|
http.get("/ipBans").handler(new GETIpBans());
|
||||||
http.post("/ipBans").blockingHandler(new POSTIpBans(), false);
|
http.post("/ipBans").blockingHandler(new POSTIpBans(), false);
|
||||||
//http.put("/ipBans/:ipBanId").blockingHandler(new PUTIpBansId(), false);
|
//http.put("/ipBans/:ipBanId").blockingHandler(new PUTIpBansId(), false);
|
||||||
http.delete("/ipBans/:ipBanId").blockingHandler(new DELETEIpBansId(), false);
|
http.delete("/ipBans/:ipBanId").blockingHandler(new DELETEIpBansId(), false);
|
||||||
|
|
||||||
http.get("/ipIntel/:userIp").handler(new GETIpInteld());
|
http.get("/ipIntel/:userIp").handler(new GETIpInteld());
|
||||||
|
|
||||||
http.get("/ipLog/:id").handler(new GETIpLogId());
|
http.get("/ipLog/:id").handler(new GETIpLogId());
|
||||||
|
|
||||||
http.get("/notificationTemplates/:notificationTemplateId").handler(new GETNotificationTemplatesId());
|
http.get("/notificationTemplates/:notificationTemplateId").handler(new GETNotificationTemplatesId());
|
||||||
http.get("/notificationTemplates").handler(new GETNotificationTemplates());
|
http.get("/notificationTemplates").handler(new GETNotificationTemplates());
|
||||||
http.post("/notificationTemplates").blockingHandler(new POSTNotificationTemplates(), false);
|
http.post("/notificationTemplates").blockingHandler(new POSTNotificationTemplates(), false);
|
||||||
//http.put("/notificationTemplates/:notificationTemplateId").blockingHandler(new PUTNotificationTemplatesId(), false);
|
//http.put("/notificationTemplates/:notificationTemplateId").blockingHandler(new PUTNotificationTemplatesId(), false);
|
||||||
http.delete("/notificationTemplates/:notificationTemplateId").blockingHandler(new DELETENotificationTemplatesId(), false);
|
http.delete("/notificationTemplates/:notificationTemplateId").blockingHandler(new DELETENotificationTemplatesId(), false);
|
||||||
|
|
||||||
http.get("/phoneIntel/:phone").handler(new GETPhoneInteld());
|
http.get("/phoneIntel/:phone").handler(new GETPhoneInteld());
|
||||||
|
|
||||||
http.get("/punishments/:punishmentId").handler(new GETPunishmentsId());
|
http.get("/punishments/:punishmentId").handler(new GETPunishmentsId());
|
||||||
http.get("/punishments").handler(new GETPunishments());
|
http.get("/punishments").handler(new GETPunishments());
|
||||||
http.post("/punishments").blockingHandler(new POSTPunishments(), false);
|
http.post("/punishments").blockingHandler(new POSTPunishments(), false);
|
||||||
//http.put("/punishments/:punishmentId").blockingHandler(new PUTPunishmentsId(), false);
|
//http.put("/punishments/:punishmentId").blockingHandler(new PUTPunishmentsId(), false);
|
||||||
http.delete("/punishments/:punishmentId").blockingHandler(new DELETEPunishmentsId(), false);
|
http.delete("/punishments/:punishmentId").blockingHandler(new DELETEPunishmentsId(), false);
|
||||||
http.delete("/users/:userId/activePunishment").blockingHandler(new DELETEUsersIdActivePunishment(), false);
|
http.delete("/users/:userId/activePunishment").blockingHandler(new DELETEUsersIdActivePunishment(), false);
|
||||||
|
|
||||||
http.get("/ranks/:rankId").handler(new GETRanksId());
|
http.get("/ranks/:rankId").handler(new GETRanksId());
|
||||||
http.get("/ranks").handler(new GETRanks());
|
http.get("/ranks").handler(new GETRanks());
|
||||||
http.post("/ranks").blockingHandler(new POSTRanks(), false);
|
http.post("/ranks").blockingHandler(new POSTRanks(), false);
|
||||||
//http.put("/ranks/:rankId").blockingHandler(new PUTRanksId(), false);
|
//http.put("/ranks/:rankId").blockingHandler(new PUTRanksId(), false);
|
||||||
http.delete("/ranks/:rankId").blockingHandler(new DELETERanksId(), false);
|
http.delete("/ranks/:rankId").blockingHandler(new DELETERanksId(), false);
|
||||||
|
|
||||||
http.get("/serverGroups/:serverGroupId").handler(new GETServerGroupsId());
|
http.get("/serverGroups/:serverGroupId").handler(new GETServerGroupsId());
|
||||||
http.get("/serverGroups").handler(new GETServerGroups());
|
http.get("/serverGroups").handler(new GETServerGroups());
|
||||||
http.post("/serverGroups").blockingHandler(new POSTServerGroups(), false);
|
http.post("/serverGroups").blockingHandler(new POSTServerGroups(), false);
|
||||||
//http.put("/serverGroups/:serverGroupId").blockingHandler(new PUTServerGroupsId(), false);
|
//http.put("/serverGroups/:serverGroupId").blockingHandler(new PUTServerGroupsId(), false);
|
||||||
http.delete("/serverGroups/:serverGroupId").blockingHandler(new DELETEServerGroupsId(), false);
|
http.delete("/serverGroups/:serverGroupId").blockingHandler(new DELETEServerGroupsId(), false);
|
||||||
|
|
||||||
http.get("/servers/:serverId").handler(new GETServersId());
|
http.get("/servers/:serverId").handler(new GETServersId());
|
||||||
http.get("/servers").handler(new GETServers());
|
http.get("/servers").handler(new GETServers());
|
||||||
http.post("/servers/heartbeat").handler(new POSTServersHeartbeat());
|
http.post("/servers/heartbeat").handler(new POSTServersHeartbeat());
|
||||||
http.post("/servers").blockingHandler(new POSTServers(), false);
|
http.post("/servers").blockingHandler(new POSTServers(), false);
|
||||||
//http.put("/servers/:serverId").blockingHandler(new PUTServersId(), false);
|
//http.put("/servers/:serverId").blockingHandler(new PUTServersId(), false);
|
||||||
http.delete("/servers/:serverId").blockingHandler(new DELETEServersId(), false);
|
http.delete("/servers/:serverId").blockingHandler(new DELETEServersId(), false);
|
||||||
|
|
||||||
http.get("/staff").blockingHandler(new GETStaff(), false);
|
http.get("/staff").blockingHandler(new GETStaff(), false);
|
||||||
http.get("/users/:userId").handler(new GETUsersId());
|
http.get("/users/:userId").handler(new GETUsersId());
|
||||||
http.get("/users/:userId/compoundedPermissions").handler(new GETUsersIdCompoundedPermissions());
|
http.get("/users/:userId/compoundedPermissions").handler(new GETUsersIdCompoundedPermissions());
|
||||||
http.get("/users/:userId/details").blockingHandler(new GETUsersIdDetails(), false);
|
http.get("/users/:userId/details").blockingHandler(new GETUsersIdDetails(), false);
|
||||||
http.get("/users/:userId/requiresTotp").handler(new GETUsersIdRequiresTotp());
|
http.get("/users/:userId/requiresTotp").handler(new GETUsersIdRequiresTotp());
|
||||||
http.get("/users/:userId/verifyPassword").blockingHandler(new GETUsersIdVerifyPassword(), false);
|
http.get("/users/:userId/verifyPassword").blockingHandler(new GETUsersIdVerifyPassword(), false);
|
||||||
http.post("/users/:userId/changePassword").blockingHandler(new POSTUsersIdChangePassword(), false);
|
http.post("/users/:userId/changePassword").blockingHandler(new POSTUsersIdChangePassword(), false);
|
||||||
http.post("/users/:userId/confirmPhone").blockingHandler(new POSTUsersIdConfirmPhone(), false);
|
http.post("/users/:userId/confirmPhone").blockingHandler(new POSTUsersIdConfirmPhone(), false);
|
||||||
http.post("/users/:userId/login").handler(new POSTUsersIdLogin());
|
http.post("/users/:userId/login").handler(new POSTUsersIdLogin());
|
||||||
http.post("/users/:userId/notify").blockingHandler(new POSTUsersIdNotify(), false);
|
http.post("/users/:userId/notify").blockingHandler(new POSTUsersIdNotify(), false);
|
||||||
http.post("/users/:userId/passwordReset").blockingHandler(new POSTUsersIdPasswordReset(), false);
|
http.post("/users/:userId/passwordReset").blockingHandler(new POSTUsersIdPasswordReset(), false);
|
||||||
http.post("/users/:userId/registerEmail").blockingHandler(new POSTUsersIdRegisterEmail(), false);
|
http.post("/users/:userId/registerEmail").blockingHandler(new POSTUsersIdRegisterEmail(), false);
|
||||||
http.post("/users/:userId/registerPhone").blockingHandler(new POSTUsersIdRegisterPhone(), false);
|
http.post("/users/:userId/registerPhone").blockingHandler(new POSTUsersIdRegisterPhone(), false);
|
||||||
http.post("/users/:userId/setupTotp").blockingHandler(new POSTUsersIdSetupTotp(), false);
|
http.post("/users/:userId/setupTotp").blockingHandler(new POSTUsersIdSetupTotp(), false);
|
||||||
http.post("/users/:userId/verifyTotp").handler(new POSTUsersIdVerifyTotp());
|
http.post("/users/:userId/verifyTotp").handler(new POSTUsersIdVerifyTotp());
|
||||||
|
|
||||||
http.get("/dumps/:dumpType").handler(new GETDumpsType());
|
http.get("/dumps/:dumpType").handler(new GETDumpsType());
|
||||||
http.get("/metrics").handler(new GETMetrics());
|
http.get("/metrics").handler(new GETMetrics());
|
||||||
http.get("/whoami").handler(new GETWhoAmI());
|
http.get("/whoami").handler(new GETWhoAmI());
|
||||||
http.post("/logout").handler(new POSTLogout());
|
http.post("/logout").handler(new POSTLogout());
|
||||||
|
|
||||||
int port = Integer.parseInt(config.getProperty("http.port"));
|
int port = Integer.parseInt(config.getProperty("http.port"));
|
||||||
webServer.requestHandler(http::accept).listen(port);
|
webServer.requestHandler(http::accept).listen(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void respondJson(RoutingContext ctx, int code, Object response) {
|
public static void respondJson(RoutingContext ctx, int code, Object response) {
|
||||||
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
|
ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
|
||||||
ctx.response().setStatusCode(code);
|
ctx.response().setStatusCode(code);
|
||||||
ctx.response().end(gson.toJson(response));
|
ctx.response().end(gson.toJson(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,11 +6,11 @@ import io.vertx.ext.dropwizard.DropwizardMetricsOptions;
|
|||||||
|
|
||||||
final class Main {
|
final class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
|
System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");
|
||||||
Vertx.vertx(new VertxOptions().setMetricsOptions(
|
Vertx.vertx(new VertxOptions().setMetricsOptions(
|
||||||
new DropwizardMetricsOptions().setEnabled(true).setRegistryName("apiv3-registry")
|
new DropwizardMetricsOptions().setEnabled(true).setRegistryName("apiv3-registry")
|
||||||
)).deployVerticle(new APIv3());
|
)).deployVerticle(new APIv3());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,8 +2,10 @@ package net.frozenorb.apiv3.actor;
|
|||||||
|
|
||||||
public interface Actor {
|
public interface Actor {
|
||||||
|
|
||||||
boolean isAuthorized();
|
boolean isAuthorized();
|
||||||
String getName();
|
|
||||||
ActorType getType();
|
String getName();
|
||||||
|
|
||||||
|
ActorType getType();
|
||||||
|
|
||||||
}
|
}
|
@ -2,6 +2,6 @@ package net.frozenorb.apiv3.actor;
|
|||||||
|
|
||||||
public enum ActorType {
|
public enum ActorType {
|
||||||
|
|
||||||
WEBSITE, STORE, BUNGEE_CORD, SERVER, UNKNOWN
|
WEBSITE, STORE, BUNGEE_CORD, SERVER, UNKNOWN
|
||||||
|
|
||||||
}
|
}
|
@ -6,8 +6,8 @@ import lombok.Getter;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class SimpleActor implements Actor {
|
public final class SimpleActor implements Actor {
|
||||||
|
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
@Getter private ActorType type;
|
@Getter private ActorType type;
|
||||||
@Getter private boolean authorized;
|
@Getter private boolean authorized;
|
||||||
|
|
||||||
}
|
}
|
@ -12,19 +12,19 @@ import java.util.UUID;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class AuditLog {
|
public class AuditLog {
|
||||||
|
|
||||||
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, SingleResultCallback<AuditLogEntry> callback) {
|
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, SingleResultCallback<AuditLogEntry> callback) {
|
||||||
log(performedBy, performedByIp, ctx, actionType, ImmutableMap.of(), callback);
|
log(performedBy, performedByIp, ctx, actionType, ImmutableMap.of(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, Map<String, Object> actionData, SingleResultCallback<AuditLogEntry> callback) {
|
public static void log(UUID performedBy, String performedByIp, RoutingContext ctx, AuditLogActionType actionType, Map<String, Object> actionData, SingleResultCallback<AuditLogEntry> callback) {
|
||||||
AuditLogEntry entry = new AuditLogEntry(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, actionData);
|
AuditLogEntry entry = new AuditLogEntry(performedBy, performedByIp, ctx.get("actor"), ctx.request().remoteAddress().host(), actionType, actionData);
|
||||||
entry.insert((ignored, error) -> {
|
entry.insert((ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(entry, null);
|
callback.onResult(entry, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,83 +9,82 @@ import java.time.Instant;
|
|||||||
|
|
||||||
public enum AuditLogActionType {
|
public enum AuditLogActionType {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
DISPOSABLE_LOGIN_TOKEN_USE(false),
|
DISPOSABLE_LOGIN_TOKEN_USE(false),
|
||||||
DISPOSABLE_LOGIN_TOKEN_CREATE(false),
|
DISPOSABLE_LOGIN_TOKEN_CREATE(false),
|
||||||
ACCESS_TOKEN_CREATE(false),
|
ACCESS_TOKEN_CREATE(false),
|
||||||
ACCESS_TOKEN_UPDATE(false),
|
ACCESS_TOKEN_UPDATE(false),
|
||||||
ACCESS_TOKEN_DELETE(false),
|
ACCESS_TOKEN_DELETE(false),
|
||||||
AUDIT_LOG_REVERT(false),
|
AUDIT_LOG_REVERT(false),
|
||||||
BANNED_ASN_CREATE(false),
|
BANNED_ASN_CREATE(false),
|
||||||
BANNED_ASN_UPDATE(false),
|
BANNED_ASN_UPDATE(false),
|
||||||
BANNED_ASN_DELETE(false),
|
BANNED_ASN_DELETE(false),
|
||||||
BANNED_CALL_CARRIER_CREATE(false),
|
BANNED_CALL_CARRIER_CREATE(false),
|
||||||
BANNED_CALL_CARRIER_UPDATE(false),
|
BANNED_CALL_CARRIER_UPDATE(false),
|
||||||
BANNED_CALL_CARRIER_DELETE(false),
|
BANNED_CALL_CARRIER_DELETE(false),
|
||||||
GRANT_CREATE(false),
|
GRANT_CREATE(false),
|
||||||
GRANT_UPDATE(false),
|
GRANT_UPDATE(false),
|
||||||
GRANT_DELETE(false),
|
GRANT_DELETE(false),
|
||||||
IP_BAN_CREATE(false),
|
IP_BAN_CREATE(false),
|
||||||
IP_BAN_UPDATE(false),
|
IP_BAN_UPDATE(false),
|
||||||
IP_BAN_DELETE(false),
|
IP_BAN_DELETE(false),
|
||||||
NOTIFICATION_TEMPLATE_CREATE(false),
|
NOTIFICATION_TEMPLATE_CREATE(false),
|
||||||
NOTIFICATION_TEMPLATE_UPDATE(false),
|
NOTIFICATION_TEMPLATE_UPDATE(false),
|
||||||
NOTIFICATION_TEMPLATE_DELETE(false),
|
NOTIFICATION_TEMPLATE_DELETE(false),
|
||||||
CHAT_FILTER_ENTRY_CREATE(false),
|
CHAT_FILTER_ENTRY_CREATE(false),
|
||||||
CHAT_FILTER_ENTRY_UPDATE(false),
|
CHAT_FILTER_ENTRY_UPDATE(false),
|
||||||
CHAT_FILTER_ENTRY_DELETE(false),
|
CHAT_FILTER_ENTRY_DELETE(false),
|
||||||
PUNISHMENT_CREATE(true) {
|
PUNISHMENT_CREATE(true) {
|
||||||
|
@Override
|
||||||
|
public void reverse(AuditLogEntry entry, SingleResultCallback<Void> callback) {
|
||||||
|
String punishmentId = (String) entry.getMetadata().get("punishmentId");
|
||||||
|
|
||||||
@Override
|
Punishment.findById(punishmentId, (punishment, error) -> {
|
||||||
public void reverse(AuditLogEntry entry, SingleResultCallback<Void> callback) {
|
if (error != null) {
|
||||||
String punishmentId = (String) entry.getMetadata().get("punishmentId");
|
callback.onResult(null, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Punishment.findById(punishmentId, (punishment, error) -> {
|
if (punishment == null || !punishment.isActive()) {
|
||||||
if (error != null) {
|
callback.onResult(null, null);
|
||||||
callback.onResult(null, error);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (punishment == null || !punishment.isActive()) {
|
punishment.delete(null, "Removed via audit log reversal at " + Instant.now().toString() + ".", callback);
|
||||||
callback.onResult(null, null);
|
});
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
punishment.delete(null, "Removed via audit log reversal at " + Instant.now().toString() + ".", callback);
|
},
|
||||||
});
|
PUNISHMENT_UPDATE(false),
|
||||||
}
|
PUNISHMENT_DELETE(false),
|
||||||
|
RANK_CREATE(false),
|
||||||
|
RANK_UPDATE(false),
|
||||||
|
RANK_DELETE(false),
|
||||||
|
SERVER_GROUP_CREATE(false),
|
||||||
|
SERVER_GROUP_UPDATE(false),
|
||||||
|
SERVER_GROUP_DELETE(false),
|
||||||
|
SERVER_CREATE(false),
|
||||||
|
SERVER_UPDATE(false),
|
||||||
|
SERVER_DELETE(false),
|
||||||
|
USER_LOGIN_SUCCESS(false),
|
||||||
|
USER_LOGIN_FAIL(false),
|
||||||
|
USER_CHANGE_PASSWORD(false),
|
||||||
|
USER_PASSWORD_RESET(false),
|
||||||
|
USER_REGISTER_EMAIL(false),
|
||||||
|
USER_REGISTER_PHONE(false),
|
||||||
|
USER_CONFIRM_EMAIL(false),
|
||||||
|
USER_CONFIRM_PHONE(false),
|
||||||
|
USER_SETUP_TOTP(false),
|
||||||
|
USER_VERIFY_TOTP(false);
|
||||||
|
|
||||||
},
|
@Getter private boolean reversible;
|
||||||
PUNISHMENT_UPDATE(false),
|
|
||||||
PUNISHMENT_DELETE(false),
|
|
||||||
RANK_CREATE(false),
|
|
||||||
RANK_UPDATE(false),
|
|
||||||
RANK_DELETE(false),
|
|
||||||
SERVER_GROUP_CREATE(false),
|
|
||||||
SERVER_GROUP_UPDATE(false),
|
|
||||||
SERVER_GROUP_DELETE(false),
|
|
||||||
SERVER_CREATE(false),
|
|
||||||
SERVER_UPDATE(false),
|
|
||||||
SERVER_DELETE(false),
|
|
||||||
USER_LOGIN_SUCCESS(false),
|
|
||||||
USER_LOGIN_FAIL(false),
|
|
||||||
USER_CHANGE_PASSWORD(false),
|
|
||||||
USER_PASSWORD_RESET(false),
|
|
||||||
USER_REGISTER_EMAIL(false),
|
|
||||||
USER_REGISTER_PHONE(false),
|
|
||||||
USER_CONFIRM_EMAIL(false),
|
|
||||||
USER_CONFIRM_PHONE(false),
|
|
||||||
USER_SETUP_TOTP(false),
|
|
||||||
USER_VERIFY_TOTP(false);
|
|
||||||
|
|
||||||
@Getter private boolean reversible;
|
AuditLogActionType(boolean reversible) {
|
||||||
|
this.reversible = reversible;
|
||||||
|
}
|
||||||
|
|
||||||
AuditLogActionType(boolean reversible) {
|
public void reverse(AuditLogEntry entry, SingleResultCallback<Void> callback) {
|
||||||
this.reversible = reversible;
|
callback.onResult(null, new UnsupportedOperationException());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reverse(AuditLogEntry entry, SingleResultCallback<Void> callback) {
|
|
||||||
callback.onResult(null, new UnsupportedOperationException());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -18,37 +18,37 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public final class V2Importer {
|
public final class V2Importer {
|
||||||
|
|
||||||
private final MongoDatabase importFrom;
|
private final MongoDatabase importFrom;
|
||||||
|
|
||||||
public V2Importer(String mongoIp, String database) {
|
public V2Importer(String mongoIp, String database) {
|
||||||
importFrom = MongoClients.create(mongoIp).getDatabase(database);
|
importFrom = MongoClients.create(mongoIp).getDatabase(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startImport(SingleResultCallback<Void> callback) {
|
public void startImport(SingleResultCallback<Void> callback) {
|
||||||
Map<ObjectId, UUID> oidToUniqueId = new HashMap<>();
|
Map<ObjectId, UUID> oidToUniqueId = new HashMap<>();
|
||||||
|
|
||||||
importFrom.getCollection("user").find().forEach(new UserConverter(oidToUniqueId), (ignored, error) -> {
|
importFrom.getCollection("user").find().forEach(new UserConverter(oidToUniqueId), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Void> punishmentsFuture = Future.future();
|
Future<Void> punishmentsFuture = Future.future();
|
||||||
Future<Void> grantsFuture = Future.future();
|
Future<Void> grantsFuture = Future.future();
|
||||||
Future<Void> ipLogFuture = Future.future();
|
Future<Void> ipLogFuture = Future.future();
|
||||||
|
|
||||||
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new MongoToVertxCallback<>(punishmentsFuture));
|
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new MongoToVertxCallback<>(punishmentsFuture));
|
||||||
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new MongoToVertxCallback<>(grantsFuture));
|
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new MongoToVertxCallback<>(grantsFuture));
|
||||||
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new MongoToVertxCallback<>(ipLogFuture));
|
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new MongoToVertxCallback<>(ipLogFuture));
|
||||||
|
|
||||||
CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> {
|
CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> {
|
||||||
if (result.succeeded()) {
|
if (result.succeeded()) {
|
||||||
callback.onResult(null, null);
|
callback.onResult(null, null);
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(null, result.cause());
|
callback.onResult(null, result.cause());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,51 +16,51 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class GrantConverter implements Block<Document> {
|
public final class GrantConverter implements Block<Document> {
|
||||||
|
|
||||||
private final Map<ObjectId, UUID> oidToUniqueId;
|
private final Map<ObjectId, UUID> oidToUniqueId;
|
||||||
|
|
||||||
public GrantConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
public GrantConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
||||||
this.oidToUniqueId = oidToUniqueId;
|
this.oidToUniqueId = oidToUniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void apply(Document grant) {
|
public void apply(Document grant) {
|
||||||
UUID target = oidToUniqueId.get(((Map<String, Object>) grant.get("target")).get("$id"));
|
UUID target = oidToUniqueId.get(((Map<String, Object>) grant.get("target")).get("$id"));
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String rank = grant.getString("role");
|
String rank = grant.getString("role");
|
||||||
|
|
||||||
if (rank.equalsIgnoreCase("unban") || rank.equalsIgnoreCase("pass") || rank.equalsIgnoreCase("pink") || rank.equalsIgnoreCase("jrdev")) {
|
if (rank.equalsIgnoreCase("unban") || rank.equalsIgnoreCase("pass") || rank.equalsIgnoreCase("pink") || rank.equalsIgnoreCase("jrdev")) {
|
||||||
return;
|
return;
|
||||||
} else if (rank.equalsIgnoreCase("high_roller")) {
|
} else if (rank.equalsIgnoreCase("high_roller")) {
|
||||||
rank = "high-roller";
|
rank = "high-roller";
|
||||||
} else if (rank.equalsIgnoreCase("dev")) {
|
} else if (rank.equalsIgnoreCase("dev")) {
|
||||||
rank = "developer";
|
rank = "developer";
|
||||||
} else if (rank.equalsIgnoreCase("coowner")) {
|
} else if (rank.equalsIgnoreCase("coowner")) {
|
||||||
rank = "owner";
|
rank = "owner";
|
||||||
}
|
}
|
||||||
|
|
||||||
Grant created = new Grant(
|
Grant created = new Grant(
|
||||||
new ObjectId().toString(),
|
new ObjectId().toString(),
|
||||||
target,
|
target,
|
||||||
grant.containsKey("comment") ? grant.getString("comment") : "",
|
grant.containsKey("comment") ? grant.getString("comment") : "",
|
||||||
grant.containsKey("scope") ? ImmutableSet.copyOf((Collection<String>) grant.get("scope")) : ImmutableSet.of(),
|
grant.containsKey("scope") ? ImmutableSet.copyOf((Collection<String>) grant.get("scope")) : ImmutableSet.of(),
|
||||||
rank,
|
rank,
|
||||||
grant.containsKey("expires") ? grant.getDate("expires").toInstant() : null,
|
grant.containsKey("expires") ? grant.getDate("expires").toInstant() : null,
|
||||||
grant.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
|
grant.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
|
||||||
grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(),
|
grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
-1,
|
-1,
|
||||||
-1
|
-1
|
||||||
);
|
);
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
||||||
log.info("Created grant " + created.getId() + " (" + created.getRank() + ")");
|
log.info("Created grant " + created.getId() + " (" + created.getRank() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,44 +15,44 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class IpLogConverter implements Block<Document> {
|
public final class IpLogConverter implements Block<Document> {
|
||||||
|
|
||||||
private final Map<ObjectId, UUID> oidToUniqueId;
|
private final Map<ObjectId, UUID> oidToUniqueId;
|
||||||
|
|
||||||
public IpLogConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
public IpLogConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
||||||
this.oidToUniqueId = oidToUniqueId;
|
this.oidToUniqueId = oidToUniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void apply(Document ipLogEntry) {
|
public void apply(Document ipLogEntry) {
|
||||||
UUID user = oidToUniqueId.get(((Map<String, Object>) ipLogEntry.get("user")).get("$id"));
|
UUID user = oidToUniqueId.get(((Map<String, Object>) ipLogEntry.get("user")).get("$id"));
|
||||||
|
|
||||||
if (user == null || ipLogEntry.getString("ip") == null) {
|
if (user == null || ipLogEntry.getString("ip") == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ip = ipLogEntry.getString("ip").replace("/", "");
|
String ip = ipLogEntry.getString("ip").replace("/", "");
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(ip)) {
|
if (!IpUtils.isValidIp(ip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date lastSeen = ipLogEntry.getDate("lastSeen");
|
Date lastSeen = ipLogEntry.getDate("lastSeen");
|
||||||
|
|
||||||
if (lastSeen == null) {
|
if (lastSeen == null) {
|
||||||
lastSeen = new Date();
|
lastSeen = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
IpLogEntry created = new IpLogEntry(
|
IpLogEntry created = new IpLogEntry(
|
||||||
new ObjectId().toString(),
|
new ObjectId().toString(),
|
||||||
user,
|
user,
|
||||||
ip,
|
ip,
|
||||||
lastSeen.toInstant(),
|
lastSeen.toInstant(),
|
||||||
lastSeen.toInstant(),
|
lastSeen.toInstant(),
|
||||||
((Number) ipLogEntry.get("uses")).intValue()
|
((Number) ipLogEntry.get("uses")).intValue()
|
||||||
);
|
);
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
||||||
log.info("Created ip log entry " + created.getId() + " (" + created.getUser() + " - " + created.getUserIp() + ")");
|
log.info("Created ip log entry " + created.getId() + " (" + created.getUser() + " - " + created.getUserIp() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,46 +16,46 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class PunishmentConverter implements Block<Document> {
|
public final class PunishmentConverter implements Block<Document> {
|
||||||
|
|
||||||
private final Map<ObjectId, UUID> oidToUniqueId;
|
private final Map<ObjectId, UUID> oidToUniqueId;
|
||||||
|
|
||||||
public PunishmentConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
public PunishmentConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
||||||
this.oidToUniqueId = oidToUniqueId;
|
this.oidToUniqueId = oidToUniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void apply(Document punishment) {
|
public void apply(Document punishment) {
|
||||||
UUID target = oidToUniqueId.get(((Map<String, Object>) punishment.get("user")).get("$id"));
|
UUID target = oidToUniqueId.get(((Map<String, Object>) punishment.get("user")).get("$id"));
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Old punishments have this value set to false to indicate they're not active anymore.
|
// Old punishments have this value set to false to indicate they're not active anymore.
|
||||||
if (punishment.containsKey("active") && !punishment.getBoolean("active")) {
|
if (punishment.containsKey("active") && !punishment.getBoolean("active")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Punishment created = new Punishment(
|
Punishment created = new Punishment(
|
||||||
new ObjectId().toString(),
|
new ObjectId().toString(),
|
||||||
target,
|
target,
|
||||||
"Hidden (legacy punishment)",
|
"Hidden (legacy punishment)",
|
||||||
punishment.getString("reason").toString(),
|
punishment.getString("reason").toString(),
|
||||||
Punishment.PunishmentType.valueOf(punishment.getString("type").toUpperCase()),
|
Punishment.PunishmentType.valueOf(punishment.getString("type").toUpperCase()),
|
||||||
punishment.containsKey("expires") ? punishment.getDate("expires").toInstant() : null,
|
punishment.containsKey("expires") ? punishment.getDate("expires").toInstant() : null,
|
||||||
punishment.containsKey("meta") ? (punishment.get("meta") instanceof List ? ImmutableMap.of() : (Document) punishment.get("meta")) : ImmutableMap.of(),
|
punishment.containsKey("meta") ? (punishment.get("meta") instanceof List ? ImmutableMap.of() : (Document) punishment.get("meta")) : ImmutableMap.of(),
|
||||||
null,
|
null,
|
||||||
punishment.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("addedBy")).get("$id")) : null,
|
punishment.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("addedBy")).get("$id")) : null,
|
||||||
punishment.getDate("created").toInstant(),
|
punishment.getDate("created").toInstant(),
|
||||||
punishment.containsKey("createdOn") ? String.valueOf(((Map<String, Object>) punishment.get("createdOn")).get("$id")) : "Old Website",
|
punishment.containsKey("createdOn") ? String.valueOf(((Map<String, Object>) punishment.get("createdOn")).get("$id")) : "Old Website",
|
||||||
punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE,
|
punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE,
|
||||||
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("removedBy")).get("$id")) : null) : null,
|
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("removedBy")).get("$id")) : null) : null,
|
||||||
punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")).toInstant() : null,
|
punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")).toInstant() : null,
|
||||||
punishment.containsKey("removedBy") ? punishment.getString("removalReason").toString() : null
|
punishment.containsKey("removedBy") ? punishment.getString("removalReason").toString() : null
|
||||||
);
|
);
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
||||||
log.info("Created punishment " + created.getId() + " (" + created.getType() + ")");
|
log.info("Created punishment " + created.getId() + " (" + created.getType() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,56 +16,56 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class UserConverter implements Block<Document> {
|
public final class UserConverter implements Block<Document> {
|
||||||
|
|
||||||
private final Map<ObjectId, UUID> oidToUniqueId;
|
private final Map<ObjectId, UUID> oidToUniqueId;
|
||||||
|
|
||||||
public UserConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
public UserConverter(Map<ObjectId, UUID> oidToUniqueId) {
|
||||||
this.oidToUniqueId = oidToUniqueId;
|
this.oidToUniqueId = oidToUniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Document user) {
|
public void apply(Document user) {
|
||||||
String uuidString = String.valueOf(user.get("uuid"));
|
String uuidString = String.valueOf(user.get("uuid"));
|
||||||
|
|
||||||
if (uuidString == null || uuidString.length() != 32 || user.get("name") == null) {
|
if (uuidString == null || uuidString.length() != 32 || user.get("name") == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = UuidUtils.parseUuid(uuidString);
|
UUID uuid = UuidUtils.parseUuid(uuidString);
|
||||||
|
|
||||||
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
oidToUniqueId.put(user.getObjectId("_id"), uuid);
|
oidToUniqueId.put(user.getObjectId("_id"), uuid);
|
||||||
|
|
||||||
User created = new User(
|
|
||||||
uuid,
|
|
||||||
user.get("name").toString(),
|
|
||||||
ImmutableMap.of(user.get("name").toString(), user.getDate("joined").toInstant()),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
user.getString("email"),
|
|
||||||
user.containsKey("email") ? Instant.EPOCH : null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
user.getString("phone"),
|
|
||||||
user.containsKey("phone") ? Instant.EPOCH : null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
"INVALID",
|
|
||||||
user.getDate("joined").toInstant(),
|
|
||||||
user.getDate("joined").toInstant(),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
User created = new User(
|
||||||
log.info("Created user " + created.getLastUsername() + " (" + created.getId() + ")");
|
uuid,
|
||||||
}
|
user.get("name").toString(),
|
||||||
|
ImmutableMap.of(user.get("name").toString(), user.getDate("joined").toInstant()),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
user.getString("email"),
|
||||||
|
user.containsKey("email") ? Instant.EPOCH : null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
user.getString("phone"),
|
||||||
|
user.containsKey("phone") ? Instant.EPOCH : null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
"INVALID",
|
||||||
|
user.getDate("joined").toInstant(),
|
||||||
|
user.getDate("joined").toInstant(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
SyncUtils.<Void>runBlocking(v -> created.insert(v));
|
||||||
|
log.info("Created user " + created.getLastUsername() + " (" + created.getId() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,51 +10,51 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class ActorAttributeHandler implements Handler<RoutingContext> {
|
public final class ActorAttributeHandler implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
String mhqAuthorizationHeader = ctx.request().getHeader("MHQ-Authorization");
|
String mhqAuthorizationHeader = ctx.request().getHeader("MHQ-Authorization");
|
||||||
|
|
||||||
if (mhqAuthorizationHeader != null) {
|
if (mhqAuthorizationHeader != null) {
|
||||||
processMHQAuthorization(mhqAuthorizationHeader, ctx);
|
processMHQAuthorization(mhqAuthorizationHeader, ctx);
|
||||||
} else {
|
} else {
|
||||||
processNoAuthorization(ctx);
|
processNoAuthorization(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMHQAuthorization(String accessTokenString, RoutingContext ctx) {
|
private void processMHQAuthorization(String accessTokenString, RoutingContext ctx) {
|
||||||
if (accessTokenString == null || accessTokenString.isEmpty()) {
|
if (accessTokenString == null || accessTokenString.isEmpty()) {
|
||||||
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoKey", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoKey", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessToken.findById(accessTokenString, (accessToken, error) -> {
|
AccessToken.findById(accessTokenString, (accessToken, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessToken == null) {
|
if (accessToken == null) {
|
||||||
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeUnknownKey", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeUnknownKey", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accessToken.getLockedIps() != null && !accessToken.getLockedIps().isEmpty()) {
|
if (accessToken.getLockedIps() != null && !accessToken.getLockedIps().isEmpty()) {
|
||||||
boolean allowed = accessToken.getLockedIps().contains(ctx.request().remoteAddress().host());
|
boolean allowed = accessToken.getLockedIps().contains(ctx.request().remoteAddress().host());
|
||||||
|
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoIpWhitelist", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoIpWhitelist", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.put("actor", new SimpleActor(accessToken.getActorName(), accessToken.getActorType(), true));
|
ctx.put("actor", new SimpleActor(accessToken.getActorName(), accessToken.getActorType(), true));
|
||||||
ctx.next();
|
ctx.next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processNoAuthorization(RoutingContext ctx) {
|
private void processNoAuthorization(RoutingContext ctx) {
|
||||||
ctx.put("actor", new SimpleActor("UNKNOWN", ActorType.UNKNOWN, false));
|
ctx.put("actor", new SimpleActor("UNKNOWN", ActorType.UNKNOWN, false));
|
||||||
ctx.next();
|
ctx.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,15 +8,15 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class AuthorizationHandler implements Handler<RoutingContext> {
|
public final class AuthorizationHandler implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Actor actor = ctx.get("actor");
|
Actor actor = ctx.get("actor");
|
||||||
|
|
||||||
if (actor.isAuthorized()) {
|
if (actor.isAuthorized()) {
|
||||||
ctx.next();
|
ctx.next();
|
||||||
} else {
|
} else {
|
||||||
ErrorUtils.respondOther(ctx, 403, "Failed to authorize as an approved actor.", "failedToAuthorizeNotApprovedActor", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 403, "Failed to authorize as an approved actor.", "failedToAuthorizeNotApprovedActor", ImmutableMap.of());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -49,7 +49,7 @@ public final class WebsiteUserSessionHandler implements Handler<RoutingContext>
|
|||||||
String path = ctx.request().path().toLowerCase();
|
String path = ctx.request().path().toLowerCase();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
http.get("/emailTokens/:emailToken/owner").blockingHandler(new GETEmailTokensIdOwner(), false);
|
http.get("/emailTokens/:emailToken/owner").blockingHandler(new GETEmailTokensIdOwner(), false);
|
||||||
http.get("/ranks/:rankId").handler(new GETRanksId());
|
http.get("/ranks/:rankId").handler(new GETRanksId());
|
||||||
http.get("/serverGroups/:serverGroupId").handler(new GETServerGroupsId());
|
http.get("/serverGroups/:serverGroupId").handler(new GETServerGroupsId());
|
||||||
http.get("/servers/:serverId").handler(new GETServersId());
|
http.get("/servers/:serverId").handler(new GETServersId());
|
||||||
|
@ -6,16 +6,16 @@ import net.frozenorb.apiv3.util.MaxMindUtils;
|
|||||||
|
|
||||||
public final class MaxMindCity {
|
public final class MaxMindCity {
|
||||||
|
|
||||||
@Getter private int confidence;
|
@Getter private int confidence;
|
||||||
@Getter private int geonameId;
|
@Getter private int geonameId;
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
|
|
||||||
private MaxMindCity() {} // For Jackson
|
private MaxMindCity() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindCity(JsonObject legacy) {
|
public MaxMindCity(JsonObject legacy) {
|
||||||
this.confidence = legacy.getInteger("confidence", -1);
|
this.confidence = legacy.getInteger("confidence", -1);
|
||||||
this.geonameId = legacy.getInteger("geoname_id", -1);
|
this.geonameId = legacy.getInteger("geoname_id", -1);
|
||||||
this.name = MaxMindUtils.getEnglishName(legacy);
|
this.name = MaxMindUtils.getEnglishName(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,16 +6,16 @@ import net.frozenorb.apiv3.util.MaxMindUtils;
|
|||||||
|
|
||||||
public final class MaxMindContinent {
|
public final class MaxMindContinent {
|
||||||
|
|
||||||
@Getter private String code;
|
@Getter private String code;
|
||||||
@Getter private int geonameId;
|
@Getter private int geonameId;
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
|
|
||||||
private MaxMindContinent() {} // For Jackson
|
private MaxMindContinent() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindContinent(JsonObject legacy) {
|
public MaxMindContinent(JsonObject legacy) {
|
||||||
this.code = legacy.getString("code", "");
|
this.code = legacy.getString("code", "");
|
||||||
this.geonameId = legacy.getInteger("geoname_id", -1);
|
this.geonameId = legacy.getInteger("geoname_id", -1);
|
||||||
this.name = MaxMindUtils.getEnglishName(legacy);
|
this.name = MaxMindUtils.getEnglishName(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,18 +6,18 @@ import net.frozenorb.apiv3.util.MaxMindUtils;
|
|||||||
|
|
||||||
public final class MaxMindCountry {
|
public final class MaxMindCountry {
|
||||||
|
|
||||||
@Getter private String isoCode;
|
@Getter private String isoCode;
|
||||||
@Getter private int confidence;
|
@Getter private int confidence;
|
||||||
@Getter private int geonameId;
|
@Getter private int geonameId;
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
|
|
||||||
private MaxMindCountry() {} // For Jackson
|
private MaxMindCountry() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindCountry(JsonObject legacy) {
|
public MaxMindCountry(JsonObject legacy) {
|
||||||
this.isoCode = legacy.getString("iso_code", "");
|
this.isoCode = legacy.getString("iso_code", "");
|
||||||
this.confidence = legacy.getInteger("confidence", -1);
|
this.confidence = legacy.getInteger("confidence", -1);
|
||||||
this.geonameId = legacy.getInteger("geoname_id", -1);
|
this.geonameId = legacy.getInteger("geoname_id", -1);
|
||||||
this.name = MaxMindUtils.getEnglishName(legacy);
|
this.name = MaxMindUtils.getEnglishName(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,24 +5,24 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public final class MaxMindLocation {
|
public final class MaxMindLocation {
|
||||||
|
|
||||||
@Getter private double latitude;
|
@Getter private double latitude;
|
||||||
@Getter private double longitude;
|
@Getter private double longitude;
|
||||||
@Getter private int accuracyRadius;
|
@Getter private int accuracyRadius;
|
||||||
@Getter private String timeZone;
|
@Getter private String timeZone;
|
||||||
@Getter private int populationDensity;
|
@Getter private int populationDensity;
|
||||||
@Getter private int metroCode;
|
@Getter private int metroCode;
|
||||||
@Getter private int averageIncome;
|
@Getter private int averageIncome;
|
||||||
|
|
||||||
private MaxMindLocation() {} // For Jackson
|
private MaxMindLocation() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindLocation(JsonObject legacy) {
|
public MaxMindLocation(JsonObject legacy) {
|
||||||
this.latitude = legacy.getDouble("latitude", -1D);
|
this.latitude = legacy.getDouble("latitude", -1D);
|
||||||
this.longitude = legacy.getDouble("longitude", -1D);
|
this.longitude = legacy.getDouble("longitude", -1D);
|
||||||
this.accuracyRadius = legacy.getInteger("accuracy_radius", -1);
|
this.accuracyRadius = legacy.getInteger("accuracy_radius", -1);
|
||||||
this.timeZone = legacy.getString("time_zone", "");
|
this.timeZone = legacy.getString("time_zone", "");
|
||||||
this.populationDensity = legacy.getInteger("population_density", -1);
|
this.populationDensity = legacy.getInteger("population_density", -1);
|
||||||
this.metroCode = legacy.getInteger("metro_code", -1);
|
this.metroCode = legacy.getInteger("metro_code", -1);
|
||||||
this.averageIncome = legacy.getInteger("average_income", -1);
|
this.averageIncome = legacy.getInteger("average_income", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,14 +5,14 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public final class MaxMindPostal {
|
public final class MaxMindPostal {
|
||||||
|
|
||||||
@Getter private String code;
|
@Getter private String code;
|
||||||
@Getter private int confidence;
|
@Getter private int confidence;
|
||||||
|
|
||||||
private MaxMindPostal() {} // For Jackson
|
private MaxMindPostal() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindPostal(JsonObject legacy) {
|
public MaxMindPostal(JsonObject legacy) {
|
||||||
this.code = legacy.getString("code", "");
|
this.code = legacy.getString("code", "");
|
||||||
this.confidence = legacy.getInteger("confidence", -1);
|
this.confidence = legacy.getInteger("confidence", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -6,16 +6,16 @@ import net.frozenorb.apiv3.util.MaxMindUtils;
|
|||||||
|
|
||||||
public final class MaxMindRegisteredCountry {
|
public final class MaxMindRegisteredCountry {
|
||||||
|
|
||||||
@Getter private String isoCode;
|
@Getter private String isoCode;
|
||||||
@Getter private int geonameId;
|
@Getter private int geonameId;
|
||||||
@Getter private String name;
|
@Getter private String name;
|
||||||
|
|
||||||
private MaxMindRegisteredCountry() {} // For Jackson
|
private MaxMindRegisteredCountry() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindRegisteredCountry(JsonObject legacy) {
|
public MaxMindRegisteredCountry(JsonObject legacy) {
|
||||||
this.isoCode = legacy.getString("iso_code", "");
|
this.isoCode = legacy.getString("iso_code", "");
|
||||||
this.geonameId = legacy.getInteger("geoname_id", -1);
|
this.geonameId = legacy.getInteger("geoname_id", -1);
|
||||||
this.name = MaxMindUtils.getEnglishName(legacy);
|
this.name = MaxMindUtils.getEnglishName(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,33 +10,33 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class MaxMindResult {
|
public final class MaxMindResult {
|
||||||
|
|
||||||
@Getter private MaxMindContinent continent;
|
@Getter private MaxMindContinent continent;
|
||||||
@Getter private MaxMindCity city;
|
@Getter private MaxMindCity city;
|
||||||
@Getter private MaxMindPostal postal;
|
@Getter private MaxMindPostal postal;
|
||||||
@Getter private MaxMindTraits traits;
|
@Getter private MaxMindTraits traits;
|
||||||
@Getter private MaxMindLocation location;
|
@Getter private MaxMindLocation location;
|
||||||
@Getter private List<MaxMindSubdivision> subdivisions;
|
@Getter private List<MaxMindSubdivision> subdivisions;
|
||||||
@Getter private MaxMindCountry country;
|
@Getter private MaxMindCountry country;
|
||||||
@Getter private MaxMindRegisteredCountry registeredCountry;
|
@Getter private MaxMindRegisteredCountry registeredCountry;
|
||||||
|
|
||||||
private MaxMindResult() {} // For Jackson
|
private MaxMindResult() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindResult(JsonObject legacy) {
|
public MaxMindResult(JsonObject legacy) {
|
||||||
this.continent = new MaxMindContinent(legacy.getJsonObject("continent", new JsonObject()));
|
this.continent = new MaxMindContinent(legacy.getJsonObject("continent", new JsonObject()));
|
||||||
this.city = new MaxMindCity(legacy.getJsonObject("city", new JsonObject()));
|
this.city = new MaxMindCity(legacy.getJsonObject("city", new JsonObject()));
|
||||||
this.postal = new MaxMindPostal(legacy.getJsonObject("postal", new JsonObject()));
|
this.postal = new MaxMindPostal(legacy.getJsonObject("postal", new JsonObject()));
|
||||||
this.traits = new MaxMindTraits(legacy.getJsonObject("traits"));
|
this.traits = new MaxMindTraits(legacy.getJsonObject("traits"));
|
||||||
this.location = new MaxMindLocation(legacy.getJsonObject("location", new JsonObject()));
|
this.location = new MaxMindLocation(legacy.getJsonObject("location", new JsonObject()));
|
||||||
this.country = new MaxMindCountry(legacy.getJsonObject("country", new JsonObject()));
|
this.country = new MaxMindCountry(legacy.getJsonObject("country", new JsonObject()));
|
||||||
this.registeredCountry = new MaxMindRegisteredCountry(legacy.getJsonObject("registered_country", new JsonObject()));
|
this.registeredCountry = new MaxMindRegisteredCountry(legacy.getJsonObject("registered_country", new JsonObject()));
|
||||||
|
|
||||||
List<MaxMindSubdivision> subdivisions = new LinkedList<>();
|
List<MaxMindSubdivision> subdivisions = new LinkedList<>();
|
||||||
|
|
||||||
for (Object subdivision : legacy.getJsonArray("subdivisions", new JsonArray())) {
|
for (Object subdivision : legacy.getJsonArray("subdivisions", new JsonArray())) {
|
||||||
subdivisions.add(new MaxMindSubdivision((JsonObject) subdivision));
|
subdivisions.add(new MaxMindSubdivision((JsonObject) subdivision));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.subdivisions = ImmutableList.copyOf(subdivisions);
|
this.subdivisions = ImmutableList.copyOf(subdivisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,22 +5,22 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public final class MaxMindTraits {
|
public final class MaxMindTraits {
|
||||||
|
|
||||||
@Getter private String isp;
|
@Getter private String isp;
|
||||||
@Getter private String domain;
|
@Getter private String domain;
|
||||||
@Getter private int asn;
|
@Getter private int asn;
|
||||||
@Getter private String asnOrganization;
|
@Getter private String asnOrganization;
|
||||||
@Getter private MaxMindUserType userType;
|
@Getter private MaxMindUserType userType;
|
||||||
@Getter private String organization;
|
@Getter private String organization;
|
||||||
|
|
||||||
private MaxMindTraits() {} // For Jackson
|
private MaxMindTraits() {} // For Jackson
|
||||||
|
|
||||||
public MaxMindTraits(JsonObject legacy) {
|
public MaxMindTraits(JsonObject legacy) {
|
||||||
this.isp = legacy.getString("isp", "");
|
this.isp = legacy.getString("isp", "");
|
||||||
this.domain = legacy.getString("domain", "");
|
this.domain = legacy.getString("domain", "");
|
||||||
this.asn = legacy.getInteger("autonomous_system_number", -1);
|
this.asn = legacy.getInteger("autonomous_system_number", -1);
|
||||||
this.asnOrganization = legacy.getString("autonomous_system_organization" , "");
|
this.asnOrganization = legacy.getString("autonomous_system_organization", "");
|
||||||
this.userType = legacy.containsKey("user_type") ? MaxMindUserType.valueOf(legacy.getString("user_type").toUpperCase()) : MaxMindUserType.UNKNOWN;
|
this.userType = legacy.containsKey("user_type") ? MaxMindUserType.valueOf(legacy.getString("user_type").toUpperCase()) : MaxMindUserType.UNKNOWN;
|
||||||
this.organization = legacy.getString("organization", "");
|
this.organization = legacy.getString("organization", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,27 +4,27 @@ import lombok.Getter;
|
|||||||
|
|
||||||
public enum MaxMindUserType {
|
public enum MaxMindUserType {
|
||||||
|
|
||||||
BUSINESS(true),
|
BUSINESS(true),
|
||||||
CAFE(true),
|
CAFE(true),
|
||||||
CELLULAR(true),
|
CELLULAR(true),
|
||||||
COLLEGE(true),
|
COLLEGE(true),
|
||||||
CONTENT_DELIVERY_NETWORK(false),
|
CONTENT_DELIVERY_NETWORK(false),
|
||||||
DIALUP(true),
|
DIALUP(true),
|
||||||
GOVERNMENT(true),
|
GOVERNMENT(true),
|
||||||
HOSTING(false),
|
HOSTING(false),
|
||||||
LIBRARY(true),
|
LIBRARY(true),
|
||||||
MILITARY(true),
|
MILITARY(true),
|
||||||
RESIDENTIAL(true),
|
RESIDENTIAL(true),
|
||||||
ROUTER(true),
|
ROUTER(true),
|
||||||
SCHOOL(true),
|
SCHOOL(true),
|
||||||
SEARCH_ENGINE_SPIDER(false),
|
SEARCH_ENGINE_SPIDER(false),
|
||||||
TRAVELER(true),
|
TRAVELER(true),
|
||||||
UNKNOWN(true);
|
UNKNOWN(true);
|
||||||
|
|
||||||
@Getter private final boolean allowed;
|
@Getter private final boolean allowed;
|
||||||
|
|
||||||
MaxMindUserType(boolean allowed) {
|
MaxMindUserType(boolean allowed) {
|
||||||
this.allowed = allowed;
|
this.allowed = allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,53 +22,53 @@ import java.util.UUID;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class AccessToken {
|
public final class AccessToken {
|
||||||
|
|
||||||
private static final MongoCollection<AccessToken> accessTokensCollection = APIv3.getDatabase().getCollection("accessTokens", AccessToken.class);
|
private static final MongoCollection<AccessToken> accessTokensCollection = APIv3.getDatabase().getCollection("accessTokens", AccessToken.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String actorName;
|
@Getter private String actorName;
|
||||||
@Getter private ActorType actorType;
|
@Getter private ActorType actorType;
|
||||||
@Getter private List<String> lockedIps;
|
@Getter private List<String> lockedIps;
|
||||||
@Getter private Instant createdAt;
|
@Getter private Instant createdAt;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<AccessToken>> callback) {
|
public static void findAll(SingleResultCallback<List<AccessToken>> callback) {
|
||||||
accessTokensCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
accessTokensCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<AccessToken> callback) {
|
public static void findById(String id, SingleResultCallback<AccessToken> callback) {
|
||||||
accessTokensCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
accessTokensCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByNameAndType(String actorName, ActorType actorType, SingleResultCallback<AccessToken> callback) {
|
public static void findByNameAndType(String actorName, ActorType actorType, SingleResultCallback<AccessToken> callback) {
|
||||||
accessTokensCollection.find(new Document("actorName", actorName).append("actorType", actorType.name())).first(SyncUtils.vertxWrap(callback));
|
accessTokensCollection.find(new Document("actorName", actorName).append("actorType", actorType.name())).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccessToken() {} // For Jackson
|
private AccessToken() {} // For Jackson
|
||||||
|
|
||||||
public AccessToken(Server server) {
|
public AccessToken(Server server) {
|
||||||
// Can't extract server host code to another line because the call to another constructor must be on the first line.
|
// Can't extract server host code to another line because the call to another constructor must be on the first line.
|
||||||
this(server.getId(), ActorType.SERVER, ImmutableList.of(server.getServerIp().split(":")[0]));
|
this(server.getId(), ActorType.SERVER, ImmutableList.of(server.getServerIp().split(":")[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccessToken(String actorName, ActorType actorType, List<String> lockedIps) {
|
public AccessToken(String actorName, ActorType actorType, List<String> lockedIps) {
|
||||||
this.id = UUID.randomUUID().toString().replace("-", "");
|
this.id = UUID.randomUUID().toString().replace("-", "");
|
||||||
this.actorName = actorName;
|
this.actorName = actorName;
|
||||||
this.actorType = actorType;
|
this.actorType = actorType;
|
||||||
this.lockedIps = lockedIps;
|
this.lockedIps = lockedIps;
|
||||||
this.createdAt = Instant.now();
|
this.createdAt = Instant.now();
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
accessTokensCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
accessTokensCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
accessTokensCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
accessTokensCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
accessTokensCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
accessTokensCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,50 +23,50 @@ import java.util.UUID;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class AuditLogEntry {
|
public final class AuditLogEntry {
|
||||||
|
|
||||||
private static final MongoCollection<AuditLogEntry> auditLogCollection = APIv3.getDatabase().getCollection("auditLog", AuditLogEntry.class);
|
private static final MongoCollection<AuditLogEntry> auditLogCollection = APIv3.getDatabase().getCollection("auditLog", AuditLogEntry.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private UUID user;
|
@Getter private UUID user;
|
||||||
@Getter private String userIp;
|
@Getter private String userIp;
|
||||||
@Getter private Instant performedAt;
|
@Getter private Instant performedAt;
|
||||||
@Getter private String actorName;
|
@Getter private String actorName;
|
||||||
@Getter private ActorType actorType;
|
@Getter private ActorType actorType;
|
||||||
@Getter private String actorIp;
|
@Getter private String actorIp;
|
||||||
// We store 'reversible' in each object in case later on we go back and
|
// We store 'reversible' in each object in case later on we go back and
|
||||||
// make something reversible (by storing more meta or such)
|
// make something reversible (by storing more meta or such)
|
||||||
@Getter private boolean reversible;
|
@Getter private boolean reversible;
|
||||||
@Getter private AuditLogActionType type;
|
@Getter private AuditLogActionType type;
|
||||||
@Getter private Map<String, Object> metadata;
|
@Getter private Map<String, Object> metadata;
|
||||||
|
|
||||||
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<AuditLogEntry>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<AuditLogEntry>> callback) {
|
||||||
auditLogCollection.find(query).sort(new Document("performedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
auditLogCollection.find(query).sort(new Document("performedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<AuditLogEntry> callback) {
|
public static void findById(String id, SingleResultCallback<AuditLogEntry> callback) {
|
||||||
auditLogCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
auditLogCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void find(Document query, SingleResultCallback<List<AuditLogEntry>> callback) {
|
public static void find(Document query, SingleResultCallback<List<AuditLogEntry>> callback) {
|
||||||
auditLogCollection.find(query).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
auditLogCollection.find(query).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuditLogEntry() {} // For Jackson
|
private AuditLogEntry() {} // For Jackson
|
||||||
|
|
||||||
public AuditLogEntry(UUID user, String userIp, Actor actor, String actorIp, AuditLogActionType type, Map<String, Object> metadata) {
|
public AuditLogEntry(UUID user, String userIp, Actor actor, String actorIp, AuditLogActionType type, Map<String, Object> metadata) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.userIp = userIp;
|
this.userIp = userIp;
|
||||||
this.performedAt = Instant.now();
|
this.performedAt = Instant.now();
|
||||||
this.actorName = actor.getName();
|
this.actorName = actor.getName();
|
||||||
this.actorType = actor.getType();
|
this.actorType = actor.getType();
|
||||||
this.actorIp = actorIp;
|
this.actorIp = actorIp;
|
||||||
this.reversible = type.isReversible();
|
this.reversible = type.isReversible();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.metadata = ImmutableMap.copyOf(metadata);
|
this.metadata = ImmutableMap.copyOf(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
auditLogCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
auditLogCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,74 +22,74 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class BannedAsn {
|
public final class BannedAsn {
|
||||||
|
|
||||||
private static final MongoCollection<BannedAsn> bannedAsnsCollection = APIv3.getDatabase().getCollection("bannedAsns", BannedAsn.class);
|
private static final MongoCollection<BannedAsn> bannedAsnsCollection = APIv3.getDatabase().getCollection("bannedAsns", BannedAsn.class);
|
||||||
|
|
||||||
private static Map<Integer, BannedAsn> bannedAsnIdCache = null;
|
private static Map<Integer, BannedAsn> bannedAsnIdCache = null;
|
||||||
private static List<BannedAsn> bannedAsnCache = null;
|
private static List<BannedAsn> bannedAsnCache = null;
|
||||||
|
|
||||||
@Getter @Id private int id;
|
@Getter @Id private int id;
|
||||||
@Getter @Setter String note;
|
@Getter @Setter String note;
|
||||||
@Getter private Instant bannedAt;
|
@Getter private Instant bannedAt;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
|
|
||||||
public static List<BannedAsn> findAll() {
|
public static List<BannedAsn> findAll() {
|
||||||
return ImmutableList.copyOf(bannedAsnCache);
|
return ImmutableList.copyOf(bannedAsnCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BannedAsn findById(int id) {
|
public static BannedAsn findById(int id) {
|
||||||
return bannedAsnIdCache.get(id);
|
return bannedAsnIdCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
bannedAsnsCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((bannedAsns, error) -> {
|
bannedAsnsCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((bannedAsns, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, BannedAsn> working = new HashMap<>();
|
Map<Integer, BannedAsn> working = new HashMap<>();
|
||||||
|
|
||||||
for (BannedAsn bannedAsn : bannedAsns) {
|
for (BannedAsn bannedAsn : bannedAsns) {
|
||||||
working.put(bannedAsn.getId(), bannedAsn);
|
working.put(bannedAsn.getId(), bannedAsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bannedAsnIdCache = working;
|
bannedAsnIdCache = working;
|
||||||
bannedAsnCache = bannedAsns;
|
bannedAsnCache = bannedAsns;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BannedAsn() {} // For Jackson
|
private BannedAsn() {} // For Jackson
|
||||||
|
|
||||||
public BannedAsn(int id, String note) {
|
public BannedAsn(int id, String note) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.note = note;
|
this.note = note;
|
||||||
this.bannedAt = Instant.now();
|
this.bannedAt = Instant.now();
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNote(String newNote) {
|
public void updateNote(String newNote) {
|
||||||
this.note = newNote;
|
this.note = newNote;
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
bannedAsnCache.add(this);
|
bannedAsnCache.add(this);
|
||||||
bannedAsnIdCache.put(id, this);
|
bannedAsnIdCache.put(id, this);
|
||||||
bannedAsnsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
bannedAsnsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
bannedAsnsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
bannedAsnsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
bannedAsnCache.remove(this);
|
bannedAsnCache.remove(this);
|
||||||
bannedAsnIdCache.remove(id);
|
bannedAsnIdCache.remove(id);
|
||||||
bannedAsnsCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
bannedAsnsCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,74 +23,74 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class BannedCellCarrier {
|
public final class BannedCellCarrier {
|
||||||
|
|
||||||
private static final MongoCollection<BannedCellCarrier> bannedCellCarriersCollection = APIv3.getDatabase().getCollection("bannedCellCarriers", BannedCellCarrier.class);
|
private static final MongoCollection<BannedCellCarrier> bannedCellCarriersCollection = APIv3.getDatabase().getCollection("bannedCellCarriers", BannedCellCarrier.class);
|
||||||
|
|
||||||
private static Map<Integer, BannedCellCarrier> bannedCellCarrierIdCache = null;
|
private static Map<Integer, BannedCellCarrier> bannedCellCarrierIdCache = null;
|
||||||
private static List<BannedCellCarrier> bannedCellCarrierCache = null;
|
private static List<BannedCellCarrier> bannedCellCarrierCache = null;
|
||||||
|
|
||||||
@Getter @Id private int id;
|
@Getter @Id private int id;
|
||||||
@Getter @Setter String note;
|
@Getter @Setter String note;
|
||||||
@Getter private Instant bannedAt;
|
@Getter private Instant bannedAt;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
|
|
||||||
public static List<BannedCellCarrier> findAll() {
|
public static List<BannedCellCarrier> findAll() {
|
||||||
return ImmutableList.copyOf(bannedCellCarrierCache);
|
return ImmutableList.copyOf(bannedCellCarrierCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BannedCellCarrier findById(int id) {
|
public static BannedCellCarrier findById(int id) {
|
||||||
return bannedCellCarrierIdCache.get(id);
|
return bannedCellCarrierIdCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
bannedCellCarriersCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((bannedCellCarriers, error) -> {
|
bannedCellCarriersCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((bannedCellCarriers, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, BannedCellCarrier> working = new HashMap<>();
|
Map<Integer, BannedCellCarrier> working = new HashMap<>();
|
||||||
|
|
||||||
for (BannedCellCarrier bannedCellCarrier : bannedCellCarriers) {
|
for (BannedCellCarrier bannedCellCarrier : bannedCellCarriers) {
|
||||||
working.put(bannedCellCarrier.getId(), bannedCellCarrier);
|
working.put(bannedCellCarrier.getId(), bannedCellCarrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
bannedCellCarrierIdCache = working;
|
bannedCellCarrierIdCache = working;
|
||||||
bannedCellCarrierCache = bannedCellCarriers;
|
bannedCellCarrierCache = bannedCellCarriers;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BannedCellCarrier() {} // For Jackson
|
private BannedCellCarrier() {} // For Jackson
|
||||||
|
|
||||||
public BannedCellCarrier(int id, String note) {
|
public BannedCellCarrier(int id, String note) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.note = note;
|
this.note = note;
|
||||||
this.bannedAt = Instant.now();
|
this.bannedAt = Instant.now();
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNote(String newNote) {
|
public void updateNote(String newNote) {
|
||||||
this.note = newNote;
|
this.note = newNote;
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
bannedCellCarrierCache.add(this);
|
bannedCellCarrierCache.add(this);
|
||||||
bannedCellCarrierIdCache.put(id, this);
|
bannedCellCarrierIdCache.put(id, this);
|
||||||
bannedCellCarriersCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
bannedCellCarriersCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
bannedCellCarriersCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
bannedCellCarriersCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
bannedCellCarrierCache.remove(this);
|
bannedCellCarrierCache.remove(this);
|
||||||
bannedCellCarrierIdCache.remove(id);
|
bannedCellCarrierIdCache.remove(id);
|
||||||
bannedCellCarriersCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
bannedCellCarriersCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,119 +21,119 @@ import java.util.stream.Collectors;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class Grant {
|
public final class Grant {
|
||||||
|
|
||||||
private static final MongoCollection<Grant> grantsCollection = APIv3.getDatabase().getCollection("grants", Grant.class);
|
private static final MongoCollection<Grant> grantsCollection = APIv3.getDatabase().getCollection("grants", Grant.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private UUID user;
|
@Getter private UUID user;
|
||||||
@Getter private String reason;
|
@Getter private String reason;
|
||||||
@Getter private Set<String> scopes;
|
@Getter private Set<String> scopes;
|
||||||
@Getter private String rank;
|
@Getter private String rank;
|
||||||
@Getter private Instant expiresAt;
|
@Getter private Instant expiresAt;
|
||||||
|
|
||||||
@Getter private UUID addedBy;
|
@Getter private UUID addedBy;
|
||||||
@Getter private Instant addedAt;
|
@Getter private Instant addedAt;
|
||||||
|
|
||||||
@Getter private UUID removedBy;
|
@Getter private UUID removedBy;
|
||||||
@Getter private Instant removedAt;
|
@Getter private Instant removedAt;
|
||||||
@Getter private String removalReason;
|
@Getter private String removalReason;
|
||||||
|
|
||||||
@Getter private int storeItemId;
|
@Getter private int storeItemId;
|
||||||
@Getter private int storeOrderId;
|
@Getter private int storeOrderId;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<Grant>> callback) {
|
public static void findAll(SingleResultCallback<List<Grant>> callback) {
|
||||||
grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByRank(Collection<Rank> ranks, SingleResultCallback<List<Grant>> callback) {
|
public static void findByRank(Collection<Rank> ranks, SingleResultCallback<List<Grant>> callback) {
|
||||||
Collection<String> convertedRanks = ranks.stream().map(Rank::getId).collect(Collectors.toList());
|
Collection<String> convertedRanks = ranks.stream().map(Rank::getId).collect(Collectors.toList());
|
||||||
grantsCollection.find(new Document("rank", new Document("$in", convertedRanks))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
grantsCollection.find(new Document("rank", new Document("$in", convertedRanks))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Grant>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Grant>> callback) {
|
||||||
grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<Grant> callback) {
|
public static void findById(String id, SingleResultCallback<Grant> callback) {
|
||||||
grantsCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
grantsCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(User user, SingleResultCallback<List<Grant>> callback) {
|
public static void findByUser(User user, SingleResultCallback<List<Grant>> callback) {
|
||||||
findByUser(user.getId(), callback);
|
findByUser(user.getId(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) {
|
public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) {
|
||||||
grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) {
|
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) {
|
||||||
grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), SyncUtils.vertxWrap((grants, error) -> {
|
grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), SyncUtils.vertxWrap((grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<UUID, List<Grant>> result = new HashMap<>();
|
Map<UUID, List<Grant>> result = new HashMap<>();
|
||||||
|
|
||||||
for (UUID user : users) {
|
for (UUID user : users) {
|
||||||
result.put(user, new LinkedList<>());
|
result.put(user, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Grant grant : grants) {
|
for (Grant grant : grants) {
|
||||||
result.get(grant.getUser()).add(grant);
|
result.get(grant.getUser()).add(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(result, null);
|
callback.onResult(result, null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Grant() {} // For Jackson
|
private Grant() {} // For Jackson
|
||||||
|
|
||||||
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy) {
|
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy) {
|
||||||
this(user, reason, scopes, rank, expiresAt, addedBy, -1, -1);
|
this(user, reason, scopes, rank, expiresAt, addedBy, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy, int storeItemId, int storeOrderId) {
|
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy, int storeItemId, int storeOrderId) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.user = user.getId();
|
this.user = user.getId();
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.scopes = new HashSet<>(Collections2.transform(scopes, ServerGroup::getId));
|
this.scopes = new HashSet<>(Collections2.transform(scopes, ServerGroup::getId));
|
||||||
this.rank = rank.getId();
|
this.rank = rank.getId();
|
||||||
this.expiresAt = expiresAt;
|
this.expiresAt = expiresAt;
|
||||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||||
this.addedAt = Instant.now();
|
this.addedAt = Instant.now();
|
||||||
this.storeItemId = storeItemId;
|
this.storeItemId = storeItemId;
|
||||||
this.storeOrderId = storeOrderId;
|
this.storeOrderId = storeOrderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return !(isExpired() || isRemoved());
|
return !(isExpired() || isRemoved());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedAt != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean appliesOn(ServerGroup serverGroup) {
|
public boolean appliesOn(ServerGroup serverGroup) {
|
||||||
return isGlobal() || scopes.contains(serverGroup.getId());
|
return isGlobal() || scopes.contains(serverGroup.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGlobal() {
|
public boolean isGlobal() {
|
||||||
return scopes.isEmpty();
|
return scopes.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
grantsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
grantsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy == null ? null : removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
grantsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
grantsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,143 +22,143 @@ import java.util.*;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class IpBan {
|
public final class IpBan {
|
||||||
|
|
||||||
private static final MongoCollection<IpBan> ipBansCollection = APIv3.getDatabase().getCollection("ipBans", IpBan.class);
|
private static final MongoCollection<IpBan> ipBansCollection = APIv3.getDatabase().getCollection("ipBans", IpBan.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String userIp;
|
@Getter private String userIp;
|
||||||
@Getter private String reason;
|
@Getter private String reason;
|
||||||
@Getter private Instant expiresAt;
|
@Getter private Instant expiresAt;
|
||||||
|
|
||||||
@Getter private UUID addedBy;
|
@Getter private UUID addedBy;
|
||||||
@Getter private Instant addedAt;
|
@Getter private Instant addedAt;
|
||||||
@Getter private String actorName;
|
@Getter private String actorName;
|
||||||
@Getter private ActorType actorType;
|
@Getter private ActorType actorType;
|
||||||
|
|
||||||
@Getter private UUID removedBy;
|
@Getter private UUID removedBy;
|
||||||
@Getter private Instant removedAt;
|
@Getter private Instant removedAt;
|
||||||
@Getter private String removalReason;
|
@Getter private String removalReason;
|
||||||
|
|
||||||
public static void find(SingleResultCallback<List<IpBan>> callback) {
|
public static void find(SingleResultCallback<List<IpBan>> callback) {
|
||||||
ipBansCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(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));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<IpBan> callback) {
|
public static void findById(String id, SingleResultCallback<IpBan> callback) {
|
||||||
ipBansCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
ipBansCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByIp(String userIp, SingleResultCallback<List<IpBan>> callback) {
|
public static void findByIp(String userIp, SingleResultCallback<List<IpBan>> callback) {
|
||||||
ipBansCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
ipBansCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByIpGrouped(Iterable<String> userIps, SingleResultCallback<Map<String, List<IpBan>>> callback) {
|
public static void findByIpGrouped(Iterable<String> userIps, SingleResultCallback<Map<String, List<IpBan>>> callback) {
|
||||||
ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new LinkedList<>(), SyncUtils.vertxWrap((ipBans, error) -> {
|
ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new LinkedList<>(), SyncUtils.vertxWrap((ipBans, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<String, List<IpBan>> result = new HashMap<>();
|
Map<String, List<IpBan>> result = new HashMap<>();
|
||||||
|
|
||||||
for (String userIp : userIps) {
|
for (String userIp : userIps) {
|
||||||
result.put(userIp, new LinkedList<>());
|
result.put(userIp, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IpBan ipBan : ipBans) {
|
for (IpBan ipBan : ipBans) {
|
||||||
result.get(ipBan.getUserIp()).add(ipBan);
|
result.get(ipBan.getUserIp()).add(ipBan);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(result, null);
|
callback.onResult(result, null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IpBan() {} // For Jackson
|
private IpBan() {} // For Jackson
|
||||||
|
|
||||||
public IpBan(String userIp, Punishment linked) {
|
public IpBan(String userIp, Punishment linked) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.userIp = userIp;
|
this.userIp = userIp;
|
||||||
this.reason = linked.getPublicReason();
|
this.reason = linked.getPublicReason();
|
||||||
this.expiresAt = linked.getExpiresAt();
|
this.expiresAt = linked.getExpiresAt();
|
||||||
this.addedBy = linked.getAddedBy();
|
this.addedBy = linked.getAddedBy();
|
||||||
this.addedAt = Instant.now();
|
this.addedAt = Instant.now();
|
||||||
this.actorName = linked.getActorName();
|
this.actorName = linked.getActorName();
|
||||||
this.actorType = linked.getActorType();
|
this.actorType = linked.getActorType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IpBan(String userIp, String reason, Instant expiresAt, User addedBy, Actor actor) {
|
public IpBan(String userIp, String reason, Instant expiresAt, User addedBy, Actor actor) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.userIp = userIp;
|
this.userIp = userIp;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.expiresAt = expiresAt;
|
this.expiresAt = expiresAt;
|
||||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||||
this.addedAt = Instant.now();
|
this.addedAt = Instant.now();
|
||||||
this.actorName = actor.getName();
|
this.actorName = actor.getName();
|
||||||
this.actorType = actor.getType();
|
this.actorType = actor.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return !(isExpired() || isRemoved());
|
return !(isExpired() || isRemoved());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedAt != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAccessDenialReason(SingleResultCallback<String> callback) {
|
public void getAccessDenialReason(SingleResultCallback<String> callback) {
|
||||||
Punishment.findByLinkedIpBanId(id, (punishment, error) -> {
|
Punishment.findByLinkedIpBanId(id, (punishment, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (punishment != null) {
|
if (punishment != null) {
|
||||||
User.findById(punishment.getUser(), (user, error2) -> {
|
User.findById(punishment.getUser(), (user, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
callback.onResult(null, error2);
|
callback.onResult(null, error2);
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(buildDenialReason(user), null);
|
callback.onResult(buildDenialReason(user), null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(buildDenialReason(null), null);
|
callback.onResult(buildDenialReason(null), null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDenialReason(User linkedIpBanUser) {
|
private String buildDenialReason(User linkedIpBanUser) {
|
||||||
String accessDenialReason;
|
String accessDenialReason;
|
||||||
|
|
||||||
if (linkedIpBanUser != null) {
|
if (linkedIpBanUser != null) {
|
||||||
accessDenialReason = "Your IP address has been suspended from the MineHQ Network for a punishment related to " + linkedIpBanUser.getLastUsername() + ". \n\n";
|
accessDenialReason = "Your IP address has been suspended from the MineHQ Network for a punishment related to " + linkedIpBanUser.getLastUsername() + ". \n\n";
|
||||||
} else {
|
} else {
|
||||||
accessDenialReason = "Your IP address has been suspended from the MineHQ Network. \n\n";
|
accessDenialReason = "Your IP address has been suspended from the MineHQ Network. \n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getExpiresAt() != null) {
|
if (getExpiresAt() != null) {
|
||||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
||||||
} else {
|
} else {
|
||||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessDenialReason;
|
return accessDenialReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
ipBansCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
ipBansCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy == null ? null : removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
ipBansCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
ipBansCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,113 +22,113 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class IpIntel {
|
public final class IpIntel {
|
||||||
|
|
||||||
private static final MongoCollection<IpIntel> ipIntelCollection = APIv3.getDatabase().getCollection("ipIntel", IpIntel.class);
|
private static final MongoCollection<IpIntel> ipIntelCollection = APIv3.getDatabase().getCollection("ipIntel", IpIntel.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
@Getter private MaxMindResult result;
|
@Getter private MaxMindResult result;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<IpIntel>> callback) {
|
public static void findAll(SingleResultCallback<List<IpIntel>> callback) {
|
||||||
ipIntelCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
ipIntelCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<IpIntel> callback) {
|
public static void findById(String id, SingleResultCallback<IpIntel> callback) {
|
||||||
ipIntelCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
ipIntelCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findOrCreateById(String id, SingleResultCallback<IpIntel> callback) {
|
public static void findOrCreateById(String id, SingleResultCallback<IpIntel> callback) {
|
||||||
findById(id, (existingIpIntel, error) -> {
|
findById(id, (existingIpIntel, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else if (existingIpIntel != null) {
|
} else if (existingIpIntel != null) {
|
||||||
callback.onResult(existingIpIntel, null);
|
callback.onResult(existingIpIntel, null);
|
||||||
} else {
|
} else {
|
||||||
MaxMindUtils.getInsights(id, (maxMindResult, error2) -> {
|
MaxMindUtils.getInsights(id, (maxMindResult, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
callback.onResult(null, error2);
|
callback.onResult(null, error2);
|
||||||
} else if (maxMindResult != null) {
|
} else if (maxMindResult != null) {
|
||||||
IpIntel newIpIntel = new IpIntel(id, maxMindResult);
|
IpIntel newIpIntel = new IpIntel(id, maxMindResult);
|
||||||
|
|
||||||
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> {
|
||||||
if (error3 != null) {
|
if (error3 != null) {
|
||||||
callback.onResult(null, error3);
|
callback.onResult(null, error3);
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(newIpIntel, null);
|
callback.onResult(newIpIntel, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// MaxMind failed to return result
|
// MaxMind failed to return result
|
||||||
callback.onResult(null, null);
|
callback.onResult(null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findOrCreateByIdGrouped(Collection<String> search, SingleResultCallback<Map<String, IpIntel>> callback) {
|
public static void findOrCreateByIdGrouped(Collection<String> search, SingleResultCallback<Map<String, IpIntel>> callback) {
|
||||||
ipIntelCollection.find(new Document("_id", new Document("$in", search))).into(new LinkedList<>(), SyncUtils.vertxWrap((existingIntel, error) -> {
|
ipIntelCollection.find(new Document("_id", new Document("$in", search))).into(new LinkedList<>(), SyncUtils.vertxWrap((existingIntel, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, IpIntel> result = new ConcurrentHashMap<>();
|
Map<String, IpIntel> result = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
for (IpIntel ipIntel : existingIntel) {
|
for (IpIntel ipIntel : existingIntel) {
|
||||||
result.put(ipIntel.getId(), ipIntel);
|
result.put(ipIntel.getId(), ipIntel);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Future> createNewIntelFutures = new ArrayList<>();
|
List<Future> createNewIntelFutures = new ArrayList<>();
|
||||||
|
|
||||||
search.forEach((ip) -> {
|
search.forEach((ip) -> {
|
||||||
if (result.containsKey(ip)) {
|
if (result.containsKey(ip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future createNewIntelFuture = Future.future();
|
Future createNewIntelFuture = Future.future();
|
||||||
createNewIntelFutures.add(createNewIntelFuture);
|
createNewIntelFutures.add(createNewIntelFuture);
|
||||||
|
|
||||||
MaxMindUtils.getInsights(ip, (maxMindResult, error2) -> {
|
MaxMindUtils.getInsights(ip, (maxMindResult, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
createNewIntelFuture.fail(error2);
|
createNewIntelFuture.fail(error2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxMind failed to return result
|
// MaxMind failed to return result
|
||||||
if (maxMindResult == null) {
|
if (maxMindResult == null) {
|
||||||
createNewIntelFuture.complete();
|
createNewIntelFuture.complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IpIntel newIpIntel = new IpIntel(ip, maxMindResult);
|
IpIntel newIpIntel = new IpIntel(ip, maxMindResult);
|
||||||
|
|
||||||
ipIntelCollection.insertOne(newIpIntel, SyncUtils.vertxWrap((ignored, error3) -> {
|
ipIntelCollection.insertOne(newIpIntel, SyncUtils.vertxWrap((ignored, error3) -> {
|
||||||
if (error3 != null) {
|
if (error3 != null) {
|
||||||
createNewIntelFuture.fail(error3);
|
createNewIntelFuture.fail(error3);
|
||||||
} else {
|
} else {
|
||||||
result.put(ip, newIpIntel);
|
result.put(ip, newIpIntel);
|
||||||
createNewIntelFuture.complete();
|
createNewIntelFuture.complete();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
CompositeFuture.all(createNewIntelFutures).setHandler((creationStatus) -> {
|
CompositeFuture.all(createNewIntelFutures).setHandler((creationStatus) -> {
|
||||||
if (creationStatus.failed()) {
|
if (creationStatus.failed()) {
|
||||||
callback.onResult(null, creationStatus.cause());
|
callback.onResult(null, creationStatus.cause());
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(result, null);
|
callback.onResult(result, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IpIntel() {} // For Jackson
|
private IpIntel() {} // For Jackson
|
||||||
|
|
||||||
private IpIntel(String ip, MaxMindResult result) {
|
private IpIntel(String ip, MaxMindResult result) {
|
||||||
this.id = ip;
|
this.id = ip;
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,65 +21,65 @@ import java.util.UUID;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class IpLogEntry {
|
public final class IpLogEntry {
|
||||||
|
|
||||||
private static final MongoCollection<IpLogEntry> ipLogCollection = APIv3.getDatabase().getCollection("ipLog", IpLogEntry.class);
|
private static final MongoCollection<IpLogEntry> ipLogCollection = APIv3.getDatabase().getCollection("ipLog", IpLogEntry.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private UUID user;
|
@Getter private UUID user;
|
||||||
@Getter private String userIp;
|
@Getter private String userIp;
|
||||||
@Getter private Instant firstSeenAt;
|
@Getter private Instant firstSeenAt;
|
||||||
@Getter private Instant lastSeenAt;
|
@Getter private Instant lastSeenAt;
|
||||||
@Getter private int uses;
|
@Getter private int uses;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<IpLogEntry>> callback) {
|
public static void findAll(SingleResultCallback<List<IpLogEntry>> callback) {
|
||||||
ipLogCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
ipLogCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<IpLogEntry> callback) {
|
public static void findById(String id, SingleResultCallback<IpLogEntry> callback) {
|
||||||
ipLogCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
ipLogCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(User user, SingleResultCallback<List<IpLogEntry>> callback) {
|
public static void findByUser(User user, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||||
findByUser(user.getId(), callback);
|
findByUser(user.getId(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(UUID user, SingleResultCallback<List<IpLogEntry>> callback) {
|
public static void findByUser(UUID user, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||||
ipLogCollection.find(new Document("user", user)).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
ipLogCollection.find(new Document("user", user)).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByIp(String userIp, SingleResultCallback<List<IpLogEntry>> callback) {
|
public static void findByIp(String userIp, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||||
ipLogCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
ipLogCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserAndIp(User user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
public static void findByUserAndIp(User user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
||||||
findByUserAndIp(user.getId(), userIp, callback);
|
findByUserAndIp(user.getId(), userIp, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserAndIp(UUID user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
public static void findByUserAndIp(UUID user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
||||||
ipLogCollection.find(new Document("user", user).append("userIp", userIp)).first(SyncUtils.vertxWrap(callback));
|
ipLogCollection.find(new Document("user", user).append("userIp", userIp)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IpLogEntry() {} // For Jackson
|
private IpLogEntry() {} // For Jackson
|
||||||
|
|
||||||
public IpLogEntry(User user, String userIp) {
|
public IpLogEntry(User user, String userIp) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.user = user.getId();
|
this.user = user.getId();
|
||||||
this.userIp = userIp;
|
this.userIp = userIp;
|
||||||
this.firstSeenAt = Instant.now();
|
this.firstSeenAt = Instant.now();
|
||||||
this.lastSeenAt = Instant.now();
|
this.lastSeenAt = Instant.now();
|
||||||
this.uses = 0;
|
this.uses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void used() {
|
public void used() {
|
||||||
this.lastSeenAt = Instant.now();
|
this.lastSeenAt = Instant.now();
|
||||||
this.uses++;
|
this.uses++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
ipLogCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
ipLogCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
ipLogCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
ipLogCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,53 +18,53 @@ import java.util.Map;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class NotificationTemplate {
|
public final class NotificationTemplate {
|
||||||
|
|
||||||
private static final MongoCollection<NotificationTemplate> notificationTemplatesCollection = APIv3.getDatabase().getCollection("notificationTemplates", NotificationTemplate.class);
|
private static final MongoCollection<NotificationTemplate> notificationTemplatesCollection = APIv3.getDatabase().getCollection("notificationTemplates", NotificationTemplate.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter @Setter private String subject;
|
@Getter @Setter private String subject;
|
||||||
@Getter @Setter private String body;
|
@Getter @Setter private String body;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<NotificationTemplate>> callback) {
|
public static void findAll(SingleResultCallback<List<NotificationTemplate>> callback) {
|
||||||
notificationTemplatesCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
notificationTemplatesCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<NotificationTemplate> callback) {
|
public static void findById(String id, SingleResultCallback<NotificationTemplate> callback) {
|
||||||
notificationTemplatesCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
notificationTemplatesCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationTemplate() {} // For Jackson
|
private NotificationTemplate() {} // For Jackson
|
||||||
|
|
||||||
public NotificationTemplate(String id, String subject, String body) {
|
public NotificationTemplate(String id, String subject, String body) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fillSubject(Map<String, Object> replacements) {
|
public String fillSubject(Map<String, Object> replacements) {
|
||||||
return fill(subject, replacements);
|
return fill(subject, replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fillBody(Map<String, Object> replacements) {
|
public String fillBody(Map<String, Object> replacements) {
|
||||||
return fill(body, replacements);
|
return fill(body, replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fill(String working, Map<String, Object> replacements) {
|
private String fill(String working, Map<String, Object> replacements) {
|
||||||
for (Map.Entry<String, Object> replacement : replacements.entrySet()) {
|
for (Map.Entry<String, Object> replacement : replacements.entrySet()) {
|
||||||
String key = replacement.getKey();
|
String key = replacement.getKey();
|
||||||
String value = String.valueOf(replacement.getValue());
|
String value = String.valueOf(replacement.getValue());
|
||||||
|
|
||||||
working = working.replace("%" + key + "%", value);
|
working = working.replace("%" + key + "%", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return working;
|
return working;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
notificationTemplatesCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
notificationTemplatesCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
notificationTemplatesCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
notificationTemplatesCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,52 +20,52 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class PhoneIntel {
|
public final class PhoneIntel {
|
||||||
|
|
||||||
private static final MongoCollection<PhoneIntel> phoneIntelCollection = APIv3.getDatabase().getCollection("phoneIntel", PhoneIntel.class);
|
private static final MongoCollection<PhoneIntel> phoneIntelCollection = APIv3.getDatabase().getCollection("phoneIntel", PhoneIntel.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
@Getter private ZangResult result;
|
@Getter private ZangResult result;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<PhoneIntel>> callback) {
|
public static void findAll(SingleResultCallback<List<PhoneIntel>> callback) {
|
||||||
phoneIntelCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
phoneIntelCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<PhoneIntel> callback) {
|
public static void findById(String id, SingleResultCallback<PhoneIntel> callback) {
|
||||||
phoneIntelCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
phoneIntelCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findOrCreateById(String id, SingleResultCallback<PhoneIntel> callback) {
|
public static void findOrCreateById(String id, SingleResultCallback<PhoneIntel> callback) {
|
||||||
findById(id, (existingPhoneIntel, error) -> {
|
findById(id, (existingPhoneIntel, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else if (existingPhoneIntel != null) {
|
} else if (existingPhoneIntel != null) {
|
||||||
callback.onResult(existingPhoneIntel, null);
|
callback.onResult(existingPhoneIntel, null);
|
||||||
} else {
|
} else {
|
||||||
ZangUtils.getCarrierInfo(id, (zangResult, error2) -> {
|
ZangUtils.getCarrierInfo(id, (zangResult, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
callback.onResult(null, error2);
|
callback.onResult(null, error2);
|
||||||
} else {
|
} else {
|
||||||
PhoneIntel newPhoneIntel = new PhoneIntel(id, zangResult);
|
PhoneIntel newPhoneIntel = new PhoneIntel(id, zangResult);
|
||||||
|
|
||||||
phoneIntelCollection.insertOne(newPhoneIntel, SyncUtils.vertxWrap((ignored, error3) -> {
|
phoneIntelCollection.insertOne(newPhoneIntel, SyncUtils.vertxWrap((ignored, error3) -> {
|
||||||
if (error3 != null) {
|
if (error3 != null) {
|
||||||
callback.onResult(null, error3);
|
callback.onResult(null, error3);
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(newPhoneIntel, null);
|
callback.onResult(newPhoneIntel, null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private PhoneIntel() {} // For Jackson
|
private PhoneIntel() {} // For Jackson
|
||||||
|
|
||||||
private PhoneIntel(String phoneNumber, ZangResult result) {
|
private PhoneIntel(String phoneNumber, ZangResult result) {
|
||||||
this.id = phoneNumber;
|
this.id = phoneNumber;
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,169 +23,169 @@ import java.util.stream.Collectors;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public final class Punishment {
|
public final class Punishment {
|
||||||
|
|
||||||
private static final MongoCollection<Punishment> punishmentsCollection = APIv3.getDatabase().getCollection("punishments", Punishment.class);
|
private static final MongoCollection<Punishment> punishmentsCollection = APIv3.getDatabase().getCollection("punishments", Punishment.class);
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private UUID user;
|
@Getter private UUID user;
|
||||||
@Getter private String publicReason;
|
@Getter private String publicReason;
|
||||||
@Getter private String privateReason;
|
@Getter private String privateReason;
|
||||||
@Getter private PunishmentType type;
|
@Getter private PunishmentType type;
|
||||||
@Getter private Instant expiresAt;
|
@Getter private Instant expiresAt;
|
||||||
@Getter private Map<String, Object> metadata;
|
@Getter private Map<String, Object> metadata;
|
||||||
@Getter private String linkedIpBanId;
|
@Getter private String linkedIpBanId;
|
||||||
|
|
||||||
@Getter private UUID addedBy;
|
@Getter private UUID addedBy;
|
||||||
@Getter private Instant addedAt;
|
@Getter private Instant addedAt;
|
||||||
@Getter private String actorName;
|
@Getter private String actorName;
|
||||||
@Getter private ActorType actorType;
|
@Getter private ActorType actorType;
|
||||||
|
|
||||||
@Getter private UUID removedBy;
|
@Getter private UUID removedBy;
|
||||||
@Getter private Instant removedAt;
|
@Getter private Instant removedAt;
|
||||||
@Getter private String removalReason;
|
@Getter private String removalReason;
|
||||||
|
|
||||||
public static void findByType(Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByType(Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
||||||
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
||||||
punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Punishment>> callback) {
|
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Punishment>> callback) {
|
||||||
punishmentsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<Punishment> callback) {
|
public static void findById(String id, SingleResultCallback<Punishment> callback) {
|
||||||
punishmentsCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByLinkedIpBanId(String id, SingleResultCallback<Punishment> callback) {
|
public static void findByLinkedIpBanId(String id, SingleResultCallback<Punishment> callback) {
|
||||||
punishmentsCollection.find(new Document("linkedIpBanId", id)).first(SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(new Document("linkedIpBanId", id)).first(SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(User user, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUser(User user, SingleResultCallback<List<Punishment>> callback) {
|
||||||
findByUser(user.getId(), callback);
|
findByUser(user.getId(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUser(UUID user, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUser(UUID user, SingleResultCallback<List<Punishment>> callback) {
|
||||||
punishmentsCollection.find(new Document("user", user)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(new Document("user", user)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Punishment>>> callback) {
|
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Punishment>>> callback) {
|
||||||
punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), SyncUtils.vertxWrap((punishments, error) -> {
|
punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), SyncUtils.vertxWrap((punishments, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
} else {
|
} else {
|
||||||
Map<UUID, List<Punishment>> result = new HashMap<>();
|
Map<UUID, List<Punishment>> result = new HashMap<>();
|
||||||
|
|
||||||
for (UUID user : users) {
|
for (UUID user : users) {
|
||||||
result.put(user, new LinkedList<>());
|
result.put(user, new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Punishment punishment : punishments) {
|
for (Punishment punishment : punishments) {
|
||||||
result.get(punishment.getUser()).add(punishment);
|
result.get(punishment.getUser()).add(punishment);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(result, null);
|
callback.onResult(result, null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserAndType(User user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUserAndType(User user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
||||||
findByUserAndType(user.getId(), types, callback);
|
findByUserAndType(user.getId(), types, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findByUserAndType(UUID user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
public static void findByUserAndType(UUID user, Collection<PunishmentType> types, SingleResultCallback<List<Punishment>> callback) {
|
||||||
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
Collection<String> convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList());
|
||||||
punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Punishment() {} // For Jackson
|
private Punishment() {} // For Jackson
|
||||||
|
|
||||||
public Punishment(User user, String publicReason, String privateReason, PunishmentType type, Instant expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
public Punishment(User user, String publicReason, String privateReason, PunishmentType type, Instant expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
||||||
this.id = new ObjectId().toString();
|
this.id = new ObjectId().toString();
|
||||||
this.user = user.getId();
|
this.user = user.getId();
|
||||||
this.publicReason = publicReason;
|
this.publicReason = publicReason;
|
||||||
this.privateReason = privateReason;
|
this.privateReason = privateReason;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.expiresAt = expiresAt;
|
this.expiresAt = expiresAt;
|
||||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||||
this.addedAt = Instant.now();
|
this.addedAt = Instant.now();
|
||||||
this.actorName = actor.getName();
|
this.actorName = actor.getName();
|
||||||
this.actorType = actor.getType();
|
this.actorType = actor.getType();
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return !(isExpired() || isRemoved());
|
return !(isExpired() || isRemoved());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
return expiresAt != null && expiresAt.isBefore(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoved() {
|
public boolean isRemoved() {
|
||||||
return removedAt != null;
|
return removedAt != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessDenialReason() {
|
public String getAccessDenialReason() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BLACKLIST:
|
case BLACKLIST:
|
||||||
return "Your account has been blacklisted from the MineHQ Network. \n\nThis type of punishment cannot be appealed.";
|
return "Your account has been blacklisted from the MineHQ Network. \n\nThis type of punishment cannot be appealed.";
|
||||||
case BAN:
|
case BAN:
|
||||||
String accessDenialReason = "Your account has been suspended from the MineHQ Network. \n\n";
|
String accessDenialReason = "Your account has been suspended from the MineHQ Network. \n\n";
|
||||||
|
|
||||||
if (getExpiresAt() != null) {
|
if (getExpiresAt() != null) {
|
||||||
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now()));
|
||||||
} else {
|
} else {
|
||||||
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
accessDenialReason += "Appeal at MineHQ.com/appeal";
|
||||||
}
|
}
|
||||||
|
|
||||||
return accessDenialReason;
|
return accessDenialReason;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void linkIpBan(IpBan ipBan) {
|
public void linkIpBan(IpBan ipBan) {
|
||||||
this.linkedIpBanId = ipBan.getId();
|
this.linkedIpBanId = ipBan.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
punishmentsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
punishmentsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
public void delete(User removedBy, String reason, SingleResultCallback<Void> callback) {
|
||||||
this.removedBy = removedBy == null ? null : removedBy.getId();
|
this.removedBy = removedBy == null ? null : removedBy.getId();
|
||||||
this.removedAt = Instant.now();
|
this.removedAt = Instant.now();
|
||||||
this.removalReason = reason;
|
this.removalReason = reason;
|
||||||
|
|
||||||
if (linkedIpBanId == null) {
|
if (linkedIpBanId == null) {
|
||||||
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IpBan.findById(linkedIpBanId, (ipBan, error) -> {
|
IpBan.findById(linkedIpBanId, (ipBan, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.onResult(null, error);
|
callback.onResult(null, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipBan != null && ipBan.isActive()) {
|
if (ipBan != null && ipBan.isActive()) {
|
||||||
ipBan.delete(removedBy, "Linked punishment removed: " + reason, (ignored, error2) -> {
|
ipBan.delete(removedBy, "Linked punishment removed: " + reason, (ignored, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
callback.onResult(null, error2);
|
callback.onResult(null, error2);
|
||||||
} else {
|
} else {
|
||||||
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
punishmentsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PunishmentType {
|
public enum PunishmentType {
|
||||||
|
|
||||||
BLACKLIST, BAN, MUTE, WARN
|
BLACKLIST, BAN, MUTE, WARN
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,73 +20,73 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class Rank {
|
public final class Rank {
|
||||||
|
|
||||||
private static final MongoCollection<Rank> ranksCollection = APIv3.getDatabase().getCollection("ranks", Rank.class);
|
private static final MongoCollection<Rank> ranksCollection = APIv3.getDatabase().getCollection("ranks", Rank.class);
|
||||||
|
|
||||||
private static Map<String, Rank> rankIdCache = null;
|
private static Map<String, Rank> rankIdCache = null;
|
||||||
private static List<Rank> rankCache = null;
|
private static List<Rank> rankCache = null;
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String inheritsFromId;
|
@Getter private String inheritsFromId;
|
||||||
@Getter private int weight;
|
@Getter private int weight;
|
||||||
@Getter private String displayName;
|
@Getter private String displayName;
|
||||||
@Getter private String gameColor;
|
@Getter private String gameColor;
|
||||||
@Getter private String websiteColor;
|
@Getter private String websiteColor;
|
||||||
@Getter private boolean staffRank;
|
@Getter private boolean staffRank;
|
||||||
@Getter private boolean higherStaffRank;
|
@Getter private boolean higherStaffRank;
|
||||||
|
|
||||||
public static List<Rank> findAll() {
|
public static List<Rank> findAll() {
|
||||||
return ImmutableList.copyOf(rankCache);
|
return ImmutableList.copyOf(rankCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Rank findById(String id) {
|
public static Rank findById(String id) {
|
||||||
return rankIdCache.get(id);
|
return rankIdCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
ranksCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((ranks, error) -> {
|
ranksCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((ranks, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Rank> working = new HashMap<>();
|
Map<String, Rank> working = new HashMap<>();
|
||||||
|
|
||||||
for (Rank rank : ranks) {
|
for (Rank rank : ranks) {
|
||||||
working.put(rank.getId(), rank);
|
working.put(rank.getId(), rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
rankIdCache = working;
|
rankIdCache = working;
|
||||||
rankCache = ranks;
|
rankCache = ranks;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rank() {} // For Jackson
|
private Rank() {} // For Jackson
|
||||||
|
|
||||||
public Rank(String id, String inheritsFromId, int weight, String displayName, String gameColor, String websiteColor, boolean staffRank, boolean higherStaffRank) {
|
public Rank(String id, String inheritsFromId, int weight, String displayName, String gameColor, String websiteColor, boolean staffRank, boolean higherStaffRank) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.inheritsFromId = inheritsFromId;
|
this.inheritsFromId = inheritsFromId;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.gameColor = gameColor;
|
this.gameColor = gameColor;
|
||||||
this.websiteColor = websiteColor;
|
this.websiteColor = websiteColor;
|
||||||
this.staffRank = staffRank;
|
this.staffRank = staffRank;
|
||||||
this.higherStaffRank = higherStaffRank;
|
this.higherStaffRank = higherStaffRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
rankCache.add(this);
|
rankCache.add(this);
|
||||||
rankIdCache.put(id, this);
|
rankIdCache.put(id, this);
|
||||||
ranksCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
ranksCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
rankCache.remove(this);
|
rankCache.remove(this);
|
||||||
rankIdCache.remove(id);
|
rankIdCache.remove(id);
|
||||||
ranksCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
ranksCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,116 +21,116 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class Server {
|
public final class Server {
|
||||||
|
|
||||||
private static final MongoCollection<Server> serversCollection = APIv3.getDatabase().getCollection("servers", Server.class);
|
private static final MongoCollection<Server> serversCollection = APIv3.getDatabase().getCollection("servers", Server.class);
|
||||||
|
|
||||||
private static Map<String, Server> serverIdCache = null;
|
private static Map<String, Server> serverIdCache = null;
|
||||||
private static List<Server> serverCache = null;
|
private static List<Server> serverCache = null;
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String displayName;
|
@Getter private String displayName;
|
||||||
@Getter private String serverGroup;
|
@Getter private String serverGroup;
|
||||||
@Getter private String serverIp;
|
@Getter private String serverIp;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter private Instant lastUpdatedAt;
|
||||||
@Getter private double lastTps;
|
@Getter private double lastTps;
|
||||||
@Getter @ExcludeFromReplies private Set<UUID> players;
|
@Getter @ExcludeFromReplies private Set<UUID> players;
|
||||||
|
|
||||||
public static List<Server> findAll() {
|
public static List<Server> findAll() {
|
||||||
return ImmutableList.copyOf(serverCache);
|
return ImmutableList.copyOf(serverCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Server findById(String id) {
|
public static Server findById(String id) {
|
||||||
return serverIdCache.get(id);
|
return serverIdCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateTimedOutServers());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateTimedOutServers());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
serversCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((servers, error) -> {
|
serversCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((servers, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Server> working = new HashMap<>();
|
Map<String, Server> working = new HashMap<>();
|
||||||
|
|
||||||
for (Server server : servers) {
|
for (Server server : servers) {
|
||||||
working.put(server.getId(), server);
|
working.put(server.getId(), server);
|
||||||
}
|
}
|
||||||
|
|
||||||
serverIdCache = working;
|
serverIdCache = working;
|
||||||
serverCache = servers;
|
serverCache = servers;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateTimedOutServers() {
|
private static void updateTimedOutServers() {
|
||||||
for (Server server : serverCache) {
|
for (Server server : serverCache) {
|
||||||
int lastUpdatedAgo = TimeUtils.getSecondsBetween(server.getLastUpdatedAt(), Instant.now());
|
int lastUpdatedAgo = TimeUtils.getSecondsBetween(server.getLastUpdatedAt(), Instant.now());
|
||||||
|
|
||||||
if (lastUpdatedAgo < 60 || lastUpdatedAgo > 30 * 5) {
|
if (lastUpdatedAgo < 60 || lastUpdatedAgo > 30 * 5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UUID online : server.getPlayers()) {
|
for (UUID online : server.getPlayers()) {
|
||||||
User.findById(online, (user, findUserError) -> {
|
User.findById(online, (user, findUserError) -> {
|
||||||
if (findUserError != null) {
|
if (findUserError != null) {
|
||||||
findUserError.printStackTrace();
|
findUserError.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.leftServer(server)) {
|
if (user.leftServer(server)) {
|
||||||
user.save((ignored, saveUserError) -> {
|
user.save((ignored, saveUserError) -> {
|
||||||
if (saveUserError != null) {
|
if (saveUserError != null) {
|
||||||
saveUserError.printStackTrace();
|
saveUserError.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
server.players = new HashSet<>();
|
server.players = new HashSet<>();
|
||||||
server.save((ignored, error) -> {
|
server.save((ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Server() {} // For Jackson
|
private Server() {} // For Jackson
|
||||||
|
|
||||||
public Server(String id, String displayName, ServerGroup serverGroup, String serverIp) {
|
public Server(String id, String displayName, ServerGroup serverGroup, String serverIp) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.serverGroup = serverGroup.getId();
|
this.serverGroup = serverGroup.getId();
|
||||||
this.serverIp = serverIp;
|
this.serverIp = serverIp;
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
this.lastTps = 0;
|
this.lastTps = 0;
|
||||||
this.players = new HashSet<>();
|
this.players = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void receivedHeartbeat(double tps, Iterable<UUID> players) {
|
public void receivedHeartbeat(double tps, Iterable<UUID> players) {
|
||||||
this.lastUpdatedAt = Instant.now();
|
this.lastUpdatedAt = Instant.now();
|
||||||
this.lastTps = tps;
|
this.lastTps = tps;
|
||||||
this.players = ImmutableSet.copyOf(players);
|
this.players = ImmutableSet.copyOf(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
serverCache.add(this);
|
serverCache.add(this);
|
||||||
serverIdCache.put(id, this);
|
serverIdCache.put(id, this);
|
||||||
serversCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
serversCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
serversCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
serversCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
serverCache.remove(this);
|
serverCache.remove(this);
|
||||||
serverIdCache.remove(id);
|
serverIdCache.remove(id);
|
||||||
serversCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
serversCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,80 +21,80 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Entity
|
@Entity
|
||||||
public final class ServerGroup {
|
public final class ServerGroup {
|
||||||
|
|
||||||
public static final String DEFAULT_GROUP_ID = "default";
|
public static final String DEFAULT_GROUP_ID = "default";
|
||||||
private static final MongoCollection<ServerGroup> serverGroupsCollection = APIv3.getDatabase().getCollection("serverGroups", ServerGroup.class);
|
private static final MongoCollection<ServerGroup> serverGroupsCollection = APIv3.getDatabase().getCollection("serverGroups", ServerGroup.class);
|
||||||
|
|
||||||
private static Map<String, ServerGroup> serverGroupIdCache = null;
|
private static Map<String, ServerGroup> serverGroupIdCache = null;
|
||||||
private static List<ServerGroup> serverGroupCache = null;
|
private static List<ServerGroup> serverGroupCache = null;
|
||||||
|
|
||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String image;
|
@Getter private String image;
|
||||||
@Getter @Setter private Set<String> announcements;
|
@Getter @Setter private Set<String> announcements;
|
||||||
@Getter @Setter @ExcludeFromReplies private Map<String, List<String>> permissions;
|
@Getter @Setter @ExcludeFromReplies private Map<String, List<String>> permissions;
|
||||||
|
|
||||||
public static List<ServerGroup> findAll() {
|
public static List<ServerGroup> findAll() {
|
||||||
return ImmutableList.copyOf(serverGroupCache);
|
return ImmutableList.copyOf(serverGroupCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerGroup findById(String id) {
|
public static ServerGroup findById(String id) {
|
||||||
return serverGroupIdCache.get(id);
|
return serverGroupIdCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerGroup findDefault() {
|
public static ServerGroup findDefault() {
|
||||||
return findById(DEFAULT_GROUP_ID);
|
return findById(DEFAULT_GROUP_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(1), (id) -> updateCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
serverGroupsCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((serverGroups, error) -> {
|
serverGroupsCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap((serverGroups, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, ServerGroup> working = new HashMap<>();
|
Map<String, ServerGroup> working = new HashMap<>();
|
||||||
|
|
||||||
for (ServerGroup serverGroup : serverGroups) {
|
for (ServerGroup serverGroup : serverGroups) {
|
||||||
working.put(serverGroup.getId(), serverGroup);
|
working.put(serverGroup.getId(), serverGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
serverGroupIdCache = working;
|
serverGroupIdCache = working;
|
||||||
serverGroupCache = serverGroups;
|
serverGroupCache = serverGroups;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerGroup() {} // For Jackson
|
private ServerGroup() {} // For Jackson
|
||||||
|
|
||||||
public ServerGroup(String id, String image) {
|
public ServerGroup(String id, String image) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Boolean> calculatePermissions(Rank rank) {
|
public Map<String, Boolean> calculatePermissions(Rank rank) {
|
||||||
if (permissions == null) {
|
if (permissions == null) {
|
||||||
return ImmutableMap.of();
|
return ImmutableMap.of();
|
||||||
} else {
|
} else {
|
||||||
return PermissionUtils.mergeUpTo(permissions, rank);
|
return PermissionUtils.mergeUpTo(permissions, rank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(SingleResultCallback<Void> callback) {
|
public void insert(SingleResultCallback<Void> callback) {
|
||||||
serverGroupCache.add(this);
|
serverGroupCache.add(this);
|
||||||
serverGroupIdCache.put(id, this);
|
serverGroupIdCache.put(id, this);
|
||||||
serverGroupsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
serverGroupsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(SingleResultCallback<Void> callback) {
|
public void save(SingleResultCallback<Void> callback) {
|
||||||
serverGroupsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
serverGroupsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(SingleResultCallback<Void> callback) {
|
public void delete(SingleResultCallback<Void> callback) {
|
||||||
serverGroupCache.remove(this);
|
serverGroupCache.remove(this);
|
||||||
serverGroupIdCache.remove(id);
|
serverGroupIdCache.remove(id);
|
||||||
serverGroupsCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
serverGroupsCollection.deleteOne(new Document("_id", id), SyncUtils.vertxWrap(new MongoToVoidMongoCallback<>(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -16,117 +16,117 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public final class GETDumpsType implements Handler<RoutingContext> {
|
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 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 {
|
||||||
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(5), (id) -> updateCache());
|
APIv3.getVertxInstance().setPeriodic(TimeUnit.MINUTES.toMillis(5), (id) -> updateCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
Punishment.findByType(ImmutableSet.of(
|
Punishment.findByType(ImmutableSet.of(
|
||||||
Punishment.PunishmentType.BAN,
|
Punishment.PunishmentType.BAN,
|
||||||
Punishment.PunishmentType.BLACKLIST
|
Punishment.PunishmentType.BLACKLIST
|
||||||
), (punishments, error) -> {
|
), (punishments, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> banCache = new LinkedList<>();
|
List<UUID> banCache = new LinkedList<>();
|
||||||
List<UUID> blacklistCache = new LinkedList<>();
|
List<UUID> blacklistCache = new LinkedList<>();
|
||||||
|
|
||||||
for (Punishment punishment : punishments) {
|
for (Punishment punishment : punishments) {
|
||||||
if (!punishment.isActive()) {
|
if (!punishment.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (punishment.getType() == Punishment.PunishmentType.BAN) {
|
if (punishment.getType() == Punishment.PunishmentType.BAN) {
|
||||||
banCache.add(punishment.getUser());
|
banCache.add(punishment.getUser());
|
||||||
} else if (punishment.getType() == Punishment.PunishmentType.BLACKLIST) {
|
} else if (punishment.getType() == Punishment.PunishmentType.BLACKLIST) {
|
||||||
blacklistCache.add(punishment.getUser());
|
blacklistCache.add(punishment.getUser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GETDumpsType.banCache = banCache;
|
GETDumpsType.banCache = banCache;
|
||||||
GETDumpsType.blacklistCache = blacklistCache;
|
GETDumpsType.blacklistCache = blacklistCache;
|
||||||
});
|
});
|
||||||
|
|
||||||
Grant.findAll((grants, error) -> {
|
Grant.findAll((grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<UUID>> grantCache = new HashMap<>();
|
Map<String, List<UUID>> grantCache = new HashMap<>();
|
||||||
|
|
||||||
for (Grant grant : grants) {
|
for (Grant grant : grants) {
|
||||||
if (!grant.isActive()) {
|
if (!grant.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> users = grantCache.get(grant.getRank());
|
List<UUID> users = grantCache.get(grant.getRank());
|
||||||
|
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
users = new LinkedList<>();
|
users = new LinkedList<>();
|
||||||
grantCache.put(grant.getRank(), users);
|
grantCache.put(grant.getRank(), users);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.add(grant.getUser());
|
users.add(grant.getUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
GETDumpsType.grantCache = grantCache;
|
GETDumpsType.grantCache = grantCache;
|
||||||
});
|
});
|
||||||
|
|
||||||
IpBan.find((ipBans, error) -> {
|
IpBan.find((ipBans, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> ipBanCache = new LinkedList<>();
|
List<String> ipBanCache = new LinkedList<>();
|
||||||
|
|
||||||
for (IpBan ipBan : ipBans) {
|
for (IpBan ipBan : ipBans) {
|
||||||
if (!ipBan.isActive()) {
|
if (!ipBan.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipBanCache.add(ipBan.getUserIp());
|
ipBanCache.add(ipBan.getUserIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
GETDumpsType.ipBanCache = ipBanCache;
|
GETDumpsType.ipBanCache = ipBanCache;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
String dumpType = ctx.request().getParam("dumpType");
|
String dumpType = ctx.request().getParam("dumpType");
|
||||||
|
|
||||||
switch (dumpType.toLowerCase()) {
|
switch (dumpType.toLowerCase()) {
|
||||||
case "ban":
|
case "ban":
|
||||||
APIv3.respondJson(ctx, 200, banCache);
|
APIv3.respondJson(ctx, 200, banCache);
|
||||||
return;
|
return;
|
||||||
case "blacklist":
|
case "blacklist":
|
||||||
APIv3.respondJson(ctx, 200, blacklistCache);
|
APIv3.respondJson(ctx, 200, blacklistCache);
|
||||||
return;
|
return;
|
||||||
case "accessdeniable": // Lowercase d because we convert to lowercase above
|
case "accessdeniable": // Lowercase d because we convert to lowercase above
|
||||||
List<UUID> result = new LinkedList<>();
|
List<UUID> result = new LinkedList<>();
|
||||||
|
|
||||||
result.addAll(banCache);
|
result.addAll(banCache);
|
||||||
result.addAll(blacklistCache);
|
result.addAll(blacklistCache);
|
||||||
|
|
||||||
APIv3.respondJson(ctx, 200, result);
|
APIv3.respondJson(ctx, 200, result);
|
||||||
return;
|
return;
|
||||||
case "ipban":
|
case "ipban":
|
||||||
APIv3.respondJson(ctx, 200, ipBanCache);
|
APIv3.respondJson(ctx, 200, ipBanCache);
|
||||||
return;
|
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, ipBan, grant]");
|
ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, ipBan, grant]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.actor.Actor;
|
|||||||
|
|
||||||
public final class GETWhoAmI implements Handler<RoutingContext> {
|
public final class GETWhoAmI implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Actor actor = ctx.get("actor");
|
Actor actor = ctx.get("actor");
|
||||||
|
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"name", actor.getName(),
|
"name", actor.getName(),
|
||||||
"type", actor.getType(),
|
"type", actor.getType(),
|
||||||
"authorized", actor.isAuthorized()
|
"authorized", actor.isAuthorized()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
AccessToken accessToken = SyncUtils.runBlocking(v -> AccessToken.findById(ctx.request().getParam("accessToken"), v));
|
AccessToken accessToken = SyncUtils.runBlocking(v -> AccessToken.findById(ctx.request().getParam("accessToken"), v));
|
||||||
|
|
||||||
if (accessToken == null) {
|
if (accessToken == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Access token", ctx.request().getParam("accessToken"));
|
ErrorUtils.respondNotFound(ctx, "Access token", ctx.request().getParam("accessToken"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> accessToken.delete(v));
|
SyncUtils.<Void>runBlocking(v -> accessToken.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_DELETE, ImmutableMap.of("accessTokenId", accessToken.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_DELETE, ImmutableMap.of("accessTokenId", accessToken.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, accessToken);
|
APIv3.respondJson(ctx, 200, accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, accessToken);
|
APIv3.respondJson(ctx, 200, accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,29 +11,29 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
|||||||
|
|
||||||
public final class GETAccessTokens implements Handler<RoutingContext> {
|
public final class GETAccessTokens implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User user = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("user"), v));
|
User user = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("user"), v));
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("user"));
|
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("user"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = Integer.parseInt(ctx.request().getParam("totpCode"));
|
int code = Integer.parseInt(ctx.request().getParam("totpCode"));
|
||||||
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> user.checkTotpAuthorization(code, null, v));
|
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> user.checkTotpAuthorization(code, null, v));
|
||||||
|
|
||||||
if (!totpAuthorizationResult.isAuthorized()) {
|
if (!totpAuthorizationResult.isAuthorized()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessToken.findAll((accessTokens, error) -> {
|
AccessToken.findAll((accessTokens, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, accessTokens);
|
APIv3.respondJson(ctx, 200, accessTokens);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETAccessTokensId implements Handler<RoutingContext> {
|
public final class GETAccessTokensId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
AccessToken.findById(ctx.request().getParam("accessToken"), (accessToken, error) -> {
|
AccessToken.findById(ctx.request().getParam("accessToken"), (accessToken, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, accessToken);
|
APIv3.respondJson(ctx, 200, accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,36 +18,36 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class POSTAccessTokens implements Handler<RoutingContext> {
|
public final class POSTAccessTokens implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String actorName = requestBody.getString("actorName");
|
String actorName = requestBody.getString("actorName");
|
||||||
ActorType actorType = ActorType.valueOf(requestBody.getString("actorType").toUpperCase());
|
ActorType actorType = ActorType.valueOf(requestBody.getString("actorType").toUpperCase());
|
||||||
List<String> lockedIps = (List<String>) requestBody.getJsonArray("lockedIps").getList();
|
List<String> lockedIps = (List<String>) requestBody.getJsonArray("lockedIps").getList();
|
||||||
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
||||||
|
|
||||||
if (addedBy == null) {
|
if (addedBy == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("addedBy"));
|
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("addedBy"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = requestBody.getInteger("totpCode");
|
int code = requestBody.getInteger("totpCode");
|
||||||
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v));
|
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v));
|
||||||
|
|
||||||
if (!totpAuthorizationResult.isAuthorized()) {
|
if (!totpAuthorizationResult.isAuthorized()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessToken accessToken = new AccessToken(actorName, actorType, lockedIps);
|
AccessToken accessToken = new AccessToken(actorName, actorType, lockedIps);
|
||||||
SyncUtils.<Void>runBlocking(v -> accessToken.insert(v));
|
SyncUtils.<Void>runBlocking(v -> accessToken.insert(v));
|
||||||
|
|
||||||
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_CREATE, ImmutableMap.of("accessTokenActorName", actorName), (ignored, error) -> {
|
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_CREATE, ImmutableMap.of("accessTokenActorName", actorName), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, accessToken);
|
APIv3.respondJson(ctx, 200, accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,34 +14,34 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
AuditLogEntry auditLogEntry = SyncUtils.runBlocking(v -> AuditLogEntry.findById(ctx.request().getParam("auditLogEntryId"), v));
|
AuditLogEntry auditLogEntry = SyncUtils.runBlocking(v -> AuditLogEntry.findById(ctx.request().getParam("auditLogEntryId"), v));
|
||||||
|
|
||||||
if (auditLogEntry == null) {
|
if (auditLogEntry == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Audit log entry", ctx.request().getParam("auditLogEntryId"));
|
ErrorUtils.respondNotFound(ctx, "Audit log entry", ctx.request().getParam("auditLogEntryId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!auditLogEntry.isReversible()) {
|
if (!auditLogEntry.isReversible()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Audit log entry referenced is not reversible.");
|
ErrorUtils.respondInvalidInput(ctx, "Audit log entry referenced is not reversible.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> auditLogEntry.getType().reverse(auditLogEntry, v));
|
SyncUtils.<Void>runBlocking(v -> auditLogEntry.getType().reverse(auditLogEntry, v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("revertedBy")) {
|
if (requestBody.containsKey("revertedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("revertedBy")), requestBody.getString("revertedByIp"), ctx, AuditLogActionType.AUDIT_LOG_REVERT, ImmutableMap.of("auditLogEntryId", auditLogEntry.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("revertedBy")), requestBody.getString("revertedByIp"), ctx, AuditLogActionType.AUDIT_LOG_REVERT, ImmutableMap.of("auditLogEntryId", auditLogEntry.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,21 +10,21 @@ import org.bson.Document;
|
|||||||
|
|
||||||
public final class GETAuditLog implements Handler<RoutingContext> {
|
public final class GETAuditLog implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
AuditLogEntry.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (auditLog, error) -> {
|
AuditLogEntry.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (auditLog, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, auditLog);
|
APIv3.respondJson(ctx, 200, auditLog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,44 +12,44 @@ import net.frozenorb.apiv3.util.IpUtils;
|
|||||||
|
|
||||||
public final class POSTAuditLog implements Handler<RoutingContext> {
|
public final class POSTAuditLog implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
User.findById(requestBody.getString("user"), (user, error) -> {
|
User.findById(requestBody.getString("user"), (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String userIp = requestBody.getString("userIp");
|
String userIp = requestBody.getString("userIp");
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(userIp)) {
|
if (!IpUtils.isValidIp(userIp)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuditLogActionType type;
|
AuditLogActionType type;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
type = AuditLogActionType.valueOf(requestBody.getString("type"));
|
type = AuditLogActionType.valueOf(requestBody.getString("type"));
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Audit log action type", requestBody.getString("type"));
|
ErrorUtils.respondNotFound(ctx, "Audit log action type", requestBody.getString("type"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuditLog.log(user.getId(), userIp, ctx, type, requestBody.getJsonObject("metadata").getMap(), (auditLogEntry, error2) -> {
|
AuditLog.log(user.getId(), userIp, ctx, type, requestBody.getJsonObject("metadata").getMap(), (auditLogEntry, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error2);
|
ErrorUtils.respondInternalError(ctx, error2);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, auditLogEntry);
|
APIv3.respondJson(ctx, 200, auditLogEntry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
BannedAsn bannedAsn = BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn")));
|
BannedAsn bannedAsn = BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn")));
|
||||||
|
|
||||||
if (bannedAsn == null) {
|
if (bannedAsn == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Banned asn", ctx.request().getParam("bannedAsn"));
|
ErrorUtils.respondNotFound(ctx, "Banned asn", ctx.request().getParam("bannedAsn"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> bannedAsn.delete(v));
|
SyncUtils.<Void>runBlocking(v -> bannedAsn.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_ASN_DELETE, ImmutableMap.of("bannedAsnId", bannedAsn.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_ASN_DELETE, ImmutableMap.of("bannedAsnId", bannedAsn.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.BannedAsn;
|
|||||||
|
|
||||||
public final class GETBannedAsns implements Handler<RoutingContext> {
|
public final class GETBannedAsns implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, BannedAsn.findAll());
|
APIv3.respondJson(ctx, 200, BannedAsn.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.BannedAsn;
|
|||||||
|
|
||||||
public final class GETBannedAsnsId implements Handler<RoutingContext> {
|
public final class GETBannedAsnsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn"))));
|
APIv3.respondJson(ctx, 200, BannedAsn.findById(Integer.parseInt(ctx.request().getParam("bannedAsn"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,25 +14,25 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTBannedAsns implements Handler<RoutingContext> {
|
public final class POSTBannedAsns implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
int id = requestBody.getInteger("id");
|
int id = requestBody.getInteger("id");
|
||||||
String note = requestBody.getString("note");
|
String note = requestBody.getString("note");
|
||||||
|
|
||||||
BannedAsn bannedAsn = new BannedAsn(id, note);
|
BannedAsn bannedAsn = new BannedAsn(id, note);
|
||||||
SyncUtils.<Void>runBlocking(v -> bannedAsn.insert(v));
|
SyncUtils.<Void>runBlocking(v -> bannedAsn.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_ASN_CREATE, ImmutableMap.of("bannedAsnId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_ASN_CREATE, ImmutableMap.of("bannedAsnId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedAsn);
|
APIv3.respondJson(ctx, 200, bannedAsn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEBannedCellCarriersId implements Handler<RoutingContext> {
|
public final class DELETEBannedCellCarriersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
BannedCellCarrier bannedCellCarrier = BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier")));
|
BannedCellCarrier bannedCellCarrier = BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier")));
|
||||||
|
|
||||||
if (bannedCellCarrier == null) {
|
if (bannedCellCarrier == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Banned cell carrier", ctx.request().getParam("bannedCellCarrier"));
|
ErrorUtils.respondNotFound(ctx, "Banned cell carrier", ctx.request().getParam("bannedCellCarrier"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> bannedCellCarrier.delete(v));
|
SyncUtils.<Void>runBlocking(v -> bannedCellCarrier.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_DELETE, ImmutableMap.of("bannedCellCarrierId", bannedCellCarrier.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_DELETE, ImmutableMap.of("bannedCellCarrierId", bannedCellCarrier.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
|
|||||||
|
|
||||||
public final class GETBannedCellCarriers implements Handler<RoutingContext> {
|
public final class GETBannedCellCarriers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, BannedCellCarrier.findAll());
|
APIv3.respondJson(ctx, 200, BannedCellCarrier.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.BannedCellCarrier;
|
|||||||
|
|
||||||
public final class GETBannedCellCarriersId implements Handler<RoutingContext> {
|
public final class GETBannedCellCarriersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier"))));
|
APIv3.respondJson(ctx, 200, BannedCellCarrier.findById(Integer.parseInt(ctx.request().getParam("bannedCellCarrier"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,25 +14,25 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
int id = requestBody.getInteger("id");
|
int id = requestBody.getInteger("id");
|
||||||
String note = requestBody.getString("note");
|
String note = requestBody.getString("note");
|
||||||
|
|
||||||
BannedCellCarrier bannedCellCarrier = new BannedCellCarrier(id, note);
|
BannedCellCarrier bannedCellCarrier = new BannedCellCarrier(id, note);
|
||||||
SyncUtils.<Void>runBlocking(v -> bannedCellCarrier.insert(v));
|
SyncUtils.<Void>runBlocking(v -> bannedCellCarrier.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_CREATE, ImmutableMap.of("bannedCellCarrierId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_CREATE, ImmutableMap.of("bannedCellCarrierId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
APIv3.respondJson(ctx, 200, bannedCellCarrier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEChatFilterId implements Handler<RoutingContext> {
|
public final class DELETEChatFilterId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
ChatFilterEntry chatFilterEntry = SyncUtils.runBlocking(v -> ChatFilterEntry.findById(ctx.request().getParam("chatFilterEntryId"), v));
|
ChatFilterEntry chatFilterEntry = SyncUtils.runBlocking(v -> ChatFilterEntry.findById(ctx.request().getParam("chatFilterEntryId"), v));
|
||||||
|
|
||||||
if (chatFilterEntry == null) {
|
if (chatFilterEntry == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Chat filter entry", ctx.request().getParam("chatFilterEntryId"));
|
ErrorUtils.respondNotFound(ctx, "Chat filter entry", ctx.request().getParam("chatFilterEntryId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> chatFilterEntry.delete(v));
|
SyncUtils.<Void>runBlocking(v -> chatFilterEntry.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.CHAT_FILTER_ENTRY_DELETE, ImmutableMap.of("chatFilterEntryId", chatFilterEntry.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.CHAT_FILTER_ENTRY_DELETE, ImmutableMap.of("chatFilterEntryId", chatFilterEntry.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETChatFilter implements Handler<RoutingContext> {
|
public final class GETChatFilter implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
ChatFilterEntry.findAll((chatFilterEntries, error) -> {
|
ChatFilterEntry.findAll((chatFilterEntries, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, chatFilterEntries);
|
APIv3.respondJson(ctx, 200, chatFilterEntries);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETChatFilterId implements Handler<RoutingContext> {
|
public final class GETChatFilterId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
ChatFilterEntry.findById(ctx.request().getParam("chatFilterEntryId"), (notificationTemplate, error) -> {
|
ChatFilterEntry.findById(ctx.request().getParam("chatFilterEntryId"), (notificationTemplate, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,25 +14,25 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTChatFilter implements Handler<RoutingContext> {
|
public final class POSTChatFilter implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String id = requestBody.getString("id");
|
String id = requestBody.getString("id");
|
||||||
String regex = requestBody.getString("regex");
|
String regex = requestBody.getString("regex");
|
||||||
|
|
||||||
ChatFilterEntry chatFilterEntry = new ChatFilterEntry(id, regex);
|
ChatFilterEntry chatFilterEntry = new ChatFilterEntry(id, regex);
|
||||||
SyncUtils.<Void>runBlocking(v -> chatFilterEntry.insert(v));
|
SyncUtils.<Void>runBlocking(v -> chatFilterEntry.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.CHAT_FILTER_ENTRY_CREATE, ImmutableMap.of("chatFilterEntryId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.CHAT_FILTER_ENTRY_CREATE, ImmutableMap.of("chatFilterEntryId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
APIv3.respondJson(ctx, 200, chatFilterEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETEmailTokensIdOwner implements Handler<RoutingContext> {
|
public final class GETEmailTokensIdOwner implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User.findByEmailToken(ctx.request().getParam("emailToken"), (user, error) -> {
|
User.findByEmailToken(ctx.request().getParam("emailToken"), (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, user);
|
APIv3.respondJson(ctx, 200, user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,45 +15,45 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
|
public final class POSTEmailTokensIdConfirm implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User user = SyncUtils.runBlocking(v -> User.findByEmailToken(ctx.request().getParam("emailToken"), v));
|
User user = SyncUtils.runBlocking(v -> User.findByEmailToken(ctx.request().getParam("emailToken"), v));
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Email token", ctx.request().getParam("emailToken"));
|
ErrorUtils.respondNotFound(ctx, "Email token", ctx.request().getParam("emailToken"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.getEmail() != null) {
|
if (user.getEmail() != null) {
|
||||||
ErrorUtils.respondOther(ctx, 409, "User provided already has email set.", "emailAlreadySet", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 409, "User provided already has email set.", "emailAlreadySet", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((System.currentTimeMillis() - user.getPendingEmailTokenSetAt().toEpochMilli()) > TimeUnit.DAYS.toMillis(2)) {
|
if ((System.currentTimeMillis() - user.getPendingEmailTokenSetAt().toEpochMilli()) > TimeUnit.DAYS.toMillis(2)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Email token is expired");
|
ErrorUtils.respondInvalidInput(ctx, "Email token is expired");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String password = requestBody.getString("password");
|
String password = requestBody.getString("password");
|
||||||
|
|
||||||
if (password.length() < 8) {
|
if (password.length() < 8) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Your password is too short.");
|
ErrorUtils.respondInvalidInput(ctx, "Your password is too short.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.completeEmailRegistration(user.getPendingEmail());
|
user.completeEmailRegistration(user.getPendingEmail());
|
||||||
user.updatePassword(password);
|
user.updatePassword(password);
|
||||||
SyncUtils.<Void>runBlocking(v -> user.save(v));
|
SyncUtils.<Void>runBlocking(v -> user.save(v));
|
||||||
|
|
||||||
AuditLog.log(user.getId(), requestBody.getString("userIp"), ctx, AuditLogActionType.USER_CONFIRM_EMAIL, (ignored, error) -> {
|
AuditLog.log(user.getId(), requestBody.getString("userIp"), ctx, AuditLogActionType.USER_CONFIRM_EMAIL, (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"success", true
|
"success", true
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,40 +14,40 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
|||||||
|
|
||||||
public final class DELETEGrantsId implements Handler<RoutingContext> {
|
public final class DELETEGrantsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Grant grant = SyncUtils.runBlocking(v -> Grant.findById(ctx.request().getParam("grantId"), v));
|
Grant grant = SyncUtils.runBlocking(v -> Grant.findById(ctx.request().getParam("grantId"), v));
|
||||||
|
|
||||||
if (grant == null) {
|
if (grant == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Grant", ctx.request().getParam("grantId"));
|
ErrorUtils.respondNotFound(ctx, "Grant", ctx.request().getParam("grantId"));
|
||||||
return;
|
return;
|
||||||
} else if (!grant.isActive()) {
|
} else if (!grant.isActive()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive grant.");
|
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive grant.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
// We purposely don't do a null check, grant removals don't have to have a user/ip.
|
// We purposely don't do a null check, grant removals don't have to have a user/ip.
|
||||||
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> grant.delete(removedBy, reason, v));
|
SyncUtils.<Void>runBlocking(v -> grant.delete(removedBy, reason, v));
|
||||||
|
|
||||||
if (removedBy != null) {
|
if (removedBy != null) {
|
||||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.GRANT_DELETE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,22 +12,22 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class GETGrants implements Handler<RoutingContext> {
|
public final class GETGrants implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (grants, error) -> {
|
Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (grants, error) -> {
|
||||||
if (ctx.request().getParam("active") != null) {
|
if (ctx.request().getParam("active") != null) {
|
||||||
boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active"));
|
boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active"));
|
||||||
APIv3.respondJson(ctx, 200, grants.stream().filter(grant -> grant.isActive() == requireActive).collect(Collectors.toList()));
|
APIv3.respondJson(ctx, 200, grants.stream().filter(grant -> grant.isActive() == requireActive).collect(Collectors.toList()));
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grants);
|
APIv3.respondJson(ctx, 200, grants);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETGrantsId implements Handler<RoutingContext> {
|
public final class GETGrantsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Grant.findById(ctx.request().getParam("grantId"), (grant, error) -> {
|
Grant.findById(ctx.request().getParam("grantId"), (grant, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,87 +22,87 @@ import java.util.Set;
|
|||||||
|
|
||||||
public final class POSTGrants implements Handler<RoutingContext> {
|
public final class POSTGrants implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
User target = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("user"), v));
|
User target = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("user"), v));
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ServerGroup> scopes = new HashSet<>();
|
Set<ServerGroup> scopes = new HashSet<>();
|
||||||
List<String> scopeIds = (List<String>) requestBody.getJsonArray("scopes").getList();
|
List<String> scopeIds = (List<String>) requestBody.getJsonArray("scopes").getList();
|
||||||
|
|
||||||
if (!scopeIds.isEmpty()) {
|
if (!scopeIds.isEmpty()) {
|
||||||
for (String serverGroupId : scopeIds) {
|
for (String serverGroupId : scopeIds) {
|
||||||
ServerGroup serverGroup = ServerGroup.findById(serverGroupId);
|
ServerGroup serverGroup = ServerGroup.findById(serverGroupId);
|
||||||
|
|
||||||
if (serverGroup == null) {
|
if (serverGroup == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Server group", serverGroupId);
|
ErrorUtils.respondNotFound(ctx, "Server group", serverGroupId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scopes.add(serverGroup);
|
scopes.add(serverGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rank rank = Rank.findById(requestBody.getString("rank"));
|
Rank rank = Rank.findById(requestBody.getString("rank"));
|
||||||
|
|
||||||
if (rank == null) {
|
if (rank == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Rank", requestBody.getString("rank"));
|
ErrorUtils.respondNotFound(ctx, "Rank", requestBody.getString("rank"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instant expiresAt = null;
|
Instant expiresAt = null;
|
||||||
|
|
||||||
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
||||||
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
||||||
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We purposely don't fail on a null check, grants don't have to have a source.
|
// We purposely don't fail on a null check, grants don't have to have a source.
|
||||||
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
||||||
|
|
||||||
if (addedBy != null && rank.isHigherStaffRank()) {
|
if (addedBy != null && rank.isHigherStaffRank()) {
|
||||||
int code = requestBody.getInteger("totpCode");
|
int code = requestBody.getInteger("totpCode");
|
||||||
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v));
|
TotpAuthorizationResult totpAuthorizationResult = SyncUtils.runBlocking(v -> addedBy.checkTotpAuthorization(code, null, v));
|
||||||
|
|
||||||
if (!totpAuthorizationResult.isAuthorized()) {
|
if (!totpAuthorizationResult.isAuthorized()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
ErrorUtils.respondInvalidInput(ctx, "Totp authorization failed: " + totpAuthorizationResult.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int storeItemId = requestBody.getInteger("storeItemId", -1);
|
int storeItemId = requestBody.getInteger("storeItemId", -1);
|
||||||
int storeOrderId = requestBody.getInteger("storeOrderId", -1);
|
int storeOrderId = requestBody.getInteger("storeOrderId", -1);
|
||||||
|
|
||||||
Grant grant = new Grant(target, reason, scopes, rank, expiresAt, addedBy, storeItemId, storeOrderId);
|
Grant grant = new Grant(target, reason, scopes, rank, expiresAt, addedBy, storeItemId, storeOrderId);
|
||||||
SyncUtils.<Void>runBlocking(v -> grant.insert(v));
|
SyncUtils.<Void>runBlocking(v -> grant.insert(v));
|
||||||
|
|
||||||
if (addedBy != null) {
|
if (addedBy != null) {
|
||||||
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.GRANT_CREATE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
|
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.GRANT_CREATE, ImmutableMap.of("grantId", grant.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grant);
|
APIv3.respondJson(ctx, 200, grant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,40 +14,40 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
|||||||
|
|
||||||
public final class DELETEIpBansId implements Handler<RoutingContext> {
|
public final class DELETEIpBansId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
IpBan ipBan = SyncUtils.runBlocking(v -> IpBan.findById(ctx.request().getParam("ipBanId"), v));
|
IpBan ipBan = SyncUtils.runBlocking(v -> IpBan.findById(ctx.request().getParam("ipBanId"), v));
|
||||||
|
|
||||||
if (ipBan == null) {
|
if (ipBan == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "IpBan", ctx.request().getParam("ipBanId"));
|
ErrorUtils.respondNotFound(ctx, "IpBan", ctx.request().getParam("ipBanId"));
|
||||||
return;
|
return;
|
||||||
} else if (!ipBan.isActive()) {
|
} else if (!ipBan.isActive()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive ip ban.");
|
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive ip ban.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
// We purposely don't do a null check, ip ban removals don't have to have a user/ip.
|
// We purposely don't do a null check, ip ban removals don't have to have a user/ip.
|
||||||
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> ipBan.delete(removedBy, reason, v));
|
SyncUtils.<Void>runBlocking(v -> ipBan.delete(removedBy, reason, v));
|
||||||
|
|
||||||
if (removedBy != null) {
|
if (removedBy != null) {
|
||||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), (ignored, error) -> {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.IP_BAN_DELETE, ImmutableMap.of("punishmentId", ipBan.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,21 +10,21 @@ import org.bson.Document;
|
|||||||
|
|
||||||
public final class GETIpBans implements Handler<RoutingContext> {
|
public final class GETIpBans implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
IpBan.findPaginated(ctx.request().getParam("userIp") == null ? new Document() : new Document("userIp", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (grants, error) -> {
|
IpBan.findPaginated(ctx.request().getParam("userIp") == null ? new Document() : new Document("userIp", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (grants, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, grants);
|
APIv3.respondJson(ctx, 200, grants);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETIpBansId implements Handler<RoutingContext> {
|
public final class GETIpBansId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
IpBan.findById(ctx.request().getParam("ipBanId"), (ipBan, error) -> {
|
IpBan.findById(ctx.request().getParam("ipBanId"), (ipBan, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,51 +17,51 @@ import java.time.Instant;
|
|||||||
|
|
||||||
public final class POSTIpBans implements Handler<RoutingContext> {
|
public final class POSTIpBans implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String userIp = requestBody.getString("userIp");
|
String userIp = requestBody.getString("userIp");
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(userIp)) {
|
if (!IpUtils.isValidIp(userIp)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instant expiresAt = null;
|
Instant expiresAt = null;
|
||||||
|
|
||||||
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
||||||
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
||||||
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We purposely don't do a null check, ip bans don't have to have a source.
|
// We purposely don't do a null check, ip bans don't have to have a source.
|
||||||
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
||||||
|
|
||||||
IpBan ipBan = new IpBan(userIp, reason, expiresAt, addedBy, ctx.get("actor"));
|
IpBan ipBan = new IpBan(userIp, reason, expiresAt, addedBy, ctx.get("actor"));
|
||||||
SyncUtils.<Void>runBlocking(v -> ipBan.insert(v));
|
SyncUtils.<Void>runBlocking(v -> ipBan.insert(v));
|
||||||
|
|
||||||
if (addedBy != null) {
|
if (addedBy != null) {
|
||||||
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.IP_BAN_CREATE, ImmutableMap.of("ipBanId", ipBan.getId()), (ignored, error) -> {
|
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.IP_BAN_CREATE, ImmutableMap.of("ipBanId", ipBan.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipBan);
|
APIv3.respondJson(ctx, 200, ipBan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,21 +9,21 @@ import net.frozenorb.apiv3.util.IpUtils;
|
|||||||
|
|
||||||
public final class GETIpInteld implements Handler<RoutingContext> {
|
public final class GETIpInteld implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
String userIp = ctx.request().getParam("userIp");
|
String userIp = ctx.request().getParam("userIp");
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(userIp)) {
|
if (!IpUtils.isValidIp(userIp)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IpIntel.findOrCreateById(userIp, (ipIntel, error) -> {
|
IpIntel.findOrCreateById(userIp, (ipIntel, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipIntel);
|
APIv3.respondJson(ctx, 200, ipIntel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,34 +9,34 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETIpLogId implements Handler<RoutingContext> {
|
public final class GETIpLogId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
String search = ctx.request().getParam("id");
|
String search = ctx.request().getParam("id");
|
||||||
|
|
||||||
if (search.length() >= 32) {
|
if (search.length() >= 32) {
|
||||||
User.findById(search, (user, error) -> {
|
User.findById(search, (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else if (user == null) {
|
} else if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", search);
|
ErrorUtils.respondNotFound(ctx, "User", search);
|
||||||
} else {
|
} else {
|
||||||
IpLogEntry.findByUser(user, (ipLog, error2) -> {
|
IpLogEntry.findByUser(user, (ipLog, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error2);
|
ErrorUtils.respondInternalError(ctx, error2);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipLog);
|
APIv3.respondJson(ctx, 200, ipLog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
IpLogEntry.findByIp(search, (ipLogs, error) -> {
|
IpLogEntry.findByIp(search, (ipLogs, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipLogs);
|
APIv3.respondJson(ctx, 200, ipLogs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETENotificationTemplatesId implements Handler<RoutingContext> {
|
public final class DELETENotificationTemplatesId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
NotificationTemplate notificationTemplate = SyncUtils.runBlocking(v -> NotificationTemplate.findById(ctx.request().getParam("notificationTemplateId"), v));
|
NotificationTemplate notificationTemplate = SyncUtils.runBlocking(v -> NotificationTemplate.findById(ctx.request().getParam("notificationTemplateId"), v));
|
||||||
|
|
||||||
if (notificationTemplate == null) {
|
if (notificationTemplate == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Notification template", ctx.request().getParam("notificationTemplateId"));
|
ErrorUtils.respondNotFound(ctx, "Notification template", ctx.request().getParam("notificationTemplateId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> notificationTemplate.delete(v));
|
SyncUtils.<Void>runBlocking(v -> notificationTemplate.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_DELETE, ImmutableMap.of("notificationTemplateId", notificationTemplate.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_DELETE, ImmutableMap.of("notificationTemplateId", notificationTemplate.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETNotificationTemplates implements Handler<RoutingContext> {
|
public final class GETNotificationTemplates implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
NotificationTemplate.findAll((notificationTemplates, error) -> {
|
NotificationTemplate.findAll((notificationTemplates, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplates);
|
APIv3.respondJson(ctx, 200, notificationTemplates);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETNotificationTemplatesId implements Handler<RoutingContext> {
|
public final class GETNotificationTemplatesId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
NotificationTemplate.findById(ctx.request().getParam("notificationTemplateId"), (notificationTemplate, error) -> {
|
NotificationTemplate.findById(ctx.request().getParam("notificationTemplateId"), (notificationTemplate, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,26 +14,26 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
|
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String id = requestBody.getString("id");
|
String id = requestBody.getString("id");
|
||||||
String subject = requestBody.getString("subject");
|
String subject = requestBody.getString("subject");
|
||||||
String body = requestBody.getString("body");
|
String body = requestBody.getString("body");
|
||||||
|
|
||||||
NotificationTemplate notificationTemplate = new NotificationTemplate(id, subject, body);
|
NotificationTemplate notificationTemplate = new NotificationTemplate(id, subject, body);
|
||||||
SyncUtils.<Void>runBlocking(v -> notificationTemplate.insert(v));
|
SyncUtils.<Void>runBlocking(v -> notificationTemplate.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_CREATE, ImmutableMap.of("notificationTemplateId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_CREATE, ImmutableMap.of("notificationTemplateId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, notificationTemplate);
|
APIv3.respondJson(ctx, 200, notificationTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,21 +9,21 @@ import net.frozenorb.apiv3.util.PhoneUtils;
|
|||||||
|
|
||||||
public final class GETPhoneInteld implements Handler<RoutingContext> {
|
public final class GETPhoneInteld implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
String phoneNumber = ctx.request().getParam("phone");
|
String phoneNumber = ctx.request().getParam("phone");
|
||||||
|
|
||||||
if (!PhoneUtils.isValidPhone(phoneNumber)) {
|
if (!PhoneUtils.isValidPhone(phoneNumber)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Phone number \"" + phoneNumber + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Phone number \"" + phoneNumber + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneIntel.findOrCreateById(phoneNumber, (ipIntel, error) -> {
|
PhoneIntel.findOrCreateById(phoneNumber, (ipIntel, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ipIntel);
|
APIv3.respondJson(ctx, 200, ipIntel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,40 +14,40 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
|||||||
|
|
||||||
public final class DELETEPunishmentsId implements Handler<RoutingContext> {
|
public final class DELETEPunishmentsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Punishment punishment = SyncUtils.runBlocking(v -> Punishment.findById(ctx.request().getParam("punishmentId"), v));
|
Punishment punishment = SyncUtils.runBlocking(v -> Punishment.findById(ctx.request().getParam("punishmentId"), v));
|
||||||
|
|
||||||
if (punishment == null) {
|
if (punishment == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Punishment", ctx.request().getParam("punishmentId"));
|
ErrorUtils.respondNotFound(ctx, "Punishment", ctx.request().getParam("punishmentId"));
|
||||||
return;
|
return;
|
||||||
} else if (!punishment.isActive()) {
|
} else if (!punishment.isActive()) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive punishment.");
|
ErrorUtils.respondInvalidInput(ctx, "Cannot remove an inactive punishment.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
// We purposely don't do a null check, punishment removals don't have to have a user/ip.
|
// We purposely don't do a null check, punishment removals don't have to have a user/ip.
|
||||||
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> punishment.delete(removedBy, reason, v));
|
SyncUtils.<Void>runBlocking(v -> punishment.delete(removedBy, reason, v));
|
||||||
|
|
||||||
if (removedBy != null) {
|
if (removedBy != null) {
|
||||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, punishment);
|
APIv3.respondJson(ctx, 200, punishment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, punishment);
|
APIv3.respondJson(ctx, 200, punishment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,54 +17,54 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class DELETEUsersIdActivePunishment implements Handler<RoutingContext> {
|
public final class DELETEUsersIdActivePunishment implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User target = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("userId"), v));
|
User target = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("userId"), v));
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type").toUpperCase());
|
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type").toUpperCase());
|
||||||
// We purposely don't do a null check, punishment removals don't have to have a user/ip.
|
// We purposely don't do a null check, punishment removals don't have to have a user/ip.
|
||||||
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
User removedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("removedBy"), v));
|
||||||
String reason = requestBody.getString("reason");
|
String reason = requestBody.getString("reason");
|
||||||
|
|
||||||
if (reason == null || reason.trim().isEmpty()) {
|
if (reason == null || reason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUserAndType(target, ImmutableSet.of(type), v));
|
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUserAndType(target, ImmutableSet.of(type), v));
|
||||||
Punishment activePunishment = null;
|
Punishment activePunishment = null;
|
||||||
|
|
||||||
for (Punishment punishment : punishments) {
|
for (Punishment punishment : punishments) {
|
||||||
if (punishment.isActive()) {
|
if (punishment.isActive()) {
|
||||||
activePunishment = punishment;
|
activePunishment = punishment;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activePunishment == null) {
|
if (activePunishment == null) {
|
||||||
ErrorUtils.respondOther(ctx, 409, "User provided has no active punishments.", "noActivePunishments", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 409, "User provided has no active punishments.", "noActivePunishments", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Punishment finalActivePunishment = activePunishment;
|
Punishment finalActivePunishment = activePunishment;
|
||||||
SyncUtils.<Void>runBlocking(v -> finalActivePunishment.delete(removedBy, reason, v));
|
SyncUtils.<Void>runBlocking(v -> finalActivePunishment.delete(removedBy, reason, v));
|
||||||
|
|
||||||
if (removedBy != null) {
|
if (removedBy != null) {
|
||||||
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), (ignored, error) -> {
|
AuditLog.log(removedBy.getId(), requestBody.getString("removedByIp"), ctx, AuditLogActionType.PUNISHMENT_DELETE, ImmutableMap.of("punishmentId", activePunishment.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
APIv3.respondJson(ctx, 200, finalActivePunishment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,26 +12,26 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class GETPunishments implements Handler<RoutingContext> {
|
public final class GETPunishments implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
try {
|
try {
|
||||||
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip"));
|
||||||
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
|
||||||
|
|
||||||
Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (punishments, error) -> {
|
Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (punishments, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
if (ctx.request().getParam("active") != null) {
|
if (ctx.request().getParam("active") != null) {
|
||||||
boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active"));
|
boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active"));
|
||||||
APIv3.respondJson(ctx, 200, punishments.stream().filter(punishment -> punishment.isActive() == requireActive).collect(Collectors.toList()));
|
APIv3.respondJson(ctx, 200, punishments.stream().filter(punishment -> punishment.isActive() == requireActive).collect(Collectors.toList()));
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, punishments);
|
APIv3.respondJson(ctx, 200, punishments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
ErrorUtils.respondInvalidInput(ctx, "skip and pageSize must be numerical inputs.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETPunishmentsId implements Handler<RoutingContext> {
|
public final class GETPunishmentsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Punishment.findById(ctx.request().getParam("punishmentId"), (punishment, error) -> {
|
Punishment.findById(ctx.request().getParam("punishmentId"), (punishment, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, punishment);
|
APIv3.respondJson(ctx, 200, punishment);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,100 +21,100 @@ import java.util.Map;
|
|||||||
|
|
||||||
public final class POSTPunishments implements Handler<RoutingContext> {
|
public final class POSTPunishments implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
User target = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("user"), v));
|
User target = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("user"), v));
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
ErrorUtils.respondNotFound(ctx, "User", requestBody.getString("user"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String publicReason = requestBody.getString("publicReason");
|
String publicReason = requestBody.getString("publicReason");
|
||||||
String privateReason = requestBody.getString("privateReason");
|
String privateReason = requestBody.getString("privateReason");
|
||||||
|
|
||||||
if (publicReason == null || publicReason.trim().isEmpty()) {
|
if (publicReason == null || publicReason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "publicReason");
|
ErrorUtils.respondRequiredInput(ctx, "publicReason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (privateReason == null || privateReason.trim().isEmpty()) {
|
if (privateReason == null || privateReason.trim().isEmpty()) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "privateReason");
|
ErrorUtils.respondRequiredInput(ctx, "privateReason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type"));
|
Punishment.PunishmentType type = Punishment.PunishmentType.valueOf(requestBody.getString("type"));
|
||||||
|
|
||||||
if (type != Punishment.PunishmentType.WARN) {
|
if (type != Punishment.PunishmentType.WARN) {
|
||||||
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUserAndType(target, ImmutableSet.of(type), v));
|
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUserAndType(target, ImmutableSet.of(type), v));
|
||||||
|
|
||||||
for (Punishment alternatePunishment : punishments) {
|
for (Punishment alternatePunishment : punishments) {
|
||||||
if (alternatePunishment.isActive()) {
|
if (alternatePunishment.isActive()) {
|
||||||
User user = SyncUtils.runBlocking(v -> User.findById(alternatePunishment.getAddedBy(), v));
|
User user = SyncUtils.runBlocking(v -> User.findById(alternatePunishment.getAddedBy(), v));
|
||||||
ErrorUtils.respondOther(ctx, 409, "User already covered by alternate punishment.", "alreadyCoveredByAlternatePunishment", ImmutableMap.of("alternatePunishmentBy", user.getLastUsername()));
|
ErrorUtils.respondOther(ctx, 409, "User already covered by alternate punishment.", "alreadyCoveredByAlternatePunishment", ImmutableMap.of("alternatePunishmentBy", user.getLastUsername()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Instant expiresAt = null;
|
Instant expiresAt = null;
|
||||||
|
|
||||||
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
if (requestBody.containsKey("expiresIn") && requestBody.getLong("expiresIn") != -1) {
|
||||||
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
long expiresInMillis = requestBody.getLong("expiresIn") * 1000;
|
||||||
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
expiresAt = Instant.ofEpochMilli(System.currentTimeMillis() + expiresInMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
if (expiresAt != null && expiresAt.isBefore(Instant.now())) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
ErrorUtils.respondInvalidInput(ctx, "Expiration time cannot be in the past.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> meta = requestBody.getJsonObject("metadata").getMap();
|
Map<String, Object> meta = requestBody.getJsonObject("metadata").getMap();
|
||||||
|
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
ErrorUtils.respondRequiredInput(ctx, "request body meta");
|
ErrorUtils.respondRequiredInput(ctx, "request body meta");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We purposely don't do a null check, punishments don't have to have a source.
|
// We purposely don't do a null check, punishments don't have to have a source.
|
||||||
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
User addedBy = SyncUtils.runBlocking(v -> User.findById(requestBody.getString("addedBy"), v));
|
||||||
boolean isProtected = SyncUtils.runBlocking(v -> target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, v));
|
boolean isProtected = SyncUtils.runBlocking(v -> target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, v));
|
||||||
|
|
||||||
if (isProtected) {
|
if (isProtected) {
|
||||||
ErrorUtils.respondOther(ctx, 409, "User is protected from punishments.", "protectedFromPunishments", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 409, "User is protected from punishments.", "protectedFromPunishments", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Punishment punishment = new Punishment(target, publicReason, privateReason, type, expiresAt, addedBy, ctx.get("actor"), meta);
|
Punishment punishment = new Punishment(target, publicReason, privateReason, type, expiresAt, addedBy, ctx.get("actor"), meta);
|
||||||
String accessDenialReason = punishment.getAccessDenialReason();
|
String accessDenialReason = punishment.getAccessDenialReason();
|
||||||
String userIp = requestBody.getString("userIp");
|
String userIp = requestBody.getString("userIp");
|
||||||
|
|
||||||
if ((type == Punishment.PunishmentType.BAN || type == Punishment.PunishmentType.BLACKLIST) && userIp != null) {
|
if ((type == Punishment.PunishmentType.BAN || type == Punishment.PunishmentType.BLACKLIST) && userIp != null) {
|
||||||
IpBan ipBan = new IpBan(userIp, punishment);
|
IpBan ipBan = new IpBan(userIp, punishment);
|
||||||
SyncUtils.<Void>runBlocking(v -> ipBan.insert(v));
|
SyncUtils.<Void>runBlocking(v -> ipBan.insert(v));
|
||||||
|
|
||||||
punishment.linkIpBan(ipBan);
|
punishment.linkIpBan(ipBan);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> punishment.insert(v));
|
SyncUtils.<Void>runBlocking(v -> punishment.insert(v));
|
||||||
|
|
||||||
if (addedBy != null) {
|
if (addedBy != null) {
|
||||||
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.PUNISHMENT_CREATE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> {
|
AuditLog.log(addedBy.getId(), requestBody.getString("addedByIp"), ctx, AuditLogActionType.PUNISHMENT_CREATE, ImmutableMap.of("punishmentId", punishment.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"punishment", punishment,
|
"punishment", punishment,
|
||||||
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"punishment", punishment,
|
"punishment", punishment,
|
||||||
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
"accessDenialReason", accessDenialReason == null ? "" : accessDenialReason
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETERanksId implements Handler<RoutingContext> {
|
public final class DELETERanksId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Rank rank = Rank.findById(ctx.request().getParam("rankId"));
|
Rank rank = Rank.findById(ctx.request().getParam("rankId"));
|
||||||
|
|
||||||
if (rank == null) {
|
if (rank == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Rank", ctx.request().getParam("rankId"));
|
ErrorUtils.respondNotFound(ctx, "Rank", ctx.request().getParam("rankId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> rank.delete(v));
|
SyncUtils.<Void>runBlocking(v -> rank.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.RANK_DELETE, ImmutableMap.of("rankId", rank.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.RANK_DELETE, ImmutableMap.of("rankId", rank.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, rank);
|
APIv3.respondJson(ctx, 200, rank);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, rank);
|
APIv3.respondJson(ctx, 200, rank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.Rank;
|
|||||||
|
|
||||||
public final class GETRanks implements Handler<RoutingContext> {
|
public final class GETRanks implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, Rank.findAll());
|
APIv3.respondJson(ctx, 200, Rank.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.Rank;
|
|||||||
|
|
||||||
public final class GETRanksId implements Handler<RoutingContext> {
|
public final class GETRanksId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, Rank.findById(ctx.request().getParam("rankId")));
|
APIv3.respondJson(ctx, 200, Rank.findById(ctx.request().getParam("rankId")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,31 +14,31 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTRanks implements Handler<RoutingContext> {
|
public final class POSTRanks implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String id = requestBody.getString("id");
|
String id = requestBody.getString("id");
|
||||||
String inheritsFromId = requestBody.getString("inheritsFromId");
|
String inheritsFromId = requestBody.getString("inheritsFromId");
|
||||||
int weight = requestBody.getInteger("weight");
|
int weight = requestBody.getInteger("weight");
|
||||||
String displayName = requestBody.getString("displayName");
|
String displayName = requestBody.getString("displayName");
|
||||||
String gameColor = requestBody.getString("gameColor");
|
String gameColor = requestBody.getString("gameColor");
|
||||||
String websiteColor = requestBody.getString("websiteColor");
|
String websiteColor = requestBody.getString("websiteColor");
|
||||||
boolean staffRank = requestBody.getBoolean("staffRank");
|
boolean staffRank = requestBody.getBoolean("staffRank");
|
||||||
boolean higherStaffRank = requestBody.getBoolean("higherStaffRank");
|
boolean higherStaffRank = requestBody.getBoolean("higherStaffRank");
|
||||||
|
|
||||||
Rank rank = new Rank(id, inheritsFromId, weight, displayName, gameColor, websiteColor, staffRank, higherStaffRank);
|
Rank rank = new Rank(id, inheritsFromId, weight, displayName, gameColor, websiteColor, staffRank, higherStaffRank);
|
||||||
SyncUtils.<Void>runBlocking(v -> rank.insert(v));
|
SyncUtils.<Void>runBlocking(v -> rank.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.RANK_CREATE, ImmutableMap.of("rankId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.RANK_CREATE, ImmutableMap.of("rankId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, rank);
|
APIv3.respondJson(ctx, 200, rank);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, rank);
|
APIv3.respondJson(ctx, 200, rank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,29 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroupId"));
|
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroupId"));
|
||||||
|
|
||||||
if (serverGroup == null) {
|
if (serverGroup == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("serverGroupId"));
|
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("serverGroupId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> serverGroup.delete(v));
|
SyncUtils.<Void>runBlocking(v -> serverGroup.delete(v));
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("emovedBy")), requestBody.getString("emovedByIp"), ctx, AuditLogActionType.SERVER_GROUP_DELETE, ImmutableMap.of("serverGroupId", serverGroup.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("emovedBy")), requestBody.getString("emovedByIp"), ctx, AuditLogActionType.SERVER_GROUP_DELETE, ImmutableMap.of("serverGroupId", serverGroup.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, serverGroup);
|
APIv3.respondJson(ctx, 200, serverGroup);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, serverGroup);
|
APIv3.respondJson(ctx, 200, serverGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
|||||||
|
|
||||||
public final class GETServerGroups implements Handler<RoutingContext> {
|
public final class GETServerGroups implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, ServerGroup.findAll());
|
APIv3.respondJson(ctx, 200, ServerGroup.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
|||||||
|
|
||||||
public final class GETServerGroupsId implements Handler<RoutingContext> {
|
public final class GETServerGroupsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
|
APIv3.respondJson(ctx, 200, ServerGroup.findById(ctx.request().getParam("serverGroupId")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,25 +14,25 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTServerGroups implements Handler<RoutingContext> {
|
public final class POSTServerGroups implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String id = requestBody.getString("id");
|
String id = requestBody.getString("id");
|
||||||
String image = requestBody.getString("image");
|
String image = requestBody.getString("image");
|
||||||
|
|
||||||
ServerGroup serverGroup = new ServerGroup(id, image);
|
ServerGroup serverGroup = new ServerGroup(id, image);
|
||||||
SyncUtils.<Void>runBlocking(v -> serverGroup.insert(v));
|
SyncUtils.<Void>runBlocking(v -> serverGroup.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_GROUP_CREATE, ImmutableMap.of("serverGroupId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_GROUP_CREATE, ImmutableMap.of("serverGroupId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, serverGroup);
|
APIv3.respondJson(ctx, 200, serverGroup);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, serverGroup);
|
APIv3.respondJson(ctx, 200, serverGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,47 +16,47 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class DELETEServersId implements Handler<RoutingContext> {
|
public final class DELETEServersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Server server = Server.findById(ctx.request().getParam("serverId"));
|
Server server = Server.findById(ctx.request().getParam("serverId"));
|
||||||
|
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Server", ctx.request().getParam("serverId"));
|
ErrorUtils.respondNotFound(ctx, "Server", ctx.request().getParam("serverId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.<Void>runBlocking(v -> server.insert(v));
|
SyncUtils.<Void>runBlocking(v -> server.insert(v));
|
||||||
|
|
||||||
SyncUtils.runBlocking(v -> {
|
SyncUtils.runBlocking(v -> {
|
||||||
AccessToken.findByNameAndType(server.getId(), ActorType.SERVER, (accessToken, error) -> {
|
AccessToken.findByNameAndType(server.getId(), ActorType.SERVER, (accessToken, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
v.onResult(null, error);
|
v.onResult(null, error);
|
||||||
} else if (accessToken != null) {
|
} else if (accessToken != null) {
|
||||||
accessToken.delete((ignored, error2) -> {
|
accessToken.delete((ignored, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
v.onResult(null, error2);
|
v.onResult(null, error2);
|
||||||
} else {
|
} else {
|
||||||
v.onResult(null, null);
|
v.onResult(null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
v.onResult(null, new NullPointerException("Access token not found."));
|
v.onResult(null, new NullPointerException("Access token not found."));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.SERVER_DELETE, ImmutableMap.of("serverId", server.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.SERVER_DELETE, ImmutableMap.of("serverId", server.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, server);
|
APIv3.respondJson(ctx, 200, server);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, server);
|
APIv3.respondJson(ctx, 200, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.Server;
|
|||||||
|
|
||||||
public final class GETServers implements Handler<RoutingContext> {
|
public final class GETServers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, Server.findAll());
|
APIv3.respondJson(ctx, 200, Server.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import net.frozenorb.apiv3.model.Server;
|
|||||||
|
|
||||||
public final class GETServersId implements Handler<RoutingContext> {
|
public final class GETServersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
APIv3.respondJson(ctx, 200, Server.findById(ctx.request().getParam("serverId")));
|
APIv3.respondJson(ctx, 200, Server.findById(ctx.request().getParam("serverId")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,42 +17,42 @@ import net.frozenorb.apiv3.util.UuidUtils;
|
|||||||
|
|
||||||
public final class POSTServers implements Handler<RoutingContext> {
|
public final class POSTServers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
String id = requestBody.getString("id");
|
String id = requestBody.getString("id");
|
||||||
String displayName = requestBody.getString("displayName");
|
String displayName = requestBody.getString("displayName");
|
||||||
ServerGroup group = ServerGroup.findById(requestBody.getString("group"));
|
ServerGroup group = ServerGroup.findById(requestBody.getString("group"));
|
||||||
String ip = requestBody.getString("ip");
|
String ip = requestBody.getString("ip");
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "Server group", requestBody.getString("group"));
|
ErrorUtils.respondNotFound(ctx, "Server group", requestBody.getString("group"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ipHost = ip.split(":")[0];
|
String ipHost = ip.split(":")[0];
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(ipHost)) {
|
if (!IpUtils.isValidIp(ipHost)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + ip + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + ip + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server server = new Server(id, displayName, group, ip);
|
Server server = new Server(id, displayName, group, ip);
|
||||||
SyncUtils.<Void>runBlocking(v -> server.insert(v));
|
SyncUtils.<Void>runBlocking(v -> server.insert(v));
|
||||||
|
|
||||||
AccessToken accessToken = new AccessToken(server);
|
AccessToken accessToken = new AccessToken(server);
|
||||||
SyncUtils.<Void>runBlocking(v -> accessToken.insert(v));
|
SyncUtils.<Void>runBlocking(v -> accessToken.insert(v));
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_CREATE, ImmutableMap.of("serverId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_CREATE, ImmutableMap.of("serverId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, server);
|
APIv3.respondJson(ctx, 200, server);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, server);
|
APIv3.respondJson(ctx, 200, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,221 +23,221 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
public final class POSTServersHeartbeat implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Actor actor = ctx.get("actor");
|
Actor actor = ctx.get("actor");
|
||||||
|
|
||||||
if (actor.getType() != ActorType.SERVER) {
|
if (actor.getType() != ActorType.SERVER) {
|
||||||
ErrorUtils.respondOther(ctx, 403, "This action can only be performed when requested by a server.", "serverOnly", ImmutableMap.of());
|
ErrorUtils.respondOther(ctx, 403, "This action can only be performed when requested by a server.", "serverOnly", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server actorServer = Server.findById(actor.getName());
|
Server actorServer = Server.findById(actor.getName());
|
||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
JsonObject players = requestBody.getJsonObject("players");
|
JsonObject players = requestBody.getJsonObject("players");
|
||||||
Map<UUID, String> playerNames = extractPlayerNames(players);
|
Map<UUID, String> playerNames = extractPlayerNames(players);
|
||||||
Map<UUID, String> playerIps = extractPlayerIps(players);
|
Map<UUID, String> playerIps = extractPlayerIps(players);
|
||||||
|
|
||||||
CompositeFuture.all(
|
CompositeFuture.all(
|
||||||
createInfoResponse(actorServer, requestBody.getDouble("lastTps"), playerNames),
|
createInfoResponse(actorServer, requestBody.getDouble("lastTps"), playerNames),
|
||||||
createPlayerResponse(actorServer, playerNames, playerIps),
|
createPlayerResponse(actorServer, playerNames, playerIps),
|
||||||
createPermissionsResponse(ServerGroup.findById(actorServer.getServerGroup())),
|
createPermissionsResponse(ServerGroup.findById(actorServer.getServerGroup())),
|
||||||
createEventsResponse(actorServer, requestBody.getJsonArray("events"))
|
createEventsResponse(actorServer, requestBody.getJsonArray("events"))
|
||||||
).setHandler((result) -> {
|
).setHandler((result) -> {
|
||||||
if (result.succeeded()) {
|
if (result.succeeded()) {
|
||||||
// We don't do anything with the info callback, as
|
// We don't do anything with the info callback, as
|
||||||
// it's just to update our database.
|
// it's just to update our database.
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"players", result.result().result(1),
|
"players", result.result().result(1),
|
||||||
"permissions", result.result().result(2),
|
"permissions", result.result().result(2),
|
||||||
"events", result.result().result(3)
|
"events", result.result().result(3)
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
ErrorUtils.respondInternalError(ctx, result.cause());
|
ErrorUtils.respondInternalError(ctx, result.cause());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<Void> createInfoResponse(Server server, double tps, Map<UUID, String> playerNames) {
|
private Future<Void> createInfoResponse(Server server, double tps, Map<UUID, String> playerNames) {
|
||||||
Future<Void> callback = Future.future();
|
Future<Void> callback = Future.future();
|
||||||
|
|
||||||
server.receivedHeartbeat(tps, playerNames.keySet());
|
server.receivedHeartbeat(tps, playerNames.keySet());
|
||||||
server.save((ignored, error) -> {
|
server.save((ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.fail(error);
|
callback.fail(error);
|
||||||
} else {
|
} else {
|
||||||
callback.complete();
|
callback.complete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<Map<String, Object>> createPlayerResponse(Server server, Map<UUID, String> playerNames, Map<UUID, String> playerIps) {
|
private Future<Map<String, Object>> createPlayerResponse(Server server, Map<UUID, String> playerNames, Map<UUID, String> playerIps) {
|
||||||
Future<Map<String, Object>> callback = Future.future();
|
Future<Map<String, Object>> callback = Future.future();
|
||||||
|
|
||||||
Future<Map<UUID, User>> userLookupCallback = Future.future();
|
Future<Map<UUID, User>> userLookupCallback = Future.future();
|
||||||
Future<Map<String, IpIntel>> ipIntelCallback = Future.future();
|
Future<Map<String, IpIntel>> ipIntelCallback = Future.future();
|
||||||
Future<Map<UUID, List<Grant>>> grantLookupCallback = Future.future();
|
Future<Map<UUID, List<Grant>>> grantLookupCallback = Future.future();
|
||||||
Future<Map<UUID, List<Punishment>>> punishmentLookupCallback = Future.future();
|
Future<Map<UUID, List<Punishment>>> punishmentLookupCallback = Future.future();
|
||||||
|
|
||||||
User.findOrCreateByIdGrouped(playerNames, new MongoToVertxCallback<>(userLookupCallback));
|
User.findOrCreateByIdGrouped(playerNames, new MongoToVertxCallback<>(userLookupCallback));
|
||||||
IpIntel.findOrCreateByIdGrouped(playerIps.values(), new MongoToVertxCallback<>(ipIntelCallback));
|
IpIntel.findOrCreateByIdGrouped(playerIps.values(), new MongoToVertxCallback<>(ipIntelCallback));
|
||||||
Grant.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(grantLookupCallback));
|
Grant.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(grantLookupCallback));
|
||||||
Punishment.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(punishmentLookupCallback));
|
Punishment.findByUserGrouped(playerNames.keySet(), new MongoToVertxCallback<>(punishmentLookupCallback));
|
||||||
|
|
||||||
CompositeFuture.all(
|
CompositeFuture.all(
|
||||||
userLookupCallback,
|
userLookupCallback,
|
||||||
ipIntelCallback,
|
ipIntelCallback,
|
||||||
grantLookupCallback,
|
grantLookupCallback,
|
||||||
punishmentLookupCallback
|
punishmentLookupCallback
|
||||||
).setHandler((batchLookupInfo) -> {
|
).setHandler((batchLookupInfo) -> {
|
||||||
if (batchLookupInfo.failed()) {
|
if (batchLookupInfo.failed()) {
|
||||||
callback.fail(batchLookupInfo.cause());
|
callback.fail(batchLookupInfo.cause());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<UUID, User> users = batchLookupInfo.result().result(0);
|
Map<UUID, User> users = batchLookupInfo.result().result(0);
|
||||||
Map<String, IpIntel> ipIntel = batchLookupInfo.result().result(1);
|
Map<String, IpIntel> ipIntel = batchLookupInfo.result().result(1);
|
||||||
Map<UUID, List<Grant>> grants = batchLookupInfo.result().result(2);
|
Map<UUID, List<Grant>> grants = batchLookupInfo.result().result(2);
|
||||||
Map<UUID, List<Punishment>> punishments = batchLookupInfo.result().result(3);
|
Map<UUID, List<Punishment>> punishments = batchLookupInfo.result().result(3);
|
||||||
Map<UUID, Future> loginInfoFutures = new HashMap<>();
|
Map<UUID, Future> loginInfoFutures = new HashMap<>();
|
||||||
|
|
||||||
users.forEach((uuid, user) -> {
|
users.forEach((uuid, user) -> {
|
||||||
Future<Map<String, Object>> loginInfoFuture = Future.future();
|
Future<Map<String, Object>> loginInfoFuture = Future.future();
|
||||||
createLoginInfo(user, server, ipIntel.get(playerIps.get(uuid)), grants.get(uuid), punishments.get(uuid), loginInfoFuture);
|
createLoginInfo(user, server, ipIntel.get(playerIps.get(uuid)), grants.get(uuid), punishments.get(uuid), loginInfoFuture);
|
||||||
loginInfoFutures.put(uuid, loginInfoFuture);
|
loginInfoFutures.put(uuid, loginInfoFuture);
|
||||||
});
|
});
|
||||||
|
|
||||||
CompositeFuture.all(ImmutableList.copyOf(loginInfoFutures.values())).setHandler((allLoginInfo) -> {
|
CompositeFuture.all(ImmutableList.copyOf(loginInfoFutures.values())).setHandler((allLoginInfo) -> {
|
||||||
if (allLoginInfo.failed()) {
|
if (allLoginInfo.failed()) {
|
||||||
callback.fail(allLoginInfo.cause());
|
callback.fail(allLoginInfo.cause());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
Map<String, Object> response = new HashMap<>();
|
||||||
loginInfoFutures.forEach((uuid, loginInfo) -> response.put(uuid.toString(), loginInfo.result()));
|
loginInfoFutures.forEach((uuid, loginInfo) -> response.put(uuid.toString(), loginInfo.result()));
|
||||||
callback.complete(response);
|
callback.complete(response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<Map<String, Object>> createPermissionsResponse(ServerGroup serverGroup) {
|
private Future<Map<String, Object>> createPermissionsResponse(ServerGroup serverGroup) {
|
||||||
Future<Map<String, Object>> callback = Future.future();
|
Future<Map<String, Object>> callback = Future.future();
|
||||||
Map<String, Object> permissionsResponse = new HashMap<>();
|
Map<String, Object> permissionsResponse = new HashMap<>();
|
||||||
|
|
||||||
for (Rank rank : Rank.findAll()) {
|
for (Rank rank : Rank.findAll()) {
|
||||||
Map<String, Boolean> scopedPermissions = PermissionUtils.mergePermissions(
|
Map<String, Boolean> scopedPermissions = PermissionUtils.mergePermissions(
|
||||||
ServerGroup.findDefault().calculatePermissions(rank),
|
ServerGroup.findDefault().calculatePermissions(rank),
|
||||||
serverGroup.calculatePermissions(rank)
|
serverGroup.calculatePermissions(rank)
|
||||||
);
|
);
|
||||||
|
|
||||||
permissionsResponse.put(rank.getId(), PermissionUtils.convertToList(scopedPermissions));
|
permissionsResponse.put(rank.getId(), PermissionUtils.convertToList(scopedPermissions));
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.complete(permissionsResponse);
|
callback.complete(permissionsResponse);
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<Map<String, Object>> createEventsResponse(Server server, JsonArray events) {
|
private Future<Map<String, Object>> createEventsResponse(Server server, JsonArray events) {
|
||||||
Future<Map<String, Object>> callback = Future.future();
|
Future<Map<String, Object>> callback = Future.future();
|
||||||
List<Future> eventFutures = new ArrayList<>();
|
List<Future> eventFutures = new ArrayList<>();
|
||||||
|
|
||||||
for (Object event : events) {
|
for (Object event : events) {
|
||||||
JsonObject eventJson = (JsonObject) event;
|
JsonObject eventJson = (JsonObject) event;
|
||||||
String type = eventJson.getString("type");
|
String type = eventJson.getString("type");
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "leave":
|
case "leave":
|
||||||
Future eventFuture = Future.future();
|
Future eventFuture = Future.future();
|
||||||
eventFutures.add(eventFuture);
|
eventFutures.add(eventFuture);
|
||||||
|
|
||||||
User.findById(eventJson.getString("user"), ((user, error) -> {
|
User.findById(eventJson.getString("user"), ((user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
eventFuture.fail(error);
|
eventFuture.fail(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
eventFuture.complete();
|
eventFuture.complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.leftServer(server)) {
|
if (!user.leftServer(server)) {
|
||||||
eventFuture.complete();
|
eventFuture.complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.save((ignored, saveError) -> {
|
user.save((ignored, saveError) -> {
|
||||||
if (saveError != null) {
|
if (saveError != null) {
|
||||||
eventFuture.fail(saveError);
|
eventFuture.fail(saveError);
|
||||||
} else {
|
} else {
|
||||||
eventFuture.complete();
|
eventFuture.complete();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.warn("Recieved event with unknown type " + type + ".");
|
log.warn("Recieved event with unknown type " + type + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositeFuture.all(eventFutures).setHandler((allEvents) -> {
|
CompositeFuture.all(eventFutures).setHandler((allEvents) -> {
|
||||||
if (allEvents.failed()) {
|
if (allEvents.failed()) {
|
||||||
callback.fail(allEvents.cause());
|
callback.fail(allEvents.cause());
|
||||||
} else {
|
} else {
|
||||||
callback.complete(ImmutableMap.of());
|
callback.complete(ImmutableMap.of());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, String> extractPlayerNames(JsonObject players) {
|
private Map<UUID, String> extractPlayerNames(JsonObject players) {
|
||||||
Map<UUID, String> result = new HashMap<>();
|
Map<UUID, String> result = new HashMap<>();
|
||||||
|
|
||||||
players.forEach((entry) -> {
|
players.forEach((entry) -> {
|
||||||
UUID uuid = UuidUtils.parseUuid(entry.getKey());
|
UUID uuid = UuidUtils.parseUuid(entry.getKey());
|
||||||
JsonObject data = (JsonObject) entry.getValue();
|
JsonObject data = (JsonObject) entry.getValue();
|
||||||
|
|
||||||
if (UuidUtils.isAcceptableUuid(uuid)) {
|
if (UuidUtils.isAcceptableUuid(uuid)) {
|
||||||
result.put(uuid, data.getString("username"));
|
result.put(uuid, data.getString("username"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, String> extractPlayerIps(JsonObject players) {
|
private Map<UUID, String> extractPlayerIps(JsonObject players) {
|
||||||
Map<UUID, String> result = new HashMap<>();
|
Map<UUID, String> result = new HashMap<>();
|
||||||
|
|
||||||
players.forEach((entry) -> {
|
players.forEach((entry) -> {
|
||||||
UUID uuid = UuidUtils.parseUuid(entry.getKey());
|
UUID uuid = UuidUtils.parseUuid(entry.getKey());
|
||||||
JsonObject data = (JsonObject) entry.getValue();
|
JsonObject data = (JsonObject) entry.getValue();
|
||||||
|
|
||||||
if (UuidUtils.isAcceptableUuid(uuid)) {
|
if (UuidUtils.isAcceptableUuid(uuid)) {
|
||||||
result.put(uuid, data.getString("userIp"));
|
result.put(uuid, data.getString("userIp"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLoginInfo(User user, Server server, IpIntel ipIntel, List<Grant> grants, List<Punishment> punishments, Future<Map<String, Object>> callback) {
|
private void createLoginInfo(User user, Server server, IpIntel ipIntel, List<Grant> grants, List<Punishment> punishments, Future<Map<String, Object>> callback) {
|
||||||
if (user.seenOnServer(server)) {
|
if (user.seenOnServer(server)) {
|
||||||
user.save((ignored, error) -> {
|
user.save((ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
callback.fail(error);
|
callback.fail(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getLoginInfo(server, ipIntel, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
user.getLoginInfo(server, ipIntel, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
user.getLoginInfo(server, ipIntel, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
user.getLoginInfo(server, ipIntel, punishments, ImmutableList.of(), grants, new MongoToVertxCallback<>(callback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,38 +12,38 @@ import java.util.*;
|
|||||||
|
|
||||||
public final class GETStaff implements Handler<RoutingContext> {
|
public final class GETStaff implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
Map<String, Rank> staffRanks = new HashMap<>();
|
Map<String, Rank> staffRanks = new HashMap<>();
|
||||||
|
|
||||||
Rank.findAll().forEach(rank -> {
|
Rank.findAll().forEach(rank -> {
|
||||||
if (rank.isStaffRank()) {
|
if (rank.isStaffRank()) {
|
||||||
staffRanks.put(rank.getId(), rank);
|
staffRanks.put(rank.getId(), rank);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, Set<User>> result = new TreeMap<>((first, second) -> {
|
Map<String, Set<User>> result = new TreeMap<>((first, second) -> {
|
||||||
Rank firstRank = staffRanks.get(first);
|
Rank firstRank = staffRanks.get(first);
|
||||||
Rank secondRank = staffRanks.get(second);
|
Rank secondRank = staffRanks.get(second);
|
||||||
|
|
||||||
return Integer.compare(firstRank.getWeight(), secondRank.getWeight());
|
return Integer.compare(firstRank.getWeight(), secondRank.getWeight());
|
||||||
});
|
});
|
||||||
|
|
||||||
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));
|
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));
|
||||||
|
|
||||||
for (Grant staffGrant : staffGrants) {
|
for (Grant staffGrant : staffGrants) {
|
||||||
if (staffGrant.isActive()) {
|
if (staffGrant.isActive()) {
|
||||||
User user = SyncUtils.runBlocking(v -> User.findById(staffGrant.getId(), v));
|
User user = SyncUtils.runBlocking(v -> User.findById(staffGrant.getId(), v));
|
||||||
Rank rank = staffRanks.get(staffGrant.getRank());
|
Rank rank = staffRanks.get(staffGrant.getRank());
|
||||||
|
|
||||||
if (!result.containsKey(rank.getId())) {
|
if (!result.containsKey(rank.getId())) {
|
||||||
result.put(rank.getId(), new HashSet<>());
|
result.put(rank.getId(), new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
result.get(rank.getId()).add(user);
|
result.get(rank.getId()).add(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
APIv3.respondJson(ctx, 200, result);
|
APIv3.respondJson(ctx, 200, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,14 +8,14 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
|||||||
|
|
||||||
public final class GETUsersId implements Handler<RoutingContext> {
|
public final class GETUsersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, user);
|
APIv3.respondJson(ctx, 200, user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,22 +9,22 @@ import net.frozenorb.apiv3.util.PermissionUtils;
|
|||||||
|
|
||||||
public final class GETUsersIdCompoundedPermissions implements Handler<RoutingContext> {
|
public final class GETUsersIdCompoundedPermissions implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else if (user == null) {
|
} else if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
||||||
} else {
|
} else {
|
||||||
user.getCompoundedPermissions((permissions, error2) -> {
|
user.getCompoundedPermissions((permissions, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error2);
|
ErrorUtils.respondInternalError(ctx, error2);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, PermissionUtils.convertToList(permissions));
|
APIv3.respondJson(ctx, 200, PermissionUtils.convertToList(permissions));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,27 +16,27 @@ import java.util.Map;
|
|||||||
|
|
||||||
public final class GETUsersIdDetails implements Handler<RoutingContext> {
|
public final class GETUsersIdDetails implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User user = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("userId"), v));
|
User user = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("userId"), v));
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Grant> grants = SyncUtils.runBlocking(v -> Grant.findByUser(user, v));
|
List<Grant> grants = SyncUtils.runBlocking(v -> Grant.findByUser(user, v));
|
||||||
List<IpLogEntry> ipLog = SyncUtils.runBlocking(v -> IpLogEntry.findByUser(user, v));
|
List<IpLogEntry> ipLog = SyncUtils.runBlocking(v -> IpLogEntry.findByUser(user, v));
|
||||||
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUser(user, v));
|
List<Punishment> punishments = SyncUtils.runBlocking(v -> Punishment.findByUser(user, v));
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
result.put("user", user);
|
result.put("user", user);
|
||||||
result.put("grants", grants);
|
result.put("grants", grants);
|
||||||
result.put("ipLog", ipLog);
|
result.put("ipLog", ipLog);
|
||||||
result.put("punishments", punishments);
|
result.put("punishments", punishments);
|
||||||
result.put("aliases", user.getAliases());
|
result.put("aliases", user.getAliases());
|
||||||
result.put("totpSetup", user.getTotpSecret() != null);
|
result.put("totpSetup", user.getTotpSecret() != null);
|
||||||
|
|
||||||
APIv3.respondJson(ctx, 200, result);
|
APIv3.respondJson(ctx, 200, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,36 +11,36 @@ import net.frozenorb.apiv3.util.IpUtils;
|
|||||||
|
|
||||||
public final class GETUsersIdRequiresTotp implements Handler<RoutingContext> {
|
public final class GETUsersIdRequiresTotp implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String userIp = ctx.request().getParam("userIp");
|
String userIp = ctx.request().getParam("userIp");
|
||||||
|
|
||||||
if (!IpUtils.isValidIp(userIp)) {
|
if (!IpUtils.isValidIp(userIp)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.requiresTotpAuthorization(userIp, (requiresTotpResult, error2) -> {
|
user.requiresTotpAuthorization(userIp, (requiresTotpResult, error2) -> {
|
||||||
if (error2 != null) {
|
if (error2 != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error2);
|
ErrorUtils.respondInternalError(ctx, error2);
|
||||||
} else {
|
} else {
|
||||||
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
APIv3.respondJson(ctx, 200, ImmutableMap.of(
|
||||||
"required", (requiresTotpResult == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS),
|
"required", (requiresTotpResult == RequiresTotpResult.REQUIRED_NO_EXEMPTIONS),
|
||||||
"message", requiresTotpResult.name()
|
"message", requiresTotpResult.name()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user