diff --git a/Common/ACConnectionManager.m b/Common/ACConnectionManager.m index 5cfc5d4..08be4e6 100644 --- a/Common/ACConnectionManager.m +++ b/Common/ACConnectionManager.m @@ -10,6 +10,7 @@ #import "ACNEService.h" #import "ACNEServicesManager.h" #import "ACPreferences.h" +#import "CoreWLAN/CoreWLAN.h" @interface ACConnectionManager () @@ -224,7 +225,25 @@ -(void)connectAllAutoConnectedServices { if([alwaysConnectedServicesIdentifiers containsObject:[neService.configuration.identifier UUIDString]]) { - [neService connect]; + BOOL shouldConnect = YES; + // Assuming we have any Wi-Fi interfaces available... + if([[CWWiFiClient interfaceNames] count] > 0) + { + CWInterface *wifi = [[CWWiFiClient sharedWiFiClient] interface]; + NSArray* ignoredSSIDs = [[ACPreferences sharedPreferences] ignoredSSIDs]; + + // ...if the current SSID exists, and it's in the list of ignored SSIDs... + if(wifi.ssid != nil && [ignoredSSIDs containsObject:wifi.ssid]) + { + // ...do not connect. + shouldConnect = NO; + } + } + + if(shouldConnect) + { + [neService connect]; + } } } } diff --git a/Common/ACPreferences.h b/Common/ACPreferences.h index 5744f1d..a2cafdd 100644 --- a/Common/ACPreferences.h +++ b/Common/ACPreferences.h @@ -23,6 +23,11 @@ */ -(NSArray*)alwaysConnectedServicesIdentifiers; +/** + Return the list of ignored SSIDs for the current service identifier + */ +-(NSArray*)ignoredSSIDs; + /** Enable or disable auto connect for the VPN service diff --git a/Common/ACPreferences.m b/Common/ACPreferences.m index 1474551..3cfdc77 100644 --- a/Common/ACPreferences.m +++ b/Common/ACPreferences.m @@ -14,6 +14,7 @@ NSString * const kServicesPrefKey = @"Services"; NSString * const kServiceIdentifierKey = @"Identifier"; NSString * const kServiceAlwaysConnectedKey = @"AlwaysConnected"; +NSString * const kServiceIgnoredSSIDsKey = @"IgnoredSSIDs"; NSString * const kAlwaysConnectedRetryDelayPrefKey = @"AlwaysConnectedRetryDelay"; @@ -88,6 +89,21 @@ -(void)setAlwaysConnected:(BOOL)inAlwaysConnected forServicesIdentifier:(NSStrin [[NSUserDefaults standardUserDefaults] setObject:services forKey:kServicesPrefKey]; } +/** + Gets the list of SSIDs that should be ignored for the + purposes of automatic connection. Note that this is input + using: + + defaults write org.timac.VPNStatus IgnoredSSIDs "FirstSSD,Second,Third" + + Also note that the SSID is ignored irrespective of the VPN service. + */ +-(NSArray *)ignoredSSIDs +{ + NSString *ignoredSSIDsString = [[NSUserDefaults standardUserDefaults] stringForKey:kServiceIgnoredSSIDsKey]; + return [ignoredSSIDsString componentsSeparatedByString:@","]; +} + -(NSInteger)alwaysConnectedRetryDelay { NSInteger retryDelay = [[NSUserDefaults standardUserDefaults] integerForKey:kAlwaysConnectedRetryDelayPrefKey]; diff --git a/README.md b/README.md index 03f10b3..686fb09 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,30 @@ VPNStatus, an application that replicates some functionalities of macOS built-in # Retry Delay - VPNStatus tries to reconnect to the VPN every 120s by default. You can change this value using a secret preference. To change the retry delay to 30s: - Quit VPNStatus -- Run this command line in a Terminal window: +- Run this command in a Terminal window: ``` defaults write org.timac.VPNStatus AlwaysConnectedRetryDelay -int 30 ``` + +# Ignored SSIDs + +VPNStatus can optionally ignore one or more SSIDs, such that services are **not** autoconnected when the current Wi-Fi SSID is on the ignored list. + +To set the list of ignored SSIDs: + +- Quit VPNStatus +- Run this command in a Terminal window: + +``` +defaults write org.timac.VPNStatus IgnoredSSIDs "OneSSID,SecondSSID,Third SSID" +``` + +With the above example, if the current Wi-Fi network SSID is `OneSSID`, `SecondSSID`, or `Third SSID`, then the VPN will **not** autoconnect. + +If the Wi-Fi network SSID is, say, `FourthSSID`, the VPN service **will** autoconnect, becuase it is not on the list. + +Note that SSIDs **are** case-sensitive. diff --git a/VPN.xcodeproj/project.pbxproj b/VPN.xcodeproj/project.pbxproj index 3ed7c17..bcab3f7 100644 --- a/VPN.xcodeproj/project.pbxproj +++ b/VPN.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -36,6 +36,8 @@ 65DE11B02600FF3E003E05A8 /* ACNEServicesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 02799F7E20F0081F00675162 /* ACNEServicesManager.m */; }; 65DE11B12600FF3E003E05A8 /* ACPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 02619DFD20F7F7BE00099652 /* ACPreferences.m */; }; 65DE11B22600FF3E003E05A8 /* ACConnectionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0231297A20F9F8CE003F7540 /* ACConnectionManager.m */; }; + C9CBC4E627B5CDCA00D25554 /* CoreWLAN.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9CBC4E527B5CDCA00D25554 /* CoreWLAN.framework */; platformFilter = maccatalyst; }; + C9CBC4E727B5CDE000D25554 /* CoreWLAN.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9CBC4E527B5CDCA00D25554 /* CoreWLAN.framework */; platformFilter = maccatalyst; }; FA53906D20EF5F7F00BA9AF7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FA53906C20EF5F7F00BA9AF7 /* AppDelegate.m */; }; FA53906F20EF5F8000BA9AF7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA53906E20EF5F8000BA9AF7 /* Assets.xcassets */; }; FA53907220EF5F8000BA9AF7 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA53907020EF5F8000BA9AF7 /* MainMenu.xib */; }; @@ -79,6 +81,7 @@ 02799F7D20F0081F00675162 /* ACNEServicesManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ACNEServicesManager.h; sourceTree = ""; }; 02799F7E20F0081F00675162 /* ACNEServicesManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ACNEServicesManager.m; sourceTree = ""; }; 65DE11952600FE38003E05A8 /* libVPNUtil.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libVPNUtil.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; + C9CBC4E527B5CDCA00D25554 /* CoreWLAN.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreWLAN.framework; path = System/Library/Frameworks/CoreWLAN.framework; sourceTree = SDKROOT; }; FA53906820EF5F7F00BA9AF7 /* VPNApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VPNApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; FA53906B20EF5F7F00BA9AF7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; FA53906C20EF5F7F00BA9AF7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -106,6 +109,7 @@ buildActionMask = 2147483647; files = ( 02619DFA20F7E25C00099652 /* AppKit.framework in Frameworks */, + C9CBC4E727B5CDE000D25554 /* CoreWLAN.framework in Frameworks */, 02619DF920F7E25700099652 /* SystemConfiguration.framework in Frameworks */, 02619DF820F7E24C00099652 /* NetworkExtension.framework in Frameworks */, ); @@ -123,6 +127,7 @@ buildActionMask = 2147483647; files = ( FA89042920EF805A008AA0BC /* NetworkExtension.framework in Frameworks */, + C9CBC4E627B5CDCA00D25554 /* CoreWLAN.framework in Frameworks */, FA53908420EF603B00BA9AF7 /* SystemConfiguration.framework in Frameworks */, FA53908220EF603700BA9AF7 /* AppKit.framework in Frameworks */, ); @@ -210,6 +215,7 @@ FA53907D20EF5FD500BA9AF7 /* Frameworks */ = { isa = PBXGroup; children = ( + C9CBC4E527B5CDCA00D25554 /* CoreWLAN.framework */, FA89042820EF8059008AA0BC /* NetworkExtension.framework */, FA53908320EF603B00BA9AF7 /* SystemConfiguration.framework */, FA53908120EF603700BA9AF7 /* AppKit.framework */,