This commit is contained in:
Adam Ierymenko 2016-11-04 15:18:35 -07:00
commit 3e865067be
7 changed files with 102 additions and 9 deletions

View File

@ -107,7 +107,7 @@ namespace WinUI
}
}
public void JoinNetwork(string nwid)
public void JoinNetwork(string nwid, bool allowManaged = true, bool allowGlobal = false, bool allowDefault = false)
{
var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest;
if (request == null)
@ -116,6 +116,17 @@ namespace WinUI
}
request.Method = "POST";
request.ContentType = "applicaiton/json";
using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream()))
{
string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," +
"\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," +
"\"allowDefault\":" + (allowDefault ? "true" : "false") + "}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
try
{

View File

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WinUI"
mc:Ignorable="d" x:Class="WinUI.MainWindow"
Title="ZeroTier One" Height="500" Width="425" Icon="ZeroTierIcon.ico">
Title="ZeroTier One" Height="500" Width="500" Icon="ZeroTierIcon.ico">
<Window.Resources>
<SolidColorBrush x:Key="GreenBrush" Color="#ff91a2a3"/>

View File

@ -26,6 +26,9 @@
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">
@ -48,8 +51,11 @@
<TextBlock TextWrapping="Wrap" Text="Bridging" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="7" Foreground="#FF000000"/>
<TextBlock TextWrapping="Wrap" Text="Device" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="8" Foreground="#FF000000"/>
<TextBlock TextWrapping="Wrap" Text="Managed IPs" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="9" Foreground="#FF000000"/>
<TextBlock TextWrapping="Wrap" Text="Allow Global IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="10" Foreground="#FF000000"/>
<TextBlock TextWrapping="Wrap" Text="Allow Managed IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="11" Foreground="#FF000000"/>
<TextBlock TextWrapping="Wrap" Text="Allow Default Route" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="12" Foreground="#FF000000"/>
<Rectangle Grid.Column="2" Grid.Row="2" Grid.RowSpan="8" Fill="#FFEEEEEE"/>
<Rectangle Grid.Column="2" Grid.Row="2" Grid.RowSpan="11" Fill="#FFEEEEEE"/>
<TextBlock x:Name="networkStatus" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Text="OK" TextAlignment="Right" Grid.Column="2" Grid.Row="2" Foreground="#FF000000"/>
<TextBlock x:Name="networkType" FontFamily="Lucida Console" TextWrapping="Wrap" Text="PUBLIC" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="3" Foreground="#FF000000"/>
@ -59,10 +65,13 @@
<TextBlock x:Name="bridgingEnabled" FontFamily="Lucida Console" TextWrapping="Wrap" Text="DISABLED" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="7" Background="#FFEEEEEE" Foreground="#FF000000"/>
<TextBlock x:Name="deviceName" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="8" Foreground="#FF000000"><Span><Run Text="ethernet_32771"/></Span></TextBlock>
<TextBlock x:Name="managedIps" TextWrapping="Wrap" FontFamily="Lucida Console" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="2" Grid.Row="9" Foreground="#FF000000"><Span><Run Text="28.2.169.248/7 "/></Span><LineBreak/><Span><Run Text="fd80:56c2:e21c:0000:0199:9383:4a02:a9f8/88"/></Span></TextBlock>
<Separator Grid.Column="0" Grid.Row="10" Grid.ColumnSpan="3"/>
<CheckBox x:Name="allowGlobal" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="10" />
<CheckBox x:Name="allowManaged" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="11" />
<CheckBox x:Name="allowDefault" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="12" />
<Grid Grid.Column="0" Grid.Row="11" Grid.ColumnSpan="3" Background="GhostWhite">
<Separator Grid.Column="0" Grid.Row="13" Grid.ColumnSpan="3"/>
<Grid Grid.Column="0" Grid.Row="14" Grid.ColumnSpan="3" Background="GhostWhite">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

View File

@ -54,6 +54,18 @@ namespace WinUI
}
this.managedIps.Text = iplist;
this.allowDefault.IsChecked = network.AllowDefault;
this.allowGlobal.IsChecked = network.AllowGlobal;
this.allowManaged.IsChecked = network.AllowManaged;
allowDefault.Checked += AllowDefault_CheckStateChanged;
allowDefault.Unchecked += AllowDefault_CheckStateChanged;
allowGlobal.Checked += AllowGlobal_CheckStateChanged;
allowGlobal.Unchecked += AllowGlobal_CheckStateChanged;
allowManaged.Checked += AllowManaged_CheckStateChanged;
allowManaged.Unchecked += AllowManaged_CheckStateChanged;
}
public bool HasNetwork(ZeroTierNetwork network)
@ -68,5 +80,32 @@ namespace WinUI
{
handler.LeaveNetwork(network.NetworkId);
}
private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false);
}
private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false);
}
private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
handler.JoinNetwork(network.NetworkId,
allowManaged.IsChecked ?? false,
allowGlobal.IsChecked ?? false,
allowDefault.IsChecked ?? false);
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace WinUI
{
public class NetworkRoute
{
[JsonProperty("target")]
public string Target { get; set; }
[JsonProperty("via")]
public string Via { get; set; }
[JsonProperty("flags")]
public int Flags { get; set; }
[JsonProperty("metric")]
public int Metric { get; set; }
}
}

View File

@ -99,6 +99,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="NetworkRoute.cs" />
<Compile Include="NetworksPage.xaml.cs">
<DependentUpon>NetworksPage.xaml</DependentUpon>
</Compile>

View File

@ -42,13 +42,22 @@ namespace WinUI
[JsonProperty("netconfRevision")]
public int NetconfRevision { get; set; }
[JsonProperty("multicastSubscriptions")]
public string[] MulticastSubscriptions { get; set; }
[JsonProperty("assignedAddresses")]
public string[] AssignedAddresses { get; set; }
[JsonProperty("routes")]
public NetworkRoute[] Routes { get; set; }
[JsonProperty("portDeviceName")]
public string DeviceName { get; set; }
[JsonProperty("allowManaged")]
public bool AllowManaged { get; set; }
[JsonProperty("allowGlobal")]
public bool AllowGlobal { get; set; }
[JsonProperty("allowDefault")]
public bool AllowDefault { get; set; }
}
}