Explorar o código

Base windows UI is working.

* No joining/leaving networks yet, but they do display.
* Nothing is updated yet after first load of the app.  Need to set up a background task to run updates.
Grant Limberg %!s(int64=9) %!d(string=hai) anos
pai
achega
5b6ddaa2d7

+ 1 - 0
.gitignore

@@ -71,3 +71,4 @@ java/build_win32/
 /java/mac32_64/
 windows/WinUI/obj/
 windows/WinUI/bin/
+windows/ZeroTierOne/Debug/

+ 69 - 0
windows/WinUI/APIHandler.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Net;
+using System.IO;
+using Newtonsoft.Json;
+
+namespace WinUI
+{
+    
+
+    public class APIHandler
+    {
+        static string authtoken = "p3ptrzds5jkr2hbx5ipbyf04";  // delete me!
+
+        private string url = null;
+
+        public APIHandler()
+        {
+            url = "http://127.0.0.1:9993";
+        }
+
+        public APIHandler(string host, int port)
+        {
+            url = "http://" + host + ":" + port;
+        }
+
+        public ZeroTierStatus getStatus()
+        {
+            var request = WebRequest.Create(url + "/status" + "?auth=" + authtoken) as HttpWebRequest;
+            if (request != null)
+            {
+                request.Method = "GET";
+                request.ContentType = "application/json";
+            }
+
+            var httpResponse = (HttpWebResponse)request.GetResponse();
+            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
+            {
+                var responseText = streamReader.ReadToEnd();
+
+                ZeroTierStatus status = JsonConvert.DeserializeObject<ZeroTierStatus>(responseText);
+                return status;
+            }
+        }
+
+        public List<ZeroTierNetwork> getNetworks()
+        {
+            var request = WebRequest.Create(url + "/network" + "?auth=" + authtoken) as HttpWebRequest;
+            if (request != null)
+            {
+                request.Method = "GET";
+                request.ContentType = "application/json";
+            }
+
+            var httpResponse = (HttpWebResponse)request.GetResponse();
+            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
+            {
+                var responseText = streamReader.ReadToEnd();
+                Console.WriteLine(responseText);
+
+                List<ZeroTierNetwork> networkList = JsonConvert.DeserializeObject<List<ZeroTierNetwork>>(responseText);
+                return networkList;
+            }
+        }
+    }
+}

+ 10 - 5
windows/WinUI/MainWindow.xaml

@@ -1,7 +1,10 @@
 <Window
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WinUI.MainWindow"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+        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="495" Width="705" Icon="ZeroTierIcon.ico">
 	
 	<Window.Resources>
@@ -84,10 +87,12 @@
 			</StatusBarItem>
 		</StatusBar>
 		<TabControl>
-			<TabItem x:Name="Networks" Header="Networks" Background="#FF234447" Foreground="White" IsSelected="True" IsManipulationEnabled="True">
-				<Grid Background="#FFE5E5E5"/>
-			</TabItem>
-			<TabItem x:Name="Peers" Header="Peers" Background="#FF234447" Foreground="White">
+            <TabItem x:Name="Networks" Header="Networks" Background="#FF234447" Foreground="White" IsSelected="True" IsManipulationEnabled="True">
+                <Grid>
+                    <local:NetworksPage x:Name="networksPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
+                </Grid>
+            </TabItem>
+            <TabItem x:Name="Peers" Header="Peers" Background="#FF234447" Foreground="White">
 				<Grid Background="#FFE5E5E5"/>
 			</TabItem>
 		</TabControl>

+ 21 - 0
windows/WinUI/MainWindow.xaml.cs

@@ -20,9 +20,30 @@ namespace WinUI
     /// </summary>
     public partial class MainWindow : Window
     {
+        APIHandler handler = new APIHandler();
+
         public MainWindow()
         {
             InitializeComponent();
+
+            updateStatus();
+            updateNetworks();
+        }
+
+        private void updateStatus()
+        {
+            var status = handler.getStatus();
+
+            this.networkId.Content = status.address;
+            this.versionString.Content = status.version;
+            this.onlineStatus.Content = (status.online ? "ONLINE" : "OFFLINE");
+        }
+
+        private void updateNetworks()
+        {
+            var networks = handler.getNetworks();
+
+            networksPage.setNetworks(networks);
         }
     }
 }

+ 57 - 50
windows/WinUI/NetworkInfoView.xaml

@@ -1,55 +1,62 @@
-<Page x:Class="WinUI.NetworkInfoView"
+<UserControl x:Class="WinUI.NetworkInfoView"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       mc:Ignorable="d"
-	Title="NetworkInfoView" FontFamily="/ZeroTier One;component/Fonts/#Segoe UI" Height="284" Width="316.333">
-	<DockPanel LastChildFill="True">
-		<StatusBar DockPanel.Dock="Top">
-			<StatusBar.ItemsPanel>
-                <ItemsPanelTemplate>
-                    <Grid>
-                        <Grid.RowDefinitions>
-                            <RowDefinition Height="*"/>
-                        </Grid.RowDefinitions>
-                        <Grid.ColumnDefinitions>
-                            <ColumnDefinition Width="Auto"/>
-                            <ColumnDefinition Width="*"/>
-							<ColumnDefinition Width="Auto"/>
-                        </Grid.ColumnDefinitions>
-                    </Grid>
-                </ItemsPanelTemplate>
-            </StatusBar.ItemsPanel>
-			<StatusBarItem Grid.Column="0">
-				<TextBlock x:Name="networkId" TextWrapping="Wrap" Text="8056c2e21c000001" Foreground="#FF91A2A3"/>
-			</StatusBarItem>
-			<StatusBarItem Grid.Column="1"/>
-			<StatusBarItem Grid.Column="2">
-				<TextBlock x:Name="networkName" TextWrapping="Wrap" Text="earth.zerotier.net"/>
-			</StatusBarItem>
-			
-		</StatusBar>
-		<StackPanel Width="80.483" OpacityMask="Black" Background="White">
-			<TextBlock TextWrapping="Wrap" Text="Status" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="Type" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="MAC" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="MTU" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="Broadcast" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="Bridging" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="Device" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="Managed IPs" HorizontalAlignment="Right"/>
-		</StackPanel>
-		<StackPanel Background="#FFEEEEEE" DockPanel.Dock="Right">
-			<TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" Text="OK" TextAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="PUBLIC" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" HorizontalAlignment="Right"><Span><Run Text="02:83:4a:1e:4b:3a"/></Span></TextBlock>
-			<TextBlock TextWrapping="Wrap" Text="2800" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="ENABLED" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" Text="DISABLED" HorizontalAlignment="Right"/>
-			<TextBlock TextWrapping="Wrap" HorizontalAlignment="Right"><Span><Run Text="ethernet_32771"/></Span></TextBlock>
-			<TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" TextAlignment="Right"><Span><Run Text="28.2.169.248/7 "/></Span><LineBreak/><Span><Run Text="fd80:56c2:e21c:0000:0199:9383:4a02:a9f8/88"/></Span></TextBlock>
-		</StackPanel>
-		<StatusBar DockPanel.Dock="Bottom"/>
-	</DockPanel>
-</Page>
+	>
+	<Grid Background="#FFFFFFFF" Margin="5,0,5,1">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="auto"/>
+            <ColumnDefinition Width="*"/>
+        </Grid.ColumnDefinitions>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
+            <RowDefinition Height="auto"/>
+            <RowDefinition Height="auto"/>
+            <RowDefinition Height="auto"/>
+            <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="2">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="auto"/>
+                <ColumnDefinition Width="*"/>
+            </Grid.ColumnDefinitions>
+
+            <TextBlock x:Name="networkId" Text="8056c2e21c000001" HorizontalAlignment="Left" Grid.Column="0" Foreground="#FF91A2A3"/>
+            <TextBlock x:Name="networkName" Text="earth.zerotier.net" HorizontalAlignment="Right" Grid.Column="1" Foreground="#FF000000"/>
+        </Grid>
+
+        <TextBlock TextWrapping="Wrap" Text="Status" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="1" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="Type" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="2" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="MAC" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="3" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="MTU" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="4" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="Broadcast" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="5" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="Bridging" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="6" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="Device" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="7" Foreground="#FF000000"/>
+        <TextBlock TextWrapping="Wrap" Text="Managed IPs" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="8" Foreground="#FF000000"/>
+
+        <TextBlock x:Name="networkStatus" TextWrapping="Wrap" HorizontalAlignment="Right" Text="OK" TextAlignment="Right"  Grid.Column="1" Grid.Row="1" Foreground="#FF000000"/>
+        <TextBlock x:Name="networkType" TextWrapping="Wrap" Text="PUBLIC" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="2" Foreground="#FF000000"/>
+        <TextBlock x:Name="macAddress" TextWrapping="Wrap" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="3" Foreground="#FF000000"><Span><Run Text="02:83:4a:1e:4b:3a"/></Span></TextBlock>
+        <TextBlock x:Name="mtu" TextWrapping="Wrap" Text="2800" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="4" Foreground="#FF000000"/>
+        <TextBlock x:Name="broadcastEnabled" TextWrapping="Wrap" Text="ENABLED" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="5" Foreground="#FF000000"/>
+        <TextBlock x:Name="bridgingEnabled" TextWrapping="Wrap" Text="DISABLED" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="6" Foreground="#FF000000"/>
+        <TextBlock x:Name="deviceName" TextWrapping="Wrap" HorizontalAlignment="Right"  Grid.Column="1" Grid.Row="7" Foreground="#FF000000"><Span><Run Text="ethernet_32771"/></Span></TextBlock>
+        <TextBlock x:Name="managedIps" TextWrapping="Wrap" HorizontalAlignment="Right" TextAlignment="Right"  Grid.Column="1" Grid.Row="8" 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>
+
+        <Grid Grid.Column="0" Grid.Row="9" Grid.ColumnSpan="2" Background="#FFFFFFFF">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="*"/>
+            </Grid.ColumnDefinitions>
+            <Button />
+            <Button x:Name="leaveButton" Content="Leave" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Background="#FFFFB354"/>
+        </Grid>
+    </Grid>
+</UserControl>

+ 38 - 2
windows/WinUI/NetworkInfoView.xaml.cs

@@ -18,11 +18,47 @@ namespace WinUI
     /// <summary>
     /// Interaction logic for NetworkInfoView.xaml
     /// </summary>
-    public partial class NetworkInfoView : Page
+    public partial class NetworkInfoView : UserControl
     {
-        public NetworkInfoView()
+        ZeroTierNetwork network;
+
+        public NetworkInfoView(ZeroTierNetwork network)
         {
             InitializeComponent();
+            this.network = network;
+
+            updateNetworkData();
+        }
+
+        private void updateNetworkData()
+        {
+            this.networkId.Text = network.nwid;
+            this.networkName.Text = network.name;
+            this.networkStatus.Text = network.status;
+            this.networkType.Text = network.type;
+            this.macAddress.Text = network.mac;
+            this.mtu.Text = network.mtu.ToString();
+            this.broadcastEnabled.Text = (network.broadcastEnabled ? "ENABLED" : "DISABLED");
+            this.bridgingEnabled.Text = (network.bridge ? "ENABLED" : "DISABLED");
+            this.deviceName.Text = network.portDeviceName;
+
+            string iplist = "";
+            for (int i = 0; i < network.assignedAddresses.Length; ++i)
+            {
+                iplist += network.assignedAddresses[i];
+                if (i < (network.assignedAddresses.Length - 1))
+                    iplist += "\n";
+            }
+
+            this.managedIps.Text = iplist;
+        }
+
+        public bool hasNetwork(ZeroTierNetwork network)
+        {
+            if (this.network.nwid.Equals(network.nwid))
+                return true;
+
+            return false;
         }
     }
 }

+ 11 - 0
windows/WinUI/NetworksPage.xaml

@@ -0,0 +1,11 @@
+<UserControl x:Class="WinUI.NetworksPage"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             mc:Ignorable="d" 
+             d:DesignHeight="300" d:DesignWidth="300">
+    <WrapPanel x:Name="wrapPanel" Background="#FF555555">
+
+    </WrapPanel>
+</UserControl>

+ 40 - 0
windows/WinUI/NetworksPage.xaml.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace WinUI
+{
+    /// <summary>
+    /// Interaction logic for NetworksPage.xaml
+    /// </summary>
+    public partial class NetworksPage : UserControl
+    {
+        public NetworksPage()
+        {
+            InitializeComponent();
+        }
+
+        public void setNetworks(List<ZeroTierNetwork> networks)
+        {
+            this.wrapPanel.Children.Clear();
+
+            for (int i = 0; i < networks.Count; ++i)
+            {
+                this.wrapPanel.Children.Add(
+                    new NetworkInfoView(
+                        networks.ElementAt<ZeroTierNetwork>(i)));
+            }
+        }
+    }
+}

+ 24 - 1
windows/WinUI/WinUI.csproj

@@ -55,7 +55,8 @@
     <StartupObject>WinUI.App</StartupObject>
   </PropertyGroup>
   <PropertyGroup>
-    <ApplicationIcon>ZeroTierIcon.ico</ApplicationIcon>
+    <ApplicationIcon>
+    </ApplicationIcon>
   </PropertyGroup>
   <PropertyGroup>
     <SignAssembly>false</SignAssembly>
@@ -64,9 +65,18 @@
     <SignManifests>false</SignManifests>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Accessibility" />
+    <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="PresentationUI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+    <Reference Include="ReachFramework" />
     <Reference Include="System" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Printing" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
@@ -76,6 +86,8 @@
     <Reference Include="System.Xaml">
       <RequiredTargetFramework>4.0</RequiredTargetFramework>
     </Reference>
+    <Reference Include="UIAutomationProvider" />
+    <Reference Include="UIAutomationTypes" />
     <Reference Include="WindowsBase" />
     <Reference Include="PresentationCore" />
     <Reference Include="PresentationFramework" />
@@ -85,10 +97,16 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="NetworksPage.xaml.cs">
+      <DependentUpon>NetworksPage.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="ZeroTierNetwork.cs" />
+    <Compile Include="ZeroTierStatus.cs" />
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Compile Include="APIHandler.cs" />
     <Compile Include="App.xaml.cs">
       <DependentUpon>App.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -101,6 +119,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="NetworksPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Simple Styles.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -131,6 +153,7 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
+    <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>

+ 26 - 0
windows/WinUI/ZeroTierNetwork.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WinUI
+{
+    public class ZeroTierNetwork
+    {
+        public string nwid;
+        public string mac;
+        public string name;
+        public string status;
+        public string type;
+        public int mtu;
+        public bool dhcp;
+        public bool bridge;
+        public bool broadcastEnabled;
+        public int portError;
+        public int netconfRevision;
+        public string[] multicastSubscriptions;
+        public string[] assignedAddresses;
+        public string portDeviceName;
+    }
+}

+ 21 - 0
windows/WinUI/ZeroTierStatus.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WinUI
+{
+    public class ZeroTierStatus
+    {
+        public string address;
+        public string publicIdentity;
+        public bool online;
+        public bool tcpFallbackActive;
+        public int versionMajor;
+        public int versionMinor;
+        public int versionRev;
+        public string version;
+        public UInt64 clock;
+    }
+}

+ 4 - 0
windows/WinUI/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
+</packages>

+ 3 - 0
windows/packages/.gitignore

@@ -0,0 +1,3 @@
+*
+!repositories.config
+!.gitignore

+ 4 - 0
windows/packages/repositories.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+  <repository path="..\WinUI\packages.config" />
+</repositories>