Commit 4fdfd995 authored by Mygod's avatar Mygod

Warn about http urls

parent 398425f9
...@@ -156,7 +156,8 @@ class Acl { ...@@ -156,7 +156,8 @@ class Acl {
val child = Acl() val child = Acl()
try { try {
child.fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1) child.fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1)
} catch (_: IOException) { } catch (e: IOException) {
e.printStackTrace()
continue continue
} }
if (bypass != child.bypass) { if (bypass != child.bypass) {
......
...@@ -127,23 +127,26 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -127,23 +127,26 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = validate(position) override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) = validate(position)
private fun validate(template: Int = templateSelector.selectedItemPosition, value: Editable = editText.text) { private fun validate(template: Int = templateSelector.selectedItemPosition, value: Editable = editText.text) {
val error = when (Template.values()[template]) { var message = ""
Template.Generic -> if (value.isEmpty()) "" else null positive.isEnabled = when (Template.values()[template]) {
Template.Generic -> value.isNotEmpty()
Template.Domain -> try { Template.Domain -> try {
IDN.toASCII(value.toString(), IDN.ALLOW_UNASSIGNED or IDN.USE_STD3_ASCII_RULES) IDN.toASCII(value.toString(), IDN.ALLOW_UNASSIGNED or IDN.USE_STD3_ASCII_RULES)
null true
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
e.cause?.message ?: e.message message = e.cause?.localizedMessage ?: e.localizedMessage
false
} }
Template.Url -> try { Template.Url -> try {
URL(value.toString()) val url = URL(value.toString())
null if ("http".equals(url.protocol, true)) message = getString(R.string.cleartext_http_warning)
true
} catch (e: MalformedURLException) { } catch (e: MalformedURLException) {
e.message message = e.localizedMessage
false
} }
} }
inputLayout.error = error inputLayout.error = message
positive.isEnabled = error == null
} }
fun add(): Int? { fun add(): Int? {
......
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
<string name="acl_rule_templates_domain">Domain name and all its subdomain names</string> <string name="acl_rule_templates_domain">Domain name and all its subdomain names</string>
<string name="acl_rule_online_config">URL to online config</string> <string name="acl_rule_online_config">URL to online config</string>
<string name="edit_rule">Edit rule</string> <string name="edit_rule">Edit rule</string>
<string name="cleartext_http_warning">Cleartext HTTP traffic is insecure</string>
<!-- plugin --> <!-- plugin -->
<string name="plugin">Plugin</string> <string name="plugin">Plugin</string>
......
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