Create an ip ban for the user's last used ip address if their current ip address is not provided when banning. Closes #46
This commit is contained in:
parent
c30f11ead4
commit
612fe880dc
@ -46,6 +46,10 @@ public final class IpLogEntry {
|
|||||||
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 findLatestByUser(UUID user, SingleResultCallback<IpLogEntry> callback) {
|
||||||
|
ipLogCollection.find(new Document("user", user)).sort(new Document("lastSeenAt", -1)).limit(1).first(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));
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import net.frozenorb.apiv3.APIv3;
|
|||||||
import net.frozenorb.apiv3.auditLog.AuditLog;
|
import net.frozenorb.apiv3.auditLog.AuditLog;
|
||||||
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
||||||
import net.frozenorb.apiv3.model.IpBan;
|
import net.frozenorb.apiv3.model.IpBan;
|
||||||
|
import net.frozenorb.apiv3.model.IpLogEntry;
|
||||||
import net.frozenorb.apiv3.model.Punishment;
|
import net.frozenorb.apiv3.model.Punishment;
|
||||||
import net.frozenorb.apiv3.model.User;
|
import net.frozenorb.apiv3.model.User;
|
||||||
import net.frozenorb.apiv3.unsorted.Permissions;
|
import net.frozenorb.apiv3.unsorted.Permissions;
|
||||||
@ -89,6 +90,14 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
|||||||
String accessDenialReason = punishment.getAccessDenialReason();
|
String accessDenialReason = punishment.getAccessDenialReason();
|
||||||
String userIp = requestBody.getString("userIp");
|
String userIp = requestBody.getString("userIp");
|
||||||
|
|
||||||
|
if (userIp == null) {
|
||||||
|
IpLogEntry latestIpLogEntry = SyncUtils.runBlocking(v -> IpLogEntry.findLatestByUser(target.getId(), v));
|
||||||
|
|
||||||
|
if (latestIpLogEntry != null) {
|
||||||
|
userIp = latestIpLogEntry.getUserIp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
Loading…
Reference in New Issue
Block a user