From e7dafb3ae66e8e121274de3f8e46eb882313b7b7 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 18 Sep 2020 09:30:43 -0700 Subject: [PATCH] allow DNS field for mac UI --- macui/ZeroTier One/AppDelegate.m | 1 + .../ZeroTier One/JoinNetworkViewController.h | 1 + .../ZeroTier One/JoinNetworkViewController.m | 2 + .../JoinNetworkViewController.xib | 87 ++++---- macui/ZeroTier One/Network.h | 1 + macui/ZeroTier One/Network.m | 15 ++ macui/ZeroTier One/NetworkInfoCell.h | 1 + macui/ZeroTier One/NetworkInfoCell.m | 1 + macui/ZeroTier One/ServiceCom.h | 2 +- macui/ZeroTier One/ServiceCom.m | 8 +- .../ZeroTier One/ShowNetworksViewController.m | 3 + .../ShowNetworksViewController.xib | 205 ++++++++++-------- 12 files changed, 195 insertions(+), 132 deletions(-) diff --git a/macui/ZeroTier One/AppDelegate.m b/macui/ZeroTier One/AppDelegate.m index ae3e042f1..6889a89aa 100644 --- a/macui/ZeroTier One/AppDelegate.m +++ b/macui/ZeroTier One/AppDelegate.m @@ -336,6 +336,7 @@ allowManaged:network.allowManaged allowGlobal:network.allowGlobal allowDefault:(network.allowDefault && ![Network defaultRouteExists:self.networks]) + allowDNS:network.allowDNS error:&error]; if (error) { diff --git a/macui/ZeroTier One/JoinNetworkViewController.h b/macui/ZeroTier One/JoinNetworkViewController.h index 428959fba..4c25cc0db 100644 --- a/macui/ZeroTier One/JoinNetworkViewController.h +++ b/macui/ZeroTier One/JoinNetworkViewController.h @@ -30,6 +30,7 @@ extern NSString * const JoinedNetworksKey; @property (nonatomic, weak) IBOutlet NSButton *allowManagedCheckBox; @property (nonatomic, weak) IBOutlet NSButton *allowGlobalCheckBox; @property (nonatomic, weak) IBOutlet NSButton *allowDefaultCheckBox; +@property (nonatomic, weak) IBOutlet NSButton *allowDNSCheckBox; @property (nonatomic, weak) IBOutlet AppDelegate *appDelegate; @property (nonatomic) NSMutableArray *values; diff --git a/macui/ZeroTier One/JoinNetworkViewController.m b/macui/ZeroTier One/JoinNetworkViewController.m index cae265416..c2d6517a1 100644 --- a/macui/ZeroTier One/JoinNetworkViewController.m +++ b/macui/ZeroTier One/JoinNetworkViewController.m @@ -54,6 +54,7 @@ NSString * const JoinedNetworksKey = @"com.zerotier.one.joined-networks"; self.allowManagedCheckBox.state = NSOnState; self.allowGlobalCheckBox.state = NSOffState; self.allowDefaultCheckBox.state = NSOffState; + self.allowDNSCheckBox.state = NSOffState; self.network.stringValue = @""; @@ -82,6 +83,7 @@ NSString * const JoinedNetworksKey = @"com.zerotier.one.joined-networks"; allowManaged:(self.allowManagedCheckBox.state == NSOnState) allowGlobal:(self.allowGlobalCheckBox.state == NSOnState) allowDefault:(self.allowDefaultCheckBox.state == NSOnState) + allowDNS:(self.allowDNSCheckBox.state == NSOnState) error:&error]; if(error) { diff --git a/macui/ZeroTier One/JoinNetworkViewController.xib b/macui/ZeroTier One/JoinNetworkViewController.xib index 59161093f..b4ea477bf 100644 --- a/macui/ZeroTier One/JoinNetworkViewController.xib +++ b/macui/ZeroTier One/JoinNetworkViewController.xib @@ -1,13 +1,14 @@ - + - + + @@ -19,11 +20,11 @@ - + - - + + @@ -31,6 +32,47 @@ + + + + + + + + + + + + + - - - - - - - - - - - - - + diff --git a/macui/ZeroTier One/Network.h b/macui/ZeroTier One/Network.h index 957ff8d56..c1cfbaf28 100644 --- a/macui/ZeroTier One/Network.h +++ b/macui/ZeroTier One/Network.h @@ -50,6 +50,7 @@ enum NetworkType { @property (readonly) BOOL allowManaged; @property (readonly) BOOL allowGlobal; @property (readonly) BOOL allowDefault; +@property (readonly) BOOL allowDNS; @property (readonly) BOOL connected; // not persisted. set to YES if loaded via json - (id)initWithJsonData:(NSDictionary*)jsonData; diff --git a/macui/ZeroTier One/Network.m b/macui/ZeroTier One/Network.m index 8474acaaf..2379eb691 100644 --- a/macui/ZeroTier One/Network.m +++ b/macui/ZeroTier One/Network.m @@ -35,6 +35,7 @@ NSString *NetworkTypeKey = @"type"; NSString *NetworkAllowManagedKey = @"allowManaged"; NSString *NetworkAllowGlobalKey = @"allowGlobal"; NSString *NetworkAllowDefaultKey = @"allowDefault"; +NSString *NetworkAllowDNSKey = @"allowDNS"; @implementation Network @@ -101,6 +102,11 @@ NSString *NetworkAllowDefaultKey = @"allowDefault"; if([jsonData objectForKey:@"allowDefault"]) { _allowDefault = [(NSNumber*)[jsonData objectForKey:@"allowDefault"] boolValue]; } + if([jsonData objectForKey:@"allowDNS"]) { + _allowDNS = [(NSNumber*)[jsonData objectForKey:@"allowDNS"] boolValue]; + } else { + _allowDNS = false; + } if([jsonData objectForKey:@"status"]) { NSString *statusStr = (NSString*)[jsonData objectForKey:@"status"]; @@ -207,6 +213,12 @@ NSString *NetworkAllowDefaultKey = @"allowDefault"; if([aDecoder containsValueForKey:NetworkAllowDefaultKey]) { _allowDefault = [aDecoder decodeBoolForKey:NetworkAllowDefaultKey]; } + + if([aDecoder containsValueForKey:NetworkAllowDNSKey]) { + _allowDNS = [aDecoder decodeBoolForKey:NetworkAllowDNSKey]; + } else { + _allowDNS = false; + } _connected = NO; } @@ -233,6 +245,7 @@ NSString *NetworkAllowDefaultKey = @"allowDefault"; [aCoder encodeBool:_allowManaged forKey:NetworkAllowManagedKey]; [aCoder encodeBool:_allowGlobal forKey:NetworkAllowGlobalKey]; [aCoder encodeBool:_allowDefault forKey:NetworkAllowDefaultKey]; + [aCoder encodeBool:_allowDNS forKey:NetworkAllowDNSKey]; } + (BOOL)defaultRouteExists:(NSArray*)netList @@ -297,6 +310,7 @@ NSString *NetworkAllowDefaultKey = @"allowDefault"; self.allowManaged == network.allowManaged && self.allowGlobal == network.allowGlobal && self.allowDefault == network.allowDefault && + self.allowDNS == network.allowDNS && self.connected == network.connected; } @@ -331,6 +345,7 @@ NSString *NetworkAllowDefaultKey = @"allowDefault"; self.allowManaged ^ self.allowGlobal ^ self.allowDefault ^ + self.allowDNS ^ self.connected; } diff --git a/macui/ZeroTier One/NetworkInfoCell.h b/macui/ZeroTier One/NetworkInfoCell.h index be9345d70..f764034ee 100644 --- a/macui/ZeroTier One/NetworkInfoCell.h +++ b/macui/ZeroTier One/NetworkInfoCell.h @@ -37,6 +37,7 @@ @property (weak, nonatomic) IBOutlet NSButton *allowManaged; @property (weak, nonatomic) IBOutlet NSButton *allowGlobal; @property (weak, nonatomic) IBOutlet NSButton *allowDefault; +@property (weak, nonatomic) IBOutlet NSButton *allowDNS; @property (weak, nonatomic) IBOutlet NSButton *connectedCheckbox; @property (weak, nonatomic) IBOutlet NSButton *deleteButton; diff --git a/macui/ZeroTier One/NetworkInfoCell.m b/macui/ZeroTier One/NetworkInfoCell.m index dc75cab39..df1bbf67e 100644 --- a/macui/ZeroTier One/NetworkInfoCell.m +++ b/macui/ZeroTier One/NetworkInfoCell.m @@ -57,6 +57,7 @@ allowManaged:(self.allowManaged.state == NSOnState) allowGlobal:(self.allowGlobal.state == NSOnState) allowDefault:![Network defaultRouteExists:_parent.networkList] && (self.allowDefault.state == NSOnState) + allowDNS:(self.allowDNS.state == NSOnState) error:&error]; if (error) { diff --git a/macui/ZeroTier One/ServiceCom.h b/macui/ZeroTier One/ServiceCom.h index c2b4692f8..17b738e4d 100644 --- a/macui/ZeroTier One/ServiceCom.h +++ b/macui/ZeroTier One/ServiceCom.h @@ -34,7 +34,7 @@ - (void)getNetworklist:(void (^)(NSArray*))completionHandler error:(NSError* __autoreleasing *)error; - (void)getNodeStatus:(void (^)(NodeStatus*))completionHandler error:(NSError*__autoreleasing*)error; -- (void)joinNetwork:(NSString*)networkId allowManaged:(BOOL)allowManaged allowGlobal:(BOOL)allowGlobal allowDefault:(BOOL)allowDefault error:(NSError*__autoreleasing*)error; +- (void)joinNetwork:(NSString*)networkId allowManaged:(BOOL)allowManaged allowGlobal:(BOOL)allowGlobal allowDefault:(BOOL)allowDefault allowDNS:(BOOL)allowDNS error:(NSError*__autoreleasing*)error; - (void)leaveNetwork:(NSString*)networkId error:(NSError*__autoreleasing*)error; @end diff --git a/macui/ZeroTier One/ServiceCom.m b/macui/ZeroTier One/ServiceCom.m index 75b98502f..55d67741a 100644 --- a/macui/ZeroTier One/ServiceCom.m +++ b/macui/ZeroTier One/ServiceCom.m @@ -377,7 +377,12 @@ [task resume]; } -- (void)joinNetwork:(NSString*)networkId allowManaged:(BOOL)allowManaged allowGlobal:(BOOL)allowGlobal allowDefault:(BOOL)allowDefault error:(NSError *__autoreleasing*)error +- (void)joinNetwork:(NSString*)networkId + allowManaged:(BOOL)allowManaged + allowGlobal:(BOOL)allowGlobal + allowDefault:(BOOL)allowDefault + allowDNS:(BOOL)allowDNS + error:(NSError *__autoreleasing*)error { NSString *key = [self key:error]; if(*error) { @@ -395,6 +400,7 @@ [jsonDict setObject:[NSNumber numberWithBool:allowManaged] forKey:@"allowManaged"]; [jsonDict setObject:[NSNumber numberWithBool:allowGlobal] forKey:@"allowGlobal"]; [jsonDict setObject:[NSNumber numberWithBool:allowDefault] forKey:@"allowDefault"]; + [jsonDict setObject:[NSNumber numberWithBool:allowDNS] forKey:@"allowDNS"]; NSError *err = nil; diff --git a/macui/ZeroTier One/ShowNetworksViewController.m b/macui/ZeroTier One/ShowNetworksViewController.m index 903a4b447..acd29479a 100644 --- a/macui/ZeroTier One/ShowNetworksViewController.m +++ b/macui/ZeroTier One/ShowNetworksViewController.m @@ -158,16 +158,19 @@ BOOL hasNetworkWithID(NSArray *list, UInt64 nwid) cell.allowGlobal.enabled = YES; cell.allowManaged.enabled = YES; + cell.allowDNS.enabled = YES; } else { cell.connectedCheckbox.state = NSOffState; cell.allowDefault.enabled = NO; cell.allowGlobal.enabled = NO; cell.allowManaged.enabled = NO; + cell.allowDNS.enabled = NO; } cell.allowGlobal.state = network.allowGlobal ? NSOnState : NSOffState; cell.allowManaged.state = network.allowManaged ? NSOnState : NSOffState; + cell.allowDNS.state = network.allowDNS ? NSOnState : NSOffState; cell.addressesField.stringValue = @""; diff --git a/macui/ZeroTier One/ShowNetworksViewController.xib b/macui/ZeroTier One/ShowNetworksViewController.xib index 62ac289a2..485adb0c0 100644 --- a/macui/ZeroTier One/ShowNetworksViewController.xib +++ b/macui/ZeroTier One/ShowNetworksViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -18,15 +18,15 @@ - + - + - + @@ -34,7 +34,6 @@ - @@ -46,109 +45,83 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - + + - - - + + - - + + @@ -156,7 +129,7 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +