|
|
@ -24,8 +24,7 @@
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
|
|
|
|
// check if the app is configured yet
|
|
|
|
// check if the app is configured yet
|
|
|
|
if (![defaults boolForKey:@"configured"])
|
|
|
|
if (![defaults boolForKey:@"configured"]) {
|
|
|
|
{
|
|
|
|
|
|
|
|
[self initDefaults];
|
|
|
|
[self initDefaults];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
[self initialize];
|
|
|
|
[self initialize];
|
|
|
@ -41,10 +40,7 @@
|
|
|
|
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
|
|
|
|
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
|
|
|
|
|
|
|
|
|
|
|
|
[wrt_client getConnectionStatus];
|
|
|
|
[wrt_client getConnectionStatus];
|
|
|
|
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
|
|
|
|
[self updateThroughput:nil];
|
|
|
|
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[_readTimer fire];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) deinitialize
|
|
|
|
- (void) deinitialize
|
|
|
@ -335,7 +331,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
- (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) {
|
|
|
|
if ([wrt_client wrtReachable] == true && _wrtReachable == false) {
|
|
|
|
_wrtReachable = true;
|
|
|
|
_wrtReachable = true;
|
|
|
|
if (showMenuIcon == true) {
|
|
|
|
if (showMenuIcon == true) {
|
|
|
@ -351,6 +347,12 @@
|
|
|
|
if (_wrtReachable == true) {
|
|
|
|
if (_wrtReachable == true) {
|
|
|
|
[wrt_client getStatusUpdate:[NSString stringWithFormat:@"fetchif.cgi?%@", [wrt_client getWanPort]] delegate:self callback:@selector(throughputCallback:)];
|
|
|
|
[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
|
|
|
|
- (void) throughputCallback:(NSData *)data
|
|
|
@ -375,7 +377,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
|
|
|
|
double timeDiff = fabs([_lastDateThroughput timeIntervalSinceNow]);
|
|
|
|
_lastDateThroughput = [[NSDate date] retain];
|
|
|
|
_lastDateThroughput = [[NSDate date] retain];
|
|
|
|
if (timeDiff <= 0) timeDiff = 1; // avoid division by zero
|
|
|
|
|
|
|
|
|
|
|
|
if (timeDiff <= 0)
|
|
|
|
|
|
|
|
timeDiff = 1; // avoid division by zero
|
|
|
|
|
|
|
|
|
|
|
|
double speedIn = diffIn / timeDiff;
|
|
|
|
double speedIn = diffIn / timeDiff;
|
|
|
|
double speedOut = diffOut / timeDiff;
|
|
|
|
double speedOut = diffOut / timeDiff;
|
|
|
@ -384,8 +388,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
[ self setMenubarText:[NSString stringWithFormat:@"%@s\n%@s", [self stringFromSpeed:speedOut], [self stringFromSpeed:speedIn]] ];
|
|
|
|
[ 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,
|
|
|
|
//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);
|
|
|
|
// _lastOutThroughput, diffIn, diffOut, speedIn, speedOut, timeDiff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_lastInThroughput = ifIn;
|
|
|
|
_lastInThroughput = ifIn;
|
|
|
@ -399,6 +403,7 @@
|
|
|
|
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 *ipconn = [wrt_client getKey:stringData key:@"ip_conntrack"];
|
|
|
|
|
|
|
|
|
|
|
|
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
|
|
|
|
[menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
|
|
|
|
|
|
|
|
|
|
|
|
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
|
|
|
|
NSString *wanip = [wrt_client getKey:stringData key:@"ipinfo"];
|
|
|
@ -666,8 +671,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *) stringFromSpeed:(uint64_t)theBytes
|
|
|
|
- (NSString *) stringFromSpeed:(uint64_t)theBytes
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int minSize = /*(useBytes ? */1023/* : 999)*/;
|
|
|
|
|
|
|
|
unsigned int divSize = /*(useBytes ? */1024/* : 1000)*/;
|
|
|
|
|
|
|
|
NSString *suffix;
|
|
|
|
NSString *suffix;
|
|
|
|
|
|
|
|
|
|
|
|
if (useBytes == false) {
|
|
|
|
if (useBytes == false) {
|
|
|
@ -677,21 +680,21 @@
|
|
|
|
double floatSize = theBytes;
|
|
|
|
double floatSize = theBytes;
|
|
|
|
suffix = (useBytes ? @"B" : @"b");
|
|
|
|
suffix = (useBytes ? @"B" : @"b");
|
|
|
|
|
|
|
|
|
|
|
|
if (theBytes<minSize)
|
|
|
|
if (theBytes<1023)
|
|
|
|
return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]);
|
|
|
|
return([NSString stringWithFormat:@"%llu%@", theBytes, suffix]);
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
suffix = (useBytes ? @"KiB" : @"Kb");
|
|
|
|
suffix = (useBytes ? @"KiB" : @"Kb");
|
|
|
|
if (floatSize<minSize)
|
|
|
|
if (floatSize<1023)
|
|
|
|
return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]);
|
|
|
|
return([NSString stringWithFormat:@"%1.1f%@", floatSize, suffix]);
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
suffix = (useBytes ? @"MiB" : @"Mb");
|
|
|
|
suffix = (useBytes ? @"MiB" : @"Mb");
|
|
|
|
if (floatSize<minSize)
|
|
|
|
if (floatSize<1023)
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
suffix = (useBytes ? @"GiB" : @"Gb");
|
|
|
|
suffix = (useBytes ? @"GiB" : @"Gb");
|
|
|
|
if (floatSize<minSize)
|
|
|
|
if (floatSize<1023)
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
floatSize = floatSize / divSize;
|
|
|
|
floatSize = floatSize / 1024;
|
|
|
|
|
|
|
|
|
|
|
|
suffix = (useBytes ? @"TiB" : @"Tb");
|
|
|
|
suffix = (useBytes ? @"TiB" : @"Tb");
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|
return([NSString stringWithFormat:@"%1.2f%@", floatSize, suffix]);
|
|
|
|