diff --git a/DDWRT_MonitorAppDelegate.m b/DDWRT_MonitorAppDelegate.m index 786a4ee..7b7902e 100644 --- a/DDWRT_MonitorAppDelegate.m +++ b/DDWRT_MonitorAppDelegate.m @@ -310,7 +310,7 @@ if ([configFieldShowIcon state] == NSOffState && [defaults boolForKey:@"showMenuIcon"] == true) { [self hideMenubarIcon]; } else if ([configFieldShowIcon state] == NSOnState && [defaults boolForKey:@"showMenuIcon"] == false) { - [self showMenubarIcon:false]; + [self showMenubarIcon:[wrt_client wrtReachable]]; } showMenuIcon = ([configFieldShowIcon state] == 1 ? true: false); @@ -388,25 +388,53 @@ [wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; - NSLog(@"%@", stringData); + NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"]; + [menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]]; NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"]; NSRange startRange = [wanip rangeOfString:@" "]; wanip = [wanip substringFromIndex:(startRange.location+1)]; + [menuWanIP setTitle:wanip]; NSString *uptime = [wrt_client getKey:stringData key:@"uptime"]; NSString *loadSplit = @", load average: "; - NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]]; - uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load - uptime = [uptime substringFromIndex:[uptime rangeOfString:@" "].location+1]; // Trim - uptime = [uptime stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[uptime substringToIndex:1] uppercaseString]]; // UCFirst + if ([uptime length] > 0) { + NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]]; + uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load + uptime = [uptime substringFromIndex:[uptime rangeOfString:@" "].location+1]; // Trim + uptime = [uptime stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[uptime substringToIndex:1] uppercaseString]]; // UCFirst + [menuUptime setTitle:uptime]; + //[menuUptime setHidden:false]; + + [menuLoad setTitle:load]; + [menuLoad setHidden:false]; + //[[AppMenu itemAtIndex:2] setHidden:false]; + } else { + [menuUptime setTitle:@"Connected"]; + //[menuUptime setHidden:true]; + [menuLoad setHidden:true]; + //[[AppMenu itemAtIndex:2] setHidden:true]; + } + /* + NSString *memInfo = [wrt_client getKey:stringData key:@"mem_info"]; - [menuWanIP setTitle:wanip]; - [menuUptime setTitle:uptime]; - [menuLoad setTitle:load]; - [menuLoad setHidden:false]; - [menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]]; + // Remove any white spaces + NSArray *parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; + memInfo = [filteredArray componentsJoinedByString:@" "]; + parts = nil; + filteredArray = nil; + + // Remove any quotes + parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\'"]]; + filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; + memInfo = [filteredArray componentsJoinedByString:@""]; + + NSArray *memData = [memInfo componentsSeparatedByString:@","]; + unsigned long memTotal = strtoull([[memData objectAtIndex:17] UTF8String], NULL, 0); + unsigned long memFree = strtoull([[memData objectAtIndex:21] UTF8String], NULL, 0); + */ } - (void) refreshMenu:(id)sender @@ -598,10 +626,11 @@ [clientMenu addItem:clientMenuItem]; // Connections - clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+3)] action:nil keyEquivalent:@""]; + unsigned long conn = strtoull([[clientsData objectAtIndex:(clientIndex+3)] UTF8String], NULL, 0); + clientMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%d Connection%@", conn, (conn > 1 ? @"s" : @"")] action:nil keyEquivalent:@""]; [clientMenu addItem:clientMenuItem]; - clientItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:clientIndex] action:nil keyEquivalent:@""]; + clientItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:clientIndex] action:nil keyEquivalent:@""]; [clientItem setSubmenu:clientMenu]; [menuClients addItem:clientItem]; diff --git a/WRTStatusClient.m b/WRTStatusClient.m index ab1451f..a8cfdc8 100644 --- a/WRTStatusClient.m +++ b/WRTStatusClient.m @@ -7,7 +7,7 @@ // #import "WRTStatusClient.h" - +#import @implementation WRTStatusClient @@ -233,21 +233,21 @@ - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { - return YES; // FIXME Turning this to NO should use keychain, but it doesn't + return NO; // FIXME Turning this to NO should use keychain, but it doesn't } - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection { return YES; } - +/* -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSLog(@"1"); if ([challenge previousFailureCount] == 0) { NSLog(@"1.1.1"); NSURLCredential *newCredential; - newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]; + newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent]; NSLog(@"1.1.2"); [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; @@ -259,7 +259,7 @@ NSLog(@"Invalid Username or Password"); } } - +*/ -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { //NSLog(@"2");