Skip to content

Commit

Permalink
Added delete subcommand #36
Browse files Browse the repository at this point in the history
  • Loading branch information
halo committed Dec 31, 2017
1 parent 787395a commit 55c3ac5
Show file tree
Hide file tree
Showing 22 changed files with 398 additions and 186 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# master

# 0.3.4

Features:

* Can delete VPN services, thanks @kooroshh for the request

# 0.3.3

Internal:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ Repeat the arguments for creating multiple Services at once (no matter which sho
sudo macosvpn create -leups Atlantic atlantic.example.com Alice p4ssw0rd s3same \\
-leups Northpole northpole.example.com Bob s3cret pr1v4te

#### Deleting VPN services by name

These commands will prompt you for your password to allow changes to your Network configuration:

macosvpn delete --name MyVPN --name AnotherOne
macosvpn delete -n ThisOneToo

Run it with sudo to avoid the prompt:

sudo macosvpn delete --name MyVPN

## Troubleshooting

* If you're stuck, try to add the `--debug` flag and see if it says something useful.
Expand Down
18 changes: 12 additions & 6 deletions macosvpn.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
324DC058198120B10048BC38 /* VPNController.m in Sources */ = {isa = PBXBuildFile; fileRef = 324DC057198120B10048BC38 /* VPNController.m */; };
32861394197FED310010BB98 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32861393197FED310010BB98 /* Foundation.framework */; };
328613A2197FEE7A0010BB98 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 328613A1197FEE7A0010BB98 /* SystemConfiguration.framework */; };
9D3D847E1982AE1B005BD5F3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D3D847D1982AE1B005BD5F3 /* Security.framework */; };
Expand Down Expand Up @@ -102,6 +101,9 @@
C2CE09E41C6E972400B97D6D /* VPNColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2CE09E31C6E972400B97D6D /* VPNColor.swift */; };
C2CE09E61C6F643400B97D6D /* VPNLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2CE09E51C6F643400B97D6D /* VPNLogFormatter.swift */; };
C2CE09E81C6F751300B97D6D /* VPNLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2CE09E71C6F751300B97D6D /* VPNLogger.swift */; };
C2D37FC31FF964EE00B44CA1 /* VPNController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2D37FC21FF964EE00B44CA1 /* VPNController.swift */; };
C2D37FC51FF9669D00B44CA1 /* VPNCommandType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2D37FC41FF9669D00B44CA1 /* VPNCommandType.swift */; };
C2D37FC71FF970B700B44CA1 /* VPNServiceRemover.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2D37FC61FF970B700B44CA1 /* VPNServiceRemover.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -117,8 +119,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
324DC056198120B10048BC38 /* VPNController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPNController.h; sourceTree = "<group>"; };
324DC057198120B10048BC38 /* VPNController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VPNController.m; sourceTree = "<group>"; };
32861390197FED310010BB98 /* macosvpn */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = macosvpn; sourceTree = BUILT_PRODUCTS_DIR; };
32861393197FED310010BB98 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
328613A1197FEE7A0010BB98 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -304,6 +304,9 @@
C2CE09E31C6E972400B97D6D /* VPNColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNColor.swift; sourceTree = "<group>"; };
C2CE09E51C6F643400B97D6D /* VPNLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNLogFormatter.swift; sourceTree = "<group>"; };
C2CE09E71C6F751300B97D6D /* VPNLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNLogger.swift; sourceTree = "<group>"; };
C2D37FC21FF964EE00B44CA1 /* VPNController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNController.swift; sourceTree = "<group>"; };
C2D37FC41FF9669D00B44CA1 /* VPNCommandType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNCommandType.swift; sourceTree = "<group>"; };
C2D37FC61FF970B700B44CA1 /* VPNServiceRemover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNServiceRemover.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -377,8 +380,8 @@
9D6198CB1981151D00FC01E8 /* VPNArguments.h */,
9D6198CC1981151D00FC01E8 /* VPNArguments.m */,
C209587F1E12F970009D2EC3 /* VPNCFArray+Sequence.swift */,
324DC056198120B10048BC38 /* VPNController.h */,
324DC057198120B10048BC38 /* VPNController.m */,
C2D37FC21FF964EE00B44CA1 /* VPNController.swift */,
C2D37FC41FF9669D00B44CA1 /* VPNCommandType.swift */,
C299053C1E12F9B500570022 /* VPNExitCode.swift */,
C233AF801C6E7DCD00F39700 /* VPNHelp.swift */,
9D3D847F1982B017005BD5F3 /* VPNKeychain.h */,
Expand All @@ -391,6 +394,7 @@
C26157481D9295E6001AD818 /* VPNCommand.swift */,
C261574A1D92961C001AD818 /* VPNServiceType.swift */,
C26157461D928F29001AD818 /* VPNServiceCreator.swift */,
C2D37FC61FF970B700B44CA1 /* VPNServiceRemover.swift */,
C267ADF61ED1F6760058CDE6 /* Optional+String.swift */,
);
name = Classes;
Expand Down Expand Up @@ -680,6 +684,7 @@
9D619892198112DA00FC01E8 /* CPLALR1Parser.m in Sources */,
C267ADF21ED1D7030058CDE6 /* Color · Named.swift in Sources */,
9D619894198112DA00FC01E8 /* CPLR1Item.m in Sources */,
C2D37FC31FF964EE00B44CA1 /* VPNController.swift in Sources */,
9D619896198112DA00FC01E8 /* CPLR1Parser.m in Sources */,
9D619898198112DA00FC01E8 /* CPNumberRecogniser.m in Sources */,
9D3D84811982B017005BD5F3 /* VPNKeychain.m in Sources */,
Expand All @@ -688,7 +693,6 @@
9D61989E198112DA00FC01E8 /* CPQuotedRecogniser.m in Sources */,
C2CE09DB1C6E935600B97D6D /* Color.swift in Sources */,
C2CE09DC1C6E935600B97D6D /* ECMA 48.swift in Sources */,
324DC058198120B10048BC38 /* VPNController.m in Sources */,
9D6198A0198112DA00FC01E8 /* CPQuotedToken.m in Sources */,
9D6198A2198112DA00FC01E8 /* CPRecoveryAction.m in Sources */,
9D6198A5198112DA00FC01E8 /* CPRHSItem.m in Sources */,
Expand Down Expand Up @@ -722,6 +726,7 @@
9D619853198112A000FC01E8 /* FSArgsKonstants.m in Sources */,
9D619855198112A000FC01E8 /* FSArgumentPackage.m in Sources */,
9D619858198112A000FC01E8 /* FSArgumentParser.m in Sources */,
C2D37FC51FF9669D00B44CA1 /* VPNCommandType.swift in Sources */,
C20958801E12F970009D2EC3 /* VPNCFArray+Sequence.swift in Sources */,
C2CE09E61C6F643400B97D6D /* VPNLogFormatter.swift in Sources */,
C26157471D928F29001AD818 /* VPNServiceCreator.swift in Sources */,
Expand All @@ -747,6 +752,7 @@
9D619873198112A000FC01E8 /* NSProcessInfo+FSArgumentParser.m in Sources */,
9D619875198112A000FC01E8 /* NSScanner+EscapedScanning.m in Sources */,
C261574B1D92961C001AD818 /* VPNServiceType.swift in Sources */,
C2D37FC71FF970B700B44CA1 /* VPNServiceRemover.swift in Sources */,
9D619877198112A000FC01E8 /* NSString+Indenter.m in Sources */,
9D61984D1981129900FC01E8 /* main.swift in Sources */,
);
Expand Down
5 changes: 4 additions & 1 deletion macosvpn/Classes/VPNArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

@class VPNServiceConfig;

@interface VPNArguments : NSObject

+ (void) setLogLevel;
Expand All @@ -22,7 +24,8 @@
+ (BOOL) versionRequested;
+ (BOOL) forceRequested;

+ (NSArray*) serviceConfigs;
+ (NSArray<NSString *>*) serviceNames;
+ (NSArray<VPNServiceConfig*>*) serviceConfigs;
+ (NSUInteger) command;

@end
56 changes: 43 additions & 13 deletions macosvpn/Classes/VPNArguments.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ + (void) setLogLevel {
}

+ (BOOL) helpRequested {
return [self.package booleanValueForSignature: self.helpSig] || [self command] == VPNCommandNone;
return [self.package booleanValueForSignature: self.helpSig] || [self command] == 0;
}

+ (BOOL) versionRequested {
Expand All @@ -51,14 +51,27 @@ + (NSUInteger) command {
if ([[self.package unknownSwitches] count] > 0) DDLogDebug(@"Unknown arguments: %@", [[self.package unknownSwitches] componentsJoinedByString:@" | "]);
if ([[self.package uncapturedValues] count] > 0) DDLogDebug(@"Uncaptured argument values: %@", [[self.package uncapturedValues] componentsJoinedByString:@" | "]);

if ([self.package countOfSignature:self.createCommandSig] == VPNCommandCreate) {
return VPNCommandCreate;
if ([self.package countOfSignature:self.createCommandSig] == 1) {
return 1;
} else if ([self.package countOfSignature:self.deleteCommandSig] == 1) {
return 2;
} else {
return VPNCommandNone;
return 0;
}
}

+ (NSArray*) serviceConfigs {
+ (NSArray<NSString *>*) serviceNames {
NSUInteger count = [self.package countOfSignature:self.nameSig];
NSMutableArray *names = [NSMutableArray arrayWithCapacity:count];

for (NSUInteger i = 0; i < count; i++) {
NSString *name = [self extractArgumentForSignature:self.nameSig withFallbackSignature:nil atIndex:i];
[names addObject:name];
}
return names;
}

+ (NSArray<VPNServiceConfig *>*) serviceConfigs {
NSArray *l2tpConfigs = [self serviceConfigsForType:VPNServiceL2TPOverIPSec andSignature:self.l2tpSig];
NSArray *ciscoConfigs = [self serviceConfigsForType:VPNServiceCiscoIPSec andSignature:self.ciscoSig];

Expand Down Expand Up @@ -137,6 +150,15 @@ + (FSArgumentSignature*) createCommandSig {
return command;
}

+ (FSArgumentSignature*) deleteCommandSig {
FSArgumentSignature *command = [FSArgumentSignature argumentSignatureWithFormat:@"[delete]"];

NSSet *deleteSignatures = [NSSet setWithObjects: self.nameSig, nil];

[command setInjectedSignatures:deleteSignatures];
return command;
}

// Internal: global Argument Flags

+ (FSArgumentSignature*) helpSig {
Expand Down Expand Up @@ -199,17 +221,25 @@ + (FSArgumentSignature*) forceSig {
return [FSArgumentSignature argumentSignatureWithFormat:@"[-o --force force]"];
}

+ (NSArray*) signatures {
return @[
self.helpSig,
self.debugSig,
self.versionSig,
self.forceSig,
self.createCommandSig
];
// Internal: Delete Configuration Arguments

+ (FSArgumentSignature*) nameSig {
return [FSArgumentSignature argumentSignatureWithFormat:@"[-n --name name]={1,}"];
}

// Wrapping up all valid argument signatures

+ (NSArray*) signatures {
return @[
self.helpSig,
self.debugSig,
self.versionSig,
self.forceSig,
self.createCommandSig,
self.deleteCommandSig
];
}

+ (FSArgumentPackage*) package {
return [[NSProcessInfo processInfo] fsargs_parseArgumentsWithSignatures:self.signatures];
}
Expand Down
4 changes: 2 additions & 2 deletions macosvpn/Classes/VPNColor.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
struct VPNColor {

// https://upload.wikimedia.org/wikipedia/en/1/15/Xterm_256color_chart.svg
// https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg
static let Blue: UInt8 = 33
static let Green: UInt8 = 35
static let Pink: UInt8 = 199
static let Brown: UInt8 = 130

static let Red: UInt8 = 124
}
5 changes: 5 additions & 0 deletions macosvpn/Classes/VPNCommandType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct VPNCommandType {
static let None: UInt8 = 0
static let Create: UInt8 = 1
static let Delete: UInt8 = 2
}
21 changes: 0 additions & 21 deletions macosvpn/Classes/VPNController.h

This file was deleted.

121 changes: 0 additions & 121 deletions macosvpn/Classes/VPNController.m

This file was deleted.

Loading

0 comments on commit 55c3ac5

Please sign in to comment.