@ -10,17 +10,17 @@
@ implementation DDWRT_MonitorAppDelegate
/ / @ synthesize window ;
/ / - ( void ) applicationDidFinishLaunching : ( NSNotification * ) aNotification
# pragma mark -
# pragma mark Application Delegates :
- ( void ) awakeFromNib
{
/ / Insert code here to initialize your application
[ self showMenubar ] ;
defaults = [ NSUserDefaults standardUserDefaults ] ;
/ / check if the app is configured yet
if ( ![ defaults boolForKey : @ "configured "] ) {
[ self initDefaults ] ;
@ -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 {
if ( _readTimer != nil ) {
[ _readTimer invalidate ] ;
}
[ AppMenu release ] ;
[ _appMenu release ] ;
[ ConfigPanel release ] ;
/ / [ BandwidthViewer release ] ;
[ modalWindow release ] ;
[ super dealloc ] ;
}
- ( 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 ) terminate : ( id ) sender {
[ [ NSUserDefaults standardUserDefaults ] synchronize ] ;
[ self dealloc ] ;
[ [ NSApplication sharedApplication ] terminate : self ] ;
}
- ( void ) readDefaults
- ( void ) initialize
{
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 "] ;
NSLog ( @ "Reading defaults ...");
[ self readDefaults ] ;
_statusDataRequestNumber = 0 ;
_statusStringData = @ "";
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 ] ;
[ wrt_update_client registerStatusCallback : self callback : @ selector ( cbUpdateStatus ) ] ;
[ wrt_update_client getConnectionStatus ] ;
}
- ( void ) writeDefaults
- ( void ) deinitialize
{
/ / 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 ] ;
}
- ( void ) terminate : ( id ) sender {
[ _readTimer invalidate ] ;
[ [ NSUserDefaults standardUserDefaults ] synchronize ] ;
[ self dealloc ] ;
[ [ NSApplication sharedApplication ] terminate : self ] ;
[ wrt_update_client release ] ;
wrt_update_client = nil ;
[ wrt_request_client release ] ;
wrt_request_client = nil ;
}
# pragma mark -
# pragma mark Menu Methods :
- ( void ) showMenubar
{
NSLog ( @ "Showing Menu Item ") ;
@ -132,12 +79,7 @@
[ _appMenu setTarget : self ] ;
[ _appMenu retain ] ;
/ / [ self setMenubarText : @ "000 KB / s \ n000KB / s "] ;
/ / BOOL showIcon = [ [ NSUserDefaults standardUserDefaults ] boolForKey : @ "showMenuIcon "] ;
/ / if ( showIcon == true ) {
[ self showMenubarIcon : false ] ;
/ / }
[ _appMenu setHighlightMode : YES ] ;
/ / [ _appMenu setMenu : AppMenu ] ;
@ -182,7 +124,61 @@
[ 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 ) ] ;
[ configFieldUseBytes setState : ( [ defaults boolForKey : @ "useBytes "] ? 1 : 0 ) ] ;
@ -210,7 +206,7 @@
[ ConfigPanel makeKeyAndOrderFront : nil ] ;
}
- ( void ) hideConfigPanel : ( id ) sender
- ( IBAction ) hideConfigPanel : ( id ) sender
{
if ( hostname == nil && [ [ sender title ] isEqualToString : @ "Cancel "] ) {
/ / TODO : Add modal alert "will quit if not configured "
@ -220,38 +216,6 @@
[ 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
{
if ( [ configFieldProtocolHTTP state ] == 1 && [ [ configFieldPort stringValue ] isEqualToString : @ "443 "] == true ) {
@ -261,56 +225,12 @@
}
}
- ( void ) setConfigPort : ( id ) sender
{
}
- ( void ) setConfigRefresh : ( id ) sender
- ( IBAction ) setConfigRefresh : ( id ) sender
{
[ configLabelRefresh setStringValue : [ NSString stringWithFormat : @ "%u s", ([sender integerValue] + 1)]];
}
- ( void ) setConfigWan : ( 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
- ( IBAction ) saveConfig : ( id ) sender
{
[ self deinitialize ] ;
@ -332,7 +252,7 @@
useBytes = ( [ configFieldUseBytes state ] == 1 ? true : false ) ;
showMenuIcon = ( [ configFieldShowIcon state ] == 1 ? true : false ) ;
[ configStateStatus stopAnimation : nil ] ;
[ configStateStatus setHidden : true ] ;
@ -345,45 +265,55 @@
[ 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]);
if ( [ wrt_ client getWrtReachable ] == true ) {
NSLog ( @ "Status %@ wan port: %@", ([wrt_ update_ client getWrtReachable] ? @"Up" : @"Down"), [wrt_update _client getWanPort]);
if ( [ wrt_ update_ client getWrtReachable ] == true ) {
if ( showMenuIcon == true ) {
[ self showMenubarIcon : true ] ;
} else {
[ self hideMenubarIcon ] ;
}
if ( _readTimer == nil ) {
_readTimer = [ NSTimer scheduledTimerWithTimeInterval : refreshTime + 1 target : self selector : @ selector ( updateThroughput : ) userInfo : nil repeats : YES ] ;
[ _readTimer fire ] ;
if ( _updateTimer != nil ) {
[ _updateTimer invalidate ] ;
_updateTimer = nil ;
}
} 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 setMenubarText : @ ""] ;
[ _readTimer invalidate ] ;
_readTimer = nil ;
if ( _updateTimer != nil ) {
[ _updateTimer invalidate ] ;
_updateTimer = nil ;
}
_updateTimer = [ NSTimer scheduledTimerWithTimeInterval : 1 target : wrt_update_client selector : @ selector ( getConnectionStatus : ) userInfo : nil repeats : NO ] ;
[ _updateTimer fire ] ;
}
}
- ( void ) updateThroughput : ( NSTimer * ) timer
- ( void ) get Throughput: ( NSTimer * ) timer
{
/ / 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 * key = [ NSString stringWithFormat : @ "%@:", [wrt_ client getWanPort]];
NSString * key = [ NSString stringWithFormat : @ "%@:", [wrt_ update_ client getWanPort]];
stringData = [ stringData substringFromIndex : ( [ stringData rangeOfString : key ] . location + [ key length ] ) ] ;
NSArray * parts = [ stringData componentsSeparatedByCharactersInSet : [ NSCharacterSet whitespaceCharacterSet ] ] ;
NSArray * listItems = [ parts filteredArrayUsingPredicate : [ NSPredicate predicateWithFormat : @ "SELF != ' ' "] ] ;
uint64_t ifIn = strtoull ( [ [ listItems objectAtIndex : 0 ] UTF8String ] , NULL , 0 ) ;
uint64_t ifOut = strtoull ( [ [ listItems objectAtIndex : 8 ] UTF8String ] , NULL , 0 ) ;
@ -412,22 +342,63 @@
_lastOutThroughput = ifOut ;
}
- ( void ) doUpdateStatus : ( NSData * ) data
- ( void ) getRouterData : ( NSData * ) data
{
[ wrt_client getStatusUpdate : @ "Status_Internet . live . asp " delegate : self callback : @ selector ( wanRequestCallback : ) ] ;
NSString * stringData = [ [ NSString alloc ] initWithData : data encoding : NSASCIIStringEncoding ] ;
NSString * ipconn = [ wrt_client getKey : stringData key : @ "ip_conntrack "] ;
[ menuClientsConnections setTitle : [ NSString stringWithFormat : @ "%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
NSLog ( @ "Gathering status data ") ;
if ( data != nil ) {
NSString * stringData = [ [ NSString alloc ] initWithData : data encoding : NSASCIIStringEncoding ] ;
NSString * newStringData = [ _statusStringData stringByAppendingString : stringData ] ;
_statusStringData = [ newStringData retain ] ;
} else {
NSLog ( @ "No data received yet ") ;
}
NSString * wanip = [ wrt_client getKey : stringData key : @ "ipinfo "] ;
NSRange startRange = [ wanip rangeOfString : @ " "] ;
wanip = [ wanip substringFromIndex : ( startRange . location + 1 ) ] ;
[ menuWanIP setTitle : wanip ] ;
switch ( _statusDataRequestNumber + + ) {
case 0 :
NSLog ( @ "Status 0 ") ;
[ 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 : ";
if ( [ uptime length ] > 0 ) {
NSString * load = [ uptime substringFromIndex : [ uptime rangeOfString : loadSplit ] . location + [ loadSplit length ] ] ;
@ -446,35 +417,35 @@
[ menuLoad 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
NSArray * parts = [ memInfo componentsSeparatedByCharactersInSet : [ NSCharacterSet whitespaceCharacterSet ] ] ;
NSArray * filteredArray = [ parts filteredArrayUsingPredicate : [ NSPredicate predicateWithFormat : @ "SELF != ' ' "] ] ;
memInfo = [ filteredArray componentsJoinedByString : @ " "] ;
parts = nil ;
filteredArray = nil ;
/ / 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 : @ ""] ;
/ / parts = [ memInfo componentsSeparatedByCharactersInSet : [ NSCharacterSet characterSetWithCharactersInString : @ "\ ' " ] ] ;
/ / filteredArray = [ parts filteredArrayUsingPredicate : [ NSPredicate predicateWithFormat : @ "SELF != ' ' "] ] ;
/ / 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 ) ;
* /
/ / NSArray * memData = [ memInfo componentsSeparatedByString : @ ", "] ;
/ / unint32_t memTotal = strtoull ( [ [ memData objectAtIndex : 17 ] 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 * 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 * wanip = [ wrt_request_client getKey : _statusStringData key : @ "ipinfo "] ;
NSRange startRange = [ wanip rangeOfString : @ " "] ;
wanip = [ wanip substringFromIndex : ( startRange . location + 1 ) ] ;
[ menuWanIP setTitle : wanip ] ;
NSString * wanStatus = [ wrt_request_client getKey : _statusStringData key : @ "wan_status "] ;
NSString * wanName = [ wrt_request_client getKey : _statusStringData key : @ "wan_shortproto "] ;
if ( [ wanName isEqualToString : @ "pppoe "] == true ) {
wanName = @ "PPPoE ";
} else if ( [ wanName isEqualToString : @ "static "] == true ) {
@ -486,13 +457,11 @@
wanStatus = [ wanStatus substringToIndex : [ wanStatus rangeOfString : @ "& "] . location ] ;
[ menuWanStatus setTitle : [ NSString stringWithFormat : @ "%@ %@", wanName, wanStatus]];
/ *
if ( [ _appMenu image ] != nil ) {
[ self showMenubarIcon : [ wanStatus isEqualToString : @ "Connected "] ] ;
}
* /
/ / if ( [ _appMenu image ] != nil ) {
/ / [ 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 ) {
[ menuWanUptime setTitle : wanUptime ] ;
[ menuWanUptime setHidden : false ] ;
@ -509,17 +478,17 @@
}
NSString * trafficIn = [ wrt_ client getKey : stringData key : @ "ttraff_in "] ;
NSString * trafficOut = [ wrt_ client getKey : stringData key : @ "ttraff_out "] ;
NSString * trafficIn = [ wrt_ request_ client getKey : _ statusS tringData key : @ "ttraff_in "] ;
NSString * trafficOut = [ wrt_ request_ client getKey : _ statusS tringData key : @ "ttraff_out "] ;
trafficIn = [ self stringFromSize : ( [ trafficIn longLongValue ] * 1024 * 1024 ) ] ;
trafficOut = [ self stringFromSize : ( [ trafficOut longLongValue ] * 1024 * 1024 ) ] ;
[ 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_ request_ client getKey : _ statusS tringData key : @ "wan_dns0 "] ;
NSString * wanDNS1 = [ wrt_ request_ client getKey : _ statusS tringData key : @ "wan_dns1 "] ;
NSString * wanDNS2 = [ wrt_ request_ client getKey : _ statusS tringData key : @ "wan_dns2 "] ;
if ( [ wanDNS0 length ] > 0 ) {
[ menuWanDNS setEnabled : true ] ;
@ -538,23 +507,15 @@
[ menuWanDNSItem2 setTitle : wanDNS2 ] ;
[ menuWanDNSItem2 setHidden : false ] ;
}
[ stringData release ] ;
}
- ( void ) refreshClientsMenu : ( id ) sender
{
}
- ( void ) cbClientsRequest: ( NSData * ) data
- ( void ) populateMenuClients
{
NSString * clientsStringData ;
NSString * stringData = [ [ NSString alloc ] initWithData : data encoding : NSASCIIStringEncoding ] ;
NSString * keyData = @ "{ arp_table : : ";
clientsStringData = [ stringData substringFromIndex : ( [ stringData rangeOfString : keyData ] . location + [ keyData length ] ) ] ;
clientsStringData = [ _ statusS tringData substringFromIndex : ( [ _ statusS tringData rangeOfString : keyData ] . location + [ keyData length ] ) ] ;
clientsStringData = [ clientsStringData substringToIndex : [ clientsStringData rangeOfString : @ "} "] . location ] ;
/ / Remove any white spaces
@ -575,6 +536,10 @@
NSMenuItem * clientMenuItem ;
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 ;
[ menuClientsCount setTitle : [ NSString stringWithFormat : @ "%lu Active Client%@", clientsCount, (clientsCount > 1 ? @"s" : @"")]];
@ -616,11 +581,6 @@
[ menuClients addItem : clientItem ] ;
}
[ _appMenu popUpStatusItemMenu : AppMenu ] ;
_readTimer = [ NSTimer scheduledTimerWithTimeInterval : refreshTime + 1 target : self selector : @ selector ( updateThroughput : ) userInfo : nil repeats : YES ] ;
[ _readTimer fire ] ;
}
- ( NSMenu * ) createCopyMenuItem
@ -633,6 +593,8 @@
return [ copyMenu retain ] ;
}
# pragma mark -
# pragma mark Utilities :
- ( IBAction ) copyParentMenuTitle : ( id ) sender
{
@ -692,9 +654,4 @@
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