added origin whitelist config option
This commit is contained in:
parent
e4b8d315b4
commit
57e08aca85
|
@ -32,6 +32,10 @@ public interface ConfigurationAdapter {
|
|||
|
||||
boolean getBlacklistOriginless();
|
||||
|
||||
boolean getSimpleWhitelistEnabled();
|
||||
|
||||
Collection<String> getBlacklistSimpleWhitelist();
|
||||
|
||||
AuthServiceInfo getAuthSettings();
|
||||
|
||||
Map<String, Object> getMap();
|
||||
|
|
|
@ -320,4 +320,22 @@ public class YamlConfig implements ConfigurationAdapter {
|
|||
return this.getBoolean("origin_blacklist_block_missing_origin_header", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSimpleWhitelistEnabled() {
|
||||
return this.getBoolean("origin_blacklist_use_simple_whitelist", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getBlacklistSimpleWhitelist() {
|
||||
Collection<String> c = this.get("origin_blacklist_simple_whitelist", null);
|
||||
if(c == null) {
|
||||
c = new ArrayList();
|
||||
c.add("type the name of your client's domain here");
|
||||
c.add("(if 'origin_blacklist_use_simple_whitelist' is true)");
|
||||
c.add("g.eags.us");
|
||||
c = this.get("origin_blacklist_simple_whitelist", c);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.net.URLConnection;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
|
@ -25,10 +26,13 @@ public class DomainBlacklist {
|
|||
public static final Collection<Pattern> regexBlacklist = new ArrayList();
|
||||
public static final Collection<Pattern> regexLocalBlacklist = new ArrayList();
|
||||
public static final Collection<Pattern> regexBlacklistReplit = new ArrayList();
|
||||
public static final Collection<String> simpleWhitelist = new ArrayList();
|
||||
public static final File localBlacklist = new File("origin_blacklist.txt");
|
||||
private static Collection<String> blacklistSubscriptions = null;
|
||||
private static boolean blockOfflineDownload = false;
|
||||
private static boolean blockAllReplits = false;
|
||||
private static boolean localWhitelistMode = false;
|
||||
private static boolean simpleWhitelistMode = false;
|
||||
private static final HashSet<String> brokenURLs = new HashSet();
|
||||
private static final HashSet<String> brokenRegex = new HashSet();
|
||||
|
||||
|
@ -51,6 +55,24 @@ public class DomainBlacklist {
|
|||
if(blockOfflineDownload && origin.equalsIgnoreCase("null")) {
|
||||
return true;
|
||||
}
|
||||
if(simpleWhitelistMode) {
|
||||
for(String st : simpleWhitelist) {
|
||||
if(origin.equalsIgnoreCase(st)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(localWhitelistMode || simpleWhitelistMode) {
|
||||
if(!blockOfflineDownload && origin.equalsIgnoreCase("null")) {
|
||||
return false;
|
||||
}
|
||||
for(Pattern m : regexLocalBlacklist) {
|
||||
if(m.matcher(origin).matches()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
if(blockAllReplits) {
|
||||
for(Pattern m : regexBlacklistReplitInternal) {
|
||||
if(m.matcher(origin).matches()) {
|
||||
|
@ -73,9 +95,10 @@ public class DomainBlacklist {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(BungeeCord bg) {
|
||||
synchronized(regexBlacklist) {
|
||||
|
@ -84,10 +107,13 @@ public class DomainBlacklist {
|
|||
regexBlacklist.clear();
|
||||
regexLocalBlacklist.clear();
|
||||
regexBlacklistReplit.clear();
|
||||
simpleWhitelist.clear();
|
||||
ConfigurationAdapter cfg = bg.getConfigurationAdapter();
|
||||
blacklistSubscriptions = cfg.getBlacklistURLs();
|
||||
blockOfflineDownload = cfg.getBlacklistOfflineDownload();
|
||||
blockAllReplits = cfg.getBlacklistReplits();
|
||||
simpleWhitelistMode = cfg.getSimpleWhitelistEnabled();
|
||||
simpleWhitelist.addAll(cfg.getBlacklistSimpleWhitelist());
|
||||
lastLocalUpdate = 0l;
|
||||
lastUpdate = System.currentTimeMillis() - updateRate - 1000l;
|
||||
update();
|
||||
|
@ -199,21 +225,48 @@ public class DomainBlacklist {
|
|||
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) {
|
||||
System.err.println("ERROR: the local blacklist regex '" + ss + "' is invalid");
|
||||
System.err.println("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("");
|
||||
BufferedReader is2 = new BufferedReader(new FileReader(localBlacklist));
|
||||
while((ss = is2.readLine()) != null) {
|
||||
newLines.add(ss);
|
||||
}
|
||||
is2.close();
|
||||
PrintWriter os = new PrintWriter(new FileWriter(localBlacklist));
|
||||
for(String str : newLines) {
|
||||
os.println(str);
|
||||
}
|
||||
os.close();
|
||||
lastLocalUpdate = localBlacklist.lastModified();
|
||||
}
|
||||
System.out.println("Reloaded '" + localBlacklist.getName() + "'.");
|
||||
}catch(IOException ex) {
|
||||
regexLocalBlacklist.clear();
|
||||
System.err.println("ERROR: failed to read local blacklist file '" + localBlacklist.getName() + "'");
|
||||
System.err.println("ERROR: failed to read local " + (localWhitelistMode ? "whitelist" : "blacklist") + " file '" + localBlacklist.getName() + "'");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +298,10 @@ public class DomainBlacklist {
|
|||
// ?
|
||||
}
|
||||
}
|
||||
if(lines.isEmpty()) {
|
||||
lines.add("#whitelist false");
|
||||
lines.add("");
|
||||
}
|
||||
if(!lines.contains(p)) {
|
||||
lines.add(p);
|
||||
try {
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user