Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added an output pane to show the current output of ipfw list & ipfw pipe list, so current rules can be seen. If this makes it in, I will be adding support for hiding & showing the output textview. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions SpeedLimit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -188,8 +188,11 @@
/* Begin PBXProject section */
089C1669FE841209C02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "SpeedLimit" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = en;
hasScannedForEncodings = 1;
knownRegions = (
Expand Down Expand Up @@ -271,7 +274,6 @@
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -308,7 +310,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;
};
name = Debug;
};
Expand All @@ -322,7 +323,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;
};
name = Release;
};
Expand All @@ -336,7 +336,7 @@
1DBD214A08BA80EA00186707 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
defaultConfigurationName = Debug;
};
1DBD214C08BA80EA00186707 /* Build configuration list for PBXProject "SpeedLimit" */ = {
isa = XCConfigurationList;
Expand All @@ -345,7 +345,7 @@
1DBD214E08BA80EA00186707 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */
};
Expand Down
11 changes: 9 additions & 2 deletions SpeedLimitPref.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
NSTableView *portsView;
NSTextField *hostsTextField;
NSTextField *delayTextField;
NSTextView *showIpfwOutputTextView;
NSPopUpButton *speedsPopUpButton;
NSButton *addButton;
NSButton *removeButton;
NSButton *startStopButton;

AuthorizationRef authorizationRef;
NSButton *showIpfwOutputButton;


AuthorizationRef authorizationRef;

NSInteger authorizationState;
SFAuthorizationView *authorizationView;
Expand All @@ -50,16 +53,20 @@
@property (readwrite, retain) IBOutlet NSTableView *portsView;
@property (readwrite, retain) IBOutlet NSTextField *hostsTextField;
@property (readwrite, retain) IBOutlet NSTextField *delayTextField;
@property (readwrite, retain) IBOutlet NSTextView *showIpfwOutputTextView;
@property (readwrite, retain) IBOutlet NSPopUpButton *speedsPopUpButton;
@property (readwrite, retain) IBOutlet NSButton *addButton;
@property (readwrite, retain) IBOutlet NSButton *removeButton;
@property (readwrite, retain) IBOutlet NSButton *startStopButton;
@property (readwrite, retain) IBOutlet NSButton *showIpfwOutputButton;
@property (readwrite, retain) IBOutlet SFAuthorizationView *authorizationView;

-(void) mainViewDidLoad;

-(IBAction)addPort:(id)sender;
-(IBAction)removePort:(id)sender;
-(IBAction)toggle:(id)sender;
-(IBAction)showIpfwOutput:(id)sender;


@end
50 changes: 49 additions & 1 deletion SpeedLimitPref.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ @implementation SpeedLimitPref
@synthesize portsView;
@synthesize hostsTextField;
@synthesize delayTextField;
@synthesize showIpfwOutputTextView;
@synthesize speedsPopUpButton;
@synthesize addButton;
@synthesize removeButton;
@synthesize startStopButton;
@synthesize showIpfwOutputButton;
@synthesize authorizationView;

- (NSString *)speedLimiterPath {
Expand All @@ -53,6 +55,45 @@ - (void) mainViewDidLoad {
[speedsController addObject:[Speed speedWithName:@"Dialup" speed:48]];
}

- (void)populateIpfwOutput {
FILE *ipfwPipe;
NSString *ipfwList = nil;
NSString *ipfwPipeList = nil;
NSMutableString *results = [NSMutableString string];
char *ipfwListArgs[2];
char *ipfwPipeListArgs[3];

//Run command /sbin/ipfw list and capture the results;
ipfwListArgs[0] = (char *)[@"list" cStringUsingEncoding:NSUTF8StringEncoding];
ipfwListArgs[1] = NULL;
OSStatus listErr = AuthorizationExecuteWithPrivileges(authorizationRef, [@"/sbin/ipfw" fileSystemRepresentation], 0, ipfwListArgs, &ipfwPipe);
if (listErr == errAuthorizationSuccess) {
NSFileHandle *ipfwPipeHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(ipfwPipe)];
ipfwList = [[NSString alloc] initWithData:[ipfwPipeHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
// NSLog(@"SpeedLimiter output = %@", ipfwPipeStr);
}
[results appendString:@"[Results for: '/sbin/ipfw list']\n------------------------------\n"];
[results appendString:ipfwList];

//Run command /sbin/ipfw pipe list and capture the results;
ipfwPipeListArgs[0] = (char *)[@"pipe" cStringUsingEncoding:NSUTF8StringEncoding];
ipfwPipeListArgs[1] = (char *)[@"list" cStringUsingEncoding:NSUTF8StringEncoding];
ipfwPipeListArgs[2] = NULL;
OSStatus pipeListErr = AuthorizationExecuteWithPrivileges(authorizationRef, [@"/sbin/ipfw" fileSystemRepresentation], 0, ipfwPipeListArgs, &ipfwPipe);
if (pipeListErr == errAuthorizationSuccess) {
NSFileHandle *ipfwPipeHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(ipfwPipe)];
ipfwPipeList = [[NSString alloc] initWithData:[ipfwPipeHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
// NSLog(@"SpeedLimiter output = %@", ipfwPipeStr);
}
[results appendString:@"\n\n[Results for: '/sbin/ipfw pipe list']\n------------------------------\n"];
[results appendString:ipfwPipeList];

[showIpfwOutputTextView setString:results];

[ipfwList autorelease];
[ipfwPipeList autorelease];

}
- (NSString *)execute:(NSString *)command withArguments:(NSArray *)arguments {
NSMutableArray *finalArguments = [NSMutableArray array];
[finalArguments addObject:command];
Expand All @@ -74,7 +115,7 @@ - (NSString *)execute:(NSString *)command withArguments:(NSArray *)arguments {
ipfwPipeStr = [[NSString alloc] initWithData:[ipfwPipeHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
// NSLog(@"SpeedLimiter output = %@", ipfwPipeStr);
}

[self populateIpfwOutput];
return [ipfwPipeStr autorelease];
}

Expand Down Expand Up @@ -257,6 +298,8 @@ - (void)enableInterfaces:(BOOL)enable {
[addButton setEnabled:enable];
[removeButton setEnabled:enable];
[startStopButton setEnabled:enable];
[showIpfwOutputButton setEnabled:enable];


if (!enable)
[startStopButton setTitle:@"-"];
Expand Down Expand Up @@ -314,6 +357,11 @@ -(IBAction)toggle:(id)sender {
}
}

- (IBAction)showIpfwOutput:(id)sender {
[self populateIpfwOutput];
}


#pragma mark SFAuthorizationView delegate methods

- (void)authorizationViewCreatedAuthorization:(SFAuthorizationView *)view {
Expand Down
Loading