mirror of
https://github.com/lax1dude/origin-blacklist-1.8.git
synced 2024-12-21 23:04: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> regexLocalBlacklist = new ArrayList();
|
||||||
public final Collection<Pattern> regexBlacklistReplit = new ArrayList();
|
public final Collection<Pattern> regexBlacklistReplit = new ArrayList();
|
||||||
public final Collection<String> simpleWhitelist = new ArrayList();
|
public final Collection<String> simpleWhitelist = new ArrayList();
|
||||||
|
private final Object localBlacklistLock = new Object();
|
||||||
private File localBlacklist = null;
|
private File localBlacklist = null;
|
||||||
private String subscriptionDownloadUserAgent = null;
|
private String subscriptionDownloadUserAgent = null;
|
||||||
private Collection<String> blacklistSubscriptions = null;
|
private Collection<String> blacklistSubscriptions = null;
|
||||||
|
@ -248,138 +249,154 @@ public class OriginBlacklist {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(localBlacklist.exists()) {
|
synchronized(localBlacklistLock) {
|
||||||
long lastLocalEdit = localBlacklist.lastModified();
|
if(localBlacklist.exists()) {
|
||||||
if(lastLocalEdit != lastLocalUpdate) {
|
long lastLocalEdit = localBlacklist.lastModified();
|
||||||
lastLocalUpdate = lastLocalEdit;
|
if(lastLocalEdit != lastLocalUpdate) {
|
||||||
synchronized(regexBlacklist) {
|
lastLocalUpdate = lastLocalEdit;
|
||||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
synchronized(regexBlacklist) {
|
||||||
regexLocalBlacklist.clear();
|
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||||
localWhitelistMode = false;
|
regexLocalBlacklist.clear();
|
||||||
boolean foundWhitelistStatement = false;
|
localWhitelistMode = false;
|
||||||
String ss;
|
boolean foundWhitelistStatement = false;
|
||||||
while((ss = is.readLine()) != null) {
|
String ss;
|
||||||
try {
|
while((ss = is.readLine()) != null) {
|
||||||
if((ss = ss.trim()).length() > 0) {
|
try {
|
||||||
if(!ss.startsWith("#")) {
|
if((ss = ss.trim()).length() > 0) {
|
||||||
regexLocalBlacklist.add(Pattern.compile(ss));
|
if(!ss.startsWith("#")) {
|
||||||
}else {
|
regexLocalBlacklist.add(Pattern.compile(ss));
|
||||||
String st = ss.substring(1).trim();
|
}else {
|
||||||
if(st.startsWith("whitelistMode:")) {
|
String st = ss.substring(1).trim();
|
||||||
foundWhitelistStatement = true;
|
if(st.startsWith("whitelistMode:")) {
|
||||||
String str = st.substring(14).trim().toLowerCase();
|
foundWhitelistStatement = true;
|
||||||
localWhitelistMode = str.equals("true") || str.equals("on") || str.equals("1");
|
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) {
|
synchronized(regexBlacklist) {
|
||||||
if(!regexLocalBlacklist.isEmpty()) {
|
if(!regexLocalBlacklist.isEmpty()) {
|
||||||
logger.warn("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
|
logger.warn("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
|
||||||
}
|
|
||||||
regexLocalBlacklist.clear();
|
|
||||||
}
|
}
|
||||||
|
regexLocalBlacklist.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLocal(String o) {
|
public void addLocal(String o) {
|
||||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
synchronized(localBlacklistLock) {
|
||||||
ArrayList<String> lines = new ArrayList();
|
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||||
if(localBlacklist.exists()) {
|
ArrayList<String> lines = new ArrayList();
|
||||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
if(localBlacklist.exists()) {
|
||||||
String ss;
|
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||||
while((ss = is.readLine()) != null) {
|
String ss;
|
||||||
if((ss = ss.trim()).length() > 0) {
|
while((ss = is.readLine()) != null) {
|
||||||
lines.add(ss);
|
if((ss = ss.trim()).length() > 0) {
|
||||||
|
lines.add(ss);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}catch(IOException ex) {
|
||||||
|
// ?
|
||||||
}
|
}
|
||||||
}catch(IOException ex) {
|
|
||||||
// ?
|
|
||||||
}
|
}
|
||||||
}
|
if(lines.isEmpty()) {
|
||||||
if(lines.isEmpty()) {
|
lines.add("#whitelistMode: false");
|
||||||
lines.add("#whitelist false");
|
lines.add("");
|
||||||
lines.add("");
|
}
|
||||||
}
|
if(!lines.contains(p)) {
|
||||||
if(!lines.contains(p)) {
|
lines.add(p);
|
||||||
lines.add(p);
|
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
for(String s : lines) {
|
||||||
for(String s : lines) {
|
os.println(s);
|
||||||
os.println(s);
|
}
|
||||||
|
}catch(IOException ex) {
|
||||||
|
// ?
|
||||||
}
|
}
|
||||||
lastLocalUpdate = 0l;
|
lastLocalUpdate = 0l;
|
||||||
update();
|
update();
|
||||||
}catch(IOException ex) {
|
|
||||||
// ?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeLocal(String o) {
|
public boolean removeLocal(String o) {
|
||||||
String p = "^" + Pattern.quote(o.trim()) + "$";
|
synchronized(localBlacklistLock) {
|
||||||
ArrayList<String> lines = new ArrayList();
|
String p = "^" + Pattern.quote(o.trim()) + "$";
|
||||||
if(localBlacklist.exists()) {
|
ArrayList<String> lines = new ArrayList();
|
||||||
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
if(localBlacklist.exists()) {
|
||||||
String ss;
|
try(BufferedReader is = new BufferedReader(new FileReader(localBlacklist))) {
|
||||||
while((ss = is.readLine()) != null) {
|
String ss;
|
||||||
if((ss = ss.trim()).length() > 0) {
|
while((ss = is.readLine()) != null) {
|
||||||
lines.add(ss);
|
if((ss = ss.trim()).length() > 0) {
|
||||||
|
lines.add(ss);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}catch(IOException ex) {
|
||||||
|
// ?
|
||||||
}
|
}
|
||||||
}catch(IOException ex) {
|
|
||||||
// ?
|
|
||||||
}
|
}
|
||||||
}
|
if(lines.remove(p)) {
|
||||||
if(lines.contains(p)) {
|
try {
|
||||||
lines.remove(p);
|
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
||||||
try {
|
for(String s : lines) {
|
||||||
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
|
os.println(s);
|
||||||
for(String s : lines) {
|
}
|
||||||
os.println(s);
|
|
||||||
}
|
}
|
||||||
|
}catch(IOException ex) {
|
||||||
|
logger.error("Failed to save '" + localBlacklist.getName() + "'");
|
||||||
|
ex.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
lastLocalUpdate = 0l;
|
lastLocalUpdate = 0l;
|
||||||
update();
|
update();
|
||||||
return true;
|
return true;
|
||||||
}catch(IOException ex) {
|
|
||||||
logger.error("Failed to save '" + localBlacklist.getName() + "'");
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getLocalBlacklist() {
|
public File getLocalBlacklist() {
|
||||||
return localBlacklist;
|
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");
|
File configFile = new File(dataDir, "config.yml");
|
||||||
if(!configFile.exists()) {
|
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)) {
|
try(OutputStream os = new FileOutputStream(configFile)) {
|
||||||
byte[] copyBuffer = new byte[1024];
|
byte[] copyBuffer = new byte[1024];
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class OriginBlacklistListenerBungee implements Listener {
|
||||||
OriginBlacklist blacklist = plugin.list;
|
OriginBlacklist blacklist = plugin.list;
|
||||||
boolean shouldKick = true;
|
boolean shouldKick = true;
|
||||||
try {
|
try {
|
||||||
shouldKick = (origin == null && blacklist.getBlockClientsWithNoOriginHeader()) || blacklist.test(origin);
|
shouldKick = origin == null ? blacklist.getBlockClientsWithNoOriginHeader() : blacklist.test(OriginBlacklist.removeProtocolFromOrigin(origin));
|
||||||
}catch(Throwable t) {
|
}catch(Throwable t) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to check origin blacklist for: " + origin, 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);
|
evt.setCancelled(true);
|
||||||
String msg = blacklist.getKickMessage();
|
String msg = blacklist.getKickMessage();
|
||||||
if(msg != null) {
|
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"));
|
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is not online"));
|
||||||
}else {
|
}else {
|
||||||
if(user.getPendingConnection() instanceof EaglerInitialHandler) {
|
if(user.getPendingConnection() instanceof EaglerInitialHandler) {
|
||||||
Object o = ((EaglerInitialHandler)user.getPendingConnection()).getOrigin();
|
String o = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)user.getPendingConnection()).getOrigin());
|
||||||
if(o != null) {
|
if(o != null) {
|
||||||
if("null".equals(o)) {
|
if("null".equals(o)) {
|
||||||
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is on an offline download"));
|
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is on an offline download"));
|
||||||
}else {
|
}else {
|
||||||
OriginBlacklist bl = OriginBlacklistPluginBungee.getPlugin().list;
|
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 + "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."));
|
p0.sendMessage(new TextComponent(ChatColor.RED + "It was added to the local block list."));
|
||||||
user.disconnect(new TextComponent(bl.getKickMessage()));
|
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
p0.sendMessage(new TextComponent(ChatColor.RED + "Domain of " + p1[0] + " is unknown (desktop runtime?)"));
|
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;
|
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.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlacklistPluginBungee;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
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.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
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"));
|
p0.sendMessage(new TextComponent(ChatColor.RED + "Please follow this command by a domain"));
|
||||||
return;
|
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"));
|
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_missing_origin_header: false
|
||||||
origin_blacklist_block_offline_download: false
|
origin_blacklist_block_offline_download: false
|
||||||
origin_blacklist_block_replit_clients: false
|
origin_blacklist_block_replit_clients: false
|
||||||
enable_web_origin_blacklist: false
|
enable_web_origin_blacklist: false
|
||||||
origin_blacklist_subscriptions:
|
origin_blacklist_subscriptions:
|
||||||
- 'add url here'
|
- "add url here"
|
||||||
origin_blacklist_use_simple_whitelist: false
|
origin_blacklist_use_simple_whitelist: false
|
||||||
origin_blacklist_simple_whitelist:
|
origin_blacklist_simple_whitelist:
|
||||||
- 'type the name of your client\'s domain here'
|
- "type the name of your client's domain here"
|
||||||
- '(if \'origin_blacklist_use_simple_whitelist\' is true)'
|
- "(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
|
main: net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlacklistPluginBungee
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
description: Plugin for EaglercraftXBungee servers to add the "origin blacklist" feature from 1.5.2
|
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