diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt index 70c8b96..7b699c6 100644 --- a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | |||
@@ -26,53 +26,53 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
26 | val blocking: Boolean = false, | 26 | val blocking: Boolean = false, |
27 | val mtu: Int? = null) { | 27 | val mtu: Int? = null) { |
28 | 28 | ||
29 | companion object { | 29 | companion object { |
30 | 30 | ||
31 | private val KEY_ADDRESSES = "Address" | 31 | private val KEY_ADDRESSES = "Address" |
32 | private val KEY_ROUTES = "Route" | 32 | private val KEY_ROUTES = "Route" |
33 | private val KEY_DNS_SERVERS = "DNSServer" | 33 | private val KEY_DNS_SERVERS = "DNSServer" |
34 | private val KEY_SEARCH_DOMAINS = "SearchDomain" | 34 | private val KEY_SEARCH_DOMAINS = "SearchDomain" |
35 | private val KEY_ALLOWED_APPLICATIONS = "AllowApplication" | 35 | private val KEY_ALLOWED_APPLICATIONS = "AllowApplication" |
36 | private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" | 36 | private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" |
37 | private val KEY_ALLOWED_FAMILIES = "AllowFamily" | 37 | private val KEY_ALLOWED_FAMILIES = "AllowFamily" |
38 | private val KEY_ALLOW_BYPASS = "AllowBypass" | 38 | private val KEY_ALLOW_BYPASS = "AllowBypass" |
39 | private val KEY_BLOCKING = "Blocking" | 39 | private val KEY_BLOCKING = "Blocking" |
40 | private val KEY_MTU = "MTU" | 40 | private val KEY_MTU = "MTU" |
41 | 41 | ||
42 | private val INVITATION_KEY_ADDRESSES = "Ifconfig" | 42 | private val INVITATION_KEY_ADDRESSES = "Ifconfig" |
43 | private val INVITATION_KEY_ROUTES = "Route" | 43 | private val INVITATION_KEY_ROUTES = "Route" |
44 | 44 | ||
45 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) | 45 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) |
46 | fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( | 46 | fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( |
47 | c.getCidrList(KEY_ADDRESSES), | 47 | c.getCidrList(KEY_ADDRESSES), |
48 | c.getCidrList(KEY_ROUTES), | 48 | c.getCidrList(KEY_ROUTES), |
49 | c.getStringList(KEY_DNS_SERVERS), | 49 | c.getStringList(KEY_DNS_SERVERS), |
50 | c.getStringList(KEY_SEARCH_DOMAINS), | 50 | c.getStringList(KEY_SEARCH_DOMAINS), |
51 | c.getStringList(KEY_ALLOWED_APPLICATIONS), | 51 | c.getStringList(KEY_ALLOWED_APPLICATIONS), |
52 | c.getStringList(KEY_DISALLOWED_APPLICATIONS), | 52 | c.getStringList(KEY_DISALLOWED_APPLICATIONS), |
53 | c.getIntList(KEY_ALLOWED_FAMILIES), | 53 | c.getIntList(KEY_ALLOWED_FAMILIES), |
54 | c.getBoolean(KEY_ALLOW_BYPASS, false), | 54 | c.getBoolean(KEY_ALLOW_BYPASS, false), |
55 | c.getBoolean(KEY_BLOCKING, false), | 55 | c.getBoolean(KEY_BLOCKING, false), |
56 | c.getInteger(KEY_MTU, null)) | 56 | c.getInteger(KEY_MTU, null)) |
57 | 57 | ||
58 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) | 58 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) |
59 | fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( | 59 | fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( |
60 | c.getStringList(INVITATION_KEY_ADDRESSES) | 60 | c.getStringList(INVITATION_KEY_ADDRESSES) |
61 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } | 61 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } |
62 | .filterNotNull(), | 62 | .filterNotNull(), |
63 | c.getStringList(INVITATION_KEY_ROUTES) | 63 | c.getStringList(INVITATION_KEY_ROUTES) |
64 | .map { it.substringBefore(' ') } | 64 | .map { it.substringBefore(' ') } |
65 | .map { CidrAddress.fromSlashSeparated(it) }) | 65 | .map { CidrAddress.fromSlashSeparated(it) }) |
66 | 66 | ||
67 | } | 67 | } |
68 | 68 | ||
69 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) | 69 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) |
70 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> | 70 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> |
71 | builder.configuration.let { cfg -> | 71 | builder.configuration.let { cfg -> |
72 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } | 72 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } |
73 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } | 73 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } |
74 | } | ||
75 | builder.save() | ||
76 | } | 74 | } |
75 | builder.save() | ||
76 | } | ||
77 | 77 | ||
78 | } | 78 | } |