aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2017-07-01 15:32:47 +0200
committerPacien TRAN-GIRARD2017-07-01 15:32:47 +0200
commit85a3892d4ecad4aae98f062e824f54e477bf8912 (patch)
tree6e6901f3ed5f1fe0cebf26551608f219132bd47f /app/src/main/java
parent3619cf121b5b496ede1a0588f77b44f9bdb8386b (diff)
downloadtincapp-85a3892d4ecad4aae98f062e824f54e477bf8912.tar.gz
Remove permission fixing options
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt7
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt20
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt52
3 files changed, 0 insertions, 79 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
index 6d39a9d..71d5403 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -13,7 +13,6 @@ import android.widget.FrameLayout
13import kotlinx.android.synthetic.main.base.* 13import kotlinx.android.synthetic.main.base.*
14 14
15import org.pacien.tincapp.R 15import org.pacien.tincapp.R
16import org.pacien.tincapp.commands.PermissionFixer
17import org.pacien.tincapp.context.AppPaths 16import org.pacien.tincapp.context.AppPaths
18import org.pacien.tincapp.service.TincVpnService 17import org.pacien.tincapp.service.TincVpnService
19 18
@@ -63,7 +62,6 @@ class StartActivity : BaseActivity() {
63 AlertDialog.Builder(this) 62 AlertDialog.Builder(this)
64 .setTitle(R.string.title_tinc_config_dir) 63 .setTitle(R.string.title_tinc_config_dir)
65 .setMessage(confDir) 64 .setMessage(confDir)
66 .setNeutralButton(R.string.action_fix_perms) { _, _ -> fixPerms() }
67 .setNegativeButton(R.string.action_copy) { _, _ -> copyIntoClipboard(resources.getString(R.string.title_tinc_config_dir), confDir) } 65 .setNegativeButton(R.string.action_copy) { _, _ -> copyIntoClipboard(resources.getString(R.string.title_tinc_config_dir), confDir) }
68 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } 66 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
69 .show() 67 .show()
@@ -74,9 +72,4 @@ class StartActivity : BaseActivity() {
74 .putExtra(TincVpnService.INTENT_EXTRA_NET_NAME, netName)) 72 .putExtra(TincVpnService.INTENT_EXTRA_NET_NAME, netName))
75 } 73 }
76 74
77 private fun fixPerms() {
78 val ok = PermissionFixer.makePrivateDirsPublic(applicationContext)
79 notify(if (ok) R.string.message_perms_fixed else R.string.message_perms_fix_failure)
80 }
81
82} 75}
diff --git a/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt b/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt
deleted file mode 100644
index 493927c..0000000
--- a/app/src/main/java/org/pacien/tincapp/commands/PermissionFixer.kt
+++ /dev/null
@@ -1,20 +0,0 @@
1package org.pacien.tincapp.commands
2
3import android.annotation.SuppressLint
4import android.content.Context
5import org.pacien.tincapp.context.AppPaths
6import java.io.File
7
8/**
9 * @author pacien
10 */
11object PermissionFixer {
12
13 @SuppressLint("SetWorldReadable", "SetWorldWritable")
14 private fun setAllRWXPermissions(f: File): Boolean =
15 f.setReadable(true, false) && f.setWritable(true, false) && f.setExecutable(true, false)
16
17 fun makePrivateDirsPublic(ctx: Context): Boolean = listOf(AppPaths.confDir(ctx), AppPaths.logDir(ctx), AppPaths.pidDir(ctx))
18 .map { setAllRWXPermissions(it) }.all { it }
19
20}
diff --git a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt b/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt
deleted file mode 100644
index 8104940..0000000
--- a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfigurator.kt
+++ /dev/null
@@ -1,52 +0,0 @@
1package org.pacien.tincapp.service
2
3import android.net.VpnService
4import org.apache.commons.configuration2.Configuration
5import org.apache.commons.configuration2.builder.fluent.Configurations
6import org.apache.commons.configuration2.ex.ConfigurationException
7import java.io.File
8
9/**
10 * @author pacien
11 */
12object VpnInterfaceConfigurator {
13
14 val KEY_ADDRESSES = "Address"
15 val KEY_ROUTES = "Route"
16 val KEY_DNS_SERVERS = "DNSServer"
17 val KEY_SEARCH_DOMAINS = "SearchDomain"
18 val KEY_ALLOWED_APPLICATIONS = "AllowApplication"
19 val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication"
20 val KEY_ALLOWED_FAMILIES = "AllowFamily"
21 val KEY_ALLOW_BYPASS = "AllowBypass"
22 val KEY_BLOCKING = "Blocking"
23 val KEY_MTU = "MTU"
24
25 private fun Configuration.getStringList(key: String): List<String> =
26 getList(String::class.java, key, emptyList())
27
28 private fun Configuration.getCidrList(key: String): List<CidrAddress> =
29 getStringList(key).map { CidrAddress(it) }
30
31 private fun Configuration.getIntList(key: String): List<Int> =
32 getList(Int::class.java, key, emptyList())
33
34 fun applyConfiguration(net: VpnService.Builder, cfg: Configuration): VpnService.Builder = net
35 .addAddresses(cfg.getCidrList(KEY_ADDRESSES))
36 .addRoutes(cfg.getCidrList(KEY_ROUTES))
37 .addDnsServers(cfg.getStringList(KEY_DNS_SERVERS))
38 .addSearchDomains(cfg.getStringList(KEY_SEARCH_DOMAINS))
39 .addAllowedApplications(cfg.getStringList(KEY_ALLOWED_APPLICATIONS))
40 .addDisallowedApplications(cfg.getStringList(KEY_DISALLOWED_APPLICATIONS))
41 .allowFamilies(cfg.getIntList(KEY_ALLOWED_FAMILIES))
42 .allowBypass(cfg.getBoolean(KEY_ALLOW_BYPASS, false))
43 .setBlocking(cfg.getBoolean(KEY_BLOCKING, false))
44 .overrideMtu(cfg.getInteger(KEY_MTU, null))
45
46 fun applyConfiguration(net: VpnService.Builder, cfg: File): VpnService.Builder = try {
47 applyConfiguration(net, Configurations().properties(cfg))
48 } catch (e: ConfigurationException) {
49 throw IllegalArgumentException(e.message)
50 }
51
52}