Feat: Add Pairing File Export URL callback and replace Wireguard with StosVPN (#962)

* Add Pairing File Export URL callback and replace Wireguard with StosVPN

* Fix Data()

* Add Switching Tab

* Fix Pairing Callback Template and fix spelling mistake

* Add Observer for openExportPairingFileConfirm

* Add Logging and fix certificate callback

* add func to Scene Delegate

* Fix ToastView and Logging

* Remove ?

* Fix Logging

* Call AppDelegate instead of SceneDelegate

* Fix Scene Delegate

* Set back SceneDelegate

* Add Logging

* Fix error

* Fix Case Sensitive

* Remove openExportPairingFileConfirm and fix AppDelegate.exportPairingFileNotification

* Remove Alert

* Remove Unnecessary code

* rename export() to exportPairingFile()
This commit is contained in:
Stossy11
2025-04-24 15:48:29 +10:00
committed by GitHub
parent 0e3c3dddfe
commit 4ff643805b
5 changed files with 82 additions and 27 deletions

View File

@@ -140,6 +140,15 @@ private extension SceneDelegate
NotificationCenter.default.post(name: AppDelegate.addSourceDeepLinkNotification, object: nil, userInfo: [AppDelegate.addSourceDeepLinkURLKey: sourceURL])
}
case "pairing":
let queryItems = components.queryItems?.reduce(into: [String: String]()) { $0[$1.name.lowercased()] = $1.value } ?? [:]
Logger.main.info("queryItems \(queryItems)")
guard let callbackTemplate = queryItems["urlname"]?.removingPercentEncoding else { return }
DispatchQueue.main.async {
exportPairingFile(callbackTemplate)
}
case "certificate":
let queryItems = components.queryItems?.reduce(into: [String: String]()) { $0[$1.name.lowercased()] = $1.value } ?? [:]
guard let callbackTemplate = queryItems["callback_template"]?.removingPercentEncoding else { return }
@@ -153,3 +162,39 @@ private extension SceneDelegate
}
}
}
func exportPairingFile(_ urlname: String) {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first, let viewcontroller = window.rootViewController {
let fm = FileManager.default
let documentsPath = fm.documentsDirectory.appendingPathComponent("ALTPairingFile.mobiledevicepairing")
guard let data = try? Data(contentsOf: documentsPath) else {
let toastView = ToastView(text: NSLocalizedString("Failed to find Pairing File!", comment: ""), detailText: nil)
toastView.show(in: viewcontroller)
return
}
let base64encodedCert = data.base64EncodedString()
var allowedQueryParamAndKey = NSCharacterSet.urlQueryAllowed
allowedQueryParamAndKey.remove(charactersIn: ";/?:@&=+$, ")
guard let encodedCert = base64encodedCert.addingPercentEncoding(withAllowedCharacters: allowedQueryParamAndKey) else {
let toastView = ToastView(text: NSLocalizedString("Failed to encode pairingFile!", comment: ""), detailText: nil)
toastView.show(in: viewcontroller)
return
}
var urlStr = "\(urlname)://pairingFile?data=$(BASE64_PAIRING)"
let finished = urlStr.replacingOccurrences(of: "$(BASE64_PAIRING)", with: encodedCert, options: .literal, range: nil)
print(finished)
guard let callbackUrl = URL(string: finished) else {
let toastView = ToastView(text: NSLocalizedString("Failed to initialize callback URL!", comment: ""), detailText: nil)
toastView.show(in: viewcontroller)
return
}
UIApplication.shared.open(callbackUrl)
}
}