1
0
Fork 0

Added clients status and copying of menu items

master
Matthieu Lalonde 14 years ago
parent 373760a17b
commit caeebacb4b

@ -34,7 +34,6 @@
IBOutlet id menuUptime; IBOutlet id menuUptime;
IBOutlet id menuLoad; IBOutlet id menuLoad;
IBOutlet id menuWanIP; IBOutlet id menuWanIP;
IBOutlet id menuConnections;
IBOutlet id menuWanStatus; IBOutlet id menuWanStatus;
IBOutlet id menuWanUptime; IBOutlet id menuWanUptime;
@ -50,6 +49,12 @@
IBOutlet id menuWanDNSItem2; IBOutlet id menuWanDNSItem2;
IBOutlet id menuWanBandwidthGraph; IBOutlet id menuWanBandwidthGraph;
IBOutlet id menuClients;
IBOutlet id menuClientsCount;
IBOutlet id menuClientsConnections;
IBOutlet id menuClientsSeparator;
NSUserDefaults *defaults; NSUserDefaults *defaults;
// application prefs: // application prefs:
@ -109,15 +114,14 @@
- (IBAction) refreshWanMenu:(id)sender; - (IBAction) refreshWanMenu:(id)sender;
- (void) wanRequestCallback:(NSData *)data; - (void) wanRequestCallback:(NSData *)data;
- (IBAction) refreshClientsMenu:(id)sender; - (IBAction) refreshClientsMenu:(id)sender;
- (void) cbClientsRequest:(NSData*)data;
- (void) saveConfig:(id)sender; - (void) saveConfig:(id)sender;
- (void) updateThroughput:(NSTimer*)timer; - (void) updateThroughput:(NSTimer*)timer;
- (void) throughputCallback:(NSData *)data; - (void) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data; - (void) doUpdateStatus:(NSData *)data;
- (IBAction) copyParentMenuTitle:(id)sender;
- (NSString *) stringFromFileSize:(unsigned long long)theSize; - (NSString *) stringFromFileSize:(unsigned long long)theSize;
//@property (assign) IBOutlet NSWindow *window;
- (void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data;
@end @end

@ -407,7 +407,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]]; [menuClientsConnections setTitle:[NSString stringWithFormat:@"%@ Connection%@", ipconn, ([ipconn isEqualToString:@"1"] ? @"" : @"s")]];
[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)]; [wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)];
} }
@ -506,7 +506,101 @@
- (void) refreshClientsMenu:(id)sender - (void) refreshClientsMenu:(id)sender
{ {
//[self updateThroughput:nil]; [wrt_client getStatusUpdate:@"Status_Lan.live.asp" delegate:self callback:@selector(cbClientsRequest:)];
}
- (void) cbClientsRequest:(NSData*)data
{
NSString * clientsStringData;
NSString *stringData = [ [NSString alloc] initWithData:data encoding:NSASCIIStringEncoding ];
NSString *keyData = @"{arp_table::";
clientsStringData = [ stringData substringFromIndex:([stringData rangeOfString:keyData].location + [keyData length]) ];
clientsStringData = [ clientsStringData substringToIndex:[clientsStringData rangeOfString:@"}"].location ];
// Remove any white spaces
NSArray *parts = [clientsStringData componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
clientsStringData = [filteredArray componentsJoinedByString:@" "];
parts = nil;
filteredArray = nil;
// Remove any quotes
parts = [clientsStringData componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\'"]];
filteredArray = [parts filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
clientsStringData = [filteredArray componentsJoinedByString:@""];
NSArray *clientsData = [clientsStringData componentsSeparatedByString:@","];
long clientIndex;
NSMenu *clientMenu;
NSMenu *copyMenu;
NSMenuItem *copyMenuItem;
NSMenuItem *clientMenuItem;
NSMenuItem *clientItem;
unsigned long clientsCount = [clientsData count] / 4;
[menuClientsCount setTitle:[NSString stringWithFormat:@"%lu Active Client%@", clientsCount, (clientsCount > 1 ? @"s" : @"")]];
for (clientIndex = 0; clientIndex < [clientsData count]; clientIndex+=4) {
NSLog(@"Client: %@ IP: %@ MAC: %@ Connections: %@",
[clientsData objectAtIndex:clientIndex],
[clientsData objectAtIndex:clientIndex+1],
[clientsData objectAtIndex:clientIndex+2],
[clientsData objectAtIndex:clientIndex+3]);
clientMenu = [[NSMenu alloc] init];
// Hostname
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:clientIndex] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenu addItem:clientMenuItem];
// IP
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+1)] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenu addItem:clientMenuItem];
// MAC
copyMenu = [[NSMenu alloc] init];
copyMenuItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyParentMenuTitle:) keyEquivalent:@""];
[copyMenuItem setEnabled:true];
[copyMenuItem setTarget:self];
[copyMenu addItem:copyMenuItem];
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+2)] action:nil keyEquivalent:@""];
[clientMenuItem setSubmenu:copyMenu];
[clientMenu addItem:clientMenuItem];
// Connections
clientMenuItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:(clientIndex+3)] action:nil keyEquivalent:@""];
[clientMenu addItem:clientMenuItem];
clientItem = [[NSMenuItem alloc] initWithTitle:[clientsData objectAtIndex:clientIndex] action:nil keyEquivalent:@""];
[clientItem setSubmenu:clientMenu];
[menuClients addItem:clientItem];
}
}
- (IBAction) copyParentMenuTitle:(id)sender
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner: nil];
[pasteBoard setString:[[sender parentItem] title] forType:NSStringPboardType];
} }
- (NSString *) stringFromFileSize:(unsigned long long)theSize - (NSString *) stringFromFileSize:(unsigned long long)theSize

@ -353,7 +353,7 @@
<object class="NSMenuItem" id="465117897"> <object class="NSMenuItem" id="465117897">
<reference key="NSMenu" ref="242724865"/> <reference key="NSMenu" ref="242724865"/>
<bool key="NSIsDisabled">YES</bool> <bool key="NSIsDisabled">YES</bool>
<string key="NSTitle">Clients: 0</string> <string key="NSTitle">clients-count</string>
<string key="NSKeyEquiv"/> <string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int> <int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="826397193"/> <reference key="NSOnImage" ref="826397193"/>
@ -380,6 +380,7 @@
</object> </object>
<object class="NSMenuItem" id="857276619"> <object class="NSMenuItem" id="857276619">
<reference key="NSMenu" ref="242724865"/> <reference key="NSMenu" ref="242724865"/>
<bool key="NSIsHidden">YES</bool>
<string key="NSTitle">host-list-item</string> <string key="NSTitle">host-list-item</string>
<string key="NSKeyEquiv"/> <string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int> <int key="NSMnemonicLoc">2147483647</int>
@ -1514,6 +1515,70 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<int key="connectionID">814</int> <int key="connectionID">814</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menuClientsCount</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="465117897"/>
</object>
<int key="connectionID">816</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menuClientsSeparator</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="876337058"/>
</object>
<int key="connectionID">817</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menuClients</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="242724865"/>
</object>
<int key="connectionID">818</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">menuClientsConnections</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="745173154"/>
</object>
<int key="connectionID">819</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">copyParentMenuTitle:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="959267392"/>
</object>
<int key="connectionID">820</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">copyParentMenuTitle:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="814338525"/>
</object>
<int key="connectionID">821</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">copyParentMenuTitle:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="1021070393"/>
</object>
<int key="connectionID">822</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">copyParentMenuTitle:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="986964814"/>
</object>
<int key="connectionID">823</int>
</object>
</object> </object>
<object class="IBMutableOrderedSet" key="objectRecords"> <object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects"> <object class="NSArray" key="orderedObjects">
@ -2566,7 +2631,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference key="dict.values" ref="0"/> <reference key="dict.values" ref="0"/>
</object> </object>
<nil key="sourceID"/> <nil key="sourceID"/>
<int key="maxID">814</int> <int key="maxID">823</int>
</object> </object>
<object class="IBClassDescriber" key="IBDocument.Classes"> <object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions"> <object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -2578,6 +2643,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<bool key="EncodedWithXMLCoder">YES</bool> <bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys"> <object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool> <bool key="EncodedWithXMLCoder">YES</bool>
<string>copyParentMenuTitle:</string>
<string>refreshClientsMenu:</string> <string>refreshClientsMenu:</string>
<string>refreshMenu:</string> <string>refreshMenu:</string>
<string>refreshSystemMenu:</string> <string>refreshSystemMenu:</string>
@ -2589,12 +2655,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string>
</object> </object>
</object> </object>
<object class="NSMutableDictionary" key="actionInfosByName"> <object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool> <bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys"> <object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool> <bool key="EncodedWithXMLCoder">YES</bool>
<string>copyParentMenuTitle:</string>
<string>refreshClientsMenu:</string> <string>refreshClientsMenu:</string>
<string>refreshMenu:</string> <string>refreshMenu:</string>
<string>refreshSystemMenu:</string> <string>refreshSystemMenu:</string>
@ -2602,6 +2670,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object> </object>
<object class="NSMutableArray" key="dict.values"> <object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool> <bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">copyParentMenuTitle:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo"> <object class="IBActionInfo">
<string key="name">refreshClientsMenu:</string> <string key="name">refreshClientsMenu:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
@ -2640,7 +2712,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>configLabelRefresh</string> <string>configLabelRefresh</string>
<string>configLabelStatus</string> <string>configLabelStatus</string>
<string>configStateStatus</string> <string>configStateStatus</string>
<string>menuConnections</string> <string>menuClients</string>
<string>menuClientsConnections</string>
<string>menuClientsCount</string>
<string>menuClientsSeparator</string>
<string>menuLoad</string> <string>menuLoad</string>
<string>menuUptime</string> <string>menuUptime</string>
<string>menuWanBandwidthGraph</string> <string>menuWanBandwidthGraph</string>
@ -2687,6 +2762,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string> <string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object> </object>
</object> </object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName"> <object class="NSMutableDictionary" key="toOneOutletInfosByName">
@ -2709,7 +2787,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>configLabelRefresh</string> <string>configLabelRefresh</string>
<string>configLabelStatus</string> <string>configLabelStatus</string>
<string>configStateStatus</string> <string>configStateStatus</string>
<string>menuConnections</string> <string>menuClients</string>
<string>menuClientsConnections</string>
<string>menuClientsCount</string>
<string>menuClientsSeparator</string>
<string>menuLoad</string> <string>menuLoad</string>
<string>menuUptime</string> <string>menuUptime</string>
<string>menuWanBandwidthGraph</string> <string>menuWanBandwidthGraph</string>
@ -2791,7 +2872,19 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string key="candidateClassName">NSProgressIndicator</string> <string key="candidateClassName">NSProgressIndicator</string>
</object> </object>
<object class="IBToOneOutletInfo"> <object class="IBToOneOutletInfo">
<string key="name">menuConnections</string> <string key="name">menuClients</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">menuClientsConnections</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">menuClientsCount</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">menuClientsSeparator</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
</object> </object>
<object class="IBToOneOutletInfo"> <object class="IBToOneOutletInfo">

Loading…
Cancel
Save