fixed logging in BanList, DomainBlacklist

This commit is contained in:
LAX1DUDE 2022-07-24 14:13:23 -07:00
parent d403cb8086
commit 7ffa94ab17
2 changed files with 29 additions and 29 deletions

View File

@ -205,31 +205,31 @@ public class BanList {
try { try {
blockedBans.add(constructIpBan("127.0.0.0/8")); blockedBans.add(constructIpBan("127.0.0.0/8"));
}catch(UnknownHostException e) { }catch(UnknownHostException e) {
System.err.println("Error: could not whitelist '127.0.0.0/8'"); BungeeCord.getInstance().getLogger().severe("Error: could not whitelist '127.0.0.0/8'");
e.printStackTrace(); e.printStackTrace();
} }
try { try {
blockedBans.add(constructIpBan("10.0.0.0/8")); blockedBans.add(constructIpBan("10.0.0.0/8"));
}catch(UnknownHostException e) { }catch(UnknownHostException e) {
System.err.println("Error: could not whitelist '10.0.0.0/8'"); BungeeCord.getInstance().getLogger().severe("Error: could not whitelist '10.0.0.0/8'");
e.printStackTrace(); e.printStackTrace();
} }
try { try {
blockedBans.add(constructIpBan("172.24.0.0/14")); blockedBans.add(constructIpBan("172.24.0.0/14"));
}catch(UnknownHostException e) { }catch(UnknownHostException e) {
System.err.println("Error: could not whitelist '172.24.0.0/14'"); BungeeCord.getInstance().getLogger().severe("Error: could not whitelist '172.24.0.0/14'");
e.printStackTrace(); e.printStackTrace();
} }
try { try {
blockedBans.add(constructIpBan("192.168.0.0/16")); blockedBans.add(constructIpBan("192.168.0.0/16"));
}catch(UnknownHostException e) { }catch(UnknownHostException e) {
System.err.println("Error: could not whitelist '192.168.0.0/16'"); BungeeCord.getInstance().getLogger().severe("Error: could not whitelist '192.168.0.0/16'");
e.printStackTrace(); e.printStackTrace();
} }
try { try {
blockedBans.add(constructIpBan("::1/128")); blockedBans.add(constructIpBan("::1/128"));
}catch(UnknownHostException e) { }catch(UnknownHostException e) {
System.err.println("Error: could not whitelist '::1/128'"); BungeeCord.getInstance().getLogger().severe("Error: could not whitelist '::1/128'");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -314,7 +314,7 @@ public class BanList {
pf.close(); pf.close();
lastListLoad = lastListTest = System.currentTimeMillis(); lastListLoad = lastListTest = System.currentTimeMillis();
}catch(Throwable t) { }catch(Throwable t) {
System.err.println("ERROR: the ban list could not be saved to file '" + bansFile.getName() + "', please fix this or you will lose all your bans next time this server restarts"); BungeeCord.getInstance().getLogger().severe("ERROR: the ban list could not be saved to file '" + bansFile.getName() + "', please fix this or you will lose all your bans next time this server restarts");
t.printStackTrace(); t.printStackTrace();
} }
} }
@ -704,7 +704,7 @@ public class BanList {
p.println("# end of file"); p.println("# end of file");
p.println(); p.println();
p.close(); p.close();
System.out.println("Wrote a new bans.txt to: " + bansFile.getAbsolutePath()); BungeeCord.getInstance().getLogger().info("Wrote a new bans.txt to: " + bansFile.getAbsolutePath());
lastListLoad = 0l; lastListLoad = 0l;
}catch(Throwable t) { }catch(Throwable t) {
fileIsBroken = true; fileIsBroken = true;
@ -712,8 +712,8 @@ public class BanList {
cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "Could not create blank 'bans.txt' list file"); cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "Could not create blank 'bans.txt' list file");
cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "(Reason: " + t.toString() + ")"); cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "(Reason: " + t.toString() + ")");
} }
System.err.println("Could not create blank 'bans.txt' list file"); BungeeCord.getInstance().getLogger().severe("Could not create blank 'bans.txt' list file");
System.err.println("(Reason: " + t.toString() + ")"); BungeeCord.getInstance().getLogger().severe("(Reason: " + t.toString() + ")");
t.printStackTrace(); t.printStackTrace();
} }
return; return;
@ -736,7 +736,7 @@ public class BanList {
} }
r.close(); r.close();
lastListLoad = lastEdit; lastListLoad = lastEdit;
System.out.println("Server bans.txt changed, it will be reloaded automatically"); BungeeCord.getInstance().getLogger().info("Server bans.txt changed, it will be reloaded automatically");
if(cs == null) { if(cs == null) {
for(ProxiedPlayer pp : BungeeCord.getInstance().getPlayers()) { for(ProxiedPlayer pp : BungeeCord.getInstance().getPlayers()) {
if(pp.hasPermission("bungeecord.command.eag.reloadban")) { if(pp.hasPermission("bungeecord.command.eag.reloadban")) {
@ -746,14 +746,14 @@ public class BanList {
} }
} }
parseListFrom(); parseListFrom();
System.out.println("Reload complete"); BungeeCord.getInstance().getLogger().info("Reload complete");
}catch(Throwable t) { }catch(Throwable t) {
if(cs != null) { if(cs != null) {
cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "Could not reload 'bans.txt' list file"); cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "Could not reload 'bans.txt' list file");
cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "(Reason: " + t.toString() + ")"); cs.sendMessage(banChatMessagePrefix + ChatColor.RED + "(Reason: " + t.toString() + ")");
} }
System.err.println("Could not reload 'bans.txt' list file"); BungeeCord.getInstance().getLogger().severe("Could not reload 'bans.txt' list file");
System.err.println("(Reason: " + t.toString() + ")"); BungeeCord.getInstance().getLogger().severe("(Reason: " + t.toString() + ")");
} }
} }
} }
@ -801,9 +801,9 @@ public class BanList {
boolean we = s.endsWith("*"); boolean we = s.endsWith("*");
if(!ws && !we) { if(!ws && !we) {
if(s.contains("*")) { if(s.contains("*")) {
System.err.println("Error: wildcard '" + s + "' contains a '*' not at the start/end of the string"); BungeeCord.getInstance().getLogger().severe("wildcard '" + s + "' contains a '*' not at the start/end of the string");
}else { }else {
System.err.println("Error: wildcard '" + s + "' does not contain a '*' wildcard character"); BungeeCord.getInstance().getLogger().severe("wildcard '" + s + "' does not contain a '*' wildcard character");
} }
}else { }else {
int total = (ws ? 1 : 0) + (we ? 1 : 0); int total = (ws ? 1 : 0) + (we ? 1 : 0);
@ -812,7 +812,7 @@ public class BanList {
if(c == '*') ++t2; if(c == '*') ++t2;
} }
if(total != t2) { if(total != t2) {
System.err.println("Error: wildcard '" + s + "' contains a '*' not at the start/end of the string"); BungeeCord.getInstance().getLogger().severe("wildcard '" + s + "' contains a '*' not at the start/end of the string");
} }
} }
wildcardBans.add(s.toLowerCase()); wildcardBans.add(s.toLowerCase());
@ -821,8 +821,8 @@ public class BanList {
try { try {
p = Pattern.compile(s); p = Pattern.compile(s);
}catch(Throwable t) { }catch(Throwable t) {
System.err.println("Error: the regex " + s.toLowerCase() + " is invalid"); BungeeCord.getInstance().getLogger().severe("the regex " + s.toLowerCase() + " is invalid");
System.err.println("Reason: " + t.getClass().getSimpleName() + ": " + t.getLocalizedMessage()); BungeeCord.getInstance().getLogger().severe("Reason: " + t.getClass().getSimpleName() + ": " + t.getLocalizedMessage());
} }
if(p != null) { if(p != null) {
regexBans.add(new RegexBan(s, p)); regexBans.add(new RegexBan(s, p));
@ -837,7 +837,7 @@ public class BanList {
try { try {
subnet = Integer.parseInt(s2); subnet = Integer.parseInt(s2);
}catch(Throwable t) { }catch(Throwable t) {
System.err.println("Error: the subnet '"+ s2 +"' for IP ban address " + s + " was invalid"); BungeeCord.getInstance().getLogger().severe("the subnet '"+ s2 +"' for IP ban address " + s + " was invalid");
subnet = -2; subnet = -2;
} }
} }
@ -858,7 +858,7 @@ public class BanList {
throw new UnknownHostException("Only ipv4 and ipv6 addresses allowed in Eaglercraft"); throw new UnknownHostException("Only ipv4 and ipv6 addresses allowed in Eaglercraft");
} }
}catch(Throwable t) { }catch(Throwable t) {
System.err.println("Error: the IP ban address " + s + " could not be parsed"); BungeeCord.getInstance().getLogger().severe("the IP ban address " + s + " could not be parsed");
t.printStackTrace(); t.printStackTrace();
} }
} }

View File

@ -139,7 +139,7 @@ public class DomainBlacklist {
u = new URL(str); u = new URL(str);
}catch(MalformedURLException e) { }catch(MalformedURLException e) {
if(brokenURLs.add(str)) { if(brokenURLs.add(str)) {
System.err.println("ERROR: the blacklist subscription URL '" + str + "' is invalid"); BungeeCord.getInstance().getLogger().severe("The blacklist subscription URL '" + str + "' is invalid");
} }
continue; continue;
} }
@ -172,7 +172,7 @@ public class DomainBlacklist {
newReplitBlacklist.add(Pattern.compile(ss)); newReplitBlacklist.add(Pattern.compile(ss));
}catch(PatternSyntaxException shit) { }catch(PatternSyntaxException shit) {
if(brokenRegex.add(ss)) { if(brokenRegex.add(ss)) {
System.err.println("ERROR: the blacklist replit wildcard regex '" + ss + "' is invalid"); BungeeCord.getInstance().getLogger().severe("the blacklist replit wildcard regex '" + ss + "' is invalid");
continue; continue;
} }
} }
@ -186,7 +186,7 @@ public class DomainBlacklist {
newBlacklist.add(Pattern.compile(ss)); newBlacklist.add(Pattern.compile(ss));
}catch(PatternSyntaxException shit) { }catch(PatternSyntaxException shit) {
if(brokenRegex.add(ss)) { if(brokenRegex.add(ss)) {
System.err.println("ERROR: the blacklist regex '" + ss + "' is invalid"); BungeeCord.getInstance().getLogger().severe("the blacklist regex '" + ss + "' is invalid");
continue; continue;
} }
} }
@ -198,7 +198,7 @@ public class DomainBlacklist {
brokenURLs.remove(str); brokenURLs.remove(str);
}catch(Throwable t) { }catch(Throwable t) {
if(brokenURLs.add(str)) { if(brokenURLs.add(str)) {
System.err.println("ERROR: the blacklist subscription URL '" + str + "' is invalid"); BungeeCord.getInstance().getLogger().severe("the blacklist subscription URL '" + str + "' is invalid");
} }
t.printStackTrace(); t.printStackTrace();
} }
@ -245,7 +245,7 @@ public class DomainBlacklist {
} }
} }
}catch(PatternSyntaxException shit) { }catch(PatternSyntaxException shit) {
System.err.println("ERROR: the local " + (localWhitelistMode ? "whitelist" : "blacklist") + " regex '" + ss + "' is invalid"); BungeeCord.getInstance().getLogger().severe("the local " + (localWhitelistMode ? "whitelist" : "blacklist") + " regex '" + ss + "' is invalid");
} }
} }
is.close(); is.close();
@ -265,10 +265,10 @@ public class DomainBlacklist {
os.close(); os.close();
lastLocalUpdate = localBlacklist.lastModified(); lastLocalUpdate = localBlacklist.lastModified();
} }
System.out.println("Reloaded '" + localBlacklist.getName() + "'."); BungeeCord.getInstance().getLogger().info("Reloaded '" + localBlacklist.getName() + "'.");
}catch(IOException ex) { }catch(IOException ex) {
regexLocalBlacklist.clear(); regexLocalBlacklist.clear();
System.err.println("ERROR: failed to read local " + (localWhitelistMode ? "whitelist" : "blacklist") + " file '" + localBlacklist.getName() + "'"); BungeeCord.getInstance().getLogger().severe("failed to read local " + (localWhitelistMode ? "whitelist" : "blacklist") + " file '" + localBlacklist.getName() + "'");
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@ -276,7 +276,7 @@ public class DomainBlacklist {
}else { }else {
synchronized(regexBlacklist) { synchronized(regexBlacklist) {
if(!regexLocalBlacklist.isEmpty()) { if(!regexLocalBlacklist.isEmpty()) {
System.err.println("WARNING: the blacklist file '" + localBlacklist.getName() + "' has been deleted"); BungeeCord.getInstance().getLogger().warning("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
} }
regexLocalBlacklist.clear(); regexLocalBlacklist.clear();
} }
@ -349,7 +349,7 @@ public class DomainBlacklist {
update(); update();
return true; return true;
}catch(IOException ex) { }catch(IOException ex) {
System.err.println("Failed to save '" + localBlacklist.getName() + "'"); BungeeCord.getInstance().getLogger().severe("Failed to save '" + localBlacklist.getName() + "'");
ex.printStackTrace(); ex.printStackTrace();
} }
} }