Sync Zonghengjia iPhone and iPad 1.0.4 source candidate
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
enum TunnelConfigurationBuilder {
|
||||
static let egressProbeURLs = [
|
||||
URL(string: "https://cp.cloudflare.com/generate_204")!,
|
||||
URL(string: "https://api.openai.com/v1/models")!,
|
||||
URL(string: "https://chatgpt.com/api/auth/session")!,
|
||||
]
|
||||
|
||||
static func makeConfiguration(
|
||||
rawJSON: String,
|
||||
tunnelFileDescriptor: Int32,
|
||||
@@ -21,6 +27,7 @@ enum TunnelConfigurationBuilder {
|
||||
if let resolvedRemoteAddress {
|
||||
try replaceProxyRemoteAddress(in: &root, with: resolvedRemoteAddress)
|
||||
}
|
||||
try addTransportRules(to: &root)
|
||||
root["inbounds"] = [[
|
||||
"tag": "tun-in",
|
||||
"port": 0,
|
||||
@@ -44,6 +51,33 @@ enum TunnelConfigurationBuilder {
|
||||
return String(decoding: output, as: UTF8.self)
|
||||
}
|
||||
|
||||
private static func addTransportRules(to root: inout [String: Any]) throws {
|
||||
guard let outbounds = root["outbounds"] as? [[String: Any]],
|
||||
outbounds.contains(where: { $0["tag"] as? String == "proxy" }),
|
||||
var routing = root["routing"] as? [String: Any],
|
||||
var rules = routing["rules"] as? [[String: Any]]
|
||||
else {
|
||||
throw UCVLError.invalidConfiguration("线路配置缺少用于代理出口验证的路由。")
|
||||
}
|
||||
// A request to any probe host must use the authorized outbound even
|
||||
// when the platform's smart routing rules would otherwise send it direct.
|
||||
rules.insert([
|
||||
"type": "field",
|
||||
"domain": egressProbeURLs.compactMap { $0.host }.map { "full:" + $0 },
|
||||
"port": "443",
|
||||
"outboundTag": "proxy",
|
||||
], at: 0)
|
||||
if outbounds.contains(where: { $0["tag"] as? String == "direct" }) {
|
||||
rules.insert([
|
||||
"type": "field",
|
||||
"domain": [#"regexp:(?i)(^|\.)(tailscale\.com|ts\.net)\.?$"#],
|
||||
"outboundTag": "direct",
|
||||
], at: 0)
|
||||
}
|
||||
routing["rules"] = rules
|
||||
root["routing"] = routing
|
||||
}
|
||||
|
||||
static func remoteAddress(from rawJSON: String) -> String? {
|
||||
guard let data = rawJSON.data(using: .utf8),
|
||||
let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
||||
|
||||
Reference in New Issue
Block a user