1
0
Fork 0

Big code restructure and cleaning.

Router data is now gathered all at once and used to populate the menu thereafter.
There is now a separate WRTStatusClient object for the router data and the throughput data. The latter is used to get status.
master
Matthieu Lalonde 14 years ago
parent 7842a01f47
commit 6948715db7

@ -61,72 +61,67 @@
NSString *hostname; NSString *hostname;
NSString *protocol; NSString *protocol;
int port; uint16_t port;
NSString *username; NSString *username;
NSString *password; NSString *password;
uint16_t refreshTime;
int refreshTime; BOOL useBytes;
bool useBytes; BOOL showMenuIcon;
bool showMenuIcon;
// end app prefs // end app prefs
NSStatusItem *_appMenu; NSStatusItem *_appMenu;
NSAlert *modalWindow;
NSTimer *_readTimer; WRTStatusClient *wrt_update_client;
NSTimeInterval _lastSpeedRead; WRTStatusClient *wrt_request_client;
WRTStatusClient *wrt_client; NSTimer *_updateTimer;
NSDate *_lastDateThroughput; NSDate *_lastDateThroughput;
unsigned long long _lastInThroughput; uint64_t _lastInThroughput;
unsigned long long _lastOutThroughput; uint64_t _lastOutThroughput;
BOOL _wrtReachable; @private
uint8_t _statusDataRequestNumber;
NSString *_statusStringData;
} }
# pragma mark Application Delegates:
- (void) terminate:(id)sender;
- (void) initialize; - (void) initialize;
- (void) deinitialize; - (void) deinitialize;
- (void) initDefaults; # pragma mark Menu Methods:
- (void) readDefaults;
- (void) writeDefaults;
- (void) terminate:(id)sender;
- (void) showConfigPanel:(id)sender;
- (void) hideConfigPanel:(id)sender;
- (void) showBandwidthViewer:(id)sender;
- (void) hideBandwidthViewer:(id)sender;
- (void) showMenubar; - (void) showMenubar;
- (void) hideMenubar; - (void) hideMenubar;
- (void) showMenubarIcon:(BOOL)enabled; - (void) showMenubarIcon:(BOOL)enabled;
- (void) hideMenubarIcon; - (void) hideMenubarIcon;
- (void) setMenubarText:(NSString *)menubarText; - (void) setMenubarText:(NSString *)menubarText;
- (void) setConfigHostname:(id)sender; # pragma mark Configs Methods:
- (void) setConfigProtocol:(id)sender; - (void) initDefaults;
- (void) setConfigPort:(id)sender; - (void) readDefaults;
- (void) setConfigRefresh:(id)sender; - (void) writeDefaults;
- (void) setConfigWan:(id)sender; - (IBAction) showConfigPanel:(id)sender;
- (void) setConfigBytes:(id)sender; - (IBAction) hideConfigPanel:(id)sender;
- (void) setConfigIcon:(id)sender; - (IBAction) setConfigProtocol:(id)sender;
- (IBAction) setConfigRefresh:(id)sender;
- (IBAction) saveConfig:(id)sender;
# pragma mark Request Handlers:
- (void) cbUpdateStatus;
- (void) getThroughput:(NSTimer *)timer;
- (void) cbThroughput:(NSData *)data;
- (void) getRouterData:(NSData *)data;
# pragma mark Menu Handlers:
- (IBAction) refreshMenu:(id)sender; - (IBAction) refreshMenu:(id)sender;
- (IBAction) refreshSystemMenu:(id)sender; - (void) populateMenuMain;
- (IBAction) refreshWanMenu:(id)sender; - (void) populateMenuWan;
- (void) wanRequestCallback:(NSData *)data; - (void) populateMenuClients;
- (IBAction) refreshClientsMenu:(id)sender;
- (void) cbClientsRequest:(NSData *)data;
- (void) saveConfig:(id)sender;
- (void) updateStatus;
- (void) updateThroughput:(NSTimer *)timer;
- (void) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data;
- (NSMenu *) createCopyMenuItem; - (NSMenu *) createCopyMenuItem;
# pragma mark Utilities:
- (IBAction) copyParentMenuTitle:(id)sender; - (IBAction) copyParentMenuTitle:(id)sender;
- (NSString *) stringFromSize:(uint64_t)theBytes; - (NSString *) stringFromSize:(uint64_t)theBytes;
- (NSString *) stringFromSpeed:(uint64_t)theBytes; - (NSString *) stringFromSpeed:(uint64_t)theBytes;

@ -10,9 +10,9 @@
@implementation DDWRT_MonitorAppDelegate @implementation DDWRT_MonitorAppDelegate
//@synthesize window;
//- (void)applicationDidFinishLaunching:(NSNotification *)aNotification # pragma mark -
# pragma mark Application Delegates:
- (void) awakeFromNib - (void) awakeFromNib
{ {
@ -29,99 +29,46 @@
} }
} }
- (void) initialize
{
NSLog(@"Reading defaults...");
[self readDefaults];
// 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];
}
- (void) deinitialize
{
[_readTimer invalidate];
_readTimer = nil;
[wrt_client release];
wrt_client = nil;
}
- (void) dealloc { - (void) dealloc {
if (_readTimer != nil) {
[_readTimer invalidate];
}
[AppMenu release]; [AppMenu release];
[_appMenu release]; [_appMenu release];
[ConfigPanel release]; [ConfigPanel release];
//[BandwidthViewer release];
[modalWindow release];
[super dealloc]; [super dealloc];
} }
- (void) initDefaults - (void) terminate:(id)sender {
{ [[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Creating new user defaults"); [self dealloc];
[[NSApplication sharedApplication] terminate:self];
// do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:@"http" forKey:@"protocol"];
[defaults setValue:@"192.168.1.1" forKey:@"hostname"];
[defaults setInteger:80 forKey:@"port"];
[defaults setValue:@"" forKey:@"username"];
[defaults setValue:@"" forKey:@"password"];
[defaults setBool:YES forKey:@"showMenuIcon"];
[defaults setBool:YES forKey:@"useBytes"];
[defaults setInteger:4 forKey:@"refreshTime"];
[defaults setBool:YES forKey:@"configured"];
// TODO: Add modal alert "First launch" here...
[self showConfigPanel:self];
} }
- (void) readDefaults - (void) initialize
{ {
hostname = [defaults valueForKey:@"hostname"]; NSLog(@"Reading defaults...");
protocol = [defaults valueForKey:@"protocol"]; [self readDefaults];
port = [defaults integerForKey:@"port"];
username = [defaults valueForKey:@"username"];
password = [defaults valueForKey:@"password"];
showMenuIcon = [defaults boolForKey:@"showMenuIcon"]; _statusDataRequestNumber = 0;
useBytes = [defaults boolForKey:@"useBytes"]; _statusStringData = @"";
refreshTime = [defaults integerForKey:@"refreshTime"];
}
- (void) writeDefaults wrt_update_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
{ wrt_request_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
// do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:hostname forKey:@"hostname"];
[defaults setValue:protocol forKey:@"protocol"];
[defaults setInteger:port forKey:@"port"];
[defaults setValue:username forKey:@"username"];
[defaults setValue:password forKey:@"password"];
[defaults setBool:showMenuIcon forKey:@"showMenuIcon"]; [wrt_update_client registerStatusCallback:self callback:@selector(cbUpdateStatus)];
[defaults setBool:useBytes forKey:@"useBytes"];
[defaults setInteger:refreshTime forKey:@"refreshTime"];
// sync the defaults to disk [wrt_update_client getConnectionStatus];
[defaults synchronize];
} }
- (void) terminate:(id)sender { - (void) deinitialize
[_readTimer invalidate]; {
[[NSUserDefaults standardUserDefaults] synchronize]; [wrt_update_client release];
[self dealloc]; wrt_update_client = nil;
[[NSApplication sharedApplication] terminate:self];
[wrt_request_client release];
wrt_request_client = nil;
} }
# pragma mark -
# pragma mark Menu Methods:
- (void) showMenubar - (void) showMenubar
{ {
NSLog(@"Showing Menu Item"); NSLog(@"Showing Menu Item");
@ -132,12 +79,7 @@
[_appMenu setTarget:self]; [_appMenu setTarget:self];
[_appMenu retain]; [_appMenu retain];
//[self setMenubarText:@"000KB/s\n000KB/s"];
//BOOL showIcon = [[NSUserDefaults standardUserDefaults] boolForKey:@"showMenuIcon"];
//if (showIcon == true) {
[self showMenubarIcon:false]; [self showMenubarIcon:false];
//}
[_appMenu setHighlightMode:YES]; [_appMenu setHighlightMode:YES];
//[_appMenu setMenu:AppMenu]; //[_appMenu setMenu:AppMenu];
@ -182,7 +124,61 @@
[menuTitle release]; [menuTitle release];
} }
- (void) showConfigPanel:(id)sender # pragma mark -
# pragma mark Configs Methods:
- (void) initDefaults
{
NSLog(@"Creating new user defaults");
// do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:@"http" forKey:@"protocol"];
[defaults setValue:@"192.168.1.1" forKey:@"hostname"];
[defaults setInteger:80 forKey:@"port"];
[defaults setValue:@"" forKey:@"username"];
[defaults setValue:@"" forKey:@"password"];
[defaults setBool:YES forKey:@"showMenuIcon"];
[defaults setBool:YES forKey:@"useBytes"];
[defaults setInteger:4 forKey:@"refreshTime"];
[defaults setBool:YES forKey:@"configured"];
// TODO: Add modal alert "First launch" here...
[self showConfigPanel:self];
}
- (void) readDefaults
{
hostname = [defaults valueForKey:@"hostname"];
protocol = [defaults valueForKey:@"protocol"];
port = [defaults integerForKey:@"port"];
username = [defaults valueForKey:@"username"];
password = [defaults valueForKey:@"password"];
showMenuIcon = [defaults boolForKey:@"showMenuIcon"];
useBytes = [defaults boolForKey:@"useBytes"];
refreshTime = [defaults integerForKey:@"refreshTime"];
}
- (void) writeDefaults
{
// do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:hostname forKey:@"hostname"];
[defaults setValue:protocol forKey:@"protocol"];
[defaults setInteger:port forKey:@"port"];
[defaults setValue:username forKey:@"username"];
[defaults setValue:password forKey:@"password"];
[defaults setBool:showMenuIcon forKey:@"showMenuIcon"];
[defaults setBool:useBytes forKey:@"useBytes"];
[defaults setInteger:refreshTime forKey:@"refreshTime"];
// sync the defaults to disk
[defaults synchronize];
}
- (IBAction) showConfigPanel:(id)sender
{ {
[configFieldShowIcon setState:([defaults boolForKey:@"showMenuIcon"] ? 1 : 0)]; [configFieldShowIcon setState:([defaults boolForKey:@"showMenuIcon"] ? 1 : 0)];
[configFieldUseBytes setState:([defaults boolForKey:@"useBytes"] ? 1 : 0)]; [configFieldUseBytes setState:([defaults boolForKey:@"useBytes"] ? 1 : 0)];
@ -210,7 +206,7 @@
[ConfigPanel makeKeyAndOrderFront:nil]; [ConfigPanel makeKeyAndOrderFront:nil];
} }
- (void) hideConfigPanel:(id)sender - (IBAction) hideConfigPanel:(id)sender
{ {
if (hostname == nil && [[sender title] isEqualToString:@"Cancel"]) { if (hostname == nil && [[sender title] isEqualToString:@"Cancel"]) {
// TODO: Add modal alert "will quit if not configured" // TODO: Add modal alert "will quit if not configured"
@ -220,38 +216,6 @@
[ConfigPanel orderOut:nil]; [ConfigPanel orderOut:nil];
} }
- (void) showBandwidthViewer:(id)sender
{
//NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain];
NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%@@%@:%d/graph_if.svg?%@",
protocol,
username,
password,
hostname,
port,
[wrt_client getWanPort]];
NSLog(@"Building request form %@", urlAddress);
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
[ [BandwidthViewerWebView mainFrame] loadRequest: [request autorelease] ];
[BandwidthViewer makeKeyAndOrderFront:nil];
}
- (void) hideBandwidthViewer:(id)sender
{
[BandwidthViewer orderOut:nil];
[BandwidthViewer release];
}
- (void) setConfigHostname:(id)sender
{
}
- (IBAction) setConfigProtocol:(id)sender - (IBAction) setConfigProtocol:(id)sender
{ {
if ([configFieldProtocolHTTP state] == 1 && [[configFieldPort stringValue] isEqualToString:@"443"] == true) { if ([configFieldProtocolHTTP state] == 1 && [[configFieldPort stringValue] isEqualToString:@"443"] == true) {
@ -261,56 +225,12 @@
} }
} }
- (void) setConfigPort:(id)sender - (IBAction) setConfigRefresh:(id)sender
{
}
- (void) setConfigRefresh:(id)sender
{ {
[configLabelRefresh setStringValue:[NSString stringWithFormat:@"%u s", ([sender integerValue] + 1)]]; [configLabelRefresh setStringValue:[NSString stringWithFormat:@"%u s", ([sender integerValue] + 1)]];
} }
- (void) setConfigWan:(id)sender - (IBAction) saveConfig:(id)sender
{
}
- (void) setConfigBytes:(id)sender
{
}
- (void) setConfigIcon:(id)sender
{
}
- (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]; [self deinitialize];
@ -345,40 +265,50 @@
[self hideConfigPanel:nil]; [self hideConfigPanel:nil];
} }
- (void) updateStatus # pragma mark -
# pragma mark Request Handlers:
- (void) cbUpdateStatus
{ {
NSLog(@"Status %@ wan port: %@", ([wrt_client getWrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); NSLog(@"Status %@ wan port: %@", ([wrt_update_client getWrtReachable] ? @"Up" : @"Down"), [wrt_update_client getWanPort]);
if ([wrt_client getWrtReachable] == true) { if ([wrt_update_client getWrtReachable] == true) {
if (showMenuIcon == true) { if (showMenuIcon == true) {
[self showMenubarIcon:true]; [self showMenubarIcon:true];
} else { } else {
[self hideMenubarIcon]; [self hideMenubarIcon];
} }
if (_readTimer == nil) { if (_updateTimer != nil) {
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; [_updateTimer invalidate];
_updateTimer = nil;
[_readTimer fire];
} }
} else if ([wrt_client getWrtReachable] == false) {
_updateTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(getThroughput:) userInfo:nil repeats:YES];
[_updateTimer fire];
} else if ([wrt_update_client getWrtReachable] == false) {
[self showMenubarIcon:false]; [self showMenubarIcon:false];
[self setMenubarText:@""];
if (_updateTimer != nil) {
[_updateTimer invalidate];
_updateTimer = nil;
}
[_readTimer invalidate]; _updateTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:wrt_update_client selector:@selector(getConnectionStatus:) userInfo:nil repeats:NO];
_readTimer = nil; [_updateTimer fire];
} }
} }
- (void) updateThroughput:(NSTimer *)timer - (void) getThroughput:(NSTimer *)timer
{ {
//NSLog(@"Status %@ wan port: %@", ([wrt_client getWrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); //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:)]; [wrt_update_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_update_client getWanPort]] delegate:self callback:@selector(cbThroughput:)];
} }
- (void) throughputCallback:(NSData *)data - (void) cbThroughput:(NSData *)data
{ {
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]]; NSString *key = [NSString stringWithFormat:@"%@:", [wrt_update_client getWanPort]];
stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])]; stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])];
NSArray *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; NSArray *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
@ -412,22 +342,63 @@
_lastOutThroughput = ifOut; _lastOutThroughput = ifOut;
} }
-(void)doUpdateStatus:(NSData *)data - (void) getRouterData:(NSData *)data
{ {
[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)]; NSLog(@"Gathering status data");
if (data != nil) {
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"]; NSString *newStringData = [_statusStringData stringByAppendingString:stringData];
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]]; _statusStringData = [newStringData retain];
} else {
NSLog(@"No data received yet");
}
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"]; switch (_statusDataRequestNumber++) {
NSRange startRange = [wanip rangeOfString:@" "]; case 0:
wanip = [wanip substringFromIndex:(startRange.location+1)]; NSLog(@"Status 0");
[menuWanIP setTitle:wanip]; [wrt_request_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(getRouterData:)];
break;
case 1:
NSLog(@"Status 1");
[wrt_request_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(getRouterData:)];
break;
case 2:
NSLog(@"Status 2");
[wrt_request_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(getRouterData:)];
break;
case 3:
default:
_statusDataRequestNumber = 0;
NSLog(@"%@", _statusStringData);
// Populate the menu items
[self populateMenuMain];
[self populateMenuWan];
[self populateMenuClients];
// Show the menu
[_appMenu popUpStatusItemMenu:AppMenu];
break;
}
}
# pragma mark -
# pragma mark Menu Handlers:
- (IBAction) refreshMenu:(id)sender
{
NSLog(@"Refresh Menu");
if ([wrt_update_client getWrtReachable] == true) {
[self getRouterData:nil];
} else {
[_appMenu popUpStatusItemMenu:AppMenu];
}
}
NSString *uptime = [wrt_client getKey:stringData key:@"uptime"]; - (void) populateMenuMain
{
NSString *uptime = [wrt_request_client getKey:_statusStringData key:@"uptime"];
NSString *loadSplit = @", load average: "; NSString *loadSplit = @", load average: ";
if ([uptime length] > 0) { if ([uptime length] > 0) {
NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]]; NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]];
@ -446,35 +417,35 @@
[menuLoad setHidden:true]; [menuLoad setHidden:true];
//[[AppMenu itemAtIndex:2] setHidden:true]; //[[AppMenu itemAtIndex:2] setHidden:true];
} }
/*
NSString *memInfo = [wrt_client getKey:stringData key:@"mem_info"]; // NSString *memInfo = [wrt_client getKey:stringData key:@"mem_info"];
// Remove any white spaces // Remove any white spaces
NSArray *parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; // NSArray *parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; // NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
memInfo = [filteredArray componentsJoinedByString:@" "]; // memInfo = [filteredArray componentsJoinedByString:@" "];
parts = nil; // parts = nil;
filteredArray = nil; // filteredArray = nil;
// Remove any quotes // Remove any quotes
parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\'"]]; // parts = [memInfo componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\'"]];
filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; // filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
memInfo = [filteredArray componentsJoinedByString:@""]; // memInfo = [filteredArray componentsJoinedByString:@""];
NSArray *memData = [memInfo componentsSeparatedByString:@","]; // NSArray *memData = [memInfo componentsSeparatedByString:@","];
unint32_t memTotal = strtoull([[memData objectAtIndex:17] UTF8String], NULL, 0); // unint32_t memTotal = strtoull([[memData objectAtIndex:17] UTF8String], NULL, 0);
unint32_t memFree = strtoull([[memData objectAtIndex:21] UTF8String], NULL, 0); // unint32_t memFree = strtoull([[memData objectAtIndex:21] UTF8String], NULL, 0);
*/
} }
- (void) wanRequestCallback:(NSData *)data - (void) populateMenuWan
{ {
[wrt_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(cbClientsRequest:)]; NSString *wanip = [wrt_request_client getKey:_statusStringData key:@"ipinfo"];
NSRange startRange = [wanip rangeOfString:@" "];
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; wanip = [wanip substringFromIndex:(startRange.location+1)];
[menuWanIP setTitle:wanip];
NSString *wanStatus = [wrt_client getKey:stringData key:@"wan_status"]; NSString *wanStatus = [wrt_request_client getKey:_statusStringData key:@"wan_status"];
NSString *wanName = [wrt_client getKey:stringData key:@"wan_shortproto"]; NSString *wanName = [wrt_request_client getKey:_statusStringData key:@"wan_shortproto"];
if ([wanName isEqualToString:@"pppoe"] == true) { if ([wanName isEqualToString:@"pppoe"] == true) {
wanName = @"PPPoE"; wanName = @"PPPoE";
} else if ([wanName isEqualToString:@"static"] == true) { } else if ([wanName isEqualToString:@"static"] == true) {
@ -486,13 +457,11 @@
wanStatus = [wanStatus substringToIndex:[wanStatus rangeOfString:@"&"].location]; wanStatus = [wanStatus substringToIndex:[wanStatus rangeOfString:@"&"].location];
[menuWanStatus setTitle:[NSString stringWithFormat:@"%@ %@", wanName, wanStatus]]; [menuWanStatus setTitle:[NSString stringWithFormat:@"%@ %@", wanName, wanStatus]];
/* //if ([_appMenu image] != nil) {
if ([_appMenu image] != nil) { // [self showMenubarIcon:[wanStatus isEqualToString:@"Connected"]];
[self showMenubarIcon:[wanStatus isEqualToString:@"Connected"]]; //}
}
*/
NSString *wanUptime = [wrt_client getKey:stringData key:@"wan_uptime"]; NSString *wanUptime = [wrt_request_client getKey:_statusStringData key:@"wan_uptime"];
if ([wanStatus isEqualToString:@"Connected"] == true) { if ([wanStatus isEqualToString:@"Connected"] == true) {
[menuWanUptime setTitle:wanUptime]; [menuWanUptime setTitle:wanUptime];
[menuWanUptime setHidden:false]; [menuWanUptime setHidden:false];
@ -509,17 +478,17 @@
} }
NSString *trafficIn = [wrt_client getKey:stringData key:@"ttraff_in"]; NSString *trafficIn = [wrt_request_client getKey:_statusStringData key:@"ttraff_in"];
NSString *trafficOut = [wrt_client getKey:stringData key:@"ttraff_out"]; NSString *trafficOut = [wrt_request_client getKey:_statusStringData key:@"ttraff_out"];
trafficIn = [self stringFromSize:([trafficIn longLongValue] * 1024 * 1024)]; trafficIn = [self stringFromSize:([trafficIn longLongValue] * 1024 * 1024)];
trafficOut = [self stringFromSize:([trafficOut longLongValue] * 1024 * 1024)]; trafficOut = [self stringFromSize:([trafficOut longLongValue] * 1024 * 1024)];
[menuWanTrafficIn setTitle:[NSString stringWithFormat:@"In: %@", trafficIn]]; [menuWanTrafficIn setTitle:[NSString stringWithFormat:@"In: %@", trafficIn]];
[menuWanTrafficOut setTitle:[NSString stringWithFormat:@"Out: %@", trafficOut]]; [menuWanTrafficOut setTitle:[NSString stringWithFormat:@"Out: %@", trafficOut]];
NSString *wanDNS0 = [wrt_client getKey:stringData key:@"wan_dns0"]; NSString *wanDNS0 = [wrt_request_client getKey:_statusStringData key:@"wan_dns0"];
NSString *wanDNS1 = [wrt_client getKey:stringData key:@"wan_dns1"]; NSString *wanDNS1 = [wrt_request_client getKey:_statusStringData key:@"wan_dns1"];
NSString *wanDNS2 = [wrt_client getKey:stringData key:@"wan_dns2"]; NSString *wanDNS2 = [wrt_request_client getKey:_statusStringData key:@"wan_dns2"];
if ([wanDNS0 length] > 0) { if ([wanDNS0 length] > 0) {
[menuWanDNS setEnabled:true]; [menuWanDNS setEnabled:true];
@ -538,23 +507,15 @@
[menuWanDNSItem2 setTitle: wanDNS2]; [menuWanDNSItem2 setTitle: wanDNS2];
[menuWanDNSItem2 setHidden:false]; [menuWanDNSItem2 setHidden:false];
} }
[stringData release];
} }
- (void) refreshClientsMenu:(id)sender - (void) populateMenuClients
{
}
- (void) cbClientsRequest:(NSData *)data
{ {
NSString * clientsStringData; NSString * clientsStringData;
NSString *stringData = [ [NSString alloc] initWithData:data encoding:NSASCIIStringEncoding ];
NSString *keyData = @"{arp_table::"; NSString *keyData = @"{arp_table::";
clientsStringData = [ stringData substringFromIndex:([stringData rangeOfString:keyData].location + [keyData length]) ]; clientsStringData = [ _statusStringData substringFromIndex:([_statusStringData rangeOfString:keyData].location + [keyData length]) ];
clientsStringData = [ clientsStringData substringToIndex:[clientsStringData rangeOfString:@"}"].location ]; clientsStringData = [ clientsStringData substringToIndex:[clientsStringData rangeOfString:@"}"].location ];
// Remove any white spaces // Remove any white spaces
@ -575,6 +536,10 @@
NSMenuItem *clientMenuItem; NSMenuItem *clientMenuItem;
NSMenuItem *clientItem; NSMenuItem *clientItem;
NSString *ipconn = [wrt_request_client getKey:_statusStringData key:@"ip_conntrack"];
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
uint16_t clientsCount = [clientsData count] / 4; uint16_t clientsCount = [clientsData count] / 4;
[menuClientsCount setTitle:[NSString stringWithFormat:@"%lu Active Client%@", clientsCount, (clientsCount > 1 ? @"s" : @"")]]; [menuClientsCount setTitle:[NSString stringWithFormat:@"%lu Active Client%@", clientsCount, (clientsCount > 1 ? @"s" : @"")]];
@ -616,11 +581,6 @@
[menuClients addItem:clientItem]; [menuClients addItem:clientItem];
} }
[_appMenu popUpStatusItemMenu:AppMenu];
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
} }
- (NSMenu *) createCopyMenuItem - (NSMenu *) createCopyMenuItem
@ -633,6 +593,8 @@
return [copyMenu retain]; return [copyMenu retain];
} }
# pragma mark -
# pragma mark Utilities:
- (IBAction) copyParentMenuTitle:(id)sender - (IBAction) copyParentMenuTitle:(id)sender
{ {
@ -692,9 +654,4 @@
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]); return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
} }
- (void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
NSLog(@"Delegate Received: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
@end @end

@ -52,7 +52,7 @@
uri]; uri];
//NSLog(@"Building request form %@", urlAddress); NSLog(@"Building request form %@", urlAddress);
NSURL *url = [NSURL URLWithString:urlAddress]; NSURL *url = [NSURL URLWithString:urlAddress];

Loading…
Cancel
Save