// // ServerNetworkViewController.swift // Passepartout-iOS // // Created by Davide De Rosa on 10/23/19. // Copyright (c) 2021 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.searchDomains?[indexPath.row] else { fatalError("Got DNS search domain with empty search domains") } 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 } }