diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h index 9116178..97e1507 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h +++ b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h @@ -11,11 +11,11 @@ #define kDNSCRYPT_PACKAGE_VERSION @"0.12" -#define KDNSCRYPT_CONFIG_UPDATER_LABEL @"com.opendns.osx.DNSCryptConfigUpdater" -#define KDNSCRYPT_PROXY_LABEL @"com.opendns.osx.DNSCryptProxy" - -#define kDNSCRYPT_PREFPANE_SUPPORT_DIR @"DNSCrypt Prefpane" -#define kDNSCRYPT_PREFPANE_FILE @"PrefPane.plist" +#define kDNSCRYPT_PREFPANE_APP_PATH @"/Library/PreferencePanes/DNSCrypt.prefPane" +#define kDNSCRYPT_USR_BASE_DIR kDNSCRYPT_PREFPANE_APP_PATH @"/Contents/Resources/usr" +#define kDNSCRIPT_SCRIPTS_BASE_DIR kDNSCRYPT_USR_BASE_DIR @"/scripts" +#define kDNSCRYPT_VAR_BASE_DIR @"/Library/Application Support/DNSCrypt" +#define kDNSCRYPT_CONTROL_DIR kDNSCRYPT_VAR_BASE_DIR @"/control" #define kOPENDNS_URL @"http://www.opendns.com" @@ -31,10 +31,10 @@ typedef enum { AuthorizationRef auth; } -@property (weak) IBOutlet NSButton *enableDNSCryptButton; -@property (weak) IBOutlet NSButton *enableOpenDNSButton; +@property (weak) IBOutlet NSButton *dnscryptButton; +@property (weak) IBOutlet NSButton *opendnsButton; @property (weak) IBOutlet NSButton *familyShieldButton; -@property (weak) IBOutlet NSButton *enableInsecureDNSButton; +@property (weak) IBOutlet NSButton *fallbackButton; @property (weak) IBOutlet NSTextField *currentResolverTextField; @property (weak) IBOutlet NSImageView *statusImageView; @@ -46,8 +46,11 @@ typedef enum { - (void) mainViewDidLoad; -- (IBAction)enableOpenDNSButtonPressed:(NSButton *)sender; -- (IBAction)enableDNSCryptButtonPressed:(NSButton *)sender; +- (IBAction)dnscryptButtonPressed:(NSButton *)sender; +- (IBAction)opendnsButtonPressed:(NSButton *)sender; +- (IBAction)familyShieldButtonPressed:(NSButton *)sender; +- (IBAction)fallbackButtonPressed:(NSButton *)sender; + - (IBAction)openDNSLinkPushed:(NSButton *)sender; @end diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m index 0a672fc..0b38f32 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m +++ b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m @@ -9,18 +9,18 @@ #import "DNSCrypt.h" @implementation DNSCrypt -@synthesize previewNotesWebView; -@synthesize releaseNotesWebView; -@synthesize feedbackWebView; -@synthesize aboutWebView; +@synthesize previewNotesWebView = _previewNotesWebView; +@synthesize releaseNotesWebView = _releaseNotesWebView; +@synthesize feedbackWebView = _feedbackWebView; +@synthesize aboutWebView = _aboutWebView; -@synthesize enableDNSCryptButton; -@synthesize enableOpenDNSButton; -@synthesize enableInsecureDNSButton; -@synthesize familyShieldButton; -@synthesize statusImageView; -@synthesize statusText; -@synthesize currentResolverTextField; +@synthesize dnscryptButton = _dnscryptButton; +@synthesize opendnsButton = _opendnsButton; +@synthesize fallbackButton = _fallbackButton; +@synthesize familyShieldButton = _familyShieldButton; +@synthesize statusImageView = _statusImageView; +@synthesize statusText = _statusText; +@synthesize currentResolverTextField = _currentResolverTextField; DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; @@ -44,26 +44,76 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; return result; } +- (void) initState +{ + NSString *res; + _dnscryptButton.state = 0; + _familyShieldButton.state = 0; + _opendnsButton.state = 0; + _fallbackButton.state = 0; + + res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && exec ./get-dnscrypt-status.sh", nil]]; + NSLog(@"%@", res); + if ([res isEqualToString: @"yes"]) { + [_dnscryptButton setState: 1]; + } + res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && exec ./get-familyshield-status.sh", nil]]; + NSLog(@"%@", res); + if ([res isEqualToString: @"yes"]) { + [_familyShieldButton setState: 1]; + } + res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && exec ./get-insecure-opendns-status.sh", nil]]; + NSLog(@"%@", res); + if ([res isEqualToString: @"yes"]) { + [_opendnsButton setState: 1]; + } + res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && exec ./get-fallback-status.sh", nil]]; + NSLog(@"%@", res); + if ([res isEqualToString: @"yes"]) { + [_fallbackButton setState: 1]; + } + +} + +- (IBAction)dnscryptButtonPressed:(NSButton *)sender +{ + +} + +- (IBAction)opendnsButtonPressed:(NSButton *)sender +{ + +} + +- (IBAction)familyShieldButtonPressed:(NSButton *)sender +{ + +} + +- (IBAction)fallbackButtonPressed:(NSButton *)sender +{ + +} - (void) initializeCheckBoxesWithState: (DNSConfigurationState) currentState { switch (currentState) { case kDNS_CONFIGURATION_OPENDNS: - enableOpenDNSButton.state = NSOnState; - enableDNSCryptButton.state = NSOffState; + _opendnsButton.state = NSOnState; + _dnscryptButton.state = NSOffState; break; case kDNS_CONFIGURATION_LOCALHOST: - enableOpenDNSButton.state = NSOnState; - enableDNSCryptButton.state = NSOnState; + _opendnsButton.state = NSOnState; + _dnscryptButton.state = NSOnState; break; default: - enableOpenDNSButton.state = NSOffState; - enableDNSCryptButton.state = NSOffState; + _opendnsButton.state = NSOffState; + _dnscryptButton.state = NSOffState; } - enableInsecureDNSButton.state = NSOnState; + _fallbackButton.state = NSOnState; } - (BOOL) updateStatusWithCurrentConfig @@ -87,26 +137,26 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; [resolversString appendFormat: @"%s%@", (resolversString.length > 0 ? "\n" : ""), resolver]; } currentState = kDNS_CONFIGURATION_VANILLA; - currentResolverTextField.stringValue = resolversString; + _currentResolverTextField.stringValue = resolversString; } NSBundle *bundle = [NSBundle bundleWithIdentifier: @"com.opendns.osx.DNSCrypt"]; switch (currentState) { case kDNS_CONFIGURATION_UNKNOWN: - statusText.stringValue = NSLocalizedString(@"No network", @"Status"); - statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_red.png"]] autorelease]; + _statusText.stringValue = NSLocalizedString(@"No network", @"Status"); + _statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_red.png"]] autorelease]; break; case kDNS_CONFIGURATION_VANILLA: - statusText.stringValue = NSLocalizedString(@"Unprotected", @"Status"); - statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_red.png"]] autorelease]; + _statusText.stringValue = NSLocalizedString(@"Unprotected", @"Status"); + _statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_red.png"]] autorelease]; break; case kDNS_CONFIGURATION_OPENDNS: - statusText.stringValue = NSLocalizedString(@"Unencrypted", @"Status"); - statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_yellow.png"]] autorelease]; + _statusText.stringValue = NSLocalizedString(@"Unencrypted", @"Status"); + _statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_yellow.png"]] autorelease]; break; case kDNS_CONFIGURATION_LOCALHOST: - statusText.stringValue = NSLocalizedString(@"Protected", @"Status"); - statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_green.png"]] autorelease]; + _statusText.stringValue = NSLocalizedString(@"Protected", @"Status"); + _statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"shield_green.png"]] autorelease]; break; default: return FALSE; @@ -118,9 +168,9 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (void) showSpinners { NSBundle *bundle = [NSBundle bundleWithIdentifier: kBUNDLE_IDENTIFIER]; - statusText.stringValue = @""; - statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"ajax-loader.gif"]] autorelease]; - currentResolverTextField.stringValue = @""; + _statusText.stringValue = @""; + _statusImageView.image = [[[NSImage alloc] initWithContentsOfFile: [bundle pathForImageResource: @"ajax-loader.gif"]] autorelease]; + _currentResolverTextField.stringValue = @""; } - (void) periodicallyUpdateStatusWithCurrentConfig { @@ -132,8 +182,10 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (void) mainViewDidLoad { currentState = kDNS_CONFIGURATION_UNKNOWN; + [_previewNotesWebView setDrawsBackground:false]; + + [self initState]; [self periodicallyUpdateStatusWithCurrentConfig]; - [previewNotesWebView setDrawsBackground:false]; NSString *version = kDNSCRYPT_PACKAGE_VERSION; NSString *softwareBlurbFormat = NSLocalizedString(@"This software (v: %@) encrypts DNS packets between your computer and OpenDNS. This prevents man-in-the-middle attacks and snooping of DNS traffic by ISPs or others.", @"Description of what the package does - %@ is replaced by the version number"); @@ -153,26 +205,25 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; [htmlString appendFormat: @"