Merge pull request #189 from passepartoutvpn/parse-domain-option

Parse DOMAIN-SEARCH option
This commit is contained in:
Davide De Rosa 2020-12-18 18:07:26 +01:00 committed by GitHub
commit 4992532e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -96,6 +96,8 @@ extension OpenVPN {
static let domain = NSRegularExpression("^dhcp-option +DOMAIN +[^ ]+")
static let domainSearch = NSRegularExpression("^dhcp-option +DOMAIN-SEARCH +[^ ]+")
static let proxy = NSRegularExpression("^dhcp-option +PROXY_(HTTPS? +[^ ]+ +\\d+|AUTO_CONFIG_URL +[^ ]+)")
static let proxyBypass = NSRegularExpression("^dhcp-option +PROXY_BYPASS +.+")
@ -225,6 +227,7 @@ extension OpenVPN {
var optRoutes4: [(String, String, String?)] = [] // address, netmask, gateway
var optRoutes6: [(String, UInt8, String?)] = [] // destination, prefix, gateway
var optDNSServers: [String]?
var optDomain: String?
var optSearchDomains: [String]?
var optHTTPProxy: Proxy?
var optHTTPSProxy: Proxy?
@ -528,6 +531,12 @@ extension OpenVPN {
optDNSServers?.append($0[1])
}
Regex.domain.enumerateArguments(in: line) {
guard $0.count == 2 else {
return
}
optDomain = $0[1]
}
Regex.domainSearch.enumerateArguments(in: line) {
guard $0.count == 2 else {
return
}
@ -749,6 +758,15 @@ extension OpenVPN {
)
}
// prepend search domains with main domain (if set)
if let domain = optDomain {
if optSearchDomains == nil {
optSearchDomains = [domain]
} else {
optSearchDomains?.insert(domain, at: 0)
}
}
sessionBuilder.dnsServers = optDNSServers
sessionBuilder.searchDomains = optSearchDomains
sessionBuilder.httpProxy = optHTTPProxy