|
|
|
@ -24,8 +24,7 @@
|
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
|
|
// check if the app is configured yet
|
|
|
|
|
if (![defaults boolForKey:@"configured"])
|
|
|
|
|
{
|
|
|
|
|
if (![defaults boolForKey:@"configured"]) {
|
|
|
|
|
[self initDefaults];
|
|
|
|
|
} else {
|
|
|
|
|
[self initialize];
|
|
|
|
@ -41,10 +40,7 @@
|
|
|
|
|
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
|
|
|
|
|
|
|
|
|
|
[wrt_client getConnectionStatus];
|
|
|
|
|
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
|
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
|
|
|
|
|
|
|
|
|
|
[_readTimer fire];
|
|
|
|
|
[self updateThroughput:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) deinitialize
|
|
|
|
@ -333,9 +329,9 @@
|
|
|
|
|
[self hideConfigPanel:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) updateThroughput:(NSTimer*)timer
|
|
|
|
|
- (void) updateThroughput:(NSTimer *)timer
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
|
//NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
|
if ([wrt_client wrtReachable] == true && _wrtReachable == false) {
|
|
|
|
|
_wrtReachable = true;
|
|
|
|
|
if (showMenuIcon == true) {
|
|
|
|
@ -351,41 +347,49 @@
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) throughputCallback:(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]];
|
|
|
|
|
stringData = [stringData substringFromIndex:([stringData rangeOfString:key].location + [key length])];
|
|
|
|
|
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 *parts = [stringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
|
|
|
|
|
stringData = [filteredArray componentsJoinedByString:@" "];
|
|
|
|
|
|
|
|
|
|
NSArray *listItems = [stringData componentsSeparatedByString:@" "];
|
|
|
|
|
NSArray *listItems = [stringData componentsSeparatedByString:@" "];
|
|
|
|
|
|
|
|
|
|
uint64_t ifIn = strtoull([[listItems objectAtIndex:0] UTF8String], NULL, 0);
|
|
|
|
|
uint64_t ifOut = strtoull([[listItems objectAtIndex:8] UTF8String], NULL, 0);
|
|
|
|
|
uint64_t ifIn = strtoull([[listItems objectAtIndex:0] UTF8String], NULL, 0);
|
|
|
|
|
uint64_t ifOut = strtoull([[listItems objectAtIndex:8] UTF8String], NULL, 0);
|
|
|
|
|
|
|
|
|
|
if (_lastInThroughput != 0) {
|
|
|
|
|
uint64_t diffIn = ifIn - _lastInThroughput;
|
|
|
|
|
uint64_t diffIn = ifIn - _lastInThroughput;
|
|
|
|
|
uint64_t diffOut = ifOut - _lastOutThroughput;
|
|
|
|
|
|
|
|
|
|
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
|
|
|
|
|
_lastDateThroughput = [[NSDate date] retain];
|
|
|
|
|
if (timeDiff <= 0) timeDiff = 1; // avoid division by zero
|
|
|
|
|
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
|
|
|
|
|
_lastDateThroughput = [[NSDate date] retain];
|
|
|
|
|
|
|
|
|
|
if (timeDiff <= 0)
|
|
|
|
|
timeDiff = 1; // avoid division by zero
|
|
|
|
|
|
|
|
|
|
double speedIn = diffIn / timeDiff;
|
|
|
|
|
double speedOut = diffOut / timeDiff;
|
|
|
|
|
speedIn = round(2.2f * speedIn) / 2.2f;
|
|
|
|
|
speedOut = round(2.2f * speedOut) / 2.2f;
|
|
|
|
|
double speedIn = diffIn / timeDiff;
|
|
|
|
|
double speedOut = diffOut / timeDiff;
|
|
|
|
|
speedIn = round(2.2f * speedIn) / 2.2f;
|
|
|
|
|
speedOut = round(2.2f * speedOut) / 2.2f;
|
|
|
|
|
|
|
|
|
|
[ self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromSpeed:speedOut], [self stringFromSpeed:speedIn]] ];
|
|
|
|
|
|
|
|
|
|
NSLog(@"In %llu Out %llu Last In %llu Last Out %llu diffIn %llu diffOut %llu In %f Out %f Interval %f", ifIn, ifOut, _lastInThroughput,
|
|
|
|
|
_lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff);
|
|
|
|
|
//NSLog(@"In %llu Out %llu Last In %llu Last Out %llu diffIn %llu diffOut %llu In %f Out %f Interval %f", ifIn, ifOut, _lastInThroughput,
|
|
|
|
|
// _lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_lastInThroughput = ifIn;
|
|
|
|
@ -398,16 +402,17 @@
|
|
|
|
|
|
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
|
|
NSString *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
|
|
|
|
|
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)];
|
|
|
|
|
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 *uptime = [wrt_client getKey:stringData key:@"uptime"];
|
|
|
|
|
NSString *loadSplit = @", load average: ";
|
|
|
|
|
if ([uptime length] > 0) {
|
|
|
|
|
NSString *load = [uptime substringFromIndex:[uptime rangeOfString:loadSplit].location+[loadSplit length]];
|
|
|
|
|
uptime = [uptime substringToIndex:[uptime rangeOfString:@", load"].location]; // Cut the load
|
|
|
|
@ -441,8 +446,8 @@
|
|
|
|
|
memInfo = [filteredArray componentsJoinedByString:@""];
|
|
|
|
|
|
|
|
|
|
NSArray *memData = [memInfo componentsSeparatedByString:@","];
|
|
|
|
|
unint32_t memTotal = strtoull([[memData objectAtIndex:17] UTF8String], NULL, 0);
|
|
|
|
|
unint32_t memFree = strtoull([[memData objectAtIndex:21] UTF8String], NULL, 0);
|
|
|
|
|
unint32_t memTotal = strtoull([[memData objectAtIndex:17] UTF8String], NULL, 0);
|
|
|
|
|
unint32_t memFree = strtoull([[memData objectAtIndex:21] UTF8String], NULL, 0);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -476,17 +481,17 @@
|
|
|
|
|
|
|
|
|
|
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
|
|
|
|
|
|
|
|
NSString *wanStatus = [wrt_client getKey:stringData key:@"wan_status"];
|
|
|
|
|
NSString *wanName = [wrt_client getKey:stringData key:@"wan_shortproto"];
|
|
|
|
|
NSString *wanStatus = [wrt_client getKey:stringData key:@"wan_status"];
|
|
|
|
|
NSString *wanName = [wrt_client getKey:stringData key:@"wan_shortproto"];
|
|
|
|
|
if ([wanName isEqualToString:@"pppoe"] == true) {
|
|
|
|
|
wanName = @"PPPoE";
|
|
|
|
|
wanName = @"PPPoE";
|
|
|
|
|
} else if ([wanName isEqualToString:@"static"] == true) {
|
|
|
|
|
wanName = @"Static";
|
|
|
|
|
wanName = @"Static";
|
|
|
|
|
} else {
|
|
|
|
|
wanName = [wanName uppercaseString];
|
|
|
|
|
wanName = [wanName uppercaseString];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wanStatus = [wanStatus substringToIndex:[wanStatus rangeOfString:@"&"].location];
|
|
|
|
|
wanStatus = [wanStatus substringToIndex:[wanStatus rangeOfString:@"&"].location];
|
|
|
|
|
[menuWanStatus setTitle:[NSString stringWithFormat:@"%@ %@", wanName, wanStatus]];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -495,7 +500,7 @@
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
NSString *wanUptime = [wrt_client getKey:stringData key:@"wan_uptime"];
|
|
|
|
|
NSString *wanUptime = [wrt_client getKey:stringData key:@"wan_uptime"];
|
|
|
|
|
if ([wanStatus isEqualToString:@"Connected"] == true) {
|
|
|
|
|
[menuWanUptime setTitle:wanUptime];
|
|
|
|
|
[menuWanUptime setHidden:false];
|
|
|
|
@ -520,9 +525,9 @@
|
|
|
|
|
[menuWanTrafficIn setTitle:[NSString stringWithFormat:@"In: %@", trafficIn]];
|
|
|
|
|
[menuWanTrafficOut setTitle:[NSString stringWithFormat:@"Out: %@", trafficOut]];
|
|
|
|
|
|
|
|
|
|
NSString *wanDNS0 = [wrt_client getKey:stringData key:@"wan_dns0"];
|
|
|
|
|
NSString *wanDNS1 = [wrt_client getKey:stringData key:@"wan_dns1"];
|
|
|
|
|
NSString *wanDNS2 = [wrt_client getKey:stringData key:@"wan_dns2"];
|
|
|
|
|
NSString *wanDNS0 = [wrt_client getKey:stringData key:@"wan_dns0"];
|
|
|
|
|
NSString *wanDNS1 = [wrt_client getKey:stringData key:@"wan_dns1"];
|
|
|
|
|
NSString *wanDNS2 = [wrt_client getKey:stringData key:@"wan_dns2"];
|
|
|
|
|
|
|
|
|
|
if ([wanDNS0 length] > 0) {
|
|
|
|
|
[menuWanDNS setEnabled:true];
|
|
|
|
@ -550,7 +555,7 @@
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) cbClientsRequest:(NSData*)data
|
|
|
|
|
- (void) cbClientsRequest:(NSData *)data
|
|
|
|
|
{
|
|
|
|
|
NSString * clientsStringData;
|
|
|
|
|
|
|
|
|
@ -626,7 +631,7 @@
|
|
|
|
|
[_readTimer fire];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSMenu*) createCopyMenuItem
|
|
|
|
|
- (NSMenu *) createCopyMenuItem
|
|
|
|
|
{
|
|
|
|
|
NSMenu *copyMenu = [[NSMenu alloc] init];
|
|
|
|
|
NSMenuItem *copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
|
|
|
|
@ -666,32 +671,30 @@
|
|
|
|
|
|
|
|
|
|
- (NSString *) stringFromSpeed:(uint64_t)theBytes
|
|
|
|
|
{
|
|
|
|
|
unsigned int minSize = /*(useBytes ? */1023/* : 999)*/;
|
|
|
|
|
unsigned int divSize = /*(useBytes ? */1024/* : 1000)*/;
|
|
|
|
|
NSString *suffix;
|
|
|
|
|
|
|
|
|
|
if (useBytes == false) {
|
|
|
|
|
theBytes *= 8;
|
|
|
|
|
theBytes *= 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double floatSize = theBytes;
|
|
|
|
|
suffix = (useBytes ? @"B" : @"b");
|
|
|
|
|
|
|
|
|
|
if (theBytes<minSize)
|
|
|
|
|
if (theBytes<1023)
|
|
|
|
|
return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]);
|
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
|
suffix = (useBytes ? @"KiB" : @"Kb");
|
|
|
|
|
if (floatSize<minSize)
|
|
|
|
|
if (floatSize<1023)
|
|
|
|
|
return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]);
|
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
|
suffix = (useBytes ? @"MiB" : @"Mb");
|
|
|
|
|
if (floatSize<minSize)
|
|
|
|
|
if (floatSize<1023)
|
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
|
suffix = (useBytes ? @"GiB" : @"Gb");
|
|
|
|
|
if (floatSize<minSize)
|
|
|
|
|
if (floatSize<1023)
|
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
|
|
|
|
|
|
suffix = (useBytes ? @"TiB" : @"Tb");
|
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
|