@ -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 : @ "000 KB / 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 ) update Throughput: ( NSTimer * ) timer
- ( void ) get Throughput: ( 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 : _ statusS tringData key : @ "wan_status "] ;
NSString * wanName = [ wrt_ client getKey : stringData key : @ "wan_shortproto "] ;
NSString * wanName = [ wrt_ request_ client getKey : _ statusS tringData 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 : _ statusS tringData key : @ "ttraff_in "] ;
NSString * trafficOut = [ wrt_ client getKey : stringData key : @ "ttraff_out "] ;
NSString * trafficOut = [ wrt_ request_ client getKey : _ statusS tringData 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 : _ statusS tringData key : @ "wan_dns0 "] ;
NSString * wanDNS1 = [ wrt_ client getKey : stringData key : @ "wan_dns1 "] ;
NSString * wanDNS1 = [ wrt_ request_ client getKey : _ statusS tringData key : @ "wan_dns1 "] ;
NSString * wanDNS2 = [ wrt_ client getKey : stringData key : @ "wan_dns2 "] ;
NSString * wanDNS2 = [ wrt_ request_ client getKey : _ statusS tringData 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 = [ _ statusS tringData substringFromIndex : ( [ _ statusS tringData 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