Save .ovpn internally associated to host profile
This commit is contained in:
parent
669477ac12
commit
346a9490ec
|
@ -31,8 +31,12 @@ private let log = SwiftyBeaver.self
|
|||
|
||||
class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
||||
private struct ParsedFile {
|
||||
let filename: String
|
||||
|
||||
let url: URL
|
||||
|
||||
var filename: String {
|
||||
return url.deletingPathExtension().lastPathComponent
|
||||
}
|
||||
|
||||
let hostname: String
|
||||
|
||||
let configuration: TunnelKitProvider.Configuration
|
||||
|
@ -106,7 +110,6 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
|||
func setConfigurationURL(_ url: URL) throws {
|
||||
log.debug("Parsing configuration URL: \(url)")
|
||||
|
||||
let filename = url.deletingPathExtension().lastPathComponent
|
||||
let hostname: String
|
||||
let configuration: TunnelKitProvider.Configuration
|
||||
do {
|
||||
|
@ -115,7 +118,7 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
|||
log.error("Could not parse .ovpn configuration file: \(e)")
|
||||
throw e
|
||||
}
|
||||
parsedFile = ParsedFile(filename: filename, hostname: hostname, configuration: configuration)
|
||||
parsedFile = ParsedFile(url: url, hostname: hostname, configuration: configuration)
|
||||
}
|
||||
|
||||
private func useSuggestedTitle() {
|
||||
|
@ -162,6 +165,15 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
|||
guard let profile = createdProfile else {
|
||||
fatalError("No profile created?")
|
||||
}
|
||||
if let url = parsedFile?.url {
|
||||
do {
|
||||
let savedUrl = try ProfileConfigurationFactory.shared.save(url: url, for: profile)
|
||||
log.debug("Associated .ovpn configuration file to profile '\(profile.id)': \(savedUrl)")
|
||||
} catch let e {
|
||||
log.error("Could not associate .ovpn configuration file to profile: \(e)")
|
||||
}
|
||||
}
|
||||
|
||||
dismiss(animated: true) {
|
||||
self.delegate?.wizard(didCreate: profile, withCredentials: credentials)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
0E1D72B4213C118500BA1586 /* ConfigurationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1D72B3213C118500BA1586 /* ConfigurationViewController.swift */; };
|
||||
0E2B494020FCFF990094784C /* Theme+Titles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2B493F20FCFF990094784C /* Theme+Titles.swift */; };
|
||||
0E2B494220FD16540094784C /* TransientStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2B494120FD16540094784C /* TransientStore.swift */; };
|
||||
0E2D11BA217DBEDE0096822C /* ProfileConfigurationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2D11B9217DBEDE0096822C /* ProfileConfigurationFactory.swift */; };
|
||||
0E39BCF0214B9EF10035E9DE /* WebServices.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E39BCEF214B9EF10035E9DE /* WebServices.swift */; };
|
||||
0E39BCF3214DA9310035E9DE /* AppConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E39BCF2214DA9310035E9DE /* AppConstants.swift */; };
|
||||
0E3DA371215CB5BF00B40FC9 /* VersionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3DA370215CB5BF00B40FC9 /* VersionViewController.swift */; };
|
||||
|
@ -134,6 +135,7 @@
|
|||
0E1D72B3213C118500BA1586 /* ConfigurationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationViewController.swift; sourceTree = "<group>"; };
|
||||
0E2B493F20FCFF990094784C /* Theme+Titles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+Titles.swift"; sourceTree = "<group>"; };
|
||||
0E2B494120FD16540094784C /* TransientStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransientStore.swift; sourceTree = "<group>"; };
|
||||
0E2D11B9217DBEDE0096822C /* ProfileConfigurationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileConfigurationFactory.swift; sourceTree = "<group>"; };
|
||||
0E39BCEF214B9EF10035E9DE /* WebServices.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebServices.swift; sourceTree = "<group>"; };
|
||||
0E39BCF2214DA9310035E9DE /* AppConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConstants.swift; sourceTree = "<group>"; };
|
||||
0E3DA370215CB5BF00B40FC9 /* VersionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionViewController.swift; sourceTree = "<group>"; };
|
||||
|
@ -379,6 +381,7 @@
|
|||
0EC7F20420E24308004EA58E /* DebugLog.swift */,
|
||||
0ED38AE621404F100004D387 /* EndpointDataSource.swift */,
|
||||
0E89DFC4213DF7AE00741BA1 /* Preferences.swift */,
|
||||
0E2D11B9217DBEDE0096822C /* ProfileConfigurationFactory.swift */,
|
||||
0E89DFC7213E8FC500741BA1 /* TunnelKitProvider+Communication.swift */,
|
||||
0E2B494120FD16540094784C /* TransientStore.swift */,
|
||||
0E4C9CB820DB9BC600A0C59C /* TrustedNetworks.swift */,
|
||||
|
@ -831,6 +834,7 @@
|
|||
0ED31C1220CF0ABA0027975F /* Infrastructure.swift in Sources */,
|
||||
0EC7F20520E24308004EA58E /* DebugLog.swift in Sources */,
|
||||
0E4FD7E120D3E4C5002221FF /* MockVPNProvider.swift in Sources */,
|
||||
0E2D11BA217DBEDE0096822C /* ProfileConfigurationFactory.swift in Sources */,
|
||||
0EBE3A90213C6F4000BFA2F5 /* TrustPolicy.swift in Sources */,
|
||||
0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */,
|
||||
0E89DFC8213E8FC500741BA1 /* TunnelKitProvider+Communication.swift in Sources */,
|
||||
|
|
|
@ -36,6 +36,8 @@ class AppConstants {
|
|||
static let serviceFilename = "ConnectionService.json"
|
||||
|
||||
static let infrastructureCacheDirectory = "Infrastructures"
|
||||
|
||||
static let profileConfigurationsDirectory = "Configurations"
|
||||
}
|
||||
|
||||
class VPN {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// ProfileConfigurationFactory.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 10/22/18.
|
||||
// Copyright (c) 2018 Davide De Rosa. All rights reserved.
|
||||
//
|
||||
// https://github.com/keeshux
|
||||
//
|
||||
// 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 Foundation
|
||||
|
||||
class ProfileConfigurationFactory {
|
||||
static let shared = ProfileConfigurationFactory(withDirectory: AppConstants.Store.profileConfigurationsDirectory)
|
||||
|
||||
private let cachePath: URL
|
||||
|
||||
private let configurationsPath: URL
|
||||
|
||||
private init(withDirectory directory: String) {
|
||||
let fm = FileManager.default
|
||||
cachePath = fm.userURL(for: .cachesDirectory, appending: directory)
|
||||
configurationsPath = fm.userURL(for: .documentDirectory, appending: directory)
|
||||
try? fm.createDirectory(at: cachePath, withIntermediateDirectories: false, attributes: nil)
|
||||
try? fm.createDirectory(at: configurationsPath, withIntermediateDirectories: false, attributes: nil)
|
||||
}
|
||||
|
||||
func save(url: URL, for profile: ConnectionProfile) throws -> URL {
|
||||
let savedUrl = configurationURL(for: profile)
|
||||
try FileManager.default.copyItem(at: url, to: savedUrl)
|
||||
return savedUrl
|
||||
}
|
||||
|
||||
func configurationURL(for profile: ConnectionProfile) -> URL {
|
||||
let filename = "\(profile.id).ovpn"
|
||||
return configurationsPath.appendingPathComponent(filename)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue