Skip to content

Commit

Permalink
rules: support more dnsmasq rules. close #122
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed May 24, 2022
1 parent e559925 commit 29b60b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/org/itxtech/daedalus/Daedalus.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public class Daedalus extends Application {
public static final ArrayList<Rule> RULES = new ArrayList<Rule>() {{
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));
}};
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -145,14 +145,21 @@ 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);
}
if (strLine.contains(":")) {//IPv6
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++;
}
Expand Down

0 comments on commit 29b60b3

Please sign in to comment.