Commit 6911b941 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added a button to create dns rules from logged queries

parent 0509030a
......@@ -9,7 +9,13 @@ import androidx.fragment.app.Fragment
import com.frostnerd.dnstunnelproxy.QueryListener
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.database.entities.DnsQuery
import com.frostnerd.smokescreen.database.entities.DnsRule
import com.frostnerd.smokescreen.database.getDatabase
import com.frostnerd.smokescreen.dialog.DnsRuleDialog
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_dns_rules.*
import kotlinx.android.synthetic.main.fragment_querylog_detail.*
import org.minidns.record.Record
import java.text.DateFormat
import java.util.*
......@@ -79,6 +85,29 @@ class QueryLogDetailFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewCreated = true
updateUi()
createDnsRule.setOnClickListener {
val query = currentQuery
if(query != null) {
DnsRuleDialog(context!!, DnsRule(query.type, query.name, if(query.type == Record.TYPE.A) "0.0.0.0" else "::1"), onRuleCreated = { newRule ->
val id = if (newRule.isWhitelistRule()) {
getDatabase().dnsRuleDao().insertWhitelist(newRule)
} else getDatabase().dnsRuleDao().insertIgnore(newRule)
if (id != -1L) {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
R.string.windows_querylogging_dnsrule_created,
Snackbar.LENGTH_LONG
).show()
} else {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
R.string.window_dnsrules_hostalreadyexists,
Snackbar.LENGTH_LONG
).show()
}
}).show()
}
}
}
fun isShowingQuery(): Boolean {
......
......@@ -9,8 +9,8 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
......@@ -202,5 +202,14 @@
android:layout_marginTop="8dp"
android:layout_height="wrap_content"/>
</RelativeLayout>
<Button
android:layout_width="match_parent"
android:id="@+id/createDnsRule"
android:background="@drawable/main_roundbuttons"
android:text="@string/windows_querylogging_create_dnsrule"
android:layout_marginTop="24dp"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
......@@ -83,4 +83,6 @@
<string name="windows_querylogging_used_server">Used server</string>
<string name="windows_querylogging_protocol">Protocol</string>
<string name="windows_querylogging_latency">Latency</string>
<string name="windows_querylogging_create_dnsrule">Create dns rule for this host</string>
<string name="windows_querylogging_dnsrule_created">Dns rule has been created.</string>
</resources>
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