Commit aa533184 authored by Max Lv's avatar Max Lv

Refine #1489

parent 7688cbe2
...@@ -46,6 +46,7 @@ class Acl { ...@@ -46,6 +46,7 @@ class Acl {
val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex() val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex()
fun getFile(id: String) = File(app.filesDir, id + ".acl") fun getFile(id: String) = File(app.filesDir, id + ".acl")
val customRules: Acl get() { val customRules: Acl get() {
val acl = Acl() val acl = Acl()
try { try {
...@@ -143,6 +144,7 @@ class Acl { ...@@ -143,6 +144,7 @@ class Acl {
for (item in (if (bypass) proxySubnets else bypassSubnets).asIterable()) this.subnets.add(item) for (item in (if (bypass) proxySubnets else bypassSubnets).asIterable()) this.subnets.add(item)
return this return this
} }
fun fromId(id: String): Acl = fromReader(Acl.getFile(id).bufferedReader()) fun fromId(id: String): Acl = fromReader(Acl.getFile(id).bufferedReader())
fun flatten(depth: Int): Acl { fun flatten(depth: Int): Acl {
......
...@@ -238,6 +238,22 @@ object BaseService { ...@@ -238,6 +238,22 @@ object BaseService {
Acl.getFile(if (route == Acl.CUSTOM_RULES) Acl.CUSTOM_RULES_FLATTENED else route) Acl.getFile(if (route == Acl.CUSTOM_RULES) Acl.CUSTOM_RULES_FLATTENED else route)
} }
fun getListFile(): File? {
val aclFile = getAclFile() ?: return null
val listFile = File(aclFile.absolutePath + ".lst")
val list = StringBuilder()
aclFile.bufferedReader().useLines {
for (line in it) {
if (line.startsWith("^(.*\\.)?")) {
list.append(line.substring(8).replace("\\","").replace("$",""))
list.append("\n")
}
}
}
listFile.bufferedWriter().use { it.write(list.toString()) }
return listFile
}
fun createNotification(): ServiceNotification fun createNotification(): ServiceNotification
fun startRunner() { fun startRunner() {
......
...@@ -89,7 +89,7 @@ object LocalDnsService { ...@@ -89,7 +89,7 @@ object LocalDnsService {
.put("PrimaryDNS", localDns) .put("PrimaryDNS", localDns)
.put("AlternativeDNS", remoteDns) .put("AlternativeDNS", remoteDns)
.put("IPNetworkFile", "china_ip_list.txt") .put("IPNetworkFile", "china_ip_list.txt")
.put("DomainFile", getAclFile()!!.absolutePath) .put("DomainFile", getListFile()!!.absolutePath)
Acl.CHINALIST -> config Acl.CHINALIST -> config
.put("PrimaryDNS", localDns) .put("PrimaryDNS", localDns)
.put("AlternativeDNS", remoteDns) .put("AlternativeDNS", remoteDns)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment