Commit 356bf4d8 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Only use rules defined by the user if they are enabled

parent f53fecca
......@@ -23,6 +23,10 @@ import com.frostnerd.smokescreen.util.SpaceItemDecorator
import kotlinx.android.synthetic.main.activity_dns_rules.*
import kotlinx.android.synthetic.main.activity_dns_rules.toolBar
import kotlinx.android.synthetic.main.item_datasource.view.*
import kotlinx.android.synthetic.main.item_datasource.view.cardContent
import kotlinx.android.synthetic.main.item_datasource.view.delete
import kotlinx.android.synthetic.main.item_datasource.view.enable
import kotlinx.android.synthetic.main.item_datasource.view.text
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
......
......@@ -51,8 +51,8 @@ interface DnsRuleDao {
@Query("SELECT COUNT(*) FROM DnsRule")
fun getCount(): Long
@Query("SELECT target FROM DnsRule WHERE host=:host AND type = :type AND (importedFrom is NULL OR (SELECT enabled FROM HostSource h WHERE h.id=importedFrom) = 1) LIMIT 1")
fun findRuleTarget(host: String, type: Record.TYPE): String?
@Query("SELECT target FROM DnsRule WHERE host=:host AND type = :type AND (importedFrom is NULL OR (SELECT enabled FROM HostSource h WHERE h.id=importedFrom) = 1) AND (importedFrom IS NOT NULL OR :useUserRules=1)LIMIT 1")
fun findRuleTarget(host: String, type: Record.TYPE, useUserRules:Boolean): String?
@Query("DELETE FROM DnsRule WHERE importedFrom=:sourceId")
fun deleteAllFromSource(sourceId: Long)
......
......@@ -922,13 +922,14 @@ class DnsVpnService : VpnService(), Runnable {
private val dao = getDatabase().dnsRuleDao()
private val resolveResults = mutableMapOf<Question, String>()
private val wwwRegex = Regex("^www\\.")
private val useUserRules = getPreferences().customHostsEnabled
override suspend fun canResolve(question: Question): Boolean {
return if(question.type != Record.TYPE.A && question.type != Record.TYPE.AAAA) {
false
} else {
val uniformQuestion = question.name.toString().replace(wwwRegex, "")
val resolveResult = dao.findRuleTarget(uniformQuestion, question.type)
val resolveResult = dao.findRuleTarget(uniformQuestion, question.type, useUserRules)
if (resolveResult != null) {
resolveResults[question] = resolveResult
true
......
Supports Markdown
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