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,16 +118,24 @@ 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);
|
||||
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) {
|
||||
//Log.d(TAG, strLine);
|
||||
if (!strLine.equals("") && !strLine.startsWith("#")) {
|
||||
data = strLine.split("/");
|
||||
if (data.length == 3 && data[0].equals("address=")) {
|
||||
@ -144,6 +152,7 @@ public class RulesResolver implements Runnable {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
status = STATUS_LOADED;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user