aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt62
1 files changed, 0 insertions, 62 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt b/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt
deleted file mode 100644
index 50ccb20..0000000
--- a/app/src/main/java/org/pacien/tincapp/service/VpnInterfaceConfiguraton.kt
+++ /dev/null
@@ -1,62 +0,0 @@
1package org.pacien.tincapp.service
2
3/**
4 * @author pacien
5 */
6
7import org.apache.commons.configuration2.Configuration
8import org.apache.commons.configuration2.builder.fluent.Configurations
9import java.io.File
10
11private val KEY_ADDRESSES = "Address"
12private val KEY_ROUTES = "Route"
13private val KEY_DNS_SERVERS = "DNSServer"
14private val KEY_SEARCH_DOMAINS = "SearchDomain"
15private val KEY_ALLOWED_APPLICATIONS = "AllowApplication"
16private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication"
17private val KEY_ALLOWED_FAMILIES = "AllowFamily"
18private val KEY_ALLOW_BYPASS = "AllowBypass"
19private val KEY_BLOCKING = "Blocking"
20private val KEY_MTU = "MTU"
21
22private fun Configuration.getStringList(key: String): List<String> = getList(String::class.java, key, emptyList())
23private fun Configuration.getCidrList(key: String): List<CidrAddress> = getStringList(key).map { CidrAddress(it) }
24private fun Configuration.getIntList(key: String): List<Int> = getList(Int::class.java, key, emptyList())
25
26data class CidrAddress(val address: String, val prefix: Int) {
27 constructor(slashSeparated: String) :
28 this(slashSeparated.substringBefore(SEPARATOR), Integer.parseInt(slashSeparated.substringAfter(SEPARATOR)))
29
30 override fun toString() = address + SEPARATOR + prefix
31
32 companion object {
33 private val SEPARATOR = "/"
34 }
35}
36
37data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyList(),
38 val routes: List<CidrAddress> = emptyList(),
39 val dnsServers: List<String> = emptyList(),
40 val searchDomains: List<String> = emptyList(),
41 val allowedApplications: List<String> = emptyList(),
42 val disallowedApplications: List<String> = emptyList(),
43 val allowedFamilies: List<Int> = emptyList(),
44 val allowBypass: Boolean = false,
45 val blocking: Boolean = false,
46 val mtu: Int? = null) {
47
48 constructor(cfg: Configuration) : this(
49 cfg.getCidrList(KEY_ADDRESSES),
50 cfg.getCidrList(KEY_ROUTES),
51 cfg.getStringList(KEY_DNS_SERVERS),
52 cfg.getStringList(KEY_SEARCH_DOMAINS),
53 cfg.getStringList(KEY_ALLOWED_APPLICATIONS),
54 cfg.getStringList(KEY_DISALLOWED_APPLICATIONS),
55 cfg.getIntList(KEY_ALLOWED_FAMILIES),
56 cfg.getBoolean(KEY_ALLOW_BYPASS, false),
57 cfg.getBoolean(KEY_BLOCKING, false),
58 cfg.getInteger(KEY_MTU, null))
59
60 constructor(cfgFile: File) : this(Configurations().properties(cfgFile))
61
62}