fix: config screen edit bug
Fixes a bug where config edit will break configs that have commas because a comma and space are required in tunnel configs #42
This commit is contained in:
parent
5a1430706b
commit
77cd328a71
|
@ -14,8 +14,8 @@ android {
|
||||||
applicationId = "com.zaneschepke.wireguardautotunnel"
|
applicationId = "com.zaneschepke.wireguardautotunnel"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 31200
|
versionCode = 31300
|
||||||
versionName = "3.1.2"
|
versionName = "3.1.3"
|
||||||
|
|
||||||
multiDexEnabled = true
|
multiDexEnabled = true
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,14 @@ data class InterfaceProxy(
|
||||||
var mtu : String = "",
|
var mtu : String = "",
|
||||||
){
|
){
|
||||||
companion object {
|
companion object {
|
||||||
private fun String.removeWhiteSpaces() = replace("\\s".toRegex(), "")
|
|
||||||
fun from(i : Interface) : InterfaceProxy {
|
fun from(i : Interface) : InterfaceProxy {
|
||||||
return InterfaceProxy(
|
return InterfaceProxy(
|
||||||
publicKey = i.keyPair.publicKey.toBase64().removeWhiteSpaces(),
|
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
||||||
privateKey = i.keyPair.privateKey.toBase64().removeWhiteSpaces(),
|
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
||||||
addresses = i.addresses.joinToString(",").removeWhiteSpaces(),
|
addresses = i.addresses.joinToString(", ").trim(),
|
||||||
dnsServers = i.dnsServers.joinToString(",").replace("/", "").removeWhiteSpaces(),
|
dnsServers = i.dnsServers.joinToString(", ").replace("/", "").trim(),
|
||||||
listenPort = if(i.listenPort.isPresent) i.listenPort.get().toString().removeWhiteSpaces() else "",
|
listenPort = if(i.listenPort.isPresent) i.listenPort.get().toString().trim() else "",
|
||||||
mtu = if(i.mtu.isPresent) i.mtu.get().toString().removeWhiteSpaces() else ""
|
mtu = if(i.mtu.isPresent) i.mtu.get().toString().trim() else ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,16 @@ data class PeerProxy(
|
||||||
var preSharedKey : String = "",
|
var preSharedKey : String = "",
|
||||||
var persistentKeepalive : String = "",
|
var persistentKeepalive : String = "",
|
||||||
var endpoint : String = "",
|
var endpoint : String = "",
|
||||||
var allowedIps: String = IPV4_WILDCARD.joinToString(",")
|
var allowedIps: String = IPV4_WILDCARD.joinToString(", ").trim()
|
||||||
){
|
){
|
||||||
companion object {
|
companion object {
|
||||||
fun from(peer : Peer) : PeerProxy {
|
fun from(peer : Peer) : PeerProxy {
|
||||||
return PeerProxy(
|
return PeerProxy(
|
||||||
publicKey = peer.publicKey.toBase64(),
|
publicKey = peer.publicKey.toBase64(),
|
||||||
preSharedKey = if(peer.preSharedKey.isPresent) peer.preSharedKey.get().toString() else "",
|
preSharedKey = if(peer.preSharedKey.isPresent) peer.preSharedKey.get().toBase64().trim() else "",
|
||||||
persistentKeepalive = if(peer.persistentKeepalive.isPresent) peer.persistentKeepalive.get().toString() else "",
|
persistentKeepalive = if(peer.persistentKeepalive.isPresent) peer.persistentKeepalive.get().toString().trim() else "",
|
||||||
endpoint = if(peer.endpoint.isPresent) peer.endpoint.get().toString() else "",
|
endpoint = if(peer.endpoint.isPresent) peer.endpoint.get().toString().trim() else "",
|
||||||
allowedIps = peer.allowedIps.joinToString(",")
|
allowedIps = peer.allowedIps.joinToString(", ").trim()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val IPV4_PUBLIC_NETWORKS = setOf(
|
val IPV4_PUBLIC_NETWORKS = setOf(
|
||||||
|
|
|
@ -271,22 +271,22 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
fun buildPeerListFromProxyPeers() : List<Peer> {
|
fun buildPeerListFromProxyPeers() : List<Peer> {
|
||||||
return _proxyPeers.value.map {
|
return _proxyPeers.value.map {
|
||||||
val builder = Peer.Builder()
|
val builder = Peer.Builder()
|
||||||
if (it.allowedIps.isNotEmpty()) builder.parseAllowedIPs(it.allowedIps.removeWhiteSpaces())
|
if (it.allowedIps.isNotEmpty()) builder.parseAllowedIPs(it.allowedIps.trim())
|
||||||
if (it.publicKey.isNotEmpty()) builder.parsePublicKey(it.publicKey.removeWhiteSpaces())
|
if (it.publicKey.isNotEmpty()) builder.parsePublicKey(it.publicKey.trim())
|
||||||
if (it.preSharedKey.isNotEmpty()) builder.parsePreSharedKey(it.preSharedKey.removeWhiteSpaces())
|
if (it.preSharedKey.isNotEmpty()) builder.parsePreSharedKey(it.preSharedKey.trim())
|
||||||
if (it.endpoint.isNotEmpty()) builder.parseEndpoint(it.endpoint.removeWhiteSpaces())
|
if (it.endpoint.isNotEmpty()) builder.parseEndpoint(it.endpoint.trim())
|
||||||
if (it.persistentKeepalive.isNotEmpty()) builder.parsePersistentKeepalive(it.persistentKeepalive.removeWhiteSpaces())
|
if (it.persistentKeepalive.isNotEmpty()) builder.parsePersistentKeepalive(it.persistentKeepalive.trim())
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildInterfaceListFromProxyInterface() : Interface {
|
fun buildInterfaceListFromProxyInterface() : Interface {
|
||||||
val builder = Interface.Builder()
|
val builder = Interface.Builder()
|
||||||
builder.parsePrivateKey(_interface.value.privateKey.removeWhiteSpaces())
|
builder.parsePrivateKey(_interface.value.privateKey.trim())
|
||||||
builder.parseAddresses(_interface.value.addresses.removeWhiteSpaces())
|
builder.parseAddresses(_interface.value.addresses.trim())
|
||||||
builder.parseDnsServers(_interface.value.dnsServers.removeWhiteSpaces())
|
builder.parseDnsServers(_interface.value.dnsServers.trim())
|
||||||
if(_interface.value.mtu.isNotEmpty()) builder.parseMtu(_interface.value.mtu.removeWhiteSpaces())
|
if(_interface.value.mtu.isNotEmpty()) builder.parseMtu(_interface.value.mtu.trim())
|
||||||
if(_interface.value.listenPort.isNotEmpty()) builder.parseListenPort(_interface.value.listenPort.removeWhiteSpaces())
|
if(_interface.value.listenPort.isNotEmpty()) builder.parseListenPort(_interface.value.listenPort.trim())
|
||||||
if(isAllApplicationsEnabled()) _checkedPackages.value.clear()
|
if(isAllApplicationsEnabled()) _checkedPackages.value.clear()
|
||||||
if(_include.value) builder.includeApplications(_checkedPackages.value)
|
if(_include.value) builder.includeApplications(_checkedPackages.value)
|
||||||
if(!_include.value) builder.excludeApplications(_checkedPackages.value)
|
if(!_include.value) builder.excludeApplications(_checkedPackages.value)
|
||||||
|
@ -397,6 +397,4 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
onInterfacePublicKeyChange("")
|
onInterfacePublicKeyChange("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.removeWhiteSpaces() = replace("\\s".toRegex(), "")
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue