Implemented hosts pan domain name resolution

This commit is contained in:
PeratX 2017-04-29 10:30:12 +08:00
parent d27b30776a
commit 6ef5be809e
6 changed files with 53 additions and 10 deletions

View File

@ -12,7 +12,7 @@ Local hosts is located in SDCard/Android/data/org.itxtech.daedalus/files <br>
<br>
__Users must comply with local laws and regulations.__<br>
DNS providers
DNS server providers
-------------
* __CuteDNS!__ - *Stop service due to police intervention.*
* __[Pure DNS](http://puredns.cn/)__ - *I DO NOT KNOW HOW TO DESCRIBE~~~*

View File

@ -103,6 +103,7 @@ public class Daedalus extends Application {
}
}
HostsResolver.startLoad(hostsPath);
HostsResolver.setPanResolution(Daedalus.getPrefs().getBoolean("settings_pan_resolution", false));
}
}
public static SharedPreferences getPrefs() {

View File

@ -30,6 +30,7 @@ public class HostsResolver implements Runnable {
private static String fileName;
private static HashMap<String, String> hosts;
private static boolean shutdown = false;
private static boolean panResolution = false;
public HostsResolver() {
status = STATUS_NOT_LOADED;
@ -51,16 +52,50 @@ public class HostsResolver implements Runnable {
status = STATUS_PENDING_LOAD;
}
public static void setPanResolution(boolean resolution) {
panResolution = resolution;
}
public static void clean() {
hosts = null;
}
public static boolean canResolve(String hostname) {
return hosts.containsKey(hostname);
if (hosts.containsKey(hostname)) {
return true;
}
if (panResolution) {
String[] pieces = hostname.split("\\.");
StringBuilder builder;
builder = new StringBuilder();
builder.append("*");
for (int i = 1; i < pieces.length; i++) {
builder.append(".").append(pieces[i]);
}
if (hosts.containsKey(builder.toString())) {
return true;
}
}
return false;
}
public static String resolve(String hostname) {
return hosts.get(hostname);
if (hosts.containsKey(hostname)) {
return hosts.get(hostname);
}
if (panResolution) {
String[] pieces = hostname.split("\\.");
StringBuilder builder;
builder = new StringBuilder();
builder.append("*");
for (int i = 1; i < pieces.length; i++) {
builder.append(".").append(pieces[i]);
}
if (hosts.containsKey(builder.toString())) {
return hosts.get(builder.toString());
}
}
return "";
}
private void load() {

View File

@ -43,7 +43,7 @@
<string name="nav_github">GitHub</string>
<string name="settings_advanced">高级系统设置</string>
<string name="settings_advanced_on">开启</string>
<string name="settings_local_hosts_resolve">本地 hosts 解析</string>
<string name="settings_local_hosts_resolution">本地 hosts 解析</string>
<string name="notice_need_restart">重新启用 Daedalus 以应用设置。</string>
<string name="notice_need_storage_perm">Daedalus 需要访问外部储存以实现本地 hosts 解析。</string>
<string name="action_hosts">Hosts</string>
@ -55,4 +55,5 @@
<string name="hosts_path">本地 hosts 路径:</string>
<string name="hosts_last_modified">最后修改:</string>
<string name="hosts_size">大小:</string>
<string name="settings_hosts_pan_domain_resolution">Hosts 域名泛解析</string>
</resources>

View File

@ -9,14 +9,14 @@
<string name="settings_system">System settings</string>
<string name="settings_boot">Auto activate on boot</string>
<string name="settings_server">Server settings</string>
<string name="primary_server">Primary DNS</string>
<string name="secondary_server">Secondary DNS</string>
<string name="notice_start_test">Testing specified DNS …</string>
<string name="primary_server">Primary DNS server</string>
<string name="secondary_server">Secondary DNS server</string>
<string name="notice_start_test">Testing specified DNS server </string>
<string name="action_dns_test">Test</string>
<string name="action_start_test">Start test</string>
<string name="test_domain">Test domain:</string>
<string name="test_time_used">Time used:</string>
<string name="test_dns_server">DNS:</string>
<string name="test_dns_server">DNS server:</string>
<string name="test_result_resolved">Address:</string>
<string name="test_failed">DNS query failed. Timeout or unknown hostname.</string>
<string name="test_test_domain">google.com</string>
@ -42,7 +42,7 @@
<string name="nav_github">GitHub</string>
<string name="settings_advanced">Advanced system settings</string>
<string name="settings_advanced_on">On</string>
<string name="settings_local_hosts_resolve">Local hosts resolution</string>
<string name="settings_local_hosts_resolution">Local hosts resolution</string>
<string name="notice_need_restart">Re-activate Daedalus to make the settings take effect.</string>
<string name="notice_need_storage_perm">Daedalus requires access to external storage for local host resolution.
</string>
@ -55,4 +55,5 @@
<string name="hosts_path">Local hosts path:</string>
<string name="hosts_last_modified">Last modified:</string>
<string name="hosts_size">Size:</string>
<string name="settings_hosts_pan_domain_resolution">Hosts pan domain name resolution</string>
</resources>

View File

@ -51,7 +51,12 @@
android:enabled="false"/>
<SwitchPreference
android:key="settings_local_host_resolution"
android:title="@string/settings_local_hosts_resolve"
android:title="@string/settings_local_hosts_resolution"
android:defaultValue="false"
android:enabled="false"/>
<SwitchPreference
android:key="settings_pan_resolution"
android:title="@string/settings_hosts_pan_domain_resolution"
android:defaultValue="false"
android:enabled="false"/>
</PreferenceCategory>