2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// ConfigurationViewController.swift
|
2021-01-01 16:53:28 +00:00
|
|
|
// Passepartout
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/2/18.
|
2020-12-27 16:30:25 +00:00
|
|
|
// Copyright (c) 2021 Davide De Rosa. All rights reserved.
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
2018-11-03 21:33:30 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-10-22 09:16:05 +00:00
|
|
|
import SwiftyBeaver
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2021-10-27 16:47:08 +00:00
|
|
|
import ConvenienceUI
|
2018-10-22 09:16:05 +00:00
|
|
|
|
|
|
|
private let log = SwiftyBeaver.self
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
class ConfigurationViewController: UIViewController, StrongTableHost {
|
2018-10-11 07:13:19 +00:00
|
|
|
@IBOutlet private weak var tableView: UITableView!
|
|
|
|
|
|
|
|
private lazy var itemRefresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh))
|
|
|
|
|
2019-05-23 21:13:45 +00:00
|
|
|
var initialConfiguration: OpenVPN.Configuration!
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-05-23 21:13:45 +00:00
|
|
|
private lazy var configuration: OpenVPN.ConfigurationBuilder = initialConfiguration.builder()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
var originalConfigurationURL: URL?
|
|
|
|
|
2018-10-25 20:51:01 +00:00
|
|
|
private var isEditable: Bool {
|
|
|
|
return originalConfigurationURL != nil
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:54:04 +00:00
|
|
|
var isServerPushed = false
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
weak var delegate: ConfigurationModificationDelegate?
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
// MARK: StrongTableHost
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-11-19 23:54:04 +00:00
|
|
|
let model: StrongTableModel<SectionType, RowType> = StrongTableModel()
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
model.clear()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// sections
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2018-10-22 09:16:05 +00:00
|
|
|
model.add(.reset)
|
2020-02-28 17:32:04 +00:00
|
|
|
model.setHeader("", forSection: .reset)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// headers
|
2021-08-07 11:57:22 +00:00
|
|
|
model.setHeader(L10n.Configuration.Sections.Communication.header, forSection: .communication)
|
|
|
|
model.setHeader(L10n.Configuration.Sections.Tls.header, forSection: .tls)
|
|
|
|
model.setHeader(L10n.Configuration.Sections.Compression.header, forSection: .compression)
|
|
|
|
model.setHeader(L10n.Configuration.Sections.Other.header, forSection: .other)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
// footers
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2021-08-07 11:57:22 +00:00
|
|
|
model.setFooter(L10n.Configuration.Sections.Reset.footer, forSection: .reset)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// rows
|
2019-11-19 23:54:04 +00:00
|
|
|
if isServerPushed {
|
|
|
|
var rows: [RowType]
|
|
|
|
|
|
|
|
rows = []
|
|
|
|
if let _ = configuration.cipher {
|
|
|
|
rows.append(.cipher)
|
|
|
|
}
|
|
|
|
if let _ = configuration.digest {
|
|
|
|
rows.append(.digest)
|
|
|
|
}
|
2019-12-11 23:45:21 +00:00
|
|
|
if !rows.isEmpty {
|
|
|
|
model.add(.communication)
|
|
|
|
model.set(rows, forSection: .communication)
|
|
|
|
}
|
2019-11-19 23:54:04 +00:00
|
|
|
|
|
|
|
rows = []
|
|
|
|
if let _ = configuration.compressionFraming {
|
|
|
|
rows.append(.compressionFraming)
|
|
|
|
}
|
|
|
|
if let _ = configuration.compressionAlgorithm {
|
|
|
|
rows.append(.compressionAlgorithm)
|
|
|
|
}
|
2019-12-11 23:45:21 +00:00
|
|
|
if !rows.isEmpty {
|
|
|
|
model.add(.compression)
|
|
|
|
model.set(rows, forSection: .compression)
|
|
|
|
}
|
2019-11-19 23:54:04 +00:00
|
|
|
|
|
|
|
rows = []
|
|
|
|
if let _ = configuration.keepAliveInterval {
|
|
|
|
rows.append(.keepAlive)
|
|
|
|
}
|
|
|
|
if let _ = configuration.renegotiatesAfter {
|
|
|
|
rows.append(.renegSeconds)
|
|
|
|
}
|
|
|
|
if let _ = configuration.randomizeEndpoint {
|
|
|
|
rows.append(.randomEndpoint)
|
|
|
|
}
|
2019-12-11 23:45:21 +00:00
|
|
|
if !rows.isEmpty {
|
|
|
|
model.add(.other)
|
|
|
|
model.set(rows, forSection: .other)
|
|
|
|
}
|
2019-11-19 23:54:04 +00:00
|
|
|
} else {
|
2019-12-11 23:45:21 +00:00
|
|
|
model.add(.communication)
|
|
|
|
model.add(.compression)
|
2021-07-23 15:27:01 +00:00
|
|
|
model.add(.tls)
|
2019-12-11 23:45:21 +00:00
|
|
|
model.add(.other)
|
2021-07-23 16:08:45 +00:00
|
|
|
model.set([.cipher, .digest, .xorMask], forSection: .communication)
|
2019-11-19 23:54:04 +00:00
|
|
|
model.set([.compressionFraming, .compressionAlgorithm], forSection: .compression)
|
2021-07-23 16:08:45 +00:00
|
|
|
model.set([.keepAlive, .renegSeconds, .randomEndpoint], forSection: .other)
|
2019-11-19 23:54:04 +00:00
|
|
|
}
|
2018-10-25 20:51:01 +00:00
|
|
|
if isEditable {
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.resetOriginal], forSection: .reset)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
2019-10-11 08:56:23 +00:00
|
|
|
model.set([.client, .tlsWrapping, .eku], forSection: .tls)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UIViewController
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2018-10-25 20:51:01 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
guard let _ = initialConfiguration else {
|
|
|
|
fatalError("Initial configuration not set")
|
|
|
|
}
|
2019-11-19 23:54:04 +00:00
|
|
|
reloadModel()
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
guard isEditable else {
|
|
|
|
tableView.allowsSelection = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
itemRefresh.isEnabled = false
|
|
|
|
navigationItem.rightBarButtonItem = itemRefresh
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
if let ip = tableView.indexPathForSelectedRow {
|
|
|
|
tableView.deselectRow(at: ip, animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
2021-02-04 15:17:50 +00:00
|
|
|
private func resetOriginalConfiguration(passphrase: String? = nil) {
|
2018-10-27 09:36:41 +00:00
|
|
|
guard let originalURL = originalConfigurationURL else {
|
2018-10-22 09:16:05 +00:00
|
|
|
log.warning("Resetting with no original configuration set? Bad table model?")
|
|
|
|
return
|
|
|
|
}
|
2019-05-23 21:13:45 +00:00
|
|
|
let parsingResult: OpenVPN.ConfigurationParser.Result
|
2018-10-22 09:31:46 +00:00
|
|
|
do {
|
2021-02-04 15:17:50 +00:00
|
|
|
parsingResult = try OpenVPN.ConfigurationParser.parsed(fromURL: originalURL, passphrase: passphrase)
|
|
|
|
} catch let e as ConfigurationError {
|
|
|
|
switch e {
|
|
|
|
case .encryptionPassphrase:
|
|
|
|
log.warning("Configuration is encrypted, ask for passphrase")
|
|
|
|
askForResetConfigurationWithPassphrase(originalURL)
|
|
|
|
|
|
|
|
default:
|
|
|
|
log.error("Could not parse original configuration: \(e)")
|
|
|
|
}
|
|
|
|
return
|
2018-10-22 09:31:46 +00:00
|
|
|
} catch let e {
|
2018-10-27 08:55:50 +00:00
|
|
|
log.error("Could not parse original configuration: \(e)")
|
2018-10-22 09:31:46 +00:00
|
|
|
return
|
|
|
|
}
|
2018-11-10 09:29:51 +00:00
|
|
|
configuration = parsingResult.configuration.builder()
|
2018-10-27 10:18:47 +00:00
|
|
|
itemRefresh.isEnabled = !configuration.canCommunicate(with: initialConfiguration)
|
2018-11-10 09:29:51 +00:00
|
|
|
initialConfiguration = parsingResult.configuration
|
2018-10-22 09:31:46 +00:00
|
|
|
tableView.reloadData()
|
|
|
|
|
2018-10-25 18:08:22 +00:00
|
|
|
delegate?.configuration(didUpdate: initialConfiguration)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
2021-02-04 15:17:50 +00:00
|
|
|
|
|
|
|
private func askForResetConfigurationWithPassphrase(_ originalURL: URL) {
|
2021-08-07 11:57:22 +00:00
|
|
|
let alert = UIAlertController.asAlert(nil, L10n.ParsedFile.Alerts.EncryptionPassphrase.message)
|
2021-02-04 15:17:50 +00:00
|
|
|
alert.addTextField { (field) in
|
|
|
|
field.isSecureTextEntry = true
|
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addPreferredAction(L10n.Global.ok) {
|
2021-02-04 15:17:50 +00:00
|
|
|
guard let passphrase = alert.textFields?.first?.text else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.resetOriginalConfiguration(passphrase: passphrase)
|
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.cancel) {
|
2021-02-04 15:17:50 +00:00
|
|
|
}
|
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
|
}
|
2018-10-22 09:16:05 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
@IBAction private func refresh() {
|
|
|
|
guard isEditable else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
initialConfiguration = configuration.build()
|
|
|
|
itemRefresh.isEnabled = false
|
|
|
|
|
|
|
|
delegate?.configurationShouldReinstall()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegate {
|
|
|
|
enum SectionType: Int {
|
|
|
|
case communication
|
2018-10-22 09:16:05 +00:00
|
|
|
|
|
|
|
case reset
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case tls
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case compression
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case other
|
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
|
|
|
case cipher
|
|
|
|
|
|
|
|
case digest
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
case resetOriginal
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case client
|
|
|
|
|
|
|
|
case tlsWrapping
|
|
|
|
|
2019-03-27 16:06:13 +00:00
|
|
|
case eku
|
|
|
|
|
2019-03-19 10:52:17 +00:00
|
|
|
case compressionFraming
|
2019-03-03 09:40:12 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case compressionAlgorithm
|
|
|
|
|
2021-07-23 15:27:01 +00:00
|
|
|
case xorMask
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case keepAlive
|
|
|
|
|
|
|
|
case renegSeconds
|
2019-03-27 16:06:13 +00:00
|
|
|
|
|
|
|
case randomEndpoint
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfSections
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.header(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.footer(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
2019-04-04 17:53:08 +00:00
|
|
|
return model.headerHeight(for: section)
|
2018-10-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfRows(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let row = model.row(at: indexPath)
|
2021-08-07 11:57:22 +00:00
|
|
|
let V = L10n.Configuration.Cells.self
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
if !isEditable {
|
|
|
|
cell.accessoryType = .none
|
|
|
|
}
|
|
|
|
cell.isTappable = isEditable
|
|
|
|
switch row {
|
2021-01-10 13:29:04 +00:00
|
|
|
case .resetOriginal:
|
|
|
|
cell.leftText = V.ResetOriginal.caption
|
|
|
|
cell.applyAction(.current)
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .cipher:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.Cipher.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.fallbackCipher.uiDescription
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .digest:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.Digest.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.fallbackDigest.uiDescription
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-30 11:43:47 +00:00
|
|
|
case .compressionFraming:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.CompressionFraming.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.fallbackCompressionFraming.uiDescription
|
2019-04-30 11:43:47 +00:00
|
|
|
|
|
|
|
case .compressionAlgorithm:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.CompressionAlgorithm.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.fallbackCompressionAlgorithm.uiDescription
|
2019-05-04 08:33:04 +00:00
|
|
|
cell.isTappable = (configuration.compressionFraming != .disabled)
|
2021-07-23 15:27:01 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .client:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.Client.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForClientCertificate
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .tlsWrapping:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.TlsWrapping.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForTLSWrap
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2019-03-03 09:40:12 +00:00
|
|
|
|
2019-03-27 16:06:13 +00:00
|
|
|
case .eku:
|
|
|
|
cell.leftText = V.Eku.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForEKU
|
2019-04-03 12:08:22 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
case .keepAlive:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.KeepAlive.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForKeepAlive
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
|
|
|
|
|
|
|
case .renegSeconds:
|
2019-06-20 18:57:27 +00:00
|
|
|
cell.leftText = V.RenegotiationSeconds.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForRenegotiatesAfter
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2019-03-27 16:06:13 +00:00
|
|
|
|
|
|
|
case .randomEndpoint:
|
|
|
|
cell.leftText = V.RandomEndpoint.caption
|
2021-01-10 13:29:04 +00:00
|
|
|
cell.rightText = configuration.uiDescriptionForRandomizeEndpoint
|
2019-03-27 16:06:13 +00:00
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2021-07-23 15:27:01 +00:00
|
|
|
|
|
|
|
case .xorMask:
|
|
|
|
cell.leftText = "XOR"
|
|
|
|
cell.rightText = configuration.uiDescriptionForXOR
|
|
|
|
cell.accessoryType = .none
|
|
|
|
cell.isTappable = false
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
guard isEditable else {
|
|
|
|
fatalError("Table should not allow selection when isEditable is false")
|
|
|
|
}
|
|
|
|
|
2018-10-27 20:21:00 +00:00
|
|
|
let settingCell = tableView.cellForRow(at: indexPath) as? SettingTableViewCell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .cipher:
|
2021-01-10 09:16:06 +00:00
|
|
|
var options: [OpenVPN.Cipher] = configuration.dataCiphers ?? []
|
|
|
|
if !options.isEmpty {
|
|
|
|
if let cipher = configuration.cipher, !options.contains(cipher) {
|
|
|
|
options.append(cipher)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options.append(contentsOf: OpenVPN.Cipher.available)
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let vc = SingleOptionViewController<OpenVPN.Cipher>()
|
2019-10-25 17:30:21 +00:00
|
|
|
vc.applyTint(.current)
|
2018-10-27 20:21:00 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2021-01-10 09:16:06 +00:00
|
|
|
vc.options = options
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.selectedOption = configuration.cipher
|
2021-01-10 13:29:04 +00:00
|
|
|
vc.descriptionBlock = { $0.uiDescription }
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.cipher = $0
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
|
|
|
|
case .digest:
|
2019-10-11 08:56:23 +00:00
|
|
|
let vc = SingleOptionViewController<OpenVPN.Digest>()
|
2019-10-25 17:30:21 +00:00
|
|
|
vc.applyTint(.current)
|
2018-10-27 20:21:00 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2019-06-22 07:34:43 +00:00
|
|
|
vc.options = OpenVPN.Digest.available
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.selectedOption = configuration.digest
|
2021-01-10 13:29:04 +00:00
|
|
|
vc.descriptionBlock = { $0.uiDescription }
|
2018-10-11 07:13:19 +00:00
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.digest = $0
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
|
2019-04-30 11:43:47 +00:00
|
|
|
case .compressionFraming:
|
2019-10-11 08:56:23 +00:00
|
|
|
let vc = SingleOptionViewController<OpenVPN.CompressionFraming>()
|
2019-10-25 17:30:21 +00:00
|
|
|
vc.applyTint(.current)
|
2019-04-30 11:43:47 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2019-06-22 07:34:43 +00:00
|
|
|
vc.options = OpenVPN.CompressionFraming.available
|
2019-05-04 08:33:04 +00:00
|
|
|
vc.selectedOption = configuration.compressionFraming ?? .disabled
|
2021-01-10 13:29:04 +00:00
|
|
|
vc.descriptionBlock = { $0.uiDescription }
|
2019-04-30 11:43:47 +00:00
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.compressionFraming = $0
|
|
|
|
if $0 == .disabled {
|
|
|
|
self?.configuration.compressionAlgorithm = .disabled
|
|
|
|
}
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-30 11:43:47 +00:00
|
|
|
case .compressionAlgorithm:
|
|
|
|
guard configuration.compressionFraming != .disabled else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let vc = SingleOptionViewController<OpenVPN.CompressionAlgorithm>()
|
2019-10-25 17:30:21 +00:00
|
|
|
vc.applyTint(.current)
|
2019-04-30 11:43:47 +00:00
|
|
|
vc.title = settingCell?.leftText
|
2019-06-22 07:34:43 +00:00
|
|
|
vc.options = OpenVPN.CompressionAlgorithm.available
|
2019-05-04 08:33:04 +00:00
|
|
|
vc.selectedOption = configuration.compressionAlgorithm ?? .disabled
|
2021-01-10 13:29:04 +00:00
|
|
|
vc.descriptionBlock = { $0.uiDescription }
|
2019-04-30 11:43:47 +00:00
|
|
|
vc.selectionBlock = { [weak self] in
|
|
|
|
self?.configuration.compressionAlgorithm = $0
|
|
|
|
self?.popAndCheckRefresh()
|
|
|
|
}
|
|
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
|
2018-10-22 09:16:05 +00:00
|
|
|
case .resetOriginal:
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
resetOriginalConfiguration()
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Helpers
|
|
|
|
|
|
|
|
private func popAndCheckRefresh() {
|
|
|
|
itemRefresh.isEnabled = !configuration.canCommunicate(with: initialConfiguration)
|
|
|
|
tableView.reloadData()
|
|
|
|
navigationController?.popViewController(animated: true)
|
|
|
|
|
|
|
|
delegate?.configuration(didUpdate: configuration.build())
|
|
|
|
}
|
|
|
|
}
|