aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-21 17:56:52 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-21 17:57:13 +0530
commit69a064d954fe39c8dc7299814fda47470b488b62 (patch)
treef71ff838b5ed3a1887033d01ba7c483f3adf3964
parentmacOS: On saving, update AllowedIPs with the current DNS servers (diff)
downloadwireguard-apple-69a064d954fe39c8dc7299814fda47470b488b62.tar.xz
wireguard-apple-69a064d954fe39c8dc7299814fda47470b488b62.zip
iOS: On changing DNS, update AllowedIPs with the current DNS servers
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift13
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift4
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift14
3 files changed, 26 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index b299bea1..9daf1aa8 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -432,7 +432,7 @@ class TunnelViewModel {
let normalizedDNSServers = normalizedIPAddressRangeStrings(dnsServers)
let ipv6Addresses = normalizedIPAddressRangeStrings(currentAllowedIPs.filter { $0.contains(":") })
if excludePrivateIPs {
- return ipv6Addresses + TunnelViewModel.PeerData.ipv4DefaultRouteModRFC1918String + dnsServers
+ return ipv6Addresses + TunnelViewModel.PeerData.ipv4DefaultRouteModRFC1918String + normalizedDNSServers
} else {
return ipv6Addresses.filter { !normalizedDNSServers.contains($0) } + [TunnelViewModel.PeerData.ipv4DefaultRouteString]
}
@@ -523,6 +523,17 @@ class TunnelViewModel {
}
}
+ func updateDNSServersInAllowedIPsIfRequired(oldDNSServers: String, newDNSServers: String) -> Bool {
+ guard peersData.count == 1, let firstPeer = peersData.first else { return false }
+ guard firstPeer.shouldAllowExcludePrivateIPsControl && firstPeer.excludePrivateIPsValue else { return false }
+ let allowedIPStrings = firstPeer[.allowedIPs].splitToArray(trimmingCharacters: .whitespacesAndNewlines)
+ let oldDNSServerStrings = TunnelViewModel.PeerData.normalizedIPAddressRangeStrings(oldDNSServers.splitToArray(trimmingCharacters: .whitespacesAndNewlines))
+ let newDNSServerStrings = TunnelViewModel.PeerData.normalizedIPAddressRangeStrings(newDNSServers.splitToArray(trimmingCharacters: .whitespacesAndNewlines))
+ let updatedAllowedIPStrings = allowedIPStrings.filter { !oldDNSServerStrings.contains($0) } + newDNSServerStrings
+ firstPeer[.allowedIPs] = updatedAllowedIPStrings.joined(separator: ", ")
+ return true
+ }
+
func save() -> SaveResult<TunnelConfiguration> {
let interfaceSaveResult = interfaceData.save()
let peerSaveResults = peersData.map { $0.save() } // Save all, to help mark erroring fields in red
diff --git a/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
index 61b2f2d4..df86752f 100644
--- a/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
@@ -68,7 +68,7 @@ class KeyValueCell: UITableViewCell {
var isStackedVertically = false
var contentSizeBasedConstraints = [NSLayoutConstraint]()
- var onValueChanged: ((String) -> Void)?
+ var onValueChanged: ((String, String) -> Void)?
var onValueBeingEdited: ((String) -> Void)?
var observationToken: AnyObject?
@@ -206,7 +206,7 @@ extension KeyValueCell: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
let isModified = textField.text ?? "" != textFieldValueOnBeginEditing
guard isModified else { return }
- onValueChanged?(textField.text ?? "")
+ onValueChanged?(textFieldValueOnBeginEditing, textField.text ?? "")
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index 0b0be6db..a15d5fe3 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -259,8 +259,18 @@ extension TunnelEditTableViewController {
cell.onValueBeingEdited = { [weak self] value in
self?.tunnelViewModel.interfaceData[field] = value
}
+ cell.onValueChanged = { [weak self] oldValue, newValue in
+ guard let self = self else { return }
+ let isAllowedIPsChanged = self.tunnelViewModel.updateDNSServersInAllowedIPsIfRequired(oldDNSServers: oldValue, newDNSServers: newValue)
+ if isAllowedIPsChanged {
+ let section = self.sections.firstIndex { if case .peer(_) = $0 { return true } else { return false } }
+ if let section = section, let row = self.peerFields.firstIndex(of: .allowedIPs) {
+ self.tableView.reloadRows(at: [IndexPath(row: row, section: section)], with: .none)
+ }
+ }
+ }
} else {
- cell.onValueChanged = { [weak self] value in
+ cell.onValueChanged = { [weak self] _, value in
self?.tunnelViewModel.interfaceData[field] = value
}
}
@@ -380,7 +390,7 @@ extension TunnelEditTableViewController {
tableView.reloadRows(at: [IndexPath(row: dnsRow, section: firstInterfaceSection + interfaceSubSection)], with: .none)
}
} else {
- cell.onValueChanged = { [weak peerData] value in
+ cell.onValueChanged = { [weak peerData] _, value in
peerData?[field] = value
}
}