Handle multiple domains in network settings
This commit is contained in:
parent
defda27835
commit
d9788d93b6
|
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Support for `--ping-restart` (Robert Patchett). [tunnelkit#122](https://github.com/passepartoutvpn/tunnelkit/pull/122)
|
||||
- Support for proxy auto-configuration URL (ThinkChaos). [tunnelkit#125](https://github.com/passepartoutvpn/tunnelkit/pull/125)
|
||||
- Disclose server configuration and network settings in Diagnostics. [#101](https://github.com/passepartoutvpn/passepartout-ios/issues/101)
|
||||
- Support multiple DNS search domains. [tunnelkit#127](https://github.com/passepartoutvpn/tunnelkit/issues/127)
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -38,6 +38,10 @@ internal enum L10n {
|
|||
}
|
||||
internal enum NetworkSettings {
|
||||
internal enum Cells {
|
||||
internal enum AddDnsDomain {
|
||||
/// Add search domain
|
||||
internal static let caption = L10n.tr("App", "network_settings.cells.add_dns_domain.caption")
|
||||
}
|
||||
internal enum AddDnsServer {
|
||||
/// Add address
|
||||
internal static let caption = L10n.tr("App", "network_settings.cells.add_dns_server.caption")
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
"provider.preset.cells.tech_details.caption" = "Technical details";
|
||||
|
||||
"network_settings.cells.add_dns_server.caption" = "Add address";
|
||||
"network_settings.cells.add_dns_domain.caption" = "Add search domain";
|
||||
"network_settings.cells.proxy_bypass.caption" = "Bypass domain";
|
||||
"network_settings.cells.add_proxy_bypass.caption" = "Add bypass domain";
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ import Convenience
|
|||
private let log = SwiftyBeaver.self
|
||||
|
||||
private enum FieldTag: Int {
|
||||
case dnsDomain = 101
|
||||
case dnsAddress = 100
|
||||
|
||||
case dnsAddress = 200
|
||||
case dnsDomain = 200
|
||||
|
||||
case proxyAddress = 301
|
||||
|
||||
|
@ -46,7 +46,9 @@ private enum FieldTag: Int {
|
|||
}
|
||||
|
||||
private struct Offsets {
|
||||
static let dnsAddress = 1
|
||||
static let dnsAddress = 0
|
||||
|
||||
static let dnsDomain = 0
|
||||
|
||||
static let proxyBypass = 2
|
||||
}
|
||||
|
@ -73,7 +75,8 @@ class NetworkSettingsViewController: UITableViewController {
|
|||
model.add(.manualGateway)
|
||||
}
|
||||
if networkChoices.dns != .server {
|
||||
model.add(.manualDNS)
|
||||
model.add(.manualDNSServers)
|
||||
model.add(.manualDNSDomains)
|
||||
}
|
||||
if networkChoices.proxy != .server {
|
||||
model.add(.manualProxy)
|
||||
|
@ -82,7 +85,7 @@ class NetworkSettingsViewController: UITableViewController {
|
|||
// headers
|
||||
model.setHeader("", forSection: .choices)
|
||||
model.setHeader(L10n.Core.NetworkSettings.Gateway.title, forSection: .manualGateway)
|
||||
model.setHeader(L10n.Core.NetworkSettings.Dns.title, forSection: .manualDNS)
|
||||
model.setHeader(L10n.Core.NetworkSettings.Dns.title, forSection: .manualDNSServers)
|
||||
model.setHeader(L10n.Core.NetworkSettings.Proxy.title, forSection: .manualProxy)
|
||||
|
||||
// footers
|
||||
|
@ -93,11 +96,16 @@ class NetworkSettingsViewController: UITableViewController {
|
|||
model.set([.gatewayIPv4, .gatewayIPv6], forSection: .manualGateway)
|
||||
|
||||
var dnsRows: [RowType] = Array(repeating: .dnsAddress, count: networkSettings.dnsServers?.count ?? 0)
|
||||
dnsRows.insert(.dnsDomain, at: 0)
|
||||
if networkChoices.dns == .manual {
|
||||
dnsRows.append(.dnsAddAddress)
|
||||
}
|
||||
model.set(dnsRows, forSection: .manualDNS)
|
||||
model.set(dnsRows, forSection: .manualDNSServers)
|
||||
|
||||
dnsRows = Array(repeating: .dnsDomain, count: networkSettings.dnsSearchDomains?.count ?? 0)
|
||||
if networkChoices.dns == .manual {
|
||||
dnsRows.append(.dnsAddDomain)
|
||||
}
|
||||
model.set(dnsRows, forSection: .manualDNSDomains)
|
||||
|
||||
var proxyRows: [RowType] = Array(repeating: .proxyBypass, count: networkSettings.proxyBypassDomains?.count ?? 0)
|
||||
proxyRows.insert(.proxyAddress, at: 0)
|
||||
|
@ -190,11 +198,25 @@ class NetworkSettingsViewController: UITableViewController {
|
|||
|
||||
private func commitTextField(_ field: UITextField) {
|
||||
|
||||
// DNS: domain, servers
|
||||
// DNS: servers, domains
|
||||
// Proxy: address, port, PAC, bypass domains
|
||||
|
||||
if field.tag == FieldTag.dnsDomain.rawValue {
|
||||
networkSettings.dnsDomainName = field.text
|
||||
|
||||
let text = field.text ?? ""
|
||||
|
||||
if field.tag >= FieldTag.dnsAddress.rawValue && field.tag < FieldTag.dnsDomain.rawValue {
|
||||
let i = field.tag - FieldTag.dnsAddress.rawValue
|
||||
if let _ = networkSettings.dnsServers {
|
||||
networkSettings.dnsServers?[i] = text
|
||||
} else {
|
||||
networkSettings.dnsServers = [text]
|
||||
}
|
||||
} else if field.tag >= FieldTag.dnsDomain.rawValue && field.tag < FieldTag.proxyAddress.rawValue {
|
||||
let i = field.tag - FieldTag.dnsDomain.rawValue
|
||||
if let _ = networkSettings.dnsSearchDomains {
|
||||
networkSettings.dnsSearchDomains?[i] = text
|
||||
} else {
|
||||
networkSettings.dnsSearchDomains = [text]
|
||||
}
|
||||
} else if field.tag == FieldTag.proxyAddress.rawValue {
|
||||
networkSettings.proxyAddress = field.text
|
||||
} else if field.tag == FieldTag.proxyPort.rawValue {
|
||||
|
@ -205,12 +227,13 @@ class NetworkSettingsViewController: UITableViewController {
|
|||
} else {
|
||||
networkSettings.proxyAutoConfigurationURL = nil
|
||||
}
|
||||
} else if field.tag >= FieldTag.dnsAddress.rawValue && field.tag < FieldTag.proxyAddress.rawValue {
|
||||
let i = field.tag - FieldTag.dnsAddress.rawValue
|
||||
networkSettings.dnsServers?[i] = field.text ?? ""
|
||||
} else if field.tag >= FieldTag.proxyBypass.rawValue {
|
||||
let i = field.tag - FieldTag.proxyBypass.rawValue
|
||||
networkSettings.proxyBypassDomains?[i] = field.text ?? ""
|
||||
if let _ = networkSettings.proxyBypassDomains {
|
||||
networkSettings.proxyBypassDomains?[i] = text
|
||||
} else {
|
||||
networkSettings.proxyBypassDomains = [text]
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("Network settings: \(networkSettings)")
|
||||
|
@ -240,7 +263,9 @@ extension NetworkSettingsViewController {
|
|||
|
||||
case manualGateway
|
||||
|
||||
case manualDNS
|
||||
case manualDNSServers
|
||||
|
||||
case manualDNSDomains
|
||||
|
||||
case manualProxy
|
||||
}
|
||||
|
@ -256,12 +281,14 @@ extension NetworkSettingsViewController {
|
|||
|
||||
case gatewayIPv6
|
||||
|
||||
case dnsDomain
|
||||
|
||||
case dnsAddress
|
||||
|
||||
case dnsAddAddress
|
||||
|
||||
case dnsDomain
|
||||
|
||||
case dnsAddDomain
|
||||
|
||||
case proxyAddress
|
||||
|
||||
case proxyPort
|
||||
|
@ -305,7 +332,7 @@ extension NetworkSettingsViewController {
|
|||
|
||||
case .dns:
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.leftText = model.header(forSection: .manualDNS)
|
||||
cell.leftText = model.header(forSection: .manualDNSServers)
|
||||
cell.rightText = networkChoices.dns.description
|
||||
return cell
|
||||
|
||||
|
@ -329,19 +356,6 @@ extension NetworkSettingsViewController {
|
|||
cell.isOn = networkSettings.gatewayPolicies?.contains(.IPv6) ?? false
|
||||
return cell
|
||||
|
||||
case .dnsDomain:
|
||||
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
|
||||
cell.caption = L10n.Core.NetworkSettings.Dns.Cells.Domain.caption
|
||||
cell.field.tag = FieldTag.dnsDomain.rawValue
|
||||
cell.field.placeholder = L10n.Core.Global.Values.none
|
||||
cell.field.text = networkSettings.dnsDomainName
|
||||
cell.field.clearButtonMode = .always
|
||||
cell.field.keyboardType = .asciiCapable
|
||||
cell.captionWidth = 160.0
|
||||
cell.delegate = self
|
||||
cell.field.isEnabled = (networkChoices.dns == .manual)
|
||||
return cell
|
||||
|
||||
case .dnsAddress:
|
||||
let i = indexPath.row - Offsets.dnsAddress
|
||||
|
||||
|
@ -363,6 +377,27 @@ extension NetworkSettingsViewController {
|
|||
cell.leftText = L10n.App.NetworkSettings.Cells.AddDnsServer.caption
|
||||
return cell
|
||||
|
||||
case .dnsDomain:
|
||||
let i = indexPath.row - Offsets.dnsDomain
|
||||
|
||||
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
|
||||
cell.caption = L10n.Core.NetworkSettings.Dns.Cells.Domain.caption
|
||||
cell.field.tag = FieldTag.dnsDomain.rawValue + i
|
||||
cell.field.placeholder = L10n.Core.Global.Values.none
|
||||
cell.field.text = networkSettings.dnsSearchDomains?[i]
|
||||
cell.field.clearButtonMode = .always
|
||||
cell.field.keyboardType = .asciiCapable
|
||||
cell.captionWidth = 160.0
|
||||
cell.delegate = self
|
||||
cell.field.isEnabled = (networkChoices.dns == .manual)
|
||||
return cell
|
||||
|
||||
case .dnsAddDomain:
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.applyAction(Theme.current)
|
||||
cell.leftText = L10n.App.NetworkSettings.Cells.AddDnsDomain.caption
|
||||
return cell
|
||||
|
||||
case .proxyAddress:
|
||||
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
|
||||
cell.caption = L10n.Core.Global.Captions.address
|
||||
|
@ -477,6 +512,15 @@ extension NetworkSettingsViewController {
|
|||
reloadModel()
|
||||
tableView.insertRows(at: [indexPath], with: .automatic)
|
||||
|
||||
case .dnsAddDomain:
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
|
||||
var dnsSearchDomains = networkSettings.dnsSearchDomains ?? []
|
||||
dnsSearchDomains.append("")
|
||||
networkSettings.dnsSearchDomains = dnsSearchDomains
|
||||
reloadModel()
|
||||
tableView.insertRows(at: [indexPath], with: .automatic)
|
||||
|
||||
case .proxyAddBypass:
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
|
||||
|
@ -526,7 +570,7 @@ extension NetworkSettingsViewController {
|
|||
|
||||
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
||||
switch model.row(at: indexPath) {
|
||||
case .dnsAddress, .proxyBypass:
|
||||
case .dnsAddress, .dnsDomain, .proxyBypass:
|
||||
return true
|
||||
|
||||
default:
|
||||
|
@ -537,11 +581,12 @@ extension NetworkSettingsViewController {
|
|||
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
||||
switch model.row(at: indexPath) {
|
||||
case .dnsAddress:
|
||||
// start at row 1
|
||||
networkSettings.dnsServers?.remove(at: indexPath.row - Offsets.dnsAddress)
|
||||
|
||||
case .dnsDomain:
|
||||
networkSettings.dnsSearchDomains?.remove(at: indexPath.row - Offsets.dnsDomain)
|
||||
|
||||
case .proxyBypass:
|
||||
// start at row 2
|
||||
networkSettings.proxyBypassDomains?.remove(at: indexPath.row - Offsets.proxyBypass)
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue