From 29b60b3ba76390bcdba3b1701228fcbb27f1a411 Mon Sep 17 00:00:00 2001 From: PeratX Date: Tue, 24 May 2022 11:37:44 +0800 Subject: [PATCH] rules: support more dnsmasq rules. close #122 --- .../main/java/org/itxtech/daedalus/Daedalus.java | 6 ++++-- .../org/itxtech/daedalus/util/RuleResolver.java | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 1bc40f2..48cc330 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -57,11 +57,13 @@ public class Daedalus extends Application { public static final ArrayList RULES = new ArrayList() {{ add(new Rule("googlehosts/hosts", "googlehosts.hosts", Rule.TYPE_HOSTS, "https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts", false)); - add(new Rule("vokins/yhosts", "vokins.hosts", Rule.TYPE_HOSTS, - "https://raw.githubusercontent.com/vokins/yhosts/master/hosts", false)); + add(new Rule("VeleSila/yhosts", "vokins.hosts", Rule.TYPE_HOSTS, + "https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts.txt", false)); add(new Rule("adaway", "adaway.hosts", Rule.TYPE_HOSTS, "https://adaway.org/hosts.txt", false)); //Build-in DNSMasq rule providers + add(new Rule("anti-AD", "antiad.dnsmasq", Rule.TYPE_DNAMASQ, + "https://anti-ad.net/anti-ad-for-dnsmasq.conf", false)); add(new Rule("vokins/yhosts/union", "union.dnsmasq", Rule.TYPE_DNAMASQ, "https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf", false)); }}; diff --git a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java index 141680b..a301d4c 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java +++ b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java @@ -108,7 +108,7 @@ private void load() { for (String hostsFile : hostsFiles) { File file = new File(hostsFile); if (file.canRead()) { - Logger.info("Loading hosts from " + file.toString()); + Logger.info("Loading hosts from " + file); FileInputStream stream = new FileInputStream(file); BufferedReader dataIO = new BufferedReader(new InputStreamReader(stream)); String strLine; @@ -136,7 +136,7 @@ private void load() { for (String dnsmasqFile : dnsmasqFiles) { File file = new File(dnsmasqFile); if (file.canRead()) { - Logger.info("Loading DNSMasq configuration from " + file.toString()); + Logger.info("Loading DNSMasq configuration from " + file); FileInputStream stream = new FileInputStream(file); BufferedReader dataIO = new BufferedReader(new InputStreamReader(stream)); String strLine; @@ -145,7 +145,12 @@ private void load() { while ((strLine = dataIO.readLine()) != null) { if (!strLine.equals("") && !strLine.startsWith("#")) { data = strLine.split("/"); - if (data.length == 3 && data[0].equals("address=")) { + if (data.length >= 2 && data[0].equals("address=")) { + if (data.length == 2) { + rulesA.put(data[1], "0.0.0.0"); + count++; + continue; + } if (data[1].startsWith(".")) { data[1] = data[1].substring(1); } @@ -153,6 +158,8 @@ private void load() { rulesAAAA.put(data[1], data[2]); } else if (strLine.contains(".")) {//IPv4 rulesA.put(data[1], data[2]); + } else { + rulesA.put(data[1], "0.0.0.0"); } count++; }