Adding additional login checks.

Added /saconfig info
This commit is contained in:
Steven Lawson 2012-12-19 20:25:29 -05:00
parent d066c1b754
commit b8b755c0c7
7 changed files with 112 additions and 21 deletions

View file

@ -48,6 +48,39 @@ public class Command_saconfig extends TFM_Command
}
else if (args.length == 2)
{
if (args[0].equalsIgnoreCase("info"))
{
if (!TFM_SuperadminList.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
if (superadmin == null)
{
try
{
superadmin = TFM_SuperadminList.getAdminEntry(getPlayer(args[1]).getName().toLowerCase());
}
catch (CantFindPlayerException ex)
{
}
}
if (superadmin == null)
{
sender.sendMessage("Superadmin not found: " + args[1]);
}
else
{
sender.sendMessage(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', superadmin.toString())));
}
return true;
}
if (!senderIsConsole)
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the console.");
@ -95,7 +128,7 @@ public class Command_saconfig extends TFM_Command
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
String target_name = args[1];
try

View file

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
@ -53,9 +54,7 @@ public class TFM_Command
ADMIN_LEVEL level = permissions.level();
SOURCE_TYPE_ALLOWED source = permissions.source();
boolean block_web_console = permissions.block_host_console();
//TFM_Log.info("Level: " + level + ", Source: " + source + ", BWC: " + block_host_console);
boolean block_host_console = permissions.block_host_console();
Player sender_p = null;
if (sender instanceof Player)
@ -73,7 +72,7 @@ public class TFM_Command
{
return false;
}
else if (block_web_console && TFM_Util.isFromHostConsole(sender.getName()))
else if (block_host_console && TFM_Util.isFromHostConsole(sender.getName()))
{
return false;
}
@ -84,9 +83,25 @@ public class TFM_Command
{
return false;
}
else if (level == ADMIN_LEVEL.SENIOR && !is_senior)
else if (level == ADMIN_LEVEL.SENIOR)
{
return false;
if (is_senior)
{
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(sender_p);
Boolean superadminIdVerified = playerdata.isSuperadminIdVerified();
if (superadminIdVerified != null)
{
if (!superadminIdVerified.booleanValue())
{
return false;
}
}
}
else
{
return false;
}
}
else if (level == ADMIN_LEVEL.SUPER && !is_super)
{

View file

@ -641,6 +641,8 @@ public class TFM_PlayerListener implements Listener
try
{
final Player p = event.getPlayer();
final TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
playerdata.setSuperadminIdVerified(null);
TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(p);
@ -659,9 +661,20 @@ public class TFM_PlayerListener implements Listener
}
else
{
p.setOp(true);
if (TFM_SuperadminList.verifyIdentity(p.getName(), p.getAddress().getAddress().getHostAddress()))
{
playerdata.setSuperadminIdVerified(Boolean.TRUE);
TFM_SuperadminList.updateLastLogin(p);
TFM_SuperadminList.updateLastLogin(p);
}
else
{
playerdata.setSuperadminIdVerified(Boolean.FALSE);
TFM_Util.bcastMsg("Warning: " + p.getName() + " is an admin, but is using a username not registered to one of their IPs.", ChatColor.RED);
}
p.setOp(true);
}
}

View file

@ -154,7 +154,7 @@ public class TFM_ServerInterface
}
else
{
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip);
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip, player_name.toLowerCase());
}
if (!is_superadmin)

View file

@ -265,7 +265,7 @@ public class TFM_SuperadminList
return false;
}
public static boolean checkPartialSuperadminIP(String user_ip)
public static boolean checkPartialSuperadminIP(String user_ip, String user_name)
{
try
{
@ -293,10 +293,13 @@ public class TFM_SuperadminList
if (admin_entry != null)
{
List<String> ips = admin_entry.getIps();
ips.add(user_ip);
admin_entry.setIps(ips);
saveSuperadminList();
if (admin_entry.getName().equalsIgnoreCase(user_name))
{
List<String> ips = admin_entry.getIps();
ips.add(user_ip);
admin_entry.setIps(ips);
saveSuperadminList();
}
}
return true;
@ -430,4 +433,22 @@ public class TFM_SuperadminList
TFM_Log.severe(ex);
}
}
public static boolean verifyIdentity(String admin_name, String ip) throws Exception
{
if (Bukkit.getOnlineMode())
{
return true;
}
TFM_Superadmin admin_entry = getAdminEntry(admin_name);
if (admin_entry != null)
{
return admin_entry.getIps().contains(ip);
}
else
{
throw new Exception();
}
}
}

View file

@ -47,6 +47,7 @@ public class TFM_UserInfo
private String last_message = "";
private boolean in_adminchat = false;
private boolean all_commands_blocked = false;
private Boolean superadmin_id_verified = null;
public TFM_UserInfo(Player player)
{
@ -438,4 +439,18 @@ public class TFM_UserInfo
{
this.all_commands_blocked = commands_blocked;
}
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
//After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public Boolean isSuperadminIdVerified()
{
return superadmin_id_verified;
}
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
//After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public void setSuperadminIdVerified(Boolean superadmin_id_verified)
{
this.superadmin_id_verified = superadmin_id_verified;
}
}

View file

@ -245,12 +245,6 @@ public class TFM_Util
return TFM_SuperadminList.isUserSuperadmin(user);
}
@Deprecated
public static boolean checkPartialSuperadminIP(String user_ip)
{
return TFM_SuperadminList.checkPartialSuperadminIP(user_ip);
}
public static int wipeEntities(boolean wipe_explosives, boolean wipe_vehicles)
{
int removed = 0;