add allowGlobal, allowDefault, allowManaged options to joining a network

This commit is contained in:
Grant Limberg 2016-06-26 16:11:30 -07:00
parent 5da4fd2aef
commit 9c94d6527a
3 changed files with 67 additions and 22 deletions

View File

@ -30,6 +30,10 @@ class JoinNetworkViewController: NSViewController, NSComboBoxDelegate, NSComboBo
@IBOutlet var network: NSComboBox! @IBOutlet var network: NSComboBox!
@IBOutlet var joinButton: NSButton! @IBOutlet var joinButton: NSButton!
@IBOutlet var allowManagedCheckBox: NSButton!
@IBOutlet var allowGlobalCheckBox: NSButton!
@IBOutlet var allowDefaultCheckBox:NSButton!
var values: [String] = [String]() var values: [String] = [String]()
override func viewDidLoad() { override func viewDidLoad() {
@ -61,8 +65,10 @@ class JoinNetworkViewController: NSViewController, NSComboBoxDelegate, NSComboBo
@IBAction func onJoinClicked(sender: AnyObject?) { @IBAction func onJoinClicked(sender: AnyObject?) {
let networkString = network.stringValue let networkString = network.stringValue
ServiceCom.joinNetwork(networkString) ServiceCom.joinNetwork(networkString,
allowManaged: allowManagedCheckBox.state == NSOnState,
allowGlobal: allowGlobalCheckBox.state == NSOnState,
allowDefault: allowDefaultCheckBox.state == NSOnState)
network.stringValue = "" network.stringValue = ""

View File

@ -6,6 +6,9 @@
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="JoinNetworkViewController" customModule="ZeroTier_One" customModuleProvider="target"> <customObject id="-2" userLabel="File's Owner" customClass="JoinNetworkViewController" customModule="ZeroTier_One" customModuleProvider="target">
<connections> <connections>
<outlet property="allowDefaultCheckBox" destination="rz3-0a-oNA" id="mYu-Wq-MHW"/>
<outlet property="allowGlobalCheckBox" destination="BH2-2O-Qeu" id="alx-Je-q9I"/>
<outlet property="allowManagedCheckBox" destination="OQS-QZ-zcY" id="7pz-vO-3IC"/>
<outlet property="joinButton" destination="BGy-vd-NQX" id="LGE-2G-7ND"/> <outlet property="joinButton" destination="BGy-vd-NQX" id="LGE-2G-7ND"/>
<outlet property="network" destination="BQy-d9-BNg" id="Yf7-BG-c84"/> <outlet property="network" destination="BQy-d9-BNg" id="Yf7-BG-c84"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/> <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
@ -14,11 +17,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY"> <customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="369" height="101"/> <rect key="frame" x="0.0" y="0.0" width="397" height="123"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="puT-Yk-CWC"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="puT-Yk-CWC">
<rect key="frame" x="18" y="61" width="107" height="17"/> <rect key="frame" x="18" y="83" width="107" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Enter Network ID" id="oYH-gS-BX5"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Enter Network ID" id="oYH-gS-BX5">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -26,7 +29,7 @@
</textFieldCell> </textFieldCell>
</textField> </textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BGy-vd-NQX"> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BGy-vd-NQX">
<rect key="frame" x="274" y="13" width="81" height="32"/> <rect key="frame" x="302" y="13" width="81" height="32"/>
<buttonCell key="cell" type="push" title="Join" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6Rp-TA-XLl"> <buttonCell key="cell" type="push" title="Join" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6Rp-TA-XLl">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@ -36,15 +39,36 @@
</connections> </connections>
</button> </button>
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BQy-d9-BNg"> <comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BQy-d9-BNg">
<rect key="frame" x="131" y="57" width="221" height="26"/> <rect key="frame" x="131" y="79" width="249" height="26"/>
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesDataSource="YES" numberOfVisibleItems="5" id="n71-4S-AaI"> <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesDataSource="YES" numberOfVisibleItems="5" id="n71-4S-AaI">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</comboBoxCell> </comboBoxCell>
</comboBox> </comboBox>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OQS-QZ-zcY">
<rect key="frame" x="18" y="59" width="115" height="18"/>
<buttonCell key="cell" type="check" title="Allow Managed" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="QEN-MJ-xaj">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BH2-2O-Qeu">
<rect key="frame" x="137" y="59" width="97" height="18"/>
<buttonCell key="cell" type="check" title="Allow Global" bezelStyle="regularSquare" imagePosition="left" inset="2" id="epO-Uh-aHN">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rz3-0a-oNA">
<rect key="frame" x="238" y="59" width="141" height="18"/>
<buttonCell key="cell" type="check" title="Allow Default Route" alternateTitle="Allow override of default route full tunnel'" bezelStyle="regularSquare" imagePosition="left" inset="2" id="Lkd-XI-Kcu">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews> </subviews>
<point key="canvasLocation" x="249.5" y="361.5"/> <point key="canvasLocation" x="263.5" y="372.5"/>
</customView> </customView>
</objects> </objects>
</document> </document>

View File

@ -119,29 +119,44 @@ class ServiceCom: NSObject {
} }
static func joinNetwork(network: String) { static func joinNetwork(network: String, allowManaged: Bool = true, allowGlobal: Bool = false, allowDefault: Bool = false) {
let urlString = baseURL + "/network/\(network)?auth=\(ServiceCom.getKey())" let urlString = baseURL + "/network/\(network)?auth=\(ServiceCom.getKey())"
let url = NSURL(string: urlString) let url = NSURL(string: urlString)
if let u = url { var jsonDict = [String: AnyObject]()
let request = NSMutableURLRequest(URL: u) jsonDict["allowManaged"] = NSNumber(bool: allowManaged)
request.HTTPMethod = "POST" jsonDict["allowGlobal"] = NSNumber(bool: allowGlobal)
jsonDict["allowDefault"] = NSNumber(bool: allowDefault)
let session = NSURLSession.sharedSession() do {
let task = session.dataTaskWithRequest(request) { (data, response, error) in let json = try NSJSONSerialization.dataWithJSONObject(jsonDict, options: NSJSONWritingOptions())
let httpResponse = response as! NSHTTPURLResponse
let status = httpResponse.statusCode
if status == 200 { if let u = url {
NSLog("join ok") let request = NSMutableURLRequest(URL: u)
} request.HTTPMethod = "POST"
else { request.HTTPBody = json
NSLog("join error: \(status)") request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request) { (data, response, error) in
let httpResponse = response as! NSHTTPURLResponse
let status = httpResponse.statusCode
if status == 200 {
NSLog("join ok")
}
else {
NSLog("join error: \(status)")
}
} }
task.resume()
} }
task.resume()
} }
catch {
NSLog("\(error)")
}
} }
static func leaveNetwork(network: String) { static func leaveNetwork(network: String) {