diff --git a/CredenialsView.xib b/CredenialsView.xib new file mode 100644 index 0000000..2398a35 --- /dev/null +++ b/CredenialsView.xib @@ -0,0 +1,420 @@ + + + + 1060 + 10J869 + 1306 + 1038.35 + 461.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 1306 + + + YES + NSView + NSForm + NSWindowTemplate + NSFormCell + NSButtonCell + NSButton + NSCustomObject + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + + + YES + + NSObject + + + FirstResponder + + + NSApplication + + + WRTStatusClient + + + 1 + 2 + {{320, 343}, {340, 115}} + 611844096 + WRT Login + NSWindow + + + + 256 + + YES + + + 268 + {{20, 43}, {300, 52}} + + + + 2 + YES + 2 + 1 + + YES + + 343014977 + 205521920 + + + LucidaGrande + 13 + 1044 + + + 70.93603515625 + + 67239424 + 67108864 + Username: + + + + + + 343014977 + 205521920 + + + + 1 + 70.93603515625 + + 67239424 + 67108864 + Password: + + + + + + {300, 22} + {1, 8} + 67633152 + NSActionCell + + 343014976 + 205521920 + + + 70.93603515625 + + 67239424 + 67108864 + Field: + + + + -1 + -1 + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 3 + MQA + + + + + + 268 + {{260, 18}, {60, 17}} + + + + YES + + -2080244224 + 134348800 + Login + + LucidaGrande + 11 + 3100 + + + -2038152961 + 164 + + DQ + 400 + 75 + + + + {{7, 11}, {340, 115}} + + + + + {{0, 0}, {2048, 1130}} + {1e+13, 1e+13} + + + + + YES + + + delegate + + + + 19 + + + + credentialsView + + + + 20 + + + + hideCredentialsWindow + + + + 24 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 11 + + + + + 13 + + + YES + + + + + + 14 + + + YES + + + + + + + 15 + + + YES + + + + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 21 + + + YES + + + + + + 22 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 11.IBPluginDependency + 13.IBPluginDependency + 13.NSWindowTemplate.visibleAtLaunch + 14.IBPluginDependency + 15.IBPluginDependency + 16.IBPluginDependency + 17.IBPluginDependency + 18.CustomClassName + 18.IBPluginDependency + 21.IBPluginDependency + 22.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + NSSecureTextFormCell + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 24 + + + + YES + + WRTStatusClient + NSObject + + YES + + YES + buttonLogin + credentialsWindow + fieldPassword + fieldUsername + + + YES + NSButton + NSWindow + NSSecureTextFieldCell + NSFormCell + + + + YES + + YES + buttonLogin + credentialsWindow + fieldPassword + fieldUsername + + + YES + + buttonLogin + NSButton + + + credentialsWindow + NSWindow + + + fieldPassword + NSSecureTextFieldCell + + + fieldUsername + NSFormCell + + + + + IBProjectSource + ./Classes/WRTStatusClient.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/DDWRT-Monitor.xcodeproj/project.pbxproj b/DDWRT-Monitor.xcodeproj/project.pbxproj index afb17a2..df966f2 100644 --- a/DDWRT-Monitor.xcodeproj/project.pbxproj +++ b/DDWRT-Monitor.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ F2511F5C13914A120053990C /* MenuIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = F2511F5B13914A120053990C /* MenuIcon.png */; }; F2511FFB1391543E0053990C /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F2511FFA1391543E0053990C /* WebKit.framework */; }; F25120A213918CD10053990C /* AppIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = F25120A113918CD10053990C /* AppIcon.icns */; }; + F2736BD0139BDAC20019957B /* CredenialsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F2736BCF139BDAC20019957B /* CredenialsView.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -38,6 +39,7 @@ F2511F5B13914A120053990C /* MenuIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MenuIcon.png; sourceTree = ""; }; F2511FFA1391543E0053990C /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; F25120A113918CD10053990C /* AppIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon.icns; sourceTree = ""; }; + F2736BCF139BDAC20019957B /* CredenialsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CredenialsView.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -120,6 +122,7 @@ 8D1107310486CEB800E47090 /* DDWRT_Monitor-Info.plist */, 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 1DDD58140DA1D0A300B32029 /* MainMenu.xib */, + F2736BCF139BDAC20019957B /* CredenialsView.xib */, ); name = Resources; sourceTree = ""; @@ -190,6 +193,7 @@ F2511F5C13914A120053990C /* MenuIcon.png in Resources */, F25120A213918CD10053990C /* AppIcon.icns in Resources */, F215851213931CF000853C55 /* MenuIconDisabled.png in Resources */, + F2736BD0139BDAC20019957B /* CredenialsView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DDWRT_MonitorAppDelegate.h b/DDWRT_MonitorAppDelegate.h index ecb3713..7b5635f 100644 --- a/DDWRT_MonitorAppDelegate.h +++ b/DDWRT_MonitorAppDelegate.h @@ -120,6 +120,8 @@ - (void) cbClientsRequest:(NSData *)data; - (void) saveConfig:(id)sender; + +- (void) updateStatus; - (void) updateThroughput:(NSTimer *)timer; - (void) throughputCallback:(NSData *)data; - (void) doUpdateStatus:(NSData *)data; diff --git a/DDWRT_MonitorAppDelegate.m b/DDWRT_MonitorAppDelegate.m index 832cb47..236ff24 100644 --- a/DDWRT_MonitorAppDelegate.m +++ b/DDWRT_MonitorAppDelegate.m @@ -19,8 +19,6 @@ // Insert code here to initialize your application [self showMenubar]; - _wrtReachable = false; - defaults = [NSUserDefaults standardUserDefaults]; // check if the app is configured yet @@ -39,8 +37,9 @@ // initialize the client wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password]; + [wrt_client registerStatusCallback:self callback:@selector(updateStatus)]; + [wrt_client getConnectionStatus]; - [self updateThroughput:nil]; } - (void) deinitialize @@ -127,8 +126,8 @@ { NSLog(@"Showing Menu Item"); - NSStatusBar* bar = [NSStatusBar systemStatusBar]; - _appMenu = [bar statusItemWithLength:NSVariableStatusItemLength]; + NSStatusBar *bar = [NSStatusBar systemStatusBar]; + _appMenu = [bar statusItemWithLength:NSVariableStatusItemLength]; [_appMenu setAction:@selector(refreshMenu:)]; [_appMenu setTarget:self]; [_appMenu retain]; @@ -147,9 +146,9 @@ - (void) hideMenubar { [_appMenu release]; - _appMenu = nil; + _appMenu = nil; [AppMenu release]; - AppMenu = nil; + AppMenu = nil; } - (void) showMenubarIcon:(BOOL)enabled @@ -208,7 +207,6 @@ [configFieldProtocolHTTPS setState:1]; } - [ConfigPanel makeKeyAndOrderFront:nil]; } @@ -288,6 +286,30 @@ } +- (void) refreshMenu:(id)sender +{ + NSLog(@"Refresh Menu"); + if ([wrt_client getWrtReachable] == true) { + [_readTimer invalidate]; + _readTimer = nil; + + [wrt_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(doUpdateStatus:)]; + } else { + [_appMenu popUpStatusItemMenu:AppMenu]; + } + +} + +- (void) refreshSystemMenu:(id)sender +{ + +} + +- (void) refreshWanMenu:(id)sender +{ + +} + - (void) saveConfig:(id)sender { [self deinitialize]; @@ -295,9 +317,9 @@ [configStateStatus startAnimation:nil]; [configStateStatus setHidden:false]; - hostname = [configFieldHostname stringValue]; + hostname = [configFieldHostname stringValue]; - port = [configFieldPort intValue]; + port = [configFieldPort intValue]; if ([configFieldProtocolHTTP state] == 1) { protocol = @"http"; @@ -305,15 +327,9 @@ protocol = @"https"; } - refreshTime = [configFieldRefresh integerValue]; + refreshTime = [configFieldRefresh integerValue]; - useBytes = ([configFieldUseBytes state] == 1 ? true: false); - - if ([configFieldShowIcon state] == NSOffState && [defaults boolForKey:@"showMenuIcon"] == true) { - [self hideMenubarIcon]; - } else if ([configFieldShowIcon state] == NSOnState && [defaults boolForKey:@"showMenuIcon"] == false) { - [self showMenubarIcon:[wrt_client wrtReachable]]; - } + useBytes = ([configFieldUseBytes state] == 1 ? true: false); showMenuIcon = ([configFieldShowIcon state] == 1 ? true: false); @@ -329,44 +345,44 @@ [self hideConfigPanel:nil]; } -- (void) updateThroughput:(NSTimer *)timer +- (void) updateStatus { - //NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); - if ([wrt_client wrtReachable] == true && _wrtReachable == false) { - _wrtReachable = true; + NSLog(@"Status %@ wan port: %@", ([wrt_client getWrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); + if ([wrt_client getWrtReachable] == true) { if (showMenuIcon == true) { [self showMenubarIcon:true]; } else { [self hideMenubarIcon]; } - } else if ([wrt_client wrtReachable] == false && _wrtReachable == true) { - _wrtReachable = false; + + if (_readTimer == nil) { + _readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; + + [_readTimer fire]; + } + } else if ([wrt_client getWrtReachable] == false) { [self showMenubarIcon:false]; - } - - if (_wrtReachable == true) { - [wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)]; - } - - if (_readTimer == nil) { - _readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; - [_readTimer fire]; + [_readTimer invalidate]; + _readTimer = nil; } } +- (void) updateThroughput:(NSTimer *)timer +{ + NSLog(@"Status %@ wan port: %@", ([wrt_client getWrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); + [wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)]; +} + - (void) throughputCallback:(NSData *)data { NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; - + NSLog(stringData); NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]]; stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])]; NSArray *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; - NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; - stringData = [filteredArray componentsJoinedByString:@" "]; - - NSArray *listItems = [stringData componentsSeparatedByString:@" "]; + NSArray *listItems = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; uint64_t ifIn = strtoull([[listItems objectAtIndex:0] UTF8String], NULL, 0); uint64_t ifOut = strtoull([[listItems objectAtIndex:8] UTF8String], NULL, 0); @@ -451,30 +467,6 @@ */ } -- (void) refreshMenu:(id)sender -{ - NSLog(@"Refresh Menu"); - if ([wrt_client wrtReachable] == true) { - [_readTimer invalidate]; - _readTimer = nil; - - [wrt_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(doUpdateStatus:)]; - } else { - [_appMenu popUpStatusItemMenu:AppMenu]; - } - -} - -- (void) refreshSystemMenu:(id)sender -{ - -} - -- (void) refreshWanMenu:(id)sender -{ - -} - - (void) wanRequestCallback:(NSData *)data { [wrt_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(cbClientsRequest:)]; diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 71e22a6..f67811a 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -533,7 +533,7 @@ 273 2 - {{247, 277}, {308, 232}} + {{961, 833}, {308, 232}} 611844096 Preferences NSPanel @@ -969,6 +969,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {{213, 20}, {75, 17}} + YES -2080244224 @@ -977,9 +978,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA -2038152961 - 268435620 + 164 - s + DQ 400 75 @@ -999,9 +1000,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA -2038152961 - 164 + 268435620 - + . 400 75 @@ -1037,12 +1038,12 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 8219 2 {{823, 723}, {555, 275}} - 611844096 + -461897728 Bandwidth Viewer NSPanel - + 256 YES @@ -1072,6 +1073,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {555, 275} + YES 2 @@ -1104,6 +1106,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {{7, 11}, {555, 275}} + + YES 2 @@ -2658,7 +2662,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 826 + 833 diff --git a/WRTStatusClient.h b/WRTStatusClient.h index 6a308a7..430aab2 100644 --- a/WRTStatusClient.h +++ b/WRTStatusClient.h @@ -28,17 +28,28 @@ id delegate; SEL callback; SEL errorCallback; + + id statusDelegate; + SEL statusCallbac; + + IBOutlet NSWindow *credentialsWindow; + IBOutlet NSFormCell *fieldUsername; + IBOutlet NSSecureTextFieldCell *fieldPassword; + IBOutlet NSButton *buttonLogin; } -@property BOOL wrtReachable; - @property(nonatomic, retain) NSMutableData *receivedData; @property(nonatomic, retain) id delegate; @property(nonatomic) SEL callback; @property(nonatomic) SEL errorCallback; +@property(nonatomic, retain) id statusDelegate; +@property(nonatomic) SEL statusCallback; + - (id) initWithHostname:(NSString*)new_hostname port:(int)new_port protocol:(NSString*)new_protocol username:(NSString*)new_username password:(NSString*)new_password; +- (void) registerStatusCallback:(id)status_delegate callback:(SEL)status_callback; + - (NSMutableURLRequest*) buildRequest:(NSString*)uri; - (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface; - (void) getStatusUpdate:(NSString*)uri delegate:(id)requestDelegate callback:(SEL)requestSelector; @@ -46,6 +57,9 @@ -(NSString *)getKey:(NSString *)stringData key:(NSString *)key; +- (BOOL) getWrtReachable; +- (void) setWrtReachable:(BOOL)new_wrtReachable; + - (NSString*) getWanPort; - (void) setWanPort:(NSString*)new_wanport; @@ -64,5 +78,7 @@ - (NSString*) getPassword; - (void) setPassword:(NSString*)new_password; +- (void) showCredentialsWindow; +- (IBAction) hideCredentialsWindow; @end diff --git a/WRTStatusClient.m b/WRTStatusClient.m index 304aaa1..27164d9 100644 --- a/WRTStatusClient.m +++ b/WRTStatusClient.m @@ -11,13 +11,14 @@ @implementation WRTStatusClient -@synthesize wrtReachable; - @synthesize receivedData; @synthesize delegate; @synthesize callback; @synthesize errorCallback; +@synthesize statusDelegate; +@synthesize statusCallback; + - (id) initWithHostname:(NSString*)new_hostname port:(int)new_port protocol:(NSString*)new_protocol username:(NSString*)new_username password:(NSString*)new_password { self = [super init]; @@ -36,6 +37,12 @@ #pragma mark - +- (void) registerStatusCallback:(id)status_delegate callback:(SEL)status_callback +{ + statusDelegate = status_delegate; + statusCallback = status_callback; +} + - (NSMutableURLRequest*) buildRequest:(NSString*)uri { NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%d/%@", @@ -44,7 +51,8 @@ port, uri]; - //NSLog(@"Building request form %@", urlAddress); + + NSLog(@"Building request form %@", urlAddress); NSURL *url = [NSURL URLWithString:urlAddress]; @@ -100,15 +108,12 @@ - (void) cbConnectionStatus:(NSData *)data { if (data == nil) { - wrtReachable = false; + [self setWrtReachable:false]; } else { NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; - //Bandwidth Monitoring - NSRange pageValid = [stringData rangeOfString:@"Bandwidth Monitoring"]; + NSRange pageValid = [stringData rangeOfString:@"Bandwidth Monitoring"]; if (pageValid.location != NSNotFound) { - wrtReachable = true; - // grab the wan port name NSRange startRange = [stringData rangeOfString:@"WAN"]; stringData = [stringData substringFromIndex:startRange.location]; @@ -117,8 +122,9 @@ stringData = [stringData substringFromIndex:(startRange.location + [key length])]; NSRange endRange = [stringData rangeOfString:@"\""]; [self setWanPort:[stringData substringToIndex:endRange.location]]; + [self setWrtReachable:true]; } else { - wrtReachable = false; + [self setWrtReachable:false]; wanPort = nil; } } @@ -157,6 +163,23 @@ #pragma mark - #pragma mark Accessors: +- (BOOL) getWrtReachable +{ + return wrtReachable; +} + +- (void) setWrtReachable:(BOOL)new_wrtReachable +{ + BOOL old_wrtReachable = wrtReachable; + wrtReachable = new_wrtReachable; + + if (old_wrtReachable != new_wrtReachable && statusDelegate && statusCallback) { + if ([statusDelegate respondsToSelector:statusCallback]) { + [statusDelegate performSelector:statusCallback withObject:nil]; + } + } +} + - (NSString*) getWanPort { return wanPort; @@ -228,16 +251,32 @@ [old_password autorelease]; } +#pragma mark - +#pragma mark Credential Window Methods: +- (void) showCredentialsWindow +{ + [credentialsWindow makeKeyAndOrderFront:nil]; +} + +- (IBAction) hideCredentialsWindow +{ + [self setUsername:[fieldUsername stringValue]]; + [self setPassword:[fieldPassword stringValue]]; +} + #pragma mark - #pragma mark NSURLConnection Delegate Methods: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { - return NO; // FIXME Turning this to NO should use keychain, but it doesn't + NSLog(@"1.0.1"); + + return NO; // FIXME this need to return YES if an entry doesn't already exist in the keychain and the user will need to be prompted for credentials } - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection { + NSLog(@"1.0.2"); return YES; } @@ -253,7 +292,6 @@ [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; } else { NSLog(@"1.2"); - wrtReachable = false; [[challenge sender] cancelAuthenticationChallenge:challenge]; // TODO Pop up authentication error NSLog(@"Invalid Username or Password"); @@ -281,7 +319,7 @@ //TODO Return alert NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); - wrtReachable = false; + [self setWrtReachable:false]; if (errorCallback) { [delegate performSelector:errorCallback withObject:error];