Skip to content

Commit

Permalink
PIA-1940: Refactor GUI client options management
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-michele-emiliani committed Jun 18, 2024
1 parent 744f78f commit 1c4ad05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
7 changes: 0 additions & 7 deletions ProxyApp/ProxyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ protocol ProxyApp {
// After the stop procedure is completed, the extension process is killed
func stopProxy() -> Bool

// Pass an array of strings, containing all the bundle ID names of the apps
// that will be managed by the Proxy.
//
// To get the bundle ID of an app, knowing its name use this command:
// `osascript -e 'id of app "Google Chrome"'`
func setBypassApps(apps: [String]) -> Void

func startDNSProxy() -> Bool
func stopDNSProxy() -> Bool
}
46 changes: 20 additions & 26 deletions ProxyApp/ProxyAppDefault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ class ProxyAppDefault : ProxyApp {
var proxyManager: NETransparentProxyManager?
var proxyDNSManager: NEDNSProxyManager?
var extensionRequestDelegate = ExtensionRequestDelegate()
var bypassApps: [String] = []
var vpnOnlyApps: [String] = []
var networkInterface: String = ""
var options: [String : Any]
static let proxyManagerName = "PIA Split Tunnel Proxy"
static let proxyDNSManagerName = "PIA DNS Split Tunnel Proxy"
static let serverAddress = "127.0.0.1"

func setBypassApps(apps: [String]) -> Void {
self.bypassApps = apps
}

func setVpnOnlyApps(apps: [String]) -> Void {
self.vpnOnlyApps = apps
}

func setNetworkInterface(interface: String) -> Void {
self.networkInterface = interface

init() {
options = [
// To get the bundle ID of an app, knowing its name use this command:
// `osascript -e 'id of app "Google Chrome"'`
"bypassApps" : ["com.apple.nslookup", "com.apple.curl", "com.apple.ping"],
"vpnOnlyApps" : [],
"bindInterface" : "en0",
"serverAddress" : ProxyAppDefault.serverAddress,
"logFile" : "/tmp/STProxy.log",
"logLevel" : "debug",
// split tunnel is in normal mode, vpn device is the default route
"routeVpn" : true,
// vpn is connected
"isConnected" : true,
// The name of the unix group PIA whitelists in the firewall
"whitelistGroupName" : "piavpn"
]
}

// MARK: TRANSPARENT PROXY MANAGER FUNCTIONS
Expand Down Expand Up @@ -140,18 +145,7 @@ class ProxyAppDefault : ProxyApp {
do {
// This function is used to start the tunnel (the proxy)
// passing it the following settings
try session.startTunnel(options: [
"bypassApps" : self.bypassApps,
"vpnOnlyApps" : self.vpnOnlyApps,
"bindInterface" : self.networkInterface,
"serverAddress" : ProxyAppDefault.serverAddress,
"logFile" : "/tmp/STProxy.log",
"logLevel" : "debug",
"routeVpn" : true,
"isConnected" : true,
// The name of the unix group PIA whitelists in the firewall
"whitelistGroupName" : "piavpn"
] as [String : Any])
try session.startTunnel(options: self.options as [String : Any])
} catch {
os_log("startProxy error!")
print(error)
Expand Down
4 changes: 0 additions & 4 deletions UI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ struct ContentView: View {
Group {
Text("PIA Split Tunnel proxy GUI")
Button("Activate") {
proxyApp.setBypassApps(apps: ["/usr/bin/curl"])

proxyApp.setVpnOnlyApps(apps: [])
proxyApp.setNetworkInterface(interface: "en0")
guard proxyApp.activateExtension() else {
fatalError("Failed to activate the extension")
}
Expand Down

0 comments on commit 1c4ad05

Please sign in to comment.