mirror of
https://github.com/lax1dude/origin-blacklist-1.8.git
synced 2024-12-21 14:54:14 -08:00
(1.0.0) First release, bungee support only
This commit is contained in:
parent
774c59998f
commit
0f853d4d4d
BIN
OriginBlacklist.jar
Normal file
BIN
OriginBlacklist.jar
Normal file
Binary file not shown.
|
@ -42,6 +42,7 @@ public class OriginBlacklist {
|
|||
public final Collection<Pattern> regexLocalBlacklist = new ArrayList();
|
||||
public final Collection<Pattern> regexBlacklistReplit = new ArrayList();
|
||||
public final Collection<String> simpleWhitelist = new ArrayList();
|
||||
private final Object localBlacklistLock = new Object();
|
||||
private File localBlacklist = null;
|
||||
private String subscriptionDownloadUserAgent = null;
|
||||
private Collection<String> blacklistSubscriptions = null;
|
||||
|
@ -248,138 +249,154 @@ public class OriginBlacklist {
|
|||
}
|
||||
}
|
||||
}
|
||||
if(localBlacklist.exists()) {
|
||||
long lastLocalEdit = localBlacklist.lastModified();
|
||||
if(lastLocalEdit != lastLocalUpdate) {
|
||||
lastLocalUpdate = lastLocalEdit;
|
||||
synchronized(regexBlacklist) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
regexLocalBlacklist.clear();
|
||||
localWhitelistMode = false;
|
||||
boolean foundWhitelistStatement = false;
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
try {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
if(!ss.startsWith("#")) {
|
||||
regexLocalBlacklist.add(Pattern.compile(ss));
|
||||
}else {
|
||||
String st = ss.substring(1).trim();
|
||||
if(st.startsWith("whitelistMode:")) {
|
||||
foundWhitelistStatement = true;
|
||||
String str = st.substring(14).trim().toLowerCase();
|
||||
localWhitelistMode = str.equals("true") || str.equals("on") || str.equals("1");
|
||||
synchronized(localBlacklistLock) {
|
||||
if(localBlacklist.exists()) {
|
||||
long lastLocalEdit = localBlacklist.lastModified();
|
||||
if(lastLocalEdit != lastLocalUpdate) {
|
||||
lastLocalUpdate = lastLocalEdit;
|
||||
synchronized(regexBlacklist) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
regexLocalBlacklist.clear();
|
||||
localWhitelistMode = false;
|
||||
boolean foundWhitelistStatement = false;
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
try {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
if(!ss.startsWith("#")) {
|
||||
regexLocalBlacklist.add(Pattern.compile(ss));
|
||||
}else {
|
||||
String st = ss.substring(1).trim();
|
||||
if(st.startsWith("whitelistMode:")) {
|
||||
foundWhitelistStatement = true;
|
||||
String str = st.substring(14).trim().toLowerCase();
|
||||
localWhitelistMode = str.equals("true") || str.equals("on") || str.equals("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(PatternSyntaxException shit) {
|
||||
logger.error("the local " + (localWhitelistMode ? "whitelist" : "blacklist") + " regex '" + ss + "' is invalid");
|
||||
}
|
||||
}catch(PatternSyntaxException shit) {
|
||||
logger.error("the local " + (localWhitelistMode ? "whitelist" : "blacklist") + " regex '" + ss + "' is invalid");
|
||||
}
|
||||
is.close();
|
||||
if(!foundWhitelistStatement) {
|
||||
List<String> newLines = new ArrayList();
|
||||
newLines.add("#whitelistMode: false");
|
||||
newLines.add("");
|
||||
try(BufferedReader is2 = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
while((ss = is2.readLine()) != null) {
|
||||
newLines.add(ss);
|
||||
}
|
||||
}
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String str : newLines) {
|
||||
os.println(str);
|
||||
}
|
||||
}
|
||||
lastLocalUpdate = localBlacklist.lastModified();
|
||||
}
|
||||
logger.info("Reloaded '" + localBlacklist.getName() + "'.");
|
||||
}catch(IOException ex) {
|
||||
regexLocalBlacklist.clear();
|
||||
logger.error("failed to read local " + (localWhitelistMode ? "whitelist" : "blacklist") + " file '" + localBlacklist.getName() + "'");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
is.close();
|
||||
if(!foundWhitelistStatement) {
|
||||
List<String> newLines = new ArrayList();
|
||||
newLines.add("#whitelistMode: false");
|
||||
newLines.add("");
|
||||
try(BufferedReader is2 = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
while((ss = is2.readLine()) != null) {
|
||||
newLines.add(ss);
|
||||
}
|
||||
}
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String str : newLines) {
|
||||
os.println(str);
|
||||
}
|
||||
}
|
||||
lastLocalUpdate = localBlacklist.lastModified();
|
||||
}
|
||||
logger.info("Reloaded '" + localBlacklist.getName() + "'.");
|
||||
}catch(IOException ex) {
|
||||
regexLocalBlacklist.clear();
|
||||
logger.error("failed to read local " + (localWhitelistMode ? "whitelist" : "blacklist") + " file '" + localBlacklist.getName() + "'");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
synchronized(regexBlacklist) {
|
||||
if(!regexLocalBlacklist.isEmpty()) {
|
||||
logger.warn("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
|
||||
}
|
||||
regexLocalBlacklist.clear();
|
||||
}
|
||||
synchronized(regexBlacklist) {
|
||||
if(!regexLocalBlacklist.isEmpty()) {
|
||||
logger.warn("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
|
||||
}
|
||||
regexLocalBlacklist.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void addLocal(String o) {
|
||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||
ArrayList<String> lines = new ArrayList();
|
||||
if(localBlacklist.exists()) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
lines.add(ss);
|
||||
synchronized(localBlacklistLock) {
|
||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||
ArrayList<String> lines = new ArrayList();
|
||||
if(localBlacklist.exists()) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
lines.add(ss);
|
||||
}
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
}
|
||||
if(lines.isEmpty()) {
|
||||
lines.add("#whitelist false");
|
||||
lines.add("");
|
||||
}
|
||||
if(!lines.contains(p)) {
|
||||
lines.add(p);
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String s : lines) {
|
||||
os.println(s);
|
||||
if(lines.isEmpty()) {
|
||||
lines.add("#whitelistMode: false");
|
||||
lines.add("");
|
||||
}
|
||||
if(!lines.contains(p)) {
|
||||
lines.add(p);
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String s : lines) {
|
||||
os.println(s);
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
lastLocalUpdate = 0l;
|
||||
update();
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeLocal(String o) {
|
||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||
ArrayList<String> lines = new ArrayList();
|
||||
if(localBlacklist.exists()) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
lines.add(ss);
|
||||
synchronized(localBlacklistLock) {
|
||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||
ArrayList<String> lines = new ArrayList();
|
||||
if(localBlacklist.exists()) {
|
||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||
String ss;
|
||||
while((ss = is.readLine()) != null) {
|
||||
if((ss = ss.trim()).length() > 0) {
|
||||
lines.add(ss);
|
||||
}
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
// ?
|
||||
}
|
||||
}
|
||||
if(lines.contains(p)) {
|
||||
lines.remove(p);
|
||||
try {
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String s : lines) {
|
||||
os.println(s);
|
||||
if(lines.remove(p)) {
|
||||
try {
|
||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||
for(String s : lines) {
|
||||
os.println(s);
|
||||
}
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
logger.error("Failed to save '" + localBlacklist.getName() + "'");
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
lastLocalUpdate = 0l;
|
||||
update();
|
||||
return true;
|
||||
}catch(IOException ex) {
|
||||
logger.error("Failed to save '" + localBlacklist.getName() + "'");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public File getLocalBlacklist() {
|
||||
return localBlacklist;
|
||||
}
|
||||
|
||||
public static String removeProtocolFromOrigin(String s) {
|
||||
if(s == null) return null;
|
||||
int idx = s.indexOf("://");
|
||||
if(idx != -1) {
|
||||
return s.substring(idx + 3);
|
||||
}else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class OriginBlacklistConfigBungee implements OriginBlacklistConfigAdapter
|
|||
}
|
||||
File configFile = new File(dataDir, "config.yml");
|
||||
if(!configFile.exists()) {
|
||||
try(InputStream defaultConf = OriginBlacklistConfigBungee.class.getResourceAsStream("../default_config.yml")) {
|
||||
try(InputStream defaultConf = OriginBlacklistConfigBungee.class.getResourceAsStream("/net/lax1dude/eaglercraft/v1_8/plugin/origin_blacklist/default_config.yml")) {
|
||||
try(OutputStream os = new FileOutputStream(configFile)) {
|
||||
byte[] copyBuffer = new byte[1024];
|
||||
int i;
|
||||
|
|
|
@ -41,7 +41,7 @@ public class OriginBlacklistListenerBungee implements Listener {
|
|||
OriginBlacklist blacklist = plugin.list;
|
||||
boolean shouldKick = true;
|
||||
try {
|
||||
shouldKick = (origin == null && blacklist.getBlockClientsWithNoOriginHeader()) || blacklist.test(origin);
|
||||
shouldKick = origin == null ? blacklist.getBlockClientsWithNoOriginHeader() : blacklist.test(OriginBlacklist.removeProtocolFromOrigin(origin));
|
||||
}catch(Throwable t) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to check origin blacklist for: " + origin, t);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class OriginBlacklistListenerBungee implements Listener {
|
|||
evt.setCancelled(true);
|
||||
String msg = blacklist.getKickMessage();
|
||||
if(msg != null) {
|
||||
evt.setReason(new TextComponent());
|
||||
evt.setReason(new TextComponent(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,25 @@ public class CommandDomainBlock extends Command {
|
|||
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is not online"));
|
||||
}else {
|
||||
if(user.getPendingConnection() instanceof EaglerInitialHandler) {
|
||||
Object o = ((EaglerInitialHandler)user.getPendingConnection()).getOrigin();
|
||||
String o = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)user.getPendingConnection()).getOrigin());
|
||||
if(o != null) {
|
||||
if("null".equals(o)) {
|
||||
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is on an offline download"));
|
||||
}else {
|
||||
OriginBlacklist bl = OriginBlacklistPluginBungee.getPlugin().list;
|
||||
bl.addLocal((String)o);
|
||||
bl.addLocal(o);
|
||||
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
||||
if(p.getPendingConnection() instanceof EaglerInitialHandler) {
|
||||
String oo = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)p.getPendingConnection()).getOrigin());
|
||||
if(oo != null) {
|
||||
if(bl.test(oo)) {
|
||||
p.disconnect(new TextComponent(bl.getKickMessage() == null ? "End of stream" : bl.getKickMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
p0.sendMessage(new TextComponent(ChatColor.RED + "Domain of " + ChatColor.WHITE + p1[0] + ChatColor.RED + " is " + ChatColor.WHITE + o));
|
||||
p0.sendMessage(new TextComponent(ChatColor.RED + "It was added to the local block list."));
|
||||
user.disconnect(new TextComponent(bl.getKickMessage()));
|
||||
}
|
||||
}else {
|
||||
p0.sendMessage(new TextComponent(ChatColor.RED + "Domain of " + p1[0] + " is unknown (desktop runtime?)"));
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.command;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.server.EaglerInitialHandler;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlacklistPluginBungee;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
/**
|
||||
|
@ -33,7 +37,18 @@ public class CommandDomainBlockDomain extends Command {
|
|||
p0.sendMessage(new TextComponent(ChatColor.RED + "Please follow this command by a domain"));
|
||||
return;
|
||||
}
|
||||
OriginBlacklistPluginBungee.getPlugin().list.addLocal(p1[0]);
|
||||
OriginBlacklist bl = OriginBlacklistPluginBungee.getPlugin().list;
|
||||
bl.addLocal(p1[0]);
|
||||
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
|
||||
if(p.getPendingConnection() instanceof EaglerInitialHandler) {
|
||||
String o = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)p.getPendingConnection()).getOrigin());
|
||||
if(o != null) {
|
||||
if(bl.test(o)) {
|
||||
p.disconnect(new TextComponent(bl.getKickMessage() == null ? "End of stream" : bl.getKickMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
p0.sendMessage(new TextComponent(ChatColor.GREEN + "The domain '" + ChatColor.WHITE + p1[0] + ChatColor.GREEN + "' was added to the block list"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
origin_blacklist_kick_message: 'End of stream'
|
||||
origin_blacklist_kick_message: "End of stream"
|
||||
origin_blacklist_block_missing_origin_header: false
|
||||
origin_blacklist_block_offline_download: false
|
||||
origin_blacklist_block_replit_clients: false
|
||||
enable_web_origin_blacklist: false
|
||||
origin_blacklist_subscriptions:
|
||||
- 'add url here'
|
||||
- "add url here"
|
||||
origin_blacklist_use_simple_whitelist: false
|
||||
origin_blacklist_simple_whitelist:
|
||||
- 'type the name of your client\'s domain here'
|
||||
- '(if \'origin_blacklist_use_simple_whitelist\' is true)'
|
||||
- "type the name of your client's domain here"
|
||||
- "(if 'origin_blacklist_use_simple_whitelist' is true)"
|
|
@ -2,4 +2,6 @@ name: OriginBlacklist
|
|||
main: net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlacklistPluginBungee
|
||||
version: 1.0.0
|
||||
description: Plugin for EaglercraftXBungee servers to add the "origin blacklist" feature from 1.5.2
|
||||
author: lax1dude
|
||||
author: lax1dude
|
||||
depends:
|
||||
- EaglercraftXBungee
|
Loading…
Reference in New Issue
Block a user