2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// IssueReporter.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/26/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 Foundation
|
|
|
|
import MessageUI
|
2021-10-27 16:47:08 +00:00
|
|
|
import PassepartoutConstants
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2021-10-27 16:47:08 +00:00
|
|
|
import TunnelKitManager
|
|
|
|
import TunnelKitOpenVPN
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
class IssueReporter: NSObject {
|
|
|
|
static let shared = IssueReporter()
|
|
|
|
|
|
|
|
private weak var viewController: UIViewController?
|
|
|
|
|
|
|
|
override private init() {
|
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
|
2019-09-05 20:50:56 +00:00
|
|
|
func present(in viewController: UIViewController, withIssue issue: Issue) {
|
2018-10-11 07:13:19 +00:00
|
|
|
guard MFMailComposeViewController.canSendMail() else {
|
2019-07-05 09:10:04 +00:00
|
|
|
let app = UIApplication.shared
|
|
|
|
let V = AppConstants.IssueReporter.Email.self
|
|
|
|
let body = V.body(V.template, DebugLog(raw: "--").decoratedString())
|
2019-10-11 08:56:23 +00:00
|
|
|
guard let url = URL.mailto(to: V.recipient, subject: V.subject, body: body), app.canOpenURL(url) else {
|
2021-08-07 11:57:22 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.IssueReporter.title, L10n.Global.emailNotConfigured)
|
|
|
|
alert.addCancelAction(L10n.Global.ok)
|
2019-07-05 09:10:04 +00:00
|
|
|
viewController.present(alert, animated: true, completion: nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
app.open(url, options: [:], completionHandler: nil)
|
2018-10-11 07:13:19 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
self.viewController = viewController
|
|
|
|
|
2019-09-05 20:50:56 +00:00
|
|
|
if issue.debugLog {
|
2021-08-07 11:57:22 +00:00
|
|
|
let alert = UIAlertController.asAlert(L10n.IssueReporter.title, L10n.IssueReporter.message)
|
|
|
|
alert.addPreferredAction(L10n.IssueReporter.Buttons.accept) {
|
2021-10-27 16:47:08 +00:00
|
|
|
VPN.shared.requestDebugLog(fallback: TransientStore.shared.debugSnapshot) {
|
2019-11-07 11:53:12 +00:00
|
|
|
self.composeEmail(withDebugLog: $0, issue: issue)
|
2018-10-23 08:25:41 +00:00
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2021-08-07 11:57:22 +00:00
|
|
|
alert.addCancelAction(L10n.Global.cancel)
|
2018-10-23 08:25:41 +00:00
|
|
|
viewController.present(alert, animated: true, completion: nil)
|
|
|
|
} else {
|
2019-11-07 11:53:12 +00:00
|
|
|
composeEmail(withDebugLog: nil, issue: issue)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:53:12 +00:00
|
|
|
private func composeEmail(withDebugLog debugLog: String?, issue: Issue) {
|
2018-10-11 07:13:19 +00:00
|
|
|
let vc = MFMailComposeViewController()
|
2019-04-07 14:27:16 +00:00
|
|
|
vc.setToRecipients([AppConstants.IssueReporter.Email.recipient])
|
2019-04-07 14:56:38 +00:00
|
|
|
vc.setSubject(AppConstants.IssueReporter.Email.subject)
|
2019-11-07 11:53:12 +00:00
|
|
|
|
|
|
|
let bodyContent = AppConstants.IssueReporter.Email.template
|
|
|
|
var bodyMetadata = "--\n\n"
|
|
|
|
bodyMetadata += DebugLog(raw: "").decoratedString()
|
2019-12-11 23:55:34 +00:00
|
|
|
if let metadata = issue.infrastructureMetadata {
|
2019-12-11 23:46:19 +00:00
|
|
|
bodyMetadata += "Provider: \(metadata.description)\n"
|
|
|
|
if let lastUpdated = InfrastructureFactory.shared.modificationDate(forName: metadata.name) {
|
2019-11-07 11:53:12 +00:00
|
|
|
bodyMetadata += "Last updated: \(lastUpdated)\n"
|
|
|
|
}
|
|
|
|
bodyMetadata += "\n"
|
|
|
|
}
|
|
|
|
bodyMetadata += "--"
|
|
|
|
vc.setMessageBody(AppConstants.IssueReporter.Email.body(bodyContent, bodyMetadata), isHTML: false)
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
if let raw = debugLog {
|
|
|
|
let attachment = DebugLog(raw: raw).decoratedData()
|
2018-10-23 08:25:41 +00:00
|
|
|
vc.addAttachmentData(attachment, mimeType: AppConstants.IssueReporter.MIME.debugLog, fileName: AppConstants.IssueReporter.Filenames.debugLog)
|
|
|
|
}
|
2019-11-07 11:53:12 +00:00
|
|
|
if let url = issue.configurationURL {
|
2018-10-26 22:17:28 +00:00
|
|
|
do {
|
2019-05-23 21:13:45 +00:00
|
|
|
let parsedFile = try OpenVPN.ConfigurationParser.parsed(fromURL: url, returnsStripped: true)
|
2018-10-27 09:36:41 +00:00
|
|
|
if let attachment = parsedFile.strippedLines?.joined(separator: "\n").data(using: .utf8) {
|
2018-10-26 22:17:28 +00:00
|
|
|
vc.addAttachmentData(attachment, mimeType: AppConstants.IssueReporter.MIME.configuration, fileName: AppConstants.IssueReporter.Filenames.configuration)
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
vc.mailComposeDelegate = self
|
2019-10-25 17:28:49 +00:00
|
|
|
vc.apply(.current)
|
2018-10-11 07:13:19 +00:00
|
|
|
viewController?.present(vc, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension IssueReporter: MFMailComposeViewControllerDelegate {
|
|
|
|
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
|
|
|
viewController?.dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|