From 92a8b0b097df2ca9572ddee9724219347dccd048 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 27 Sep 2012 23:13:40 +0200 Subject: [PATCH] Handle exceptions --- DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h | 3 ++ DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m | 20 +++++++++++++ .../DNSCrypt/en.lproj/DNSCrypt.xib | 30 +++++++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h index 19b1678..b9054b7 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h +++ b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.h @@ -21,6 +21,7 @@ #define kDNSCRYPT_QUERY_LOG_FILE @"/var/log/dnscrypt-query.log" #define kDNSCRYPT_BLACKLIST_IPS_TMP_FILE kDNSCRYPT_CONTROL_DIR @"/blacklist-ips.tmp" #define kDNSCRYPT_BLACKLIST_DOMAINS_TMP_FILE kDNSCRYPT_CONTROL_DIR @"/blacklist-domains.tmp" +#define kDNSCRYPT_EXCEPTIONS_TMP_FILE kDNSCRYPT_CONTROL_DIR @"/exceptions.tmp" #define kOPENDNS_URL @"http://www.opendns.com" @@ -59,6 +60,7 @@ typedef enum { @property (nonatomic, retain) IBOutlet NSButton *lockinButton; @property (nonatomic, retain) IBOutlet NSTextField *blacklistIPsTextField; @property (nonatomic, retain) IBOutlet NSTextField *blacklistDomainsTextField; +@property (nonatomic, retain) IBOutlet NSTextField *exceptionsTextField; @property (nonatomic, retain) IBOutlet WebView *helpWebView; - (void) mainViewDidLoad; @@ -77,6 +79,7 @@ typedef enum { - (IBAction)lockinButtonPressed:(NSButton *)sender; - (IBAction)blacklistIPsUpdated:(NSTextField *)sender; - (IBAction)blacklistDomainsUpdated:(NSTextField *)sender; +- (IBAction)exceptionsUpdated:(NSTextField *)sender; - (IBAction)helpButtonPressed:(NSButton *)sender; @end diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m index c9d68f1..8691340 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m +++ b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m @@ -23,6 +23,7 @@ @synthesize blacklistIPsTextField = _blacklistIPsTextField; @synthesize blacklistDomainsTextField = _blacklistDomainsTextField; @synthesize helpWebView = _helpWebView; +@synthesize exceptionsTextField = _exceptionsTextField; @synthesize dnscryptButton = _dnscryptButton; @synthesize opendnsButton = _opendnsButton; @synthesize fallbackButton = _fallbackButton; @@ -110,6 +111,10 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; if (fileContent != nil) { [_blacklistDomainsTextField setStringValue: fileContent]; } + fileContent = [NSString stringWithContentsOfFile: kDNSCRYPT_EXCEPTIONS_TMP_FILE encoding:NSUTF8StringEncoding error: nil]; + if (fileContent != nil) { + [_exceptionsTextField setStringValue: fileContent]; + } } - (void) updateLedStatus @@ -507,6 +512,21 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; [self updateBlacklistDomains]; } +- (BOOL) updateExceptions { + [self showSpinners]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./create-ticket.sh && ./update-exceptions.sh", nil]]; + (void) res; + return TRUE; +} + +- (IBAction)exceptionsUpdated:(NSTextField *)sender { + NSString *content = sender.stringValue; + if ([content writeToFile: kDNSCRYPT_EXCEPTIONS_TMP_FILE atomically: YES encoding: NSUTF8StringEncoding error: nil] != YES) { + return; + } + [self updateExceptions]; +} + - (IBAction)helpButtonPressed:(NSButton *)sender { if (_helpWebView.isHidden) { [_helpWebView setHidden: NO]; diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/en.lproj/DNSCrypt.xib b/DNSCrypt-Preference-Pane/DNSCrypt/en.lproj/DNSCrypt.xib index c764f8c..f711ce4 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/en.lproj/DNSCrypt.xib +++ b/DNSCrypt-Preference-Pane/DNSCrypt/en.lproj/DNSCrypt.xib @@ -65,7 +65,6 @@ {{13, 10}, {563, 359}} - _NS:461 @@ -854,7 +853,6 @@ aW91cy5leGFtcGxlLm5ldA {{511, 0}, {25, 25}} - _NS:1598 YES @@ -1449,6 +1447,22 @@ aW91cy5leGFtcGxlLm5ldA 451 + + + exceptionsTextField + + + + 452 + + + + exceptionsUpdated: + + + + 453 + @@ -2147,7 +2161,7 @@ aW91cy5leGFtcGxlLm5ldA - 451 + 453 @@ -2158,6 +2172,7 @@ aW91cy5leGFtcGxlLm5ldA NSTextField NSTextField NSButton + NSTextField NSButton NSButton NSButton @@ -2183,6 +2198,10 @@ aW91cy5leGFtcGxlLm5ldA dnscryptButtonPressed: NSButton + + exceptionsUpdated: + NSTextField + fallbackButtonPressed: NSButton @@ -2235,6 +2254,7 @@ aW91cy5leGFtcGxlLm5ldA NSTextField NSTextField NSButton + NSTextField NSButton NSButton WebView @@ -2276,6 +2296,10 @@ aW91cy5leGFtcGxlLm5ldA dnscryptButton NSButton + + exceptionsTextField + NSTextField + fallbackButton NSButton