1
0
Fork 0
master
Matthieu Lalonde 14 years ago
parent 211f4d5216
commit c73c8f0c2f

@ -1 +0,0 @@
*UserInterfaceState.xcuserstate

@ -51,31 +51,31 @@
IBOutlet id menuWanBandwidthGraph; IBOutlet id menuWanBandwidthGraph;
NSUserDefaults *defaults; NSUserDefaults *defaults;
// application prefs: // application prefs:
NSString *hostname; NSString *hostname;
int port; NSInteger port;
NSString *username; NSString *username;
NSString *password; NSString *password;
int refreshTime; int refreshTime;
bool useBytes; bool useBytes;
bool showMenuIcon; bool showMenuIcon;
// end app prefs // end app prefs
NSStatusItem *_appMenu; NSStatusItem *_appMenu;
NSAlert *modalWindow; NSAlert *modalWindow;
NSTimer *_readTimer; NSTimer *_readTimer;
NSTimeInterval _lastSpeedRead; NSTimeInterval _lastSpeedRead;
WRTStatusClient *wrt_client; WRTStatusClient *wrt_client;
unsigned long long _lastInThroughput; unsigned long long _lastInThroughput;
unsigned long long _lastOutThroughput; unsigned long long _lastOutThroughput;
BOOL _wrtReachable; BOOL _wrtReachable;
} }

@ -18,31 +18,31 @@
// Insert code here to initialize your application // Insert code here to initialize your application
[self showMenubar]; [self showMenubar];
_wrtReachable = false; _wrtReachable = false;
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];
} }
NSLog(@"Reading defaults..."); NSLog(@"Reading defaults...");
[self readDefaults]; [self readDefaults];
// initialize the client // initialize the client
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port username:username password:password]; wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:&port username:username password:password];
//_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; //_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
//[_readTimer fire]; //[_readTimer fire];
[self updateThroughput]; [self updateThroughput];
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(doUpdateStatus:) uri:@"Status_Router.live.asp"]; //[wrtr doRequest:self requestSelector:@selector(doUpdateStatus:) uri:@"Status_Router.live.asp"];
} }
- (void) dealloc { - (void) dealloc {
@ -57,58 +57,55 @@
- (void) initDefaults - (void) initDefaults
{ {
NSLog(@"Creating new user defaults");
NSLog(@"Creating new user defaults");
// do any other initialization you want to do here - e.g. the starting default values.
// do any other initialization you want to do here - e.g. the starting default values. [defaults setValue:@"192.168.1.1" forKey:@"hostname"];
[defaults setValue:@"192.168.1.1" forKey:@"hostname"]; [defaults setInteger:80 forKey:@"port"];
[defaults setInteger:80 forKey:@"port"]; [defaults setValue:@"" forKey:@"username"];
[defaults setValue:@"" forKey:@"username"]; [defaults setValue:@"" forKey:@"password"];
[defaults setValue:@"" forKey:@"password"];
[defaults setBool:YES forKey:@"showMenuIcon"];
[defaults setBool:YES forKey:@"showMenuIcon"]; [defaults setBool:YES forKey:@"useBytes"];
[defaults setBool:YES forKey:@"useBytes"]; [defaults setInteger:4 forKey:@"refreshTime"];
[defaults setInteger:4 forKey:@"refreshTime"];
[defaults setBool:YES forKey:@"configured"];
[defaults setBool:YES forKey:@"configured"];
// sync the defaults to disk
// sync the defaults to disk //[defaults registerDefaults:appDefaults];
//[defaults registerDefaults:appDefaults]; [defaults synchronize];
[defaults synchronize];
// TODO: Add modal alert "First launch" here...
// TODO: Add modal alert "First launch" here... [self showConfigPanel:self];
[self showConfigPanel:self];
} }
- (void) readDefaults - (void) readDefaults
{ {
hostname = [defaults valueForKey:@"hostname"]; hostname = [defaults valueForKey:@"hostname"];
port = [defaults integerForKey:@"port"]; port = [defaults integerForKey:@"port"];
username = [defaults valueForKey:@"username"]; username = [defaults valueForKey:@"username"];
password = [defaults valueForKey:@"password"]; password = [defaults valueForKey:@"password"];
showMenuIcon = [defaults boolForKey:@"showMenuIcon"]; showMenuIcon = [defaults boolForKey:@"showMenuIcon"];
useBytes = [defaults boolForKey:@"useBytes"]; useBytes = [defaults boolForKey:@"useBytes"];
refreshTime = [defaults integerForKey:@"refreshTime"]; refreshTime = [defaults integerForKey:@"refreshTime"];
} }
- (void) writeDefaults - (void) writeDefaults
{ {
// do any other initialization you want to do here - e.g. the starting default values. // do any other initialization you want to do here - e.g. the starting default values.
[defaults setValue:hostname forKey:@"hostname"]; [defaults setValue:hostname forKey:@"hostname"];
[defaults setInteger:port forKey:@"port"]; [defaults setInteger:port forKey:@"port"];
[defaults setValue:username forKey:@"username"]; [defaults setValue:username forKey:@"username"];
[defaults setValue:password forKey:@"password"]; [defaults setValue:password forKey:@"password"];
[defaults setBool:showMenuIcon forKey:@"showMenuIcon"]; [defaults setBool:showMenuIcon forKey:@"showMenuIcon"];
[defaults setBool:useBytes forKey:@"useBytes"]; [defaults setBool:useBytes forKey:@"useBytes"];
[defaults setInteger:refreshTime forKey:@"refreshTime"]; [defaults setInteger:refreshTime forKey:@"refreshTime"];
// sync the defaults to disk // sync the defaults to disk
//[defaults registerDefaults:appDefaults]; //[defaults registerDefaults:appDefaults];
[defaults synchronize]; [defaults synchronize];
} }
- (void) terminate:(id)sender { - (void) terminate:(id)sender {
@ -178,32 +175,31 @@
- (void) showConfigPanel:(id)sender - (void) showConfigPanel:(id)sender
{ {
[configFieldShowIcon setState:([[NSUserDefaults standardUserDefaults] boolForKey:@"showMenuIcon"] ? 1 : 0)]; [configFieldShowIcon setState:([defaults boolForKey:@"showMenuIcon"] ? 1 : 0)];
[configFieldUseBytes setState:([[NSUserDefaults standardUserDefaults] boolForKey:@"useBytes"] ? 1 : 0)]; [configFieldUseBytes setState:([defaults boolForKey:@"useBytes"] ? 1 : 0)];
NSString *hostname = [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"];
if (hostname != nil) { if (hostname != nil) {
[configFieldHostname setStringValue:hostname]; [configFieldHostname setStringValue:hostname];
} }
[configFieldPort setIntValue:[[NSUserDefaults standardUserDefaults] integerForKey:@"port"]]; [configFieldPort setIntValue:[defaults integerForKey:@"port"]];
[configFieldRefresh setIntegerValue:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"]]; [configFieldRefresh setIntegerValue:[defaults integerForKey:@"refreshTime"]];
[configLabelRefresh setStringValue:[NSString stringWithFormat:@"%d s", ([[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] + 1)]]; [configLabelRefresh setStringValue:[NSString stringWithFormat:@"%d s", ([defaults integerForKey:@"refreshTime"] + 1)]];
[ConfigPanel makeKeyAndOrderFront:nil]; [ConfigPanel makeKeyAndOrderFront:nil];
} }
- (void) hideConfigPanel:(id)sender - (void) hideConfigPanel:(id)sender
{ {
NSString *hostname = [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"]; /*NSString *hostname = [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"];
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"
[self terminate:nil]; [self terminate:nil];
} }
*/
[ConfigPanel orderOut:nil]; [ConfigPanel orderOut:nil];
} }
@ -220,7 +216,7 @@
[BandwidthViewer makeKeyAndOrderFront:nil]; [BandwidthViewer makeKeyAndOrderFront:nil];
NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:@"vlan2"] retain]; NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:@"ppp1"] retain];
[ [BandwidthViewerWebView mainFrame] loadRequest: request ]; [ [BandwidthViewerWebView mainFrame] loadRequest: request ];
} }
@ -280,6 +276,7 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(configSaveRequestCallback:) uri:@"Status_Router.live.asp"]; //[wrtr doRequest:self requestSelector:@selector(configSaveRequestCallback:) uri:@"Status_Router.live.asp"];
[self configSaveRequestCallback:nil];
} }
-(NSString *)getKey:(NSString *)stringData key:(NSString *)key -(NSString *)getKey:(NSString *)stringData key:(NSString *)key
@ -311,39 +308,43 @@
{ {
// TODO check that the request is actually successful // TODO check that the request is actually successful
NSString *hostname = [configFieldHostname stringValue]; hostname = [configFieldHostname stringValue];
[[NSUserDefaults standardUserDefaults] setObject:hostname forKey:@"hostname"]; [defaults setValue:hostname forKey:@"hostname"];
NSString *port = [configFieldPort stringValue]; port = [configFieldPort intValue];
[[NSUserDefaults standardUserDefaults] setObject:port forKey:@"port"]; [defaults setInteger:port forKey:@"port"];
NSLog(@"Got %@", hostname); NSLog(@"Got %@ for %@", hostname, [configFieldHostname stringValue]);
//NSLog(@"%@", [configFieldProtocol str]); //NSLog(@"%@", [configFieldProtocol str]);
[[NSUserDefaults standardUserDefaults] setInteger:[configFieldRefresh integerValue] forKey:@"refreshTime"]; refreshTime = [configFieldRefresh integerValue];
[defaults setInteger:refreshTime forKey:@"refreshTime"];
[[NSUserDefaults standardUserDefaults] setBool:([configFieldUseBytes state] == 1 ? true: false) forKey:@"useBytes"]; useBytes = ([configFieldUseBytes state] == 1 ? true: false);
[defaults setBool:useBytes forKey:@"useBytes"];
if ([configFieldShowIcon state] == NSOffState && [[NSUserDefaults standardUserDefaults] boolForKey:@"showMenuIcon"] == true) { if ([configFieldShowIcon state] == NSOffState && [defaults boolForKey:@"showMenuIcon"] == true) {
[self hideMenubarIcon]; [self hideMenubarIcon];
} else if ([configFieldShowIcon state] == NSOnState && [[NSUserDefaults standardUserDefaults] boolForKey:@"showMenuIcon"] == false) { } else if ([configFieldShowIcon state] == NSOnState && [defaults boolForKey:@"showMenuIcon"] == false) {
[self showMenubarIcon:false]; [self showMenubarIcon:false];
} }
[[NSUserDefaults standardUserDefaults] setBool:([configFieldShowIcon state] == 1 ? true: false) forKey:@"showMenuIcon"]; showMenuIcon = ([configFieldShowIcon state] == 1 ? true: false);
[defaults setBool:showMenuIcon forKey:@"showMenuIcon"];
[configStateStatus stopAnimation:nil]; [configStateStatus stopAnimation:nil];
[configStateStatus setHidden:true]; [configStateStatus setHidden:true];
[self doUpdateStatus:data]; [defaults synchronize];
//[self doUpdateStatus:data];
[self hideConfigPanel:nil]; [self hideConfigPanel:nil];
} }
- (void) updateThroughput - (void) updateThroughput
{ {
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"]; //[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"];
@ -352,7 +353,7 @@
- (void) throughputCallback:(NSData *)data - (void) throughputCallback:(NSData *)data
{ {
NSDate *start = [NSDate date]; /*NSDate *start = [NSDate date];
NSTimeInterval timeInterval = [start timeIntervalSinceNow]; NSTimeInterval timeInterval = [start timeIntervalSinceNow];
NSLog(@"%f", timeInterval); NSLog(@"%f", timeInterval);
@ -364,7 +365,7 @@
unsigned long long ifIn = [NSNumber numberWithString:[listItems objectAtIndex:0]]; unsigned long long ifIn = [NSNumber numberWithString:[listItems objectAtIndex:0]];
unsigned long long ifOut = [NSNumber numberWithString:[listItems objectAtIndex:8]]; unsigned long long ifOut = [NSNumber numberWithString:[listItems objectAtIndex:8]];
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate]; NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];*/
} }
-(void)doUpdateStatus:(NSData *)data -(void)doUpdateStatus:(NSData *)data
@ -406,12 +407,15 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"]; //[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
[wrt_client getStatusUpdate:@"Status_Bandwidth.asp" delegate:wanRequestCallback];
} }
- (void) wanRequestCallback:(NSData *)data - (void) wanRequestCallback:(NSData *)data
{ {
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@", stringData);
/*
NSString *wanStatus = [self getKey:stringData key:@"wan_status"]; NSString *wanStatus = [self getKey:stringData key:@"wan_status"];
NSString *wanName = [self getKey:stringData key:@"wan_shortproto"]; NSString *wanName = [self getKey:stringData key:@"wan_shortproto"];
if ([wanName isEqualToString:@"pppoe"] == true) { if ([wanName isEqualToString:@"pppoe"] == true) {
@ -437,7 +441,6 @@
[menuWanBandwidthGraph setEnabled:true]; [menuWanBandwidthGraph setEnabled:true];
[menuWanTrafficIn setHidden:false]; [menuWanTrafficIn setHidden:false];
[menuWanTrafficOut setHidden:false]; [menuWanTrafficOut setHidden:false];
} else { } else {
[menuWanUptime setHidden:true]; [menuWanUptime setHidden:true];
[menuWanSeparator setHidden:true]; [menuWanSeparator setHidden:true];
@ -476,7 +479,7 @@
[menuWanDNSItem2 setTitle: wanDNS2]; [menuWanDNSItem2 setTitle: wanDNS2];
[menuWanDNSItem2 setHidden:false]; [menuWanDNSItem2 setHidden:false];
} }
*/
[stringData release]; [stringData release];
} }
@ -508,8 +511,7 @@
- (void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data - (void) connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{ {
NSLog(@"Delegate Received: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); NSLog(@"Delegate Received: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
} }
@end @end

@ -0,0 +1,17 @@
//
// WRTRequestParser.h
// DDWRT-Monitor
//
// Created by Matthieu Lalonde on 11-06-02.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface WRTRequestParser : NSObject {
@private
}
@end

@ -0,0 +1,29 @@
//
// WRTRequestParser.m
// DDWRT-Monitor
//
// Created by Matthieu Lalonde on 11-06-02.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "WRTRequestParser.h"
@implementation WRTRequestParser
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end

@ -10,14 +10,13 @@
@interface WRTStatusClient : NSObject { @interface WRTStatusClient : NSObject {
BOOL wrtReachable; BOOL wrtReachable;
@private @private
NSString *hostname; NSString *hostname;
NSInteger *port; NSInteger *port;
NSString *username; NSString *username;
NSString *password; NSString *password;
//NSMutableData *receivedData; //NSMutableData *receivedData;
//NSURLRequest *theRequest; //NSURLRequest *theRequest;
//NSURLConnection *theConnection; //NSURLConnection *theConnection;
@ -27,7 +26,7 @@
//SEL errorCallback; //SEL errorCallback;
} }
- (id) initWithHostname:(NSString*)new_hostname port:(int)new_port username:(NSString*)new_username password:(NSString*)new_password; - (id) initWithHostname:(NSString*)new_hostname port:(NSInteger*)new_port username:(NSString*)new_username password:(NSString*)new_password;
- (NSMutableURLRequest*) buildRequest:(NSString*)uri; - (NSMutableURLRequest*) buildRequest:(NSString*)uri;
- (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface; - (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface;
@ -36,8 +35,8 @@
- (NSString*) getHostname; - (NSString*) getHostname;
- (void) setHostname:(NSString*)new_hostname; - (void) setHostname:(NSString*)new_hostname;
- (int) getPort; - (NSInteger*) getPort;
- (void) setPort:(int)new_port; - (void) setPort:(NSInteger*)new_port;
- (NSString*) getUsername; - (NSString*) getUsername;
- (void) setUsername:(NSString*)new_username; - (void) setUsername:(NSString*)new_username;

@ -11,7 +11,7 @@
@implementation WRTStatusClient @implementation WRTStatusClient
- (id) initWithHostname:(NSString*)new_hostname port:(int)new_port username:(NSString*)new_username password:(NSString*)new_password - (id) initWithHostname:(NSString*)new_hostname port:(NSInteger*)new_port username:(NSString*)new_username password:(NSString*)new_password
{ {
self = [super init]; self = [super init];
@ -27,7 +27,9 @@
- (NSMutableURLRequest*) buildRequest:(NSString*)uri - (NSMutableURLRequest*) buildRequest:(NSString*)uri
{ {
NSString *urlAddress = [NSString stringWithFormat:@"http://%@:%d/%@", NSString *urlAddress = [NSString stringWithFormat:@"http://%@:%@@%@:%d/%@",
username,
password,
hostname, hostname,
port, port,
uri]; uri];
@ -45,17 +47,16 @@
- (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface - (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface
{ {
NSString *endpoint = [NSString stringWithFormat:@"graph_if.svg?%@", interface]; NSString *endpoint = [NSString stringWithFormat:@"graph_if.svg?%@", interface];
return [self buildRequest:endpoint]; return [self buildRequest:endpoint];
} }
- (void) getStatusUpdate:(NSString*)uri delegate:(id)delegate - (void) getStatusUpdate:(NSString*)uri delegate:(id)delegate
{ {
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:[self buildRequest: uri] delegate:delegate]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:[self buildRequest: uri] delegate:delegate];
[theConnection autorelease]; [theConnection autorelease];
// this function returns immediately // this function returns immediately
@ -70,48 +71,48 @@
- (NSString*) getHostname - (NSString*) getHostname
{ {
return hostname; return hostname;
} }
- (void) setHostname:(NSString*)new_hostname - (void) setHostname:(NSString*)new_hostname
{ {
NSString *old_hostname = hostname; NSString *old_hostname = hostname;
hostname = [new_hostname retain]; hostname = [new_hostname retain];
[old_hostname autorelease]; [old_hostname autorelease];
} }
- (NSInteger*) getPort - (NSInteger *) getPort
{ {
return port; return port;
} }
- (void) setPort:(NSInteger*)new_port - (void) setPort:(NSInteger *)new_port
{ {
port = new_port; port = new_port;
} }
- (NSString*) getUsername - (NSString*) getUsername
{ {
return username; return username;
} }
- (void) setUsername:(NSString*)new_username - (void) setUsername:(NSString*)new_username
{ {
NSString *old_username = username; NSString *old_username = username;
username = [new_username retain]; username = [new_username retain];
[old_username autorelease]; [old_username autorelease];
} }
- (NSString*) getPassword - (NSString*) getPassword
{ {
return password; return password;
} }
- (void) setPassword:(NSString*)new_password - (void) setPassword:(NSString*)new_password
{ {
NSString *old_password = password; NSString *old_password = password;
password = [new_password retain]; password = [new_password retain];
[old_password autorelease]; [old_password autorelease];
} }

Loading…
Cancel
Save