Merge branch 'multiple-search-domains'

This commit is contained in:
Davide De Rosa 2019-10-25 19:10:59 +02:00
commit a82ee1939b
8 changed files with 122 additions and 55 deletions

View File

@ -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 `--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) - 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) - 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 ### Changed

View File

@ -38,6 +38,10 @@ internal enum L10n {
} }
internal enum NetworkSettings { internal enum NetworkSettings {
internal enum Cells { 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 { internal enum AddDnsServer {
/// Add address /// Add address
internal static let caption = L10n.tr("App", "network_settings.cells.add_dns_server.caption") internal static let caption = L10n.tr("App", "network_settings.cells.add_dns_server.caption")

View File

@ -51,6 +51,7 @@
"provider.preset.cells.tech_details.caption" = "Technical details"; "provider.preset.cells.tech_details.caption" = "Technical details";
"network_settings.cells.add_dns_server.caption" = "Add address"; "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.proxy_bypass.caption" = "Bypass domain";
"network_settings.cells.add_proxy_bypass.caption" = "Add bypass domain"; "network_settings.cells.add_proxy_bypass.caption" = "Add bypass domain";

View File

@ -32,9 +32,9 @@ import Convenience
private let log = SwiftyBeaver.self private let log = SwiftyBeaver.self
private enum FieldTag: Int { private enum FieldTag: Int {
case dnsDomain = 101 case dnsAddress = 100
case dnsAddress = 200 case dnsDomain = 200
case proxyAddress = 301 case proxyAddress = 301
@ -46,7 +46,9 @@ private enum FieldTag: Int {
} }
private struct Offsets { private struct Offsets {
static let dnsAddress = 1 static let dnsAddress = 0
static let dnsDomain = 0
static let proxyBypass = 2 static let proxyBypass = 2
} }
@ -67,22 +69,23 @@ class NetworkSettingsViewController: UITableViewController {
func reloadModel() { func reloadModel() {
model.clear() model.clear()
// sections // sections (candidate)
model.add(.choices) var sections: [SectionType] = []
sections.append(.choices)
if networkChoices.gateway != .server { if networkChoices.gateway != .server {
model.add(.manualGateway) sections.append(.manualGateway)
} }
if networkChoices.dns != .server { if networkChoices.dns != .server {
model.add(.manualDNS) sections.append(.manualDNSServers)
sections.append(.manualDNSDomains)
} }
if networkChoices.proxy != .server { if networkChoices.proxy != .server {
model.add(.manualProxy) sections.append(.manualProxy)
} }
// headers // headers
model.setHeader("", forSection: .choices) model.setHeader("", forSection: .choices)
model.setHeader(L10n.Core.NetworkSettings.Gateway.title, forSection: .manualGateway) model.setHeader(L10n.Core.NetworkSettings.Gateway.title, forSection: .manualGateway)
model.setHeader(L10n.Core.NetworkSettings.Dns.title, forSection: .manualDNS)
model.setHeader(L10n.Core.NetworkSettings.Proxy.title, forSection: .manualProxy) model.setHeader(L10n.Core.NetworkSettings.Proxy.title, forSection: .manualProxy)
// footers // footers
@ -92,13 +95,18 @@ class NetworkSettingsViewController: UITableViewController {
model.set([.gateway, .dns, .proxy], forSection: .choices) model.set([.gateway, .dns, .proxy], forSection: .choices)
model.set([.gatewayIPv4, .gatewayIPv6], forSection: .manualGateway) model.set([.gatewayIPv4, .gatewayIPv6], forSection: .manualGateway)
var dnsRows: [RowType] = Array(repeating: .dnsAddress, count: networkSettings.dnsServers?.count ?? 0) var dnsServers: [RowType] = Array(repeating: .dnsAddress, count: networkSettings.dnsServers?.count ?? 0)
dnsRows.insert(.dnsDomain, at: 0)
if networkChoices.dns == .manual { if networkChoices.dns == .manual {
dnsRows.append(.dnsAddAddress) dnsServers.append(.dnsAddAddress)
} }
model.set(dnsRows, forSection: .manualDNS) model.set(dnsServers, forSection: .manualDNSServers)
var dnsDomains: [RowType] = Array(repeating: .dnsDomain, count: networkSettings.dnsSearchDomains?.count ?? 0)
if networkChoices.dns == .manual {
dnsDomains.append(.dnsAddDomain)
}
model.set(dnsDomains, forSection: .manualDNSDomains)
var proxyRows: [RowType] = Array(repeating: .proxyBypass, count: networkSettings.proxyBypassDomains?.count ?? 0) var proxyRows: [RowType] = Array(repeating: .proxyBypass, count: networkSettings.proxyBypassDomains?.count ?? 0)
proxyRows.insert(.proxyAddress, at: 0) proxyRows.insert(.proxyAddress, at: 0)
proxyRows.insert(.proxyPort, at: 1) proxyRows.insert(.proxyPort, at: 1)
@ -107,6 +115,20 @@ class NetworkSettingsViewController: UITableViewController {
proxyRows.append(.proxyAddBypass) proxyRows.append(.proxyAddBypass)
} }
model.set(proxyRows, forSection: .manualProxy) model.set(proxyRows, forSection: .manualProxy)
// refine sections before add (DNS is tricky)
if !dnsServers.isEmpty {
model.setHeader(L10n.Core.NetworkSettings.Dns.title, forSection: .manualDNSServers)
} else if !dnsDomains.isEmpty {
sections.removeAll { $0 == .manualDNSServers }
model.setHeader(L10n.Core.NetworkSettings.Dns.title, forSection: .manualDNSDomains)
} else {
sections.removeAll { $0 == .manualDNSServers }
sections.removeAll { $0 == .manualDNSDomains }
}
for s in sections {
model.add(s)
}
} }
// MARK: UIViewController // MARK: UIViewController
@ -190,11 +212,25 @@ class NetworkSettingsViewController: UITableViewController {
private func commitTextField(_ field: UITextField) { private func commitTextField(_ field: UITextField) {
// DNS: domain, servers // DNS: servers, domains
// Proxy: address, port, PAC, bypass domains // Proxy: address, port, PAC, bypass domains
if field.tag == FieldTag.dnsDomain.rawValue { let text = field.text ?? ""
networkSettings.dnsDomainName = 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 { } else if field.tag == FieldTag.proxyAddress.rawValue {
networkSettings.proxyAddress = field.text networkSettings.proxyAddress = field.text
} else if field.tag == FieldTag.proxyPort.rawValue { } else if field.tag == FieldTag.proxyPort.rawValue {
@ -205,12 +241,13 @@ class NetworkSettingsViewController: UITableViewController {
} else { } else {
networkSettings.proxyAutoConfigurationURL = nil 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 { } else if field.tag >= FieldTag.proxyBypass.rawValue {
let i = 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)") log.debug("Network settings: \(networkSettings)")
@ -240,7 +277,9 @@ extension NetworkSettingsViewController {
case manualGateway case manualGateway
case manualDNS case manualDNSServers
case manualDNSDomains
case manualProxy case manualProxy
} }
@ -256,12 +295,14 @@ extension NetworkSettingsViewController {
case gatewayIPv6 case gatewayIPv6
case dnsDomain
case dnsAddress case dnsAddress
case dnsAddAddress case dnsAddAddress
case dnsDomain
case dnsAddDomain
case proxyAddress case proxyAddress
case proxyPort case proxyPort
@ -299,19 +340,19 @@ extension NetworkSettingsViewController {
switch row { switch row {
case .gateway: case .gateway:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = model.header(forSection: .manualGateway) cell.leftText = L10n.Core.NetworkSettings.Gateway.title
cell.rightText = networkChoices.gateway.description cell.rightText = networkChoices.gateway.description
return cell return cell
case .dns: case .dns:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = model.header(forSection: .manualDNS) cell.leftText = L10n.Core.NetworkSettings.Dns.title
cell.rightText = networkChoices.dns.description cell.rightText = networkChoices.dns.description
return cell return cell
case .proxy: case .proxy:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = model.header(forSection: .manualProxy) cell.leftText = L10n.Core.NetworkSettings.Proxy.title
cell.rightText = networkChoices.proxy.description cell.rightText = networkChoices.proxy.description
return cell return cell
@ -329,19 +370,6 @@ extension NetworkSettingsViewController {
cell.isOn = networkSettings.gatewayPolicies?.contains(.IPv6) ?? false cell.isOn = networkSettings.gatewayPolicies?.contains(.IPv6) ?? false
return cell 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: case .dnsAddress:
let i = indexPath.row - Offsets.dnsAddress let i = indexPath.row - Offsets.dnsAddress
@ -363,6 +391,27 @@ extension NetworkSettingsViewController {
cell.leftText = L10n.App.NetworkSettings.Cells.AddDnsServer.caption cell.leftText = L10n.App.NetworkSettings.Cells.AddDnsServer.caption
return cell 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: case .proxyAddress:
let cell = Cells.field.dequeue(from: tableView, for: indexPath) let cell = Cells.field.dequeue(from: tableView, for: indexPath)
cell.caption = L10n.Core.Global.Captions.address cell.caption = L10n.Core.Global.Captions.address
@ -477,6 +526,15 @@ extension NetworkSettingsViewController {
reloadModel() reloadModel()
tableView.insertRows(at: [indexPath], with: .automatic) 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: case .proxyAddBypass:
tableView.deselectRow(at: indexPath, animated: true) tableView.deselectRow(at: indexPath, animated: true)
@ -526,7 +584,7 @@ extension NetworkSettingsViewController {
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
switch model.row(at: indexPath) { switch model.row(at: indexPath) {
case .dnsAddress, .proxyBypass: case .dnsAddress, .dnsDomain, .proxyBypass:
return true return true
default: default:
@ -537,11 +595,12 @@ extension NetworkSettingsViewController {
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
switch model.row(at: indexPath) { switch model.row(at: indexPath) {
case .dnsAddress: case .dnsAddress:
// start at row 1
networkSettings.dnsServers?.remove(at: indexPath.row - Offsets.dnsAddress) networkSettings.dnsServers?.remove(at: indexPath.row - Offsets.dnsAddress)
case .dnsDomain:
networkSettings.dnsSearchDomains?.remove(at: indexPath.row - Offsets.dnsDomain)
case .proxyBypass: case .proxyBypass:
// start at row 2
networkSettings.proxyBypassDomains?.remove(at: indexPath.row - Offsets.proxyBypass) networkSettings.proxyBypassDomains?.remove(at: indexPath.row - Offsets.proxyBypass)
default: default:

View File

@ -67,11 +67,13 @@ class ServerNetworkViewController: UITableViewController, StrongTableHost {
} }
rows = [] rows = []
if let dnsDomain = configuration.searchDomain, !dnsDomain.isEmpty { if let dnsDomains = configuration.searchDomains, !dnsDomains.isEmpty {
indexOfFirstDNSAddress = 1 for i in 0..<dnsDomains.count {
rows.append(.dnsDomain) rows.append(.dnsDomain)
}
} }
if let dnsServers = configuration.dnsServers, !dnsServers.isEmpty { if let dnsServers = configuration.dnsServers, !dnsServers.isEmpty {
indexOfFirstDNSAddress = rows.count
for i in 0..<dnsServers.count { for i in 0..<dnsServers.count {
rows.append(.dnsAddress) rows.append(.dnsAddress)
} }
@ -240,8 +242,8 @@ extension ServerNetworkViewController {
// shared rows // shared rows
switch row { switch row {
case .dnsDomain: case .dnsDomain:
guard let domain = configuration.searchDomain, !domain.isEmpty else { guard let domain = configuration.searchDomains?[indexPath.row] else {
fatalError("Got DNS domain without a domain") fatalError("Got DNS search domain with empty search domains")
} }
cell.leftText = L10n.Core.NetworkSettings.Dns.Cells.Domain.caption cell.leftText = L10n.Core.NetworkSettings.Dns.Cells.Domain.caption
cell.rightText = domain cell.rightText = domain

View File

@ -9,7 +9,7 @@ $tunnelkit_specs = ['Protocols/OpenVPN', 'Extra/LZO']
def shared_pods def shared_pods
#pod_version $tunnelkit_name, $tunnelkit_specs, '~> 2.0.5' #pod_version $tunnelkit_name, $tunnelkit_specs, '~> 2.0.5'
pod_git $tunnelkit_name, $tunnelkit_specs, '4959442' pod_git $tunnelkit_name, $tunnelkit_specs, '4d930d3'
#pod_path $tunnelkit_name, $tunnelkit_specs, '..' #pod_path $tunnelkit_name, $tunnelkit_specs, '..'
pod 'SSZipArchive' pod 'SSZipArchive'

View File

@ -37,8 +37,8 @@ DEPENDENCIES:
- Convenience/Tables (from `https://github.com/keeshux/convenience`, commit `b990a8c`) - Convenience/Tables (from `https://github.com/keeshux/convenience`, commit `b990a8c`)
- MBProgressHUD - MBProgressHUD
- SSZipArchive - SSZipArchive
- TunnelKit/Extra/LZO (from `https://github.com/passepartoutvpn/tunnelkit`, commit `4959442`) - TunnelKit/Extra/LZO (from `https://github.com/passepartoutvpn/tunnelkit`, commit `4d930d3`)
- TunnelKit/Protocols/OpenVPN (from `https://github.com/passepartoutvpn/tunnelkit`, commit `4959442`) - TunnelKit/Protocols/OpenVPN (from `https://github.com/passepartoutvpn/tunnelkit`, commit `4d930d3`)
SPEC REPOS: SPEC REPOS:
https://github.com/cocoapods/specs.git: https://github.com/cocoapods/specs.git:
@ -52,7 +52,7 @@ EXTERNAL SOURCES:
:commit: b990a8c :commit: b990a8c
:git: https://github.com/keeshux/convenience :git: https://github.com/keeshux/convenience
TunnelKit: TunnelKit:
:commit: '4959442' :commit: 4d930d3
:git: https://github.com/passepartoutvpn/tunnelkit :git: https://github.com/passepartoutvpn/tunnelkit
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
@ -60,7 +60,7 @@ CHECKOUT OPTIONS:
:commit: b990a8c :commit: b990a8c
:git: https://github.com/keeshux/convenience :git: https://github.com/keeshux/convenience
TunnelKit: TunnelKit:
:commit: '4959442' :commit: 4d930d3
:git: https://github.com/passepartoutvpn/tunnelkit :git: https://github.com/passepartoutvpn/tunnelkit
SPEC CHECKSUMS: SPEC CHECKSUMS:
@ -71,6 +71,6 @@ SPEC CHECKSUMS:
SwiftyBeaver: aaf2ebd7dac2e952991f46a82ed24ad642867ae2 SwiftyBeaver: aaf2ebd7dac2e952991f46a82ed24ad642867ae2
TunnelKit: 0743f0306be0869d51118ac33e274e7507a93537 TunnelKit: 0743f0306be0869d51118ac33e274e7507a93537
PODFILE CHECKSUM: a0028109a65292b76d72edb188291804eac46868 PODFILE CHECKSUM: f45a3fd3744e646a5513e3e25d447d1550c9fefa
COCOAPODS: 1.8.4 COCOAPODS: 1.8.4

@ -1 +1 @@
Subproject commit 2b4ae2d4f5034b44c60bd5ad79c092c094362c30 Subproject commit 4fb306195bbb71973adf4d03290952226c2b5dab