diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-11-04 20:34:49 -0800 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-11-04 20:34:49 -0800 |
commit | 86c74d8a65ae45d6ff0433da7d4d4acb6cba8fcb (patch) | |
tree | aaa63e4fba3a2fa86803721753e8903d0957a910 /windows/WinUI/MainWindow.xaml.cs | |
parent | 49086e4556bbe0c31abb8d4e640d854859430d49 (diff) | |
download | infinitytier-86c74d8a65ae45d6ff0433da7d4d4acb6cba8fcb.tar.gz infinitytier-86c74d8a65ae45d6ff0433da7d4d4acb6cba8fcb.zip |
set manifest to require administrator privileges and read the authtoken and port from disk
Diffstat (limited to 'windows/WinUI/MainWindow.xaml.cs')
-rw-r--r-- | windows/WinUI/MainWindow.xaml.cs | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index 103165b3..535cb386 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -23,7 +24,7 @@ namespace WinUI /// </summary> public partial class MainWindow : Window { - APIHandler handler = new APIHandler(); + APIHandler handler; Regex charRegex = new Regex("[0-9a-fxA-FX]"); Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); @@ -35,22 +36,63 @@ namespace WinUI { InitializeComponent(); - networksPage.SetAPIHandler(handler); - - updateStatus(); - if (!connected) + if (InitAPIHandler()) { - MessageBox.Show("Unable to connect to ZeroTier Service."); + networksPage.SetAPIHandler(handler); + + updateStatus(); + if (!connected) + { + MessageBox.Show("Unable to connect to ZeroTier Service."); + } + + updateNetworks(); + updatePeers(); + + DataObject.AddPastingHandler(joinNetworkID, OnPaste); + + timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); + timer.Interval = 2000; + timer.Enabled = true; } + } - updateNetworks(); - updatePeers(); + private bool InitAPIHandler() + { + String ztDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; + String authToken = ""; + Int32 port = 9993; + try + { + byte[] tmp = File.ReadAllBytes(ztDir + "\\authtoken.secret"); + authToken = System.Text.Encoding.ASCII.GetString(tmp).Trim(); + } + catch + { + MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One"); + this.Close(); + return false; + } - DataObject.AddPastingHandler(joinNetworkID, OnPaste); + if ((authToken == null) || (authToken.Length <= 0)) + { + MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One"); + this.Close(); + return false; + } + try + { + byte[] tmp = File.ReadAllBytes(ztDir + "\\zerotier-one.port"); + port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); + if ((port <= 0) || (port > 65535)) + port = 9993; + } + catch + { + } - timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); - timer.Interval = 2000; - timer.Enabled = true; + handler = new APIHandler(port, authToken); + return true; } private void updateStatus() |