From 33e9218884f8ac42c07efed75ac028254f4e5cd1 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 31 Jul 2012 21:06:45 -0700 Subject: [PATCH] Add support for the fallback to insecure thing to the menubar thing. --- CU2/common.inc | 3 + CU2/get-dnscrypt-status.sh | 9 ++ CU2/get-fallback-status.sh | 9 ++ CU2/get-familyshield-status.sh | 9 ++ CU2/get-insecure-opendns-status.sh | 9 ++ CU2/handle-network-change.sh | 2 - CU2/set-dns-to-dhcp.sh | 7 +- CU2/start-dnscrypt-proxy.sh | 2 - CU2/switch-fallback-off.sh | 5 + CU2/switch-fallback-on.sh | 5 + CU2/switch-familyshield-off.sh | 5 + CU2/switch-familyshield-on.sh | 5 + CU2/switch-insecure-opendns-off.sh | 5 + CU2/switch-insecure-opendns-on.sh | 5 + .../DNSCrypt-Menubar/AppDelegate.h | 2 + .../DNSCrypt-Menubar/AppDelegate.m | 107 +++++++++++++++--- .../DNSCrypt-Menubar/en.lproj/MainMenu.xib | 60 +++++++--- 17 files changed, 216 insertions(+), 33 deletions(-) create mode 100755 CU2/get-dnscrypt-status.sh create mode 100755 CU2/get-fallback-status.sh create mode 100755 CU2/get-familyshield-status.sh create mode 100755 CU2/get-insecure-opendns-status.sh create mode 100755 CU2/switch-fallback-off.sh create mode 100755 CU2/switch-fallback-on.sh create mode 100755 CU2/switch-familyshield-off.sh create mode 100755 CU2/switch-familyshield-on.sh create mode 100755 CU2/switch-insecure-opendns-off.sh create mode 100755 CU2/switch-insecure-opendns-on.sh diff --git a/CU2/common.inc b/CU2/common.inc index b45276a..2a53ddf 100644 --- a/CU2/common.inc +++ b/CU2/common.inc @@ -10,6 +10,9 @@ PROXY_PID_FILE="${DNSCRYPT_PROXY_VAR_BASE_DIR}/dnscrypt-proxy.pid" STATES_DIR="${DNSCRYPT_VAR_BASE_DIR}/states" DNSCRYPT_FILE="${CONTROL_DIR}/dnscrypt" +FAMILYSHIELD_FILE="${CONTROL_DIR}/familyshield" +INSECURE_OPENDNS_FILE="${CONTROL_DIR}/insecure-opendns" +FALLBACK_FILE="${CONTROL_DIR}/fallback" INTERFACE_UNBOUND="127.0.0.53" INTERFACE_UNBOUND_MASK="24" diff --git a/CU2/get-dnscrypt-status.sh b/CU2/get-dnscrypt-status.sh new file mode 100755 index 0000000..13cf2f2 --- /dev/null +++ b/CU2/get-dnscrypt-status.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. ./common.inc + +if [ -e "$DNSCRYPT_FILE" ]; then + echo 'yes' +else + echo 'no' +fi diff --git a/CU2/get-fallback-status.sh b/CU2/get-fallback-status.sh new file mode 100755 index 0000000..b444567 --- /dev/null +++ b/CU2/get-fallback-status.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. ./common.inc + +if [ -e "$FALLBACK_FILE" ]; then + echo 'yes' +else + echo 'no' +fi diff --git a/CU2/get-familyshield-status.sh b/CU2/get-familyshield-status.sh new file mode 100755 index 0000000..919ecd4 --- /dev/null +++ b/CU2/get-familyshield-status.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. ./common.inc + +if [ -e "$FAMILYSHIELD_FILE" ]; then + echo 'yes' +else + echo 'no' +fi diff --git a/CU2/get-insecure-opendns-status.sh b/CU2/get-insecure-opendns-status.sh new file mode 100755 index 0000000..0dadcf5 --- /dev/null +++ b/CU2/get-insecure-opendns-status.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. ./common.inc + +if [ -e "$INSECURE_OPENDNS_FILE" ]; then + echo 'yes' +else + echo 'no' +fi diff --git a/CU2/handle-network-change.sh b/CU2/handle-network-change.sh index 9604116..e0af817 100755 --- a/CU2/handle-network-change.sh +++ b/CU2/handle-network-change.sh @@ -2,8 +2,6 @@ . ./common.inc -FALLBACK_FILE="${CONTROL_DIR}/fallback" - [ ! -e "$FALLBACK_FILE" ] && exit 0 ./check-network-change.sh || exit 0 ./set-dns-to-dhcp.sh diff --git a/CU2/set-dns-to-dhcp.sh b/CU2/set-dns-to-dhcp.sh index ea241a0..7685a0f 100755 --- a/CU2/set-dns-to-dhcp.sh +++ b/CU2/set-dns-to-dhcp.sh @@ -2,7 +2,12 @@ . ./common.inc +servers='empty' + +[ -e "$INSECURE_OPENDNS_FILE" ] && servers='208.67.220.220' +[ -e "$FAMILYSHIELD_FILE" ] && servers='208.67.220.123' + exec networksetup -listallnetworkservices 2>/dev/null | \ fgrep -v '*' | while read x ; do - networksetup -setdnsservers "$x" empty + networksetup -setdnsservers "$x" "$servers" done diff --git a/CU2/start-dnscrypt-proxy.sh b/CU2/start-dnscrypt-proxy.sh index f5628a3..34333ba 100755 --- a/CU2/start-dnscrypt-proxy.sh +++ b/CU2/start-dnscrypt-proxy.sh @@ -2,8 +2,6 @@ . ./common.inc -FAMILYSHIELD_FILE="${CONTROL_DIR}/familyshield" - init_interfaces mkdir -p -- "$DNSCRYPT_VAR_BASE_DIR" || exit 1 diff --git a/CU2/switch-fallback-off.sh b/CU2/switch-fallback-off.sh new file mode 100755 index 0000000..22deae2 --- /dev/null +++ b/CU2/switch-fallback-off.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +rm -f "$FALLBACK_FILE" diff --git a/CU2/switch-fallback-on.sh b/CU2/switch-fallback-on.sh new file mode 100755 index 0000000..714cb55 --- /dev/null +++ b/CU2/switch-fallback-on.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +touch "$FALLBACK_FILE" diff --git a/CU2/switch-familyshield-off.sh b/CU2/switch-familyshield-off.sh new file mode 100755 index 0000000..48c765a --- /dev/null +++ b/CU2/switch-familyshield-off.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +rm -f "$FAMILYSHIELD_FILE" diff --git a/CU2/switch-familyshield-on.sh b/CU2/switch-familyshield-on.sh new file mode 100755 index 0000000..64a077d --- /dev/null +++ b/CU2/switch-familyshield-on.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +touch "$FAMILYSHIELD_FILE" diff --git a/CU2/switch-insecure-opendns-off.sh b/CU2/switch-insecure-opendns-off.sh new file mode 100755 index 0000000..b9741ee --- /dev/null +++ b/CU2/switch-insecure-opendns-off.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +rm -f "$INSECURE_OPENDNS_FILE" diff --git a/CU2/switch-insecure-opendns-on.sh b/CU2/switch-insecure-opendns-on.sh new file mode 100755 index 0000000..b353b07 --- /dev/null +++ b/CU2/switch-insecure-opendns-on.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +. ./common.inc + +touch "$INSECURE_OPENDNS_FILE" diff --git a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.h b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.h index 18bed5d..f5e62b8 100644 --- a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.h +++ b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.h @@ -35,10 +35,12 @@ typedef enum { @property (strong) IBOutlet NSMenuItem *familyShieldMenuItem; @property (strong) IBOutlet NSMenuItem *dnscryptMenuItem; @property (strong) IBOutlet NSMenuItem *fallbackMenuItem; +@property (strong) IBOutlet NSMenuItem *opendnsMenuItem; - (IBAction)preferencesMenuItemPushed:(NSMenuItem *)sender; - (IBAction)dnscryptMenuItemPushed:(NSMenuItem *)sender; - (IBAction)familyShieldMenuItemPushed:(NSMenuItem *)sender; - (IBAction)fallbackMenuItemPushed:(NSMenuItem *)sender; +- (IBAction)opendnsMenuItemPushed:(NSMenuItem *)sender; @end diff --git a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m index a1f420c..f84f3c0 100644 --- a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m +++ b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m @@ -15,6 +15,7 @@ @synthesize familyShieldMenuItem = _familyShieldMenuItem; @synthesize dnscryptMenuItem = _dnscryptMenuItem; @synthesize fallbackMenuItem = _fallbackMenuItem; +@synthesize opendnsMenuItem = _opendnsMenuItem; @synthesize window = _window; @synthesize dnscryptMenu = _dnscryptMenu; @synthesize statusItem = _statusItem; @@ -43,21 +44,32 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (void) initState { - NSString *stateDescription = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./get-current-resolvers.sh | ./get-resolvers-description.sh", nil]]; - NSLog(@"%@", stateDescription); - [_dnscryptMenuItem setState: 0]; - [_familyShieldMenuItem setState: 0]; - [_fallbackMenuItem setState: 0]; - if ([stateDescription isEqualToString: @"FamilyShield"]) { - [_familyShieldMenuItem setState: 1]; - } else if ([stateDescription isEqualToString: @"DNSCrypt"]) { + NSString *res; + + _dnscryptMenuItem.state = 0; + _familyShieldMenuItem.state = 0; + _opendnsMenuItem.state = 0; + _fallbackMenuItem.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"]) { [_dnscryptMenuItem setState: 1]; - } else if ([stateDescription isEqualToString: @"OpenDNS"]) { - } else if ([stateDescription isEqualToString: @"OpenDNS IPv6"]) { - } else if ([stateDescription isEqualToString: @"Localhost"]) { - } else if ([stateDescription isEqualToString: @"Localhost IPv6"]) { - } else if ([stateDescription isEqualToString: @"None"]) { - } else if ([stateDescription isEqualToString: @"Updating"]) { + } + 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"]) { + [_familyShieldMenuItem 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"]) { + [_opendnsMenuItem 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"]) { + [_fallbackMenuItem setState: 1]; } } @@ -190,6 +202,48 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; return TRUE; } +- (BOOL) setFamilyShieldOn { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-familyshield-on.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + +- (BOOL) setFamilyShieldOff { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-familyshield-off.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + +- (BOOL) setInsecureOpenDNSOn { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-insecure-opendns-on.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + +- (BOOL) setInsecureOpenDNSOff { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-insecure-opendns-off.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + +- (BOOL) setFallbackOn { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-fallback-on.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + +- (BOOL) setFallbackOff { + [self updateLedStatusWaiting]; + NSString *res = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./switch-fallback-off.sh", nil]]; + NSLog(@"%@", res); + return TRUE; +} + - (IBAction)dnscryptMenuItemPushed:(NSMenuItem *)sender { if (sender.state == 0) { @@ -203,12 +257,35 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (IBAction)familyShieldMenuItemPushed:(NSMenuItem *)sender { + if (sender.state == 0) { + sender.state = 1; + [self setFamilyShieldOn]; + } else { + sender.state = 0; + [self setFamilyShieldOff]; + } +} +- (IBAction)opendnsMenuItemPushed:(NSMenuItem *)sender +{ + if (sender.state == 0) { + sender.state = 1; + [self setInsecureOpenDNSOn]; + } else { + sender.state = 0; + [self setInsecureOpenDNSOff]; + } } - (IBAction)fallbackMenuItemPushed:(NSMenuItem *)sender { - + if (sender.state == 0) { + sender.state = 1; + [self setFallbackOn]; + } else { + sender.state = 0; + [self setFallbackOff]; + } } @end diff --git a/DNSCrypt-Menubar/DNSCrypt-Menubar/en.lproj/MainMenu.xib b/DNSCrypt-Menubar/DNSCrypt-Menubar/en.lproj/MainMenu.xib index 24e8ec8..e03aa91 100644 --- a/DNSCrypt-Menubar/DNSCrypt-Menubar/en.lproj/MainMenu.xib +++ b/DNSCrypt-Menubar/DNSCrypt-Menubar/en.lproj/MainMenu.xib @@ -53,9 +53,18 @@ NSMenuMixedState + + + Fallback to insecure + x + 1048576 + 2147483647 + + + - Enable FamilyShield + Always use FamilyShield f 1048576 2147483647 @@ -64,8 +73,8 @@ - Fallback to insecure - x + Always use OpenDNS + o 1048576 2147483647 @@ -285,14 +294,6 @@ 578 - - - fallbackMenuItem - - - - 579 - dnscryptMenuItemPushed: @@ -313,9 +314,25 @@ fallbackMenuItemPushed: + + + 584 + + + + opendnsMenuItem + - 582 + 587 + + + + opendnsMenuItemPushed: + + + + 588 @@ -378,6 +395,7 @@ + @@ -471,6 +489,11 @@ + + 583 + + + @@ -497,12 +520,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 582 + 588 @@ -513,6 +537,7 @@ NSMenuItem NSMenuItem NSMenuItem + NSMenuItem NSMenuItem @@ -528,6 +553,10 @@ familyShieldMenuItemPushed: NSMenuItem + + opendnsMenuItemPushed: + NSMenuItem + preferencesMenuItemPushed: NSMenuItem @@ -538,6 +567,7 @@ NSMenuItem NSMenuItem NSMenuItem + NSMenuItem NSMenuItem NSMenuItem NSMenuItem @@ -560,6 +590,10 @@ familyShieldMenuItem NSMenuItem + + opendnsMenuItem + NSMenuItem + statusConfigurationMenuItem NSMenuItem