Allow local DNS server

This commit is contained in:
M66B 2019-05-21 21:07:23 +02:00
parent eba4e7200a
commit f1948e7c5d
1 changed files with 9 additions and 7 deletions

View File

@ -630,7 +630,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
else if ("vpn4".equals(name)) {
String vpn4 = prefs.getString(name, null);
try {
checkAddress(vpn4);
checkAddress(vpn4, false);
prefs.edit().putString(name, vpn4.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
@ -645,7 +645,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
} else if ("vpn6".equals(name)) {
String vpn6 = prefs.getString(name, null);
try {
checkAddress(vpn6);
checkAddress(vpn6, false);
prefs.edit().putString(name, vpn6.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
@ -660,7 +660,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
} else if ("dns".equals(name) || "dns2".equals(name)) {
String dns = prefs.getString(name, null);
try {
checkAddress(dns);
checkAddress(dns, true);
prefs.edit().putString(name, dns.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
@ -783,16 +783,18 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
ServiceSinkhole.reload("permission granted", this, false);
}
private void checkAddress(String address) throws IllegalArgumentException, UnknownHostException {
private void checkAddress(String address, boolean allow_local) throws IllegalArgumentException, UnknownHostException {
if (address != null)
address = address.trim();
if (TextUtils.isEmpty(address))
throw new IllegalArgumentException("Bad address");
if (!Util.isNumericAddress(address))
throw new IllegalArgumentException("Bad address");
InetAddress idns = InetAddress.getByName(address);
if (idns.isLoopbackAddress() || idns.isAnyLocalAddress())
throw new IllegalArgumentException("Bad address");
if (!allow_local) {
InetAddress iaddr = InetAddress.getByName(address);
if (iaddr.isLoopbackAddress() || iaddr.isAnyLocalAddress())
throw new IllegalArgumentException("Bad address");
}
}
private BroadcastReceiver interactiveStateReceiver = new BroadcastReceiver() {