From 343fb69ae37088b694289891e5746814d6ff4db6 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 23 Oct 2019 10:17:46 +0200 Subject: [PATCH 1/3] Update TunnelKit --- Podfile | 2 +- Podfile.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Podfile b/Podfile index ed4cf3a6..f31233af 100644 --- a/Podfile +++ b/Podfile @@ -9,7 +9,7 @@ $tunnelkit_specs = ['Protocols/OpenVPN', 'Extra/LZO'] def shared_pods #pod_version $tunnelkit_name, $tunnelkit_specs, '~> 2.0.5' - pod_git $tunnelkit_name, $tunnelkit_specs, '74ec321' + pod_git $tunnelkit_name, $tunnelkit_specs, 'dcac7cb' #pod_path $tunnelkit_name, $tunnelkit_specs, '..' pod 'SSZipArchive' diff --git a/Podfile.lock b/Podfile.lock index 62419284..00a07d2b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -37,8 +37,8 @@ DEPENDENCIES: - Convenience/Tables (from `https://github.com/keeshux/convenience`, commit `b990a8c`) - MBProgressHUD - SSZipArchive - - TunnelKit/Extra/LZO (from `https://github.com/passepartoutvpn/tunnelkit`, commit `74ec321`) - - TunnelKit/Protocols/OpenVPN (from `https://github.com/passepartoutvpn/tunnelkit`, commit `74ec321`) + - TunnelKit/Extra/LZO (from `https://github.com/passepartoutvpn/tunnelkit`, commit `dcac7cb`) + - TunnelKit/Protocols/OpenVPN (from `https://github.com/passepartoutvpn/tunnelkit`, commit `dcac7cb`) SPEC REPOS: https://github.com/cocoapods/specs.git: @@ -52,7 +52,7 @@ EXTERNAL SOURCES: :commit: b990a8c :git: https://github.com/keeshux/convenience TunnelKit: - :commit: 74ec321 + :commit: dcac7cb :git: https://github.com/passepartoutvpn/tunnelkit CHECKOUT OPTIONS: @@ -60,7 +60,7 @@ CHECKOUT OPTIONS: :commit: b990a8c :git: https://github.com/keeshux/convenience TunnelKit: - :commit: 74ec321 + :commit: dcac7cb :git: https://github.com/passepartoutvpn/tunnelkit SPEC CHECKSUMS: @@ -71,6 +71,6 @@ SPEC CHECKSUMS: SwiftyBeaver: aaf2ebd7dac2e952991f46a82ed24ad642867ae2 TunnelKit: 0743f0306be0869d51118ac33e274e7507a93537 -PODFILE CHECKSUM: e1ca27d97d74f8df1b842b73e96cd7e549b960f4 +PODFILE CHECKSUM: d4e710af29f32c4b095a1ba28f308af40031483d COCOAPODS: 1.8.4 From 458041bdc82b70b84f57be728871e8969ba7874f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 23 Oct 2019 10:17:56 +0200 Subject: [PATCH 2/3] Add cells to disclose server settings TODO: server network. --- .../Global/SwiftGen+Strings.swift | 12 ++++ .../Scenes/ServiceViewController.swift | 57 ++++++++++++++++++- Submodules/Core | 2 +- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Passepartout-iOS/Global/SwiftGen+Strings.swift b/Passepartout-iOS/Global/SwiftGen+Strings.swift index 7d5332ec..5080cfd0 100644 --- a/Passepartout-iOS/Global/SwiftGen+Strings.swift +++ b/Passepartout-iOS/Global/SwiftGen+Strings.swift @@ -712,6 +712,10 @@ internal enum L10n { /// Reconnect internal static let reconnect = L10n.tr("Core", "service.alerts.buttons.reconnect") } + internal enum Configuration { + /// Configuration unavailable, make sure you are connected to the VPN. + internal static let disconnected = L10n.tr("Core", "service.alerts.configuration.disconnected") + } internal enum CredentialsNeeded { /// You need to enter account credentials first. internal static let message = L10n.tr("Core", "service.alerts.credentials_needed.message") @@ -808,6 +812,14 @@ internal enum L10n { /// Report connectivity issue internal static let caption = L10n.tr("Core", "service.cells.report_issue.caption") } + internal enum ServerConfiguration { + /// Server configuration + internal static let caption = L10n.tr("Core", "service.cells.server_configuration.caption") + } + internal enum ServerNetwork { + /// Server network + internal static let caption = L10n.tr("Core", "service.cells.server_network.caption") + } internal enum TestConnectivity { /// Test connectivity internal static let caption = L10n.tr("Core", "service.cells.test_connectivity.caption") diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index dc93c9ea..baefc88d 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -476,6 +476,41 @@ class ServiceViewController: UIViewController, StrongTableHost { // } // } + private func discloseServerConfiguration() { + let caption = L10n.Core.Service.Cells.ServerConfiguration.caption + tryRequestServerConfiguration(withCaption: caption) { [weak self] in + let vc = StoryboardScene.Main.configurationIdentifier.instantiate() + vc.title = caption + vc.initialConfiguration = $0 + self?.navigationController?.pushViewController(vc, animated: true) + } + } + + private func discloseServerNetwork() { + let caption = L10n.Core.Service.Cells.ServerNetwork.caption + tryRequestServerConfiguration(withCaption: caption) { [weak self] in + let vc = StoryboardScene.Main.configurationIdentifier.instantiate() + vc.title = caption + vc.initialConfiguration = $0 + self?.navigationController?.pushViewController(vc, animated: true) + } + } + + private func tryRequestServerConfiguration(withCaption caption: String, completionHandler: @escaping (OpenVPN.Configuration) -> Void) { + vpn.requestServerConfiguration { [weak self] in + guard let cfg = $0 as? OpenVPN.Configuration else { + let alert = UIAlertController.asAlert( + caption, + L10n.Core.Service.Alerts.Configuration.disconnected + ) + alert.addCancelAction(L10n.Core.Global.ok) + self?.present(alert, animated: true, completion: nil) + return + } + completionHandler(cfg) + } + } + private func togglePrivateDataMasking(cell: ToggleTableViewCell) { let handler = { TransientStore.masksPrivateData = cell.isOn @@ -658,6 +693,10 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog case dataCount + case serverConfiguration + + case serverNetwork + case debugLog case masksPrivateData @@ -884,6 +923,16 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog cell.accessoryType = .none cell.isTappable = false return cell + + case .serverConfiguration: + let cell = Cells.setting.dequeue(from: tableView, for: indexPath) + cell.leftText = L10n.Core.Service.Cells.ServerConfiguration.caption + return cell + + case .serverNetwork: + let cell = Cells.setting.dequeue(from: tableView, for: indexPath) + cell.leftText = L10n.Core.Service.Cells.ServerNetwork.caption + return cell case .debugLog: let cell = Cells.setting.dequeue(from: tableView, for: indexPath) @@ -987,6 +1036,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog // case .dataCount: // displayDataCount() + + case .serverConfiguration: + discloseServerConfiguration() + + case .serverNetwork: + discloseServerNetwork() case .debugLog: perform(segue: StoryboardSegue.Main.debugLogSegueIdentifier, sender: cell) @@ -1125,7 +1180,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog } model.set([.vpnSurvivesSleep], forSection: .vpnSurvivesSleep) model.set([.trustedPolicy], forSection: .trustedPolicy) - model.set([.dataCount, .debugLog, .masksPrivateData], forSection: .diagnostics) + model.set([.dataCount, .serverConfiguration, .serverNetwork, .debugLog, .masksPrivateData], forSection: .diagnostics) model.set([.reportIssue], forSection: .feedback) } diff --git a/Submodules/Core b/Submodules/Core index 7fabb48c..8c09f2c3 160000 --- a/Submodules/Core +++ b/Submodules/Core @@ -1 +1 @@ -Subproject commit 7fabb48cee5189bd3c0d65c3af30cf458f69a1e3 +Subproject commit 8c09f2c3c70da0478cc1b6e94837b1aeb3a0ddde From e0a9fadac4ab5bc72edc26a118f44025bc820586 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 23 Oct 2019 10:52:15 +0200 Subject: [PATCH 3/3] Add server network screen --- Passepartout-iOS/Base.lproj/Main.storyboard | 50 +++- Passepartout-iOS/Global/SwiftGen+Scenes.swift | 2 + Passepartout-iOS/Global/SwiftGen+Segues.swift | 1 + .../Global/SwiftGen+Strings.swift | 8 + .../Scenes/ServerNetworkViewController.swift | 283 ++++++++++++++++++ .../Scenes/ServiceViewController.swift | 7 +- Passepartout.xcodeproj/project.pbxproj | 4 + Submodules/Core | 2 +- 8 files changed, 352 insertions(+), 5 deletions(-) create mode 100644 Passepartout-iOS/Scenes/ServerNetworkViewController.swift diff --git a/Passepartout-iOS/Base.lproj/Main.storyboard b/Passepartout-iOS/Base.lproj/Main.storyboard index 1e447ae3..3e17ade3 100644 --- a/Passepartout-iOS/Base.lproj/Main.storyboard +++ b/Passepartout-iOS/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -123,6 +123,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,6 +277,7 @@ + diff --git a/Passepartout-iOS/Global/SwiftGen+Scenes.swift b/Passepartout-iOS/Global/SwiftGen+Scenes.swift index 8ad7cbb6..c019e041 100644 --- a/Passepartout-iOS/Global/SwiftGen+Scenes.swift +++ b/Passepartout-iOS/Global/SwiftGen+Scenes.swift @@ -28,6 +28,8 @@ internal enum StoryboardScene { internal static let providerPoolViewController = SceneType(storyboard: Main.self, identifier: "ProviderPoolViewController") + internal static let serverNetworkViewController = SceneType(storyboard: Main.self, identifier: "ServerNetworkViewController") + internal static let serviceIdentifier = SceneType(storyboard: Main.self, identifier: "ServiceIdentifier") } internal enum Organizer: StoryboardType { diff --git a/Passepartout-iOS/Global/SwiftGen+Segues.swift b/Passepartout-iOS/Global/SwiftGen+Segues.swift index eea1a797..05c138ee 100644 --- a/Passepartout-iOS/Global/SwiftGen+Segues.swift +++ b/Passepartout-iOS/Global/SwiftGen+Segues.swift @@ -24,6 +24,7 @@ internal enum StoryboardSegue { case networkSettingsSegueIdentifier = "NetworkSettingsSegueIdentifier" case providerPoolSegueIdentifier = "ProviderPoolSegueIdentifier" case providerPresetSegueIdentifier = "ProviderPresetSegueIdentifier" + case serverNetworkSegueIdentifier = "ServerNetworkSegueIdentifier" } internal enum Organizer: String, SegueType { case aboutSegueIdentifier = "AboutSegueIdentifier" diff --git a/Passepartout-iOS/Global/SwiftGen+Strings.swift b/Passepartout-iOS/Global/SwiftGen+Strings.swift index 5080cfd0..c0817dde 100644 --- a/Passepartout-iOS/Global/SwiftGen+Strings.swift +++ b/Passepartout-iOS/Global/SwiftGen+Strings.swift @@ -706,6 +706,14 @@ internal enum L10n { internal static let subscribe = L10n.tr("Core", "reddit.buttons.subscribe") } } + internal enum ServerNetwork { + internal enum Cells { + internal enum Route { + /// Route + internal static let caption = L10n.tr("Core", "server_network.cells.route.caption") + } + } + } internal enum Service { internal enum Alerts { internal enum Buttons { diff --git a/Passepartout-iOS/Scenes/ServerNetworkViewController.swift b/Passepartout-iOS/Scenes/ServerNetworkViewController.swift new file mode 100644 index 00000000..5cbeaf8b --- /dev/null +++ b/Passepartout-iOS/Scenes/ServerNetworkViewController.swift @@ -0,0 +1,283 @@ +// +// ServerNetworkViewController.swift +// Passepartout-iOS +// +// Created by Davide De Rosa on 10/23/19. +// Copyright (c) 2019 Davide De Rosa. All rights reserved. +// +// https://github.com/passepartoutvpn +// +// This file is part of Passepartout. +// +// Passepartout is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Passepartout is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Passepartout. If not, see . +// + +import UIKit +import TunnelKit +import SwiftyBeaver +import PassepartoutCore +import Convenience + +private let log = SwiftyBeaver.self + +class ServerNetworkViewController: UITableViewController, StrongTableHost { + var configuration: OpenVPN.Configuration! + + private let indexOfFirstRoute4 = 2 + + private let indexOfFirstRoute6 = 2 + + private var indexOfFirstDNSAddress = 0 + + private var indexOfFirstProxyBypassDomain = 0 + + // MARK: StrongTableHost + + lazy var model: StrongTableModel = { + let model: StrongTableModel = StrongTableModel() + var rows: [RowType] + + if let ipv4 = configuration.ipv4 { + model.add(.ipv4) + rows = [.address, .defaultGateway] + for i in 0.. Int { + return model.numberOfSections + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return model.header(forSection: section) + } + + override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { + return model.footer(forSection: section) + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return model.numberOfRows(forSection: section) + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let section = model.section(forIndex: indexPath.section) + let row = model.row(at: indexPath) + + let cell = Cells.setting.dequeue(from: tableView, for: indexPath) + cell.accessoryType = .none + cell.isTappable = false + + // family-specific rows + switch section { + case .ipv4: + switch row { + case .address: + cell.leftText = L10n.Core.Global.Captions.address + if let ipv4 = configuration.ipv4 { + cell.rightText = "\(ipv4.address)/\(ipv4.addressMask)" + } else { + cell.rightText = L10n.Core.Global.Values.none + } + + case .defaultGateway: + cell.leftText = L10n.Core.NetworkSettings.Gateway.title + cell.rightText = configuration.ipv4?.defaultGateway ?? L10n.Core.Global.Values.none + + case .route: + guard let route = configuration.ipv4?.routes[indexPath.row - indexOfFirstRoute4] else { + fatalError("Got an IPv4 route cell with empty routes") + } + cell.leftText = L10n.Core.ServerNetwork.Cells.Route.caption + cell.rightText = "\(route.destination)/\(route.mask) -> \(route.gateway)" + + default: + break + } + + case .ipv6: + switch row { + case .address: + cell.leftText = L10n.Core.Global.Captions.address + if let ipv6 = configuration.ipv6 { + cell.rightText = "\(ipv6.address)/\(ipv6.addressPrefixLength)" + } else { + cell.rightText = L10n.Core.Global.Values.none + } + + case .defaultGateway: + cell.leftText = L10n.Core.NetworkSettings.Gateway.title + cell.rightText = configuration.ipv6?.defaultGateway ?? L10n.Core.Global.Values.none + + case .route: + guard let route = configuration.ipv6?.routes[indexPath.row - indexOfFirstRoute6] else { + fatalError("Got an IPv6 route cell with empty routes") + } + cell.leftText = L10n.Core.ServerNetwork.Cells.Route.caption + cell.rightText = "\(route.destination)/\(route.prefixLength) -> \(route.gateway)" + + default: + break + } + + default: + break + } + + // shared rows + switch row { + case .dnsDomain: + guard let domain = configuration.searchDomain, !domain.isEmpty else { + fatalError("Got DNS domain without a domain") + } + cell.leftText = L10n.Core.NetworkSettings.Dns.Cells.Domain.caption + cell.rightText = domain + + case .dnsAddress: + guard let server = configuration.dnsServers?[indexPath.row - indexOfFirstDNSAddress] else { + fatalError("Got DNS server with empty servers") + } + cell.leftText = L10n.Core.Global.Captions.address + cell.rightText = server + + case .proxyAddress: + guard let proxy = configuration.httpsProxy ?? configuration.httpProxy else { + fatalError("Got proxy section without a proxy") + } + cell.leftText = L10n.Core.Global.Captions.address + cell.rightText = "\(proxy.address):\(proxy.port)" + + case .proxyAutoConfigurationURL: + cell.leftText = "PAC" + guard let url = configuration.proxyAutoConfigurationURL else { + fatalError("Got PAC cell without a PAC") + } + cell.rightText = url.absoluteString + + case .proxyBypassDomains: + guard let domain = configuration.proxyBypassDomains?[indexPath.row - indexOfFirstProxyBypassDomain] else { + fatalError("Got proxy bypass domain with empty domains") + } + cell.leftText = L10n.App.NetworkSettings.Cells.ProxyBypass.caption + cell.rightText = domain + + default: + break + } + + return cell + } +} diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index baefc88d..81341a05 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -194,6 +194,9 @@ class ServiceViewController: UIViewController, StrongTableHost { vc?.title = L10n.Core.NetworkSettings.title vc?.profile = profile + case .serverNetworkSegueIdentifier: + break + case .debugLogSegueIdentifier: break } @@ -489,9 +492,9 @@ class ServiceViewController: UIViewController, StrongTableHost { private func discloseServerNetwork() { let caption = L10n.Core.Service.Cells.ServerNetwork.caption tryRequestServerConfiguration(withCaption: caption) { [weak self] in - let vc = StoryboardScene.Main.configurationIdentifier.instantiate() + let vc = StoryboardScene.Main.serverNetworkViewController.instantiate() vc.title = caption - vc.initialConfiguration = $0 + vc.configuration = $0 self?.navigationController?.pushViewController(vc, animated: true) } } diff --git a/Passepartout.xcodeproj/project.pbxproj b/Passepartout.xcodeproj/project.pbxproj index 3d696a96..d7454f2a 100644 --- a/Passepartout.xcodeproj/project.pbxproj +++ b/Passepartout.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ 0E89DFCE213EEDFA00741BA1 /* WizardProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */; }; 0E9CD7872257462800D033B4 /* Providers.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E9CD7862257462800D033B4 /* Providers.xcassets */; }; 0E9CD789225746B300D033B4 /* Flags.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E9CD788225746B300D033B4 /* Flags.xcassets */; }; + 0E9CDB6723604AD5006733B4 /* ServerNetworkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9CDB6623604AD5006733B4 /* ServerNetworkViewController.swift */; }; 0EAAD71920E6669A0088754A /* GroupConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EDE8DED20C93E4C004C739C /* GroupConstants.swift */; }; 0EB60FDA2111136E00AD27F3 /* UITextView+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB60FD92111136E00AD27F3 /* UITextView+Search.swift */; }; 0EB67D6B2184581E00BA6200 /* ImportedHostsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB67D6A2184581E00BA6200 /* ImportedHostsViewController.swift */; }; @@ -248,6 +249,7 @@ 0E8D97E121388B52006FB4A0 /* InfrastructurePreset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfrastructurePreset.swift; sourceTree = ""; }; 0E9CD7862257462800D033B4 /* Providers.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Providers.xcassets; sourceTree = ""; }; 0E9CD788225746B300D033B4 /* Flags.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Flags.xcassets; sourceTree = ""; }; + 0E9CDB6623604AD5006733B4 /* ServerNetworkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerNetworkViewController.swift; sourceTree = ""; }; 0EB60FD92111136E00AD27F3 /* UITextView+Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+Search.swift"; sourceTree = ""; }; 0EB67D6A2184581E00BA6200 /* ImportedHostsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportedHostsViewController.swift; sourceTree = ""; }; 0EBBE8F42182361700106008 /* ConnectionService+Migration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConnectionService+Migration.swift"; sourceTree = ""; }; @@ -590,6 +592,7 @@ 0EFB90192276D7F1006405E4 /* NetworkSettingsViewController.swift */, 0ED31C2B20CF2D6F0027975F /* ProviderPoolViewController.swift */, 0E1D72B1213BFFCF00BA1586 /* ProviderPresetViewController.swift */, + 0E9CDB6623604AD5006733B4 /* ServerNetworkViewController.swift */, 0E57F63D20C83FC5008323CF /* ServiceViewController.swift */, ); path = Scenes; @@ -986,6 +989,7 @@ 0E05C5D620D1645F006EE732 /* SwiftGen+Scenes.swift in Sources */, 0E773BF8224BF37600CDDC8E /* ShortcutsViewController.swift in Sources */, 0E3419AD2350815E00419E18 /* Donation.swift in Sources */, + 0E9CDB6723604AD5006733B4 /* ServerNetworkViewController.swift in Sources */, 0E3262D9235EE8DA00B5E470 /* HostImporter.swift in Sources */, 0EFD9440215BED8E00529B64 /* LabelViewController.swift in Sources */, 0ED31C2C20CF2D6F0027975F /* ProviderPoolViewController.swift in Sources */, diff --git a/Submodules/Core b/Submodules/Core index 8c09f2c3..0afd18fe 160000 --- a/Submodules/Core +++ b/Submodules/Core @@ -1 +1 @@ -Subproject commit 8c09f2c3c70da0478cc1b6e94837b1aeb3a0ddde +Subproject commit 0afd18fec96f0e915a6bddc9917f5846c95919f6