From 4762311977a2ebe26c6ac140bdcfc44d7733ff9a Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Nov 2016 12:39:57 -0700 Subject: work in progress windows UI update --- windows/WinUI/APIHandler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'windows/WinUI/APIHandler.cs') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 92b83021..83a22c66 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -107,7 +107,7 @@ namespace WinUI } } - public void JoinNetwork(string nwid) + public void JoinNetwork(string nwid, bool allowManaged = false, 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 { -- cgit v1.2.3 From 1ab9c431350b1e8cf22f27fe5814f1d4608b24a7 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Nov 2016 14:50:07 -0700 Subject: wire up allowDefault, allowManaged, allowGlobal, allowDefault options --- windows/WinUI/APIHandler.cs | 2 +- windows/WinUI/NetworkInfoView.xaml | 6 +++--- windows/WinUI/NetworkInfoView.xaml.cs | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'windows/WinUI/APIHandler.cs') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 83a22c66..2a8dea13 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -107,7 +107,7 @@ namespace WinUI } } - public void JoinNetwork(string nwid, bool allowManaged = false, bool allowGlobal = false, bool allowDefault = false) + 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) diff --git a/windows/WinUI/NetworkInfoView.xaml b/windows/WinUI/NetworkInfoView.xaml index 1ca488b1..aea85490 100644 --- a/windows/WinUI/NetworkInfoView.xaml +++ b/windows/WinUI/NetworkInfoView.xaml @@ -65,9 +65,9 @@ - - - + + + diff --git a/windows/WinUI/NetworkInfoView.xaml.cs b/windows/WinUI/NetworkInfoView.xaml.cs index 5c96b985..3ecc31b8 100644 --- a/windows/WinUI/NetworkInfoView.xaml.cs +++ b/windows/WinUI/NetworkInfoView.xaml.cs @@ -58,6 +58,14 @@ namespace WinUI 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) -- cgit v1.2.3 From e1f9f7b6dc80a5ad0db3fedc8f5b92d47cbdb1fe Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 15:50:08 -0800 Subject: turn APIHandler into a singleton --- windows/WinUI/APIHandler.cs | 91 ++++++++++++++++++++++++++++++++++++++- windows/WinUI/ToolbarItem.xaml.cs | 85 +----------------------------------- 2 files changed, 91 insertions(+), 85 deletions(-) (limited to 'windows/WinUI/APIHandler.cs') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 2a8dea13..f2fb1d21 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -7,6 +7,7 @@ using System.Net; using System.IO; using System.Windows; using Newtonsoft.Json; +using System.Diagnostics; namespace WinUI { @@ -18,7 +19,95 @@ namespace WinUI private string url = null; - public APIHandler() + private static APIHandler instance; + + public static APIHandler Instance + { + get + { + if (instance == null) + { + + } + + return instance; + } + } + + private static bool initHandler() + { + String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; + String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; + + String authToken = ""; + Int32 port = 9993; + + if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) + { + // launch external process to copy file into place + String curPath = System.Reflection.Assembly.GetEntryAssembly().Location; + int index = curPath.LastIndexOf("\\"); + curPath = curPath.Substring(0, index); + ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", globalZtDir + " " + localZtDir); + startInfo.Verb = "runas"; + + + var process = Process.Start(startInfo); + process.WaitForExit(); + } + + authToken = readAuthToken(localZtDir + "\\authtoken.secret"); + + if ((authToken == null) || (authToken.Length <= 0)) + { + MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); + return false; + } + + port = readPort(localZtDir + "\\zerotier-one.port"); + instance = new APIHandler(port, authToken); + return true; + } + + private static String readAuthToken(String path) + { + String authToken = ""; + + if (File.Exists(path)) + { + try + { + byte[] tmp = File.ReadAllBytes(path); + authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); + } + catch + { + MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); + } + } + + return authToken; + } + + private static Int32 readPort(String path) + { + Int32 port = 9993; + + try + { + byte[] tmp = File.ReadAllBytes(path); + port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); + if ((port <= 0) || (port > 65535)) + port = 9993; + } + catch + { + } + + return port; + } + + private APIHandler() { url = "http://127.0.0.1:9993"; } diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index e34863dd..9ff7e860 100644 --- a/windows/WinUI/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -24,94 +24,11 @@ namespace WinUI /// public partial class ToolbarItem : Window { - APIHandler handler; + APIHandler handler = APIHandler.Instance; public ToolbarItem() { InitializeComponent(); - - if (InitAPIHandler()) - { - - } - else - { - MessageBox.Show("ZeroTier API Initialization Failed"); - } - } - - private String readAuthToken(String path) - { - String authToken = ""; - - if (File.Exists(path)) - { - try - { - byte[] tmp = File.ReadAllBytes(path); - authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); - } - catch - { - MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); - } - } - - return authToken; - } - - private Int32 readPort(String path) - { - Int32 port = 9993; - - try - { - byte[] tmp = File.ReadAllBytes(path); - port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); - if ((port <= 0) || (port > 65535)) - port = 9993; - } - catch - { - } - - return port; - } - - private bool InitAPIHandler() - { - String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; - String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; - - String authToken = ""; - Int32 port = 9993; - - if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) - { - // launch external process to copy file into place - String curPath = System.Reflection.Assembly.GetEntryAssembly().Location; - int index = curPath.LastIndexOf("\\"); - curPath = curPath.Substring(0, index); - ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", globalZtDir + " " + localZtDir); - startInfo.Verb = "runas"; - - - var process = Process.Start(startInfo); - process.WaitForExit(); - } - - authToken = readAuthToken(localZtDir + "\\authtoken.secret"); - - if ((authToken == null) || (authToken.Length <= 0)) - { - MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); - this.Close(); - return false; - } - - port = readPort(localZtDir + "\\zerotier-one.port"); - handler = new APIHandler(port, authToken); - return true; } private void ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) -- cgit v1.2.3 From 7cf3d2caa19da076ebd3539c8786ce62a53d35f9 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 16:31:07 -0800 Subject: Network list window opens with click on the menu item --- windows/WinUI/APIHandler.cs | 14 ++- windows/WinUI/MainWindow.xaml | 132 --------------------------- windows/WinUI/MainWindow.xaml.cs | 166 ---------------------------------- windows/WinUI/NetworkInfoView.xaml.cs | 12 +-- windows/WinUI/NetworkList.xaml | 132 +++++++++++++++++++++++++++ windows/WinUI/NetworkList.xaml.cs | 153 +++++++++++++++++++++++++++++++ windows/WinUI/NetworksPage.xaml.cs | 8 -- windows/WinUI/ToolbarItem.xaml | 6 +- windows/WinUI/ToolbarItem.xaml.cs | 28 +++++- windows/WinUI/WinUI.csproj | 6 +- 10 files changed, 336 insertions(+), 321 deletions(-) delete mode 100644 windows/WinUI/MainWindow.xaml delete mode 100644 windows/WinUI/MainWindow.xaml.cs create mode 100644 windows/WinUI/NetworkList.xaml create mode 100644 windows/WinUI/NetworkList.xaml.cs (limited to 'windows/WinUI/APIHandler.cs') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index f2fb1d21..9cddd916 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -19,7 +19,8 @@ namespace WinUI private string url = null; - private static APIHandler instance; + private static volatile APIHandler instance; + private static object syncRoot = new Object(); public static APIHandler Instance { @@ -27,7 +28,16 @@ namespace WinUI { if (instance == null) { - + lock (syncRoot) + { + if (instance == null) + { + if (!initHandler()) + { + return null; + } + } + } } return instance; diff --git a/windows/WinUI/MainWindow.xaml b/windows/WinUI/MainWindow.xaml deleted file mode 100644 index 9d4a9fc1..00000000 --- a/windows/WinUI/MainWindow.xaml +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs b/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs new file mode 100644 index 00000000..72ba2182 --- /dev/null +++ b/windows/WinUI/OnboardProcess/CreateAccount.xaml.cs @@ -0,0 +1,66 @@ +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.OnboardProcess +{ + /// + /// Interaction logic for CreateAccount.xaml + /// + public partial class CreateAccount : UserControl, ISwitchable + { + public CreateAccount() + { + InitializeComponent(); + } + + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + public void CreateAccount_Click(object sender, RoutedEventArgs e) + { + DoCreateAccount(); + } + + public void BackButton_Click(object sender, RoutedEventArgs e) + { + Switcher.Switch(new RegisterOrLogIn()); + } + + public async void DoCreateAccount() + { + if (PasswordTextBox1.Password.ToString() != PasswordTextBox2.Password.ToString()) + { + ErrorText.Content = "Passwords do not match!"; + } + else + { + CentralAPI api = CentralAPI.Instance; + bool accountCreated = await api.Login(EmailAddressTextBox.Text, + PasswordTextBox1.Password.ToString(), true); + + if (accountCreated) + { + Switcher.Switch(new CreateOrJoin()); + } + else + { + ErrorText.Content = "An error ocurred while creating your account."; + } + } + } + } +} diff --git a/windows/WinUI/OnboardProcess/CreateOrJoin.xaml b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml new file mode 100644 index 00000000..21413e84 --- /dev/null +++ b/windows/WinUI/OnboardProcess/CreateOrJoin.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/OnboardProcess/Finished.xaml.cs b/windows/WinUI/OnboardProcess/Finished.xaml.cs new file mode 100644 index 00000000..a34abfe2 --- /dev/null +++ b/windows/WinUI/OnboardProcess/Finished.xaml.cs @@ -0,0 +1,37 @@ +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.OnboardProcess +{ + /// + /// Interaction logic for Finished.xaml + /// + public partial class Finished : UserControl, ISwitchable + { + public Finished() + { + InitializeComponent(); + } + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + private void DoneButton_Click(object sender, RoutedEventArgs e) + { + Window.GetWindow(this).Close(); + } + } +} diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml b/windows/WinUI/OnboardProcess/LogIn.xaml new file mode 100644 index 00000000..501f7e0f --- /dev/null +++ b/windows/WinUI/OnboardProcess/LogIn.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/OnboardProcess/LogIn.xaml.cs b/windows/WinUI/OnboardProcess/LogIn.xaml.cs new file mode 100644 index 00000000..8657b800 --- /dev/null +++ b/windows/WinUI/OnboardProcess/LogIn.xaml.cs @@ -0,0 +1,57 @@ +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.OnboardProcess +{ + /// + /// Interaction logic for LogIn.xaml + /// + public partial class LogIn : UserControl, ISwitchable + { + public LogIn() + { + InitializeComponent(); + } + + public void UtilizeState(object state) + { + throw new NotImplementedException(); + } + + public void LoginButton_Click(object sender, RoutedEventArgs e) + { + DoLogin(); + } + + public void BackButton_Click(object sender, RoutedEventArgs e) + { + Switcher.Switch(new RegisterOrLogIn()); + } + + private async void DoLogin() + { + CentralAPI api = CentralAPI.Instance; + bool didLogIn = await api.Login(EmailAddressTextBox.Text, PasswordTextBox.Password.ToString(), false); + if (didLogIn) + { + Switcher.Switch(new CreateOrJoin()); + } + else + { + ErrorText.Content = "Invalid username or password"; + } + } + } +} diff --git a/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml new file mode 100644 index 00000000..01f3ba9d --- /dev/null +++ b/windows/WinUI/OnboardProcess/RegisterOrLogIn.xaml @@ -0,0 +1,27 @@ + + + Welcome to ZeroTier + Let's get started! + + If you haven't yet created an account, click "Create Account" below. If you have an account, you can log in with your username/password, or simply enter an API key. + + + + +