Added support for multi dnsmasq configs
This commit is contained in:
parent
471a59e2c7
commit
d63451c155
@ -92,9 +92,12 @@ public class Daedalus extends Application {
|
||||
mHostsResolver.start();
|
||||
|
||||
hostsPath = getExternalFilesDir(null).getPath() + "/hosts";
|
||||
dnsmasqPath = getExternalFilesDir(null).getPath() + "/dnsmasq";
|
||||
dnsmasqPath = getExternalFilesDir(null).getPath() + "/dnsmasq/";
|
||||
configPath = getExternalFilesDir(null).getPath() + "/config.json";
|
||||
|
||||
File file = new File(dnsmasqPath);
|
||||
Log.d(TAG, "mkdir result: " + file.mkdirs());
|
||||
|
||||
initData();
|
||||
|
||||
instance = this;
|
||||
|
@ -132,10 +132,6 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
if (mThread != null) {
|
||||
running = false;
|
||||
shouldRefresh = true;
|
||||
provider.shutdown();
|
||||
mThread.interrupt();
|
||||
provider.stop();
|
||||
mThread = null;
|
||||
if (provider != null) {
|
||||
provider.shutdown();
|
||||
mThread.interrupt();
|
||||
|
@ -33,14 +33,14 @@ public class RulesResolver implements Runnable {
|
||||
private static int status = STATUS_NOT_LOADED;
|
||||
private static int mode = MODE_HOSTS;
|
||||
private static String hostsFile;
|
||||
private static String dnsmasqFile;
|
||||
private static String dnsmasqPath;
|
||||
private static HashMap<String, String> rules;
|
||||
private static boolean shutdown = false;
|
||||
|
||||
public RulesResolver() {
|
||||
status = STATUS_NOT_LOADED;
|
||||
hostsFile = "";
|
||||
dnsmasqFile = "";
|
||||
dnsmasqPath = "";
|
||||
shutdown = false;
|
||||
}
|
||||
|
||||
@ -59,9 +59,9 @@ public class RulesResolver implements Runnable {
|
||||
status = STATUS_PENDING_LOAD;
|
||||
}
|
||||
|
||||
public static void startLoadDnsmasq(String loadFile) {
|
||||
Log.d(TAG, "Loading DNSMasq file " + loadFile);
|
||||
dnsmasqFile = loadFile;
|
||||
public static void startLoadDnsmasq(String loadPath) {
|
||||
Log.d(TAG, "Loading DNSMasq file " + loadPath);
|
||||
dnsmasqPath = loadPath;
|
||||
mode = MODE_DNSMASQ;
|
||||
status = STATUS_PENDING_LOAD;
|
||||
}
|
||||
@ -118,30 +118,39 @@ public class RulesResolver implements Runnable {
|
||||
|
||||
dataIO.close();
|
||||
stream.close();
|
||||
} else {
|
||||
status = STATUS_NOT_LOADED;
|
||||
return;
|
||||
}
|
||||
} else if (mode == MODE_DNSMASQ) {
|
||||
File file = new File(dnsmasqFile);
|
||||
if (file.exists() && file.canRead()) {
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
BufferedReader dataIO = new BufferedReader(new InputStreamReader(stream));
|
||||
String strLine;
|
||||
String[] data;
|
||||
while ((strLine = dataIO.readLine()) != null) {
|
||||
//Log.d(TAG, strLine);
|
||||
if (!strLine.equals("") && !strLine.startsWith("#")) {
|
||||
data = strLine.split("/");
|
||||
if (data.length == 3 && data[0].equals("address=")) {
|
||||
if (data[1].startsWith(".")) {
|
||||
data[1] = data[1].substring(1, data[1].length());
|
||||
File file = new File(dnsmasqPath);
|
||||
if (!file.mkdirs() && !file.exists()) {
|
||||
status = STATUS_NOT_LOADED;
|
||||
return;
|
||||
}
|
||||
for (File conf : file.listFiles()) {
|
||||
if (file.canRead()) {
|
||||
Log.d(TAG, "load: Loading DNSMasq configuration " + conf.toString());
|
||||
FileInputStream stream = new FileInputStream(conf);
|
||||
BufferedReader dataIO = new BufferedReader(new InputStreamReader(stream));
|
||||
String strLine;
|
||||
String[] data;
|
||||
while ((strLine = dataIO.readLine()) != null) {
|
||||
if (!strLine.equals("") && !strLine.startsWith("#")) {
|
||||
data = strLine.split("/");
|
||||
if (data.length == 3 && data[0].equals("address=")) {
|
||||
if (data[1].startsWith(".")) {
|
||||
data[1] = data[1].substring(1, data[1].length());
|
||||
}
|
||||
rules.put(data[1], data[2]);
|
||||
Log.d(TAG, "Putting " + data[1] + " " + data[2]);
|
||||
}
|
||||
rules.put(data[1], data[2]);
|
||||
Log.d(TAG, "Putting " + data[1] + " " + data[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataIO.close();
|
||||
stream.close();
|
||||
dataIO.close();
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
status = STATUS_LOADED;
|
||||
|
Loading…
Reference in New Issue
Block a user