Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
iHongRen committed Aug 16, 2018
1 parent 9b5c235 commit 0561218
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 281 deletions.
70 changes: 28 additions & 42 deletions HelpTool/HelperTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ - (id)init {
if (self = [super init]) {
// Set up our XPC listener to handle requests on our Mach service.
self->_listener = [[NSXPCListener alloc] initWithMachServiceName:@"com.cxy.PPTPVPN.HelpTool"];
self->_listener.delegate = self;



self->_listener.delegate = self;
}
return self;
}
Expand Down Expand Up @@ -53,52 +50,41 @@ - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConne

#pragma mark - protocol
- (void)executeShellPath:(NSString*)path arguments:(NSArray*)args withReply:(void(^)(NSError *error, NSString *outputString))reply {

NSTask *task = [NSTask new];
task.launchPath = path;
task.arguments = args;

NSPipe *pipe = [NSPipe pipe];
// __block NSString *outputString = @"";
// pipe.fileHandleForReading.readabilityHandler = ^ (NSFileHandle *fileHandle) {
// NSData *data = [fileHandle availableData];
// NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSLog(@"read: %@", str);
// outputString = [outputString stringByAppendingString:str];
// !reply?:reply(nil, str);
//
// if ([str containsString:@"pptp_wait_input: Address added"]) {
// !reply?:reply(nil, @"ss");
// }
// };
[task setStandardOutput:pipe];

[task setStandardError:[NSPipe pipe]];
NSError *err;
[task launchAndReturnError:&err];
[task waitUntilExit];

NSData *outputData = [[task.standardOutput fileHandleForReading] readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData:outputData encoding: NSUTF8StringEncoding];
!reply?:reply(err, output);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSTask *task = [NSTask new];
task.launchPath = path;
task.arguments = args;

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];

[task setStandardError:[NSPipe pipe]];
NSError *err;
[task launchAndReturnError:&err];
[task waitUntilExit];

NSData *outputData = [[task.standardOutput fileHandleForReading] readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData:outputData encoding: NSUTF8StringEncoding];
!reply?:reply(err, output);
});
}


- (void)executeShellCommand:(NSString*)command withReply:(void(^)(NSDictionary * errorInfo))reply {
NSString *script = [NSString stringWithFormat:@"do shell script \"%@\"",command];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
NSDictionary *dicError = nil;
[appleScript executeAndReturnError:&dicError];
if (dicError) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSString *script = [NSString stringWithFormat:@"do shell script \"%@\"",command];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
NSDictionary *dicError = nil;
[appleScript executeAndReturnError:&dicError];
!reply?:reply(dicError);
} else {
!reply?:reply(nil);
}
});
}

- (void)executeShellSystemCommand:(NSString *)command withReply:(void (^)(NSInteger))reply {
int res = system([command UTF8String]);
!reply?:reply(res);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
int res = system([command UTF8String]);
!reply?:reply(res);
});
}

@end
3 changes: 2 additions & 1 deletion PPTPVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
742FB4FE21154D2D000FEB1E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 8;
dstPath = /usr/share/man/man1/;
dstPath = "";
dstSubfolderSpec = 0;
files = (
742FB51321155867000FEB1E /* com.cxy.PPTPVPN.HelpTool in CopyFiles */,
Expand Down Expand Up @@ -428,6 +428,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = C98SFK75FC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,196 +2,4 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181707"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "191"
endingLineNumber = "191"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181762"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "179"
endingLineNumber = "179"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "-[VPNManager executeShellCommand:block:]"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.329221"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "179"
endingLineNumber = "179"
offsetFromSymbolStart = "98">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__40-[VPNManager executeShellCommand:block:]_block_invoke"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.331226"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "180"
endingLineNumber = "180"
offsetFromSymbolStart = "47">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__destroy_helper_block_.169"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.3347239"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "179"
endingLineNumber = "179"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181812"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "184"
endingLineNumber = "184"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__40-[VPNManager executeShellCommand:block:]_block_invoke"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.344644"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "184"
endingLineNumber = "184"
offsetFromSymbolStart = "156">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__40-[VPNManager executeShellCommand:block:]_block_invoke_2"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.348074"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "185"
endingLineNumber = "185"
offsetFromSymbolStart = "44">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__destroy_helper_block_.149"
moduleName = "PPTPVPN"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chen/Documents/project/my_opensource/PPTPVPN/PPTPVPN/VPNManager.m"
timestampString = "556087971.350642"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "184"
endingLineNumber = "184"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181859"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "181"
endingLineNumber = "181"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181905"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "185"
endingLineNumber = "185"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PPTPVPN/VPNManager.m"
timestampString = "556088568.181951"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "190"
endingLineNumber = "190"
landmarkName = "-executeShellCommand:block:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
10 changes: 4 additions & 6 deletions PPTPVPN/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ @interface AppDelegate ()
@property (nonatomic, strong) PreferencesWindow *preferencesWindow;

@property (weak) IBOutlet ITSwitch *connectSwitch;
@property (weak) IBOutlet NSProgressIndicator *progressIndicator;
@property (weak) IBOutlet NSTextField *wait;

@end

Expand Down Expand Up @@ -55,21 +55,19 @@ - (void)setupVPNItem {
self.vpnItem.image = [NSImage imageNamed:@"vpn_disconnect"];
self.connectSwitch.checked = NO;
self.connectSwitch.hidden = NO;
self.progressIndicator.hidden = YES;

self.wait.hidden = YES;
break;
case VPNStatusConnecting:
self.vpnItem.image = [NSImage imageNamed:@"vpn_disconnect"];
self.connectSwitch.checked = NO;
self.connectSwitch.hidden = YES;
self.progressIndicator.hidden = NO;
[self.progressIndicator startAnimation:nil];
self.wait.hidden = NO;
break;
case VPNStatusConnected:
self.vpnItem.image = [NSImage imageNamed:@"vpn_connect"];
self.connectSwitch.checked = YES;
self.connectSwitch.hidden = NO;
self.progressIndicator.hidden = YES;
self.wait.hidden = YES;
break;
default:
break;
Expand Down
4 changes: 3 additions & 1 deletion PPTPVPN/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand All @@ -33,7 +35,7 @@
<key>SMPrivilegedExecutables</key>
<dict>
<key>com.cxy.PPTPVPN.HelpTool</key>
<string>identifier &quot;com.cxy.PPTPVPN.HelpTool&quot; and anchor apple generic and certificate leaf[subject.CN] = &quot;Mac Developer: [email protected] (A6N22GWPU9)&quot; and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
<string>identifier "com.cxy.PPTPVPN.HelpTool" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: [email protected] (A6N22GWPU9)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
</dict>
</dict>
</plist>
18 changes: 11 additions & 7 deletions PPTPVPN/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="connectSwitch" destination="gwL-XT-rvz" id="kkH-aD-9cj"/>
<outlet property="progressIndicator" destination="dfd-fX-MpQ" id="IUI-Kr-2Jj"/>
<outlet property="vpnMenu" destination="WN0-yC-FnI" id="Amk-8F-EoN"/>
<outlet property="wait" destination="fST-dY-KCC" id="IiX-M8-H67"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
Expand Down Expand Up @@ -67,17 +67,21 @@
<action selector="onConnectSwitch:" target="Voe-Tx-rLC" id="xAt-v0-KgE"/>
</connections>
</customView>
<progressIndicator hidden="YES" wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="dfd-fX-MpQ">
<rect key="frame" x="47" y="12" width="32" height="32"/>
</progressIndicator>
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fST-dY-KCC">
<rect key="frame" x="-2" y="20" width="126" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Waiting..." id="jWI-Vi-giH">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="gwL-XT-rvz" firstAttribute="centerX" secondItem="RGX-aa-CK2" secondAttribute="centerX" id="DVF-xs-lM0"/>
<constraint firstItem="dfd-fX-MpQ" firstAttribute="centerX" secondItem="gwL-XT-rvz" secondAttribute="centerX" id="Tic-4Z-r2e"/>
<constraint firstItem="dfd-fX-MpQ" firstAttribute="centerY" secondItem="gwL-XT-rvz" secondAttribute="centerY" id="WUQ-Bc-tYF"/>
<constraint firstItem="gwL-XT-rvz" firstAttribute="centerY" secondItem="RGX-aa-CK2" secondAttribute="centerY" id="myV-xX-lCh"/>
</constraints>
<point key="canvasLocation" x="-11" y="229.5"/>
<point key="canvasLocation" x="-125" y="262"/>
</customView>
</objects>
</document>
Loading

0 comments on commit 0561218

Please sign in to comment.