diff options
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.kt | 62 |
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 @@ | |||
1 | package org.pacien.tincapp.service | ||
2 | |||
3 | /** | ||
4 | * @author pacien | ||
5 | */ | ||
6 | |||
7 | import org.apache.commons.configuration2.Configuration | ||
8 | import org.apache.commons.configuration2.builder.fluent.Configurations | ||
9 | import java.io.File | ||
10 | |||
11 | private val KEY_ADDRESSES = "Address" | ||
12 | private val KEY_ROUTES = "Route" | ||
13 | private val KEY_DNS_SERVERS = "DNSServer" | ||
14 | private val KEY_SEARCH_DOMAINS = "SearchDomain" | ||
15 | private val KEY_ALLOWED_APPLICATIONS = "AllowApplication" | ||
16 | private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" | ||
17 | private val KEY_ALLOWED_FAMILIES = "AllowFamily" | ||
18 | private val KEY_ALLOW_BYPASS = "AllowBypass" | ||
19 | private val KEY_BLOCKING = "Blocking" | ||
20 | private val KEY_MTU = "MTU" | ||
21 | |||
22 | private fun Configuration.getStringList(key: String): List<String> = getList(String::class.java, key, emptyList()) | ||
23 | private fun Configuration.getCidrList(key: String): List<CidrAddress> = getStringList(key).map { CidrAddress(it) } | ||
24 | private fun Configuration.getIntList(key: String): List<Int> = getList(Int::class.java, key, emptyList()) | ||
25 | |||
26 | data 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 | |||
37 | data 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 | } | ||