Commit 4fdfd995 authored by Mygod's avatar Mygod

Warn about http urls

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