2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// EndpointAdvancedView+OpenVPN.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 3/8/22.
|
2024-01-14 13:34:21 +00:00
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
2023-04-04 07:50:45 +00:00
|
|
|
import PassepartoutLibrary
|
2022-04-12 13:09:14 +00:00
|
|
|
import SwiftUI
|
|
|
|
import TunnelKitOpenVPN
|
|
|
|
|
|
|
|
extension EndpointAdvancedView {
|
|
|
|
struct OpenVPNView: View {
|
|
|
|
@Binding var builder: OpenVPN.ConfigurationBuilder
|
|
|
|
|
|
|
|
let isReadonly: Bool
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
let isServerPushed: Bool
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-09-23 20:40:57 +00:00
|
|
|
private let fallbackConfiguration = OpenVPN.ConfigurationBuilder(withFallbacks: true).build()
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var body: some View {
|
|
|
|
List {
|
|
|
|
let cfg = builder.build()
|
2022-10-29 11:23:43 +00:00
|
|
|
if !isServerPushed {
|
|
|
|
pullSection(configuration: cfg)
|
|
|
|
}
|
|
|
|
if builder.ipv4 != nil || builder.routes4 != nil {
|
|
|
|
ipv4Section
|
|
|
|
}
|
|
|
|
if builder.ipv6 != nil || builder.routes6 != nil {
|
|
|
|
ipv6Section
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
dnsSection(configuration: cfg)
|
|
|
|
proxySection(configuration: cfg)
|
|
|
|
if !isReadonly {
|
|
|
|
communicationEditableSection
|
|
|
|
compressionEditableSection
|
|
|
|
} else {
|
|
|
|
communicationSection(configuration: cfg)
|
|
|
|
compressionSection(configuration: cfg)
|
|
|
|
}
|
|
|
|
if !isServerPushed {
|
|
|
|
tlsSection
|
|
|
|
}
|
|
|
|
otherSection(configuration: cfg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
private extension EndpointAdvancedView.OpenVPNView {
|
|
|
|
func pullSection(configuration: OpenVPN.Configuration) -> some View {
|
2022-10-29 11:23:43 +00:00
|
|
|
configuration.pullMask.map { mask in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-10-29 11:23:43 +00:00
|
|
|
ForEach(mask, id: \.self) {
|
|
|
|
Text($0.localizedDescription)
|
2022-10-29 09:22:06 +00:00
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
2022-10-29 11:23:43 +00:00
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Pull.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-29 11:23:43 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
var ipv4Section: some View {
|
2022-10-29 11:23:43 +00:00
|
|
|
Section {
|
|
|
|
if let settings = builder.ipv4 {
|
|
|
|
themeLongContentLinkDefault(
|
|
|
|
L10n.Global.Strings.address,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(settings.localizedDescription(style: .address))
|
2022-10-29 11:23:43 +00:00
|
|
|
)
|
|
|
|
themeLongContentLinkDefault(
|
|
|
|
L10n.NetworkSettings.Gateway.title,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(settings.localizedDescription(style: .defaultGateway))
|
2022-10-29 11:23:43 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
builder.routes4.map { routes in
|
|
|
|
ForEach(routes, id: \.self) { route in
|
2022-10-29 09:22:06 +00:00
|
|
|
themeLongContentLinkDefault(
|
2022-10-29 11:23:43 +00:00
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.Route.caption,
|
|
|
|
content: .constant(route.localizedDescription)
|
2022-10-29 09:22:06 +00:00
|
|
|
)
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-10-29 11:23:43 +00:00
|
|
|
} header: {
|
|
|
|
Text(Unlocalized.Network.ipv4)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
var ipv6Section: some View {
|
2022-10-29 11:23:43 +00:00
|
|
|
Section {
|
|
|
|
if let settings = builder.ipv6 {
|
|
|
|
themeLongContentLinkDefault(
|
|
|
|
L10n.Global.Strings.address,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(settings.localizedDescription(style: .address))
|
2022-10-29 11:23:43 +00:00
|
|
|
)
|
|
|
|
themeLongContentLinkDefault(
|
|
|
|
L10n.NetworkSettings.Gateway.title,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(settings.localizedDescription(style: .defaultGateway))
|
2022-10-29 11:23:43 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
builder.routes6.map { routes in
|
|
|
|
ForEach(routes, id: \.self) { route in
|
|
|
|
themeLongContentLinkDefault(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.Route.caption,
|
|
|
|
content: .constant(route.localizedDescription)
|
|
|
|
)
|
2022-10-13 17:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-29 11:23:43 +00:00
|
|
|
} header: {
|
|
|
|
Text(Unlocalized.Network.ipv6)
|
2022-10-13 17:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
func communicationSection(configuration: OpenVPN.Configuration) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
configuration.communicationSettings.map { settings in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
settings.cipher.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.Cipher.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
settings.digest.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.Digest.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 16:52:57 +00:00
|
|
|
if let xor = settings.xor {
|
|
|
|
themeLongContentLink(
|
|
|
|
Unlocalized.VPN.xor,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(xor.longDescription),
|
|
|
|
withPreview: xor.shortDescription
|
2023-03-17 16:52:57 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Text(Unlocalized.VPN.xor)
|
|
|
|
.withTrailingText(L10n.Global.Strings.disabled)
|
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Communication.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
var communicationEditableSection: some View {
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeTextPicker(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.Cipher.caption,
|
2022-09-23 20:40:57 +00:00
|
|
|
selection: $builder.cipher ?? fallbackCipher,
|
2022-04-12 13:09:14 +00:00
|
|
|
values: OpenVPN.Cipher.available,
|
|
|
|
description: \.localizedDescription
|
|
|
|
)
|
|
|
|
themeTextPicker(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.Digest.caption,
|
2022-09-23 20:40:57 +00:00
|
|
|
selection: $builder.digest ?? fallbackDigest,
|
2022-04-12 13:09:14 +00:00
|
|
|
values: OpenVPN.Digest.available,
|
|
|
|
description: \.localizedDescription
|
|
|
|
)
|
2023-03-17 16:52:57 +00:00
|
|
|
if let xor = builder.xorMethod {
|
|
|
|
themeLongContentLink(
|
|
|
|
Unlocalized.VPN.xor,
|
2023-07-05 15:18:33 +00:00
|
|
|
content: .constant(xor.localizedDescription(style: .long)),
|
|
|
|
withPreview: xor.localizedDescription(style: .short)
|
2023-03-17 16:52:57 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Text(Unlocalized.VPN.xor)
|
|
|
|
.withTrailingText(L10n.Global.Strings.disabled)
|
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Communication.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
func compressionSection(configuration: OpenVPN.Configuration) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
configuration.compressionSettings.map { settings in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
settings.framing.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.CompressionFraming.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
settings.algorithm.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.CompressionAlgorithm.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Compression.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
var compressionEditableSection: some View {
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeTextPicker(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.CompressionFraming.caption,
|
2022-09-23 20:40:57 +00:00
|
|
|
selection: $builder.compressionFraming ?? fallbackCompressionFraming,
|
2022-04-12 13:09:14 +00:00
|
|
|
values: OpenVPN.CompressionFraming.available,
|
|
|
|
description: \.localizedDescription
|
|
|
|
)
|
|
|
|
themeTextPicker(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.CompressionAlgorithm.caption,
|
2022-09-23 20:40:57 +00:00
|
|
|
selection: $builder.compressionAlgorithm ?? fallbackCompressionAlgorithm,
|
2022-04-12 13:09:14 +00:00
|
|
|
values: OpenVPN.CompressionAlgorithm.available,
|
|
|
|
description: \.localizedDescription
|
|
|
|
).disabled(builder.compressionFraming == .disabled)
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Compression.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
func dnsSection(configuration: OpenVPN.Configuration) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
configuration.dnsSettings.map { settings in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
ForEach(settings.servers, id: \.self) {
|
|
|
|
Text(L10n.Global.Strings.address)
|
2022-04-13 07:45:58 +00:00
|
|
|
.withTrailingText($0, copyOnTap: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
ForEach(settings.domains, id: \.self) {
|
|
|
|
Text(L10n.Global.Strings.domain)
|
2022-04-13 07:45:58 +00:00
|
|
|
.withTrailingText($0, copyOnTap: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(Unlocalized.Network.dns)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
func proxySection(configuration: OpenVPN.Configuration) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
configuration.proxySettings.map { settings in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
settings.proxy.map {
|
|
|
|
Text(L10n.Global.Strings.address)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0, copyOnTap: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
settings.pac.map {
|
|
|
|
Text(Unlocalized.Network.proxyAutoConfiguration)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0, copyOnTap: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
ForEach(settings.bypass, id: \.self) {
|
|
|
|
Text(L10n.NetworkSettings.Items.ProxyBypass.caption)
|
2022-04-13 07:45:58 +00:00
|
|
|
.withTrailingText($0, copyOnTap: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Global.Strings.proxy)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
var tlsSection: some View {
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
builder.ca.map { ca in
|
|
|
|
themeLongContentLink(
|
|
|
|
Unlocalized.VPN.certificateAuthority,
|
|
|
|
content: .constant(ca.pem)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
builder.clientCertificate.map { cert in
|
|
|
|
themeLongContentLink(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.Client.caption,
|
|
|
|
content: .constant(cert.pem)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
builder.clientKey.map { key in
|
|
|
|
themeLongContentLink(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.ClientKey.caption,
|
|
|
|
content: .constant(key.pem)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
builder.tlsWrap.map { wrap in
|
|
|
|
themeLongContentLink(
|
|
|
|
L10n.Endpoint.Advanced.Openvpn.Items.TlsWrapping.caption,
|
|
|
|
content: .constant(wrap.key.hexString),
|
2023-07-05 15:18:33 +00:00
|
|
|
withPreview: builder.localizedDescription(style: .tlsWrap)
|
2022-04-12 13:09:14 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.Eku.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText(builder.localizedDescription(style: .eku))
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(Unlocalized.Network.tls)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:54:43 +00:00
|
|
|
func otherSection(configuration: OpenVPN.Configuration) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
configuration.otherSettings.map { settings in
|
2022-05-01 17:43:33 +00:00
|
|
|
Section {
|
2022-04-12 13:09:14 +00:00
|
|
|
settings.keepAlive.map {
|
|
|
|
Text(L10n.Global.Strings.keepalive)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
settings.reneg.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.RenegotiationSeconds.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-10-16 12:19:36 +00:00
|
|
|
settings.randomizeEndpoint.map {
|
2022-04-12 13:09:14 +00:00
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.RandomEndpoint.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-10-16 12:19:36 +00:00
|
|
|
settings.randomizeHostnames.map {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Items.RandomHostname.caption)
|
2023-07-05 15:18:33 +00:00
|
|
|
.withTrailingText($0)
|
2022-10-16 12:19:36 +00:00
|
|
|
}
|
2022-05-01 17:43:33 +00:00
|
|
|
} header: {
|
|
|
|
Text(L10n.Endpoint.Advanced.Openvpn.Sections.Other.header)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-19 13:41:53 +00:00
|
|
|
private extension OpenVPN.Configuration {
|
|
|
|
struct CommunicationOptions {
|
2023-07-05 15:18:33 +00:00
|
|
|
let cipher: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let digest: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let xor: (shortDescription: String, longDescription: String)?
|
2023-03-19 13:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CompressionOptions {
|
2023-07-05 15:18:33 +00:00
|
|
|
let framing: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let algorithm: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct DNSOptions {
|
|
|
|
let servers: [String]
|
|
|
|
|
|
|
|
let domains: [String]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ProxyOptions {
|
2023-07-05 15:18:33 +00:00
|
|
|
let proxy: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let pac: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
|
|
|
let bypass: [String]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct OtherOptions {
|
2023-07-05 15:18:33 +00:00
|
|
|
let keepAlive: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let reneg: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let randomizeEndpoint: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
let randomizeHostnames: String?
|
2023-03-19 13:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var communicationSettings: CommunicationOptions? {
|
2022-11-06 17:08:41 +00:00
|
|
|
guard cipher != nil || digest != nil || xorMethod != nil else {
|
2022-04-12 13:09:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-07-05 15:18:33 +00:00
|
|
|
return .init(
|
|
|
|
cipher: cipher?.localizedDescription,
|
|
|
|
digest: digest?.localizedDescription,
|
|
|
|
xor: xorMethod.map {
|
|
|
|
($0.localizedDescription(style: .short), $0.localizedDescription(style: .long))
|
|
|
|
}
|
|
|
|
)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2023-03-19 13:41:53 +00:00
|
|
|
var compressionSettings: CompressionOptions? {
|
2022-04-12 13:09:14 +00:00
|
|
|
guard compressionFraming != nil || compressionAlgorithm != nil else {
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-05 15:18:33 +00:00
|
|
|
return .init(
|
|
|
|
framing: compressionFraming?.localizedDescription,
|
|
|
|
algorithm: compressionAlgorithm?.localizedDescription
|
|
|
|
)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-03-19 13:41:53 +00:00
|
|
|
var dnsSettings: DNSOptions? {
|
2022-04-12 13:09:14 +00:00
|
|
|
guard !(dnsServers?.isEmpty ?? true) || !(searchDomains?.isEmpty ?? true) else {
|
|
|
|
return nil
|
|
|
|
}
|
2023-03-19 13:41:53 +00:00
|
|
|
return .init(servers: dnsServers ?? [], domains: searchDomains ?? [])
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-03-19 13:41:53 +00:00
|
|
|
var proxySettings: ProxyOptions? {
|
|
|
|
guard httpsProxy != nil || httpProxy != nil ||
|
|
|
|
proxyAutoConfigurationURL != nil || !(proxyBypassDomains?.isEmpty ?? true) else {
|
2022-04-12 13:09:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-03-19 13:41:53 +00:00
|
|
|
return .init(
|
2023-07-05 15:18:33 +00:00
|
|
|
proxy: (httpsProxy ?? httpProxy)?.rawValue,
|
|
|
|
pac: proxyAutoConfigurationURL?.absoluteString,
|
2023-03-19 13:41:53 +00:00
|
|
|
bypass: proxyBypassDomains ?? []
|
|
|
|
)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-03-19 13:41:53 +00:00
|
|
|
var otherSettings: OtherOptions? {
|
|
|
|
guard keepAliveInterval != nil || renegotiatesAfter != nil ||
|
|
|
|
randomizeEndpoint != nil || randomizeHostnames != nil else {
|
2022-04-12 13:09:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-03-19 13:41:53 +00:00
|
|
|
return .init(
|
2023-07-05 15:18:33 +00:00
|
|
|
keepAlive: localizedDescription(optionalStyle: .keepAlive),
|
|
|
|
reneg: localizedDescription(optionalStyle: .renegotiatesAfter),
|
|
|
|
randomizeEndpoint: localizedDescription(optionalStyle: .randomizeEndpoint),
|
|
|
|
randomizeHostnames: localizedDescription(optionalStyle: .randomizeHostnames)
|
2023-03-19 13:41:53 +00:00
|
|
|
)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-23 20:40:57 +00:00
|
|
|
|
|
|
|
private extension EndpointAdvancedView.OpenVPNView {
|
|
|
|
var fallbackCipher: OpenVPN.Cipher {
|
|
|
|
fallbackConfiguration.cipher!
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-09-23 20:40:57 +00:00
|
|
|
var fallbackDigest: OpenVPN.Digest {
|
|
|
|
fallbackConfiguration.digest!
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-09-23 20:40:57 +00:00
|
|
|
var fallbackCompressionFraming: OpenVPN.CompressionFraming {
|
|
|
|
fallbackConfiguration.compressionFraming!
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-09-23 20:40:57 +00:00
|
|
|
var fallbackCompressionAlgorithm: OpenVPN.CompressionAlgorithm {
|
|
|
|
fallbackConfiguration.compressionAlgorithm!
|
|
|
|
}
|
|
|
|
}
|