Extra permissions for /seen and /whois information (#735)

* Implemented separate permissions for seen extras

* Add an extra permission to the whois command too.
IPs are sensitive information that should only be accessible to an as small as possible amount of people
This commit is contained in:
Max Lee 2018-03-21 05:50:42 +01:00 committed by Trent Hensler
parent 0d5da063fb
commit 95ac4a4853
3 changed files with 22 additions and 13 deletions

View File

@ -28,16 +28,16 @@ public class Commandseen extends EssentialsCommand {
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
seen(server, sender, commandLabel, args, true, true, true);
seen(server, sender, commandLabel, args, true, true, true, true);
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
seen(server, user.getSource(), commandLabel, args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.extra"), user.isAuthorized("essentials.seen.ipsearch"));
seen(server, user.getSource(), commandLabel, args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.ip"), user.isAuthorized("essentials.seen.location"), user.isAuthorized("essentials.seen.ipsearch"));
}
protected void seen(final Server server, final CommandSource sender, final String commandLabel, final String[] args,
final boolean showBan, final boolean extra, final boolean ipLookup) throws Exception {
final boolean showBan, final boolean showIp, final boolean showLocation, final boolean ipLookup) throws Exception {
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
@ -80,23 +80,23 @@ public class Commandseen extends EssentialsCommand {
if (user == null) {
throw new PlayerNotFoundException();
}
showSeenMessage(server, sender, user, showBan, extra);
showSeenMessage(server, sender, user, showBan, showIp, showLocation);
}
});
} else {
showSeenMessage(server, sender, player, showBan, extra);
showSeenMessage(server, sender, player, showBan, showIp, showLocation);
}
}
private void showSeenMessage(Server server, CommandSource sender, User player, boolean showBan, boolean extra) throws Exception {
private void showSeenMessage(Server server, CommandSource sender, User player, boolean showBan, boolean showIp, boolean showLocation) throws Exception {
if (player.getBase().isOnline() && canInteractWith(sender, player)) {
seenOnline(server, sender, player, showBan, extra);
seenOnline(server, sender, player, showBan, showIp, showLocation);
} else {
seenOffline(server, sender, player, showBan, extra);
seenOffline(server, sender, player, showBan, showIp, showLocation);
}
}
private void seenOnline(final Server server, final CommandSource sender, final User user, final boolean showBan, final boolean extra) throws Exception {
private void seenOnline(final Server server, final CommandSource sender, final User user, final boolean showBan, final boolean showIp, final boolean showLocation) throws Exception {
user.setDisplayNick();
sender.sendMessage(tl("seenOnline", user.getDisplayName(), DateUtil.formatDateDiff(user.getLastLogin())));
@ -123,12 +123,12 @@ public class Commandseen extends EssentialsCommand {
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) {
sender.sendMessage(tl("whoisGeoLocation", location));
}
if (extra) {
if (showIp) {
sender.sendMessage(tl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()));
}
}
private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean extra) throws Exception {
private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean showIp, final boolean showLocation) throws Exception {
user.setDisplayNick();
if (user.getLastLogout() > 0) {
sender.sendMessage(tl("seenOffline", user.getName(), DateUtil.formatDateDiff(user.getLastLogout())));
@ -163,10 +163,12 @@ public class Commandseen extends EssentialsCommand {
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) {
sender.sendMessage(tl("whoisGeoLocation", location));
}
if (extra) {
if (showIp) {
if (!user.getLastLoginAddress().isEmpty()) {
sender.sendMessage(tl("whoisIPAddress", user.getLastLoginAddress()));
}
}
if (showLocation) {
final Location loc = user.getLogoutLocation();
if (loc != null) {
sender.sendMessage(tl("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));

View File

@ -41,7 +41,9 @@ public class Commandwhois extends EssentialsCommand {
if (!ess.getSettings().isEcoDisabled()) {
sender.sendMessage(tl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess)));
}
sender.sendMessage(tl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()));
if (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.whois.ip")) {
sender.sendMessage(tl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()));
}
final String location = user.getGeoLocation();
if (location != null && (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) {
sender.sendMessage(tl("whoisGeoLocation", location));

View File

@ -535,3 +535,8 @@ permissions:
essentials.gamemode: true
essentials.gamemode.others: true
essentials.gamemode.all: true
essentials.seen.extra:
default: op
children:
essentials.seen.ip: true
essentials.seen.location: true