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;
NSUserDefaults *defaults;
// application prefs:
NSString *hostname;
int port;
NSString *username;
NSString *password;
int refreshTime;
bool useBytes;
bool showMenuIcon;
// end app prefs
// application prefs:
NSString *hostname;
NSInteger port;
NSString *username;
NSString *password;
int refreshTime;
bool useBytes;
bool showMenuIcon;
// end app prefs
NSStatusItem *_appMenu;
NSAlert *modalWindow;
NSTimer *_readTimer;
NSTimeInterval _lastSpeedRead;
WRTStatusClient *wrt_client;
WRTStatusClient *wrt_client;
unsigned long long _lastInThroughput;
unsigned long long _lastOutThroughput;
BOOL _wrtReachable;
}

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

@ -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 {
BOOL wrtReachable;
BOOL wrtReachable;
@private
NSString *hostname;
NSInteger *port;
NSString *username;
NSString *password;
NSString *hostname;
NSInteger *port;
NSString *username;
NSString *password;
//NSMutableData *receivedData;
//NSURLRequest *theRequest;
//NSURLConnection *theConnection;
@ -27,7 +26,7 @@
//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*) requestForBandwidthViewerForInterface:(NSString*)interface;
@ -36,8 +35,8 @@
- (NSString*) getHostname;
- (void) setHostname:(NSString*)new_hostname;
- (int) getPort;
- (void) setPort:(int)new_port;
- (NSInteger*) getPort;
- (void) setPort:(NSInteger*)new_port;
- (NSString*) getUsername;
- (void) setUsername:(NSString*)new_username;

@ -11,7 +11,7 @@
@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];
@ -27,7 +27,9 @@
- (NSMutableURLRequest*) buildRequest:(NSString*)uri
{
NSString *urlAddress = [NSString stringWithFormat:@"http://%@:%d/%@",
NSString *urlAddress = [NSString stringWithFormat:@"http://%@:%@@%@:%d/%@",
username,
password,
hostname,
port,
uri];
@ -45,17 +47,16 @@
- (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
{
{
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:[self buildRequest: uri] delegate:delegate];
[theConnection autorelease];
[theConnection autorelease];
// this function returns immediately
@ -70,48 +71,48 @@
- (NSString*) getHostname
{
return hostname;
return hostname;
}
- (void) setHostname:(NSString*)new_hostname
{
NSString *old_hostname = hostname;
hostname = [new_hostname retain];
[old_hostname autorelease];
NSString *old_hostname = hostname;
hostname = [new_hostname retain];
[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
{
return username;
return username;
}
- (void) setUsername:(NSString*)new_username
{
NSString *old_username = username;
username = [new_username retain];
[old_username autorelease];
NSString *old_username = username;
username = [new_username retain];
[old_username autorelease];
}
- (NSString*) getPassword
{
return password;
return password;
}
- (void) setPassword:(NSString*)new_password
{
NSString *old_password = password;
password = [new_password retain];
[old_password autorelease];
NSString *old_password = password;
password = [new_password retain];
[old_password autorelease];
}

Loading…
Cancel
Save