|
|
@ -37,7 +37,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
[wrt_client getConnectionStatus];
|
|
|
|
[wrt_client getConnectionStatus];
|
|
|
|
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
|
|
|
|
_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"]+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
|
|
|
|
|
|
|
|
|
|
|
|
[_readTimer fire];
|
|
|
|
[_readTimer fire];
|
|
|
|
|
|
|
|
|
|
|
@ -334,6 +334,12 @@
|
|
|
|
[self showMenubarIcon:false];
|
|
|
|
[self showMenubarIcon:false];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_wrtReachable == true) {
|
|
|
|
|
|
|
|
[wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)];
|
|
|
|
|
|
|
|
//[wrt_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(doUpdateStatus:)];
|
|
|
|
|
|
|
|
//[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//WRTRequest *wrtr = [[WRTRequest alloc] init];
|
|
|
|
//WRTRequest *wrtr = [[WRTRequest alloc] init];
|
|
|
|
|
|
|
|
|
|
|
|
//[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"];
|
|
|
|
//[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"];
|
|
|
@ -341,32 +347,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
- (void) throughputCallback:(NSData *)data
|
|
|
|
- (void) throughputCallback:(NSData *)data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
|
|
|
|
/*NSDate *start = [NSDate date];
|
|
|
|
NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]];
|
|
|
|
NSTimeInterval timeInterval = [start timeIntervalSinceNow];
|
|
|
|
stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])];
|
|
|
|
NSLog(@"%f", timeInterval);
|
|
|
|
|
|
|
|
|
|
|
|
NSArray *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
|
|
|
NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
|
|
|
|
|
|
|
|
stringData = [filteredArray componentsJoinedByString:@" "];
|
|
|
|
|
|
|
|
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
stringData = [stringData substringFromIndex:([stringData rangeOfString:@":"].location + 1)];
|
|
|
|
|
|
|
|
NSArray *listItems = [stringData componentsSeparatedByString:@" "];
|
|
|
|
NSArray *listItems = [stringData componentsSeparatedByString:@" "];
|
|
|
|
|
|
|
|
|
|
|
|
NSLog(@"%@", [listItems objectAtIndex:0]);
|
|
|
|
unsigned long long ifIn = strtoull([[listItems objectAtIndex:0] UTF8String], NULL, 0);
|
|
|
|
unsigned long long ifIn = [NSNumber numberWithString:[listItems objectAtIndex:0]];
|
|
|
|
unsigned long long ifOut = strtoull([[listItems objectAtIndex:8] UTF8String], NULL, 0);
|
|
|
|
unsigned long long ifOut = [NSNumber numberWithString:[listItems objectAtIndex:8]];
|
|
|
|
|
|
|
|
|
|
|
|
if (_lastInThroughput != 0) {
|
|
|
|
|
|
|
|
unsigned long long diffIn = ifIn - _lastInThroughput;
|
|
|
|
|
|
|
|
unsigned long long diffOut = ifOut - _lastOutThroughput;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double speedIn = diffIn / ([NSDate timeIntervalSinceReferenceDate] - _lastDateThroughput);
|
|
|
|
|
|
|
|
double speedOut = diffOut / ([NSDate timeIntervalSinceReferenceDate] - _lastDateThroughput);
|
|
|
|
|
|
|
|
speedIn = round(2.2f * speedIn) / 2.2f;
|
|
|
|
|
|
|
|
speedOut = round(2.2f * speedOut) / 2.2f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromFileSize:speedIn], [self stringFromFileSize:speedOut]]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_lastDateThroughput = [NSDate timeIntervalSinceReferenceDate];
|
|
|
|
|
|
|
|
_lastInThroughput = ifIn;
|
|
|
|
|
|
|
|
_lastOutThroughput = ifOut;
|
|
|
|
|
|
|
|
|
|
|
|
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];*/
|
|
|
|
NSLog(@"In %llu Out %llu", ifIn, ifOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)doUpdateStatus:(NSData *)data
|
|
|
|
-(void)doUpdateStatus:(NSData *)data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
/*
|
|
|
|
|
|
|
|
NSString *ipconn = [self getKey:stringData key:@"ip_conntrack"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSString *wanip = [self getKey:stringData key:@"ipinfo"];
|
|
|
|
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
|
|
|
|
wanip = [wanip substringFromIndex:([wanip rangeOfString:@" "].location+1)];
|
|
|
|
|
|
|
|
|
|
|
|
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
|
|
|
|
|
|
|
|
NSRange startRange = [wanip rangeOfString:@" "];
|
|
|
|
|
|
|
|
wanip = [wanip substringFromIndex:(startRange.location+1)];
|
|
|
|
|
|
|
|
|
|
|
|
NSString *uptime = [self getKey:stringData key:@"uptime"];
|
|
|
|
NSString *uptime = [wrt_client getKey:stringData key:@"uptime"];
|
|
|
|
NSString *loadSplit = @", load average: ";
|
|
|
|
NSString *loadSplit = @", load average: ";
|
|
|
|
NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]];
|
|
|
|
NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]];
|
|
|
|
uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load
|
|
|
|
uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load
|
|
|
@ -377,7 +402,7 @@
|
|
|
|
[menuUptime setTitle:uptime];
|
|
|
|
[menuUptime setTitle:uptime];
|
|
|
|
[menuLoad setTitle:load];
|
|
|
|
[menuLoad setTitle:load];
|
|
|
|
[menuLoad setHidden:false];
|
|
|
|
[menuLoad setHidden:false];
|
|
|
|
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];*/
|
|
|
|
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) refreshMenu:(id)sender
|
|
|
|
- (void) refreshMenu:(id)sender
|
|
|
@ -396,20 +421,14 @@
|
|
|
|
//WRTRequest *wrtr = [[WRTRequest alloc] init];
|
|
|
|
//WRTRequest *wrtr = [[WRTRequest alloc] init];
|
|
|
|
|
|
|
|
|
|
|
|
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
|
|
|
|
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
|
|
|
|
|
|
|
|
|
|
|
|
[wrt_client getStatusUpdate:@"Status_Bandwidth.asp" delegate:self callback:@selector(wanRequestCallback:)];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) wanRequestCallback:(NSData *)data
|
|
|
|
- (void) wanRequestCallback:(NSData *)data
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NSLog(@"Received callback for request");
|
|
|
|
|
|
|
|
NSLog(@"Length: %lu", [data length]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
NSLog(@"%@", stringData);
|
|
|
|
|
|
|
|
/*
|
|
|
|
NSString *wanStatus = [wrt_client getKey:stringData key:@"wan_status"];
|
|
|
|
NSString *wanStatus = [self getKey:stringData key:@"wan_status"];
|
|
|
|
NSString *wanName = [wrt_client getKey:stringData key:@"wan_shortproto"];
|
|
|
|
NSString *wanName = [self getKey:stringData 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) {
|
|
|
@ -421,11 +440,13 @@
|
|
|
|
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 = [self getKey:stringData key:@"wan_uptime"];
|
|
|
|
NSString *wanUptime = [wrt_client getKey:stringData 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];
|
|
|
@ -442,17 +463,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSString *trafficIn = [self getKey:stringData key:@"ttraff_in"];
|
|
|
|
NSString *trafficIn = [wrt_client getKey:stringData key:@"ttraff_in"];
|
|
|
|
NSString *trafficOut = [self getKey:stringData key:@"ttraff_out"];
|
|
|
|
NSString *trafficOut = [wrt_client getKey:stringData key:@"ttraff_out"];
|
|
|
|
trafficIn = [self stringFromFileSize:([trafficIn longLongValue] * 1024 * 1024)];
|
|
|
|
trafficIn = [self stringFromFileSize:([trafficIn longLongValue] * 1024 * 1024)];
|
|
|
|
trafficOut = [self stringFromFileSize:([trafficOut longLongValue] * 1024 * 1024)];
|
|
|
|
trafficOut = [self stringFromFileSize:([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 = [self getKey:stringData key:@"wan_dns0"];
|
|
|
|
NSString *wanDNS0 = [wrt_client getKey:stringData key:@"wan_dns0"];
|
|
|
|
NSString *wanDNS1 = [self getKey:stringData key:@"wan_dns1"];
|
|
|
|
NSString *wanDNS1 = [wrt_client getKey:stringData key:@"wan_dns1"];
|
|
|
|
NSString *wanDNS2 = [self getKey:stringData key:@"wan_dns2"];
|
|
|
|
NSString *wanDNS2 = [wrt_client getKey:stringData key:@"wan_dns2"];
|
|
|
|
|
|
|
|
|
|
|
|
if ([wanDNS0 length] > 0) {
|
|
|
|
if ([wanDNS0 length] > 0) {
|
|
|
|
[menuWanDNS setEnabled:true];
|
|
|
|
[menuWanDNS setEnabled:true];
|
|
|
@ -471,7 +492,7 @@
|
|
|
|
[menuWanDNSItem2 setTitle: wanDNS2];
|
|
|
|
[menuWanDNSItem2 setTitle: wanDNS2];
|
|
|
|
[menuWanDNSItem2 setHidden:false];
|
|
|
|
[menuWanDNSItem2 setHidden:false];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
[stringData release];
|
|
|
|
[stringData release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|