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