summaryrefslogtreecommitdiff
path: root/windows/WebUIWrapper/Form1.cs
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-05-13 20:52:23 -0700
committerGrant Limberg <glimberg@gmail.com>2015-05-13 20:52:23 -0700
commit4a0280686c7a74b58a060375ffce385554d90040 (patch)
treeaddbccc48f967f5e80ff31641f530c9d282766a2 /windows/WebUIWrapper/Form1.cs
parentda45840e5ad87aa86f67fbe20d0cb003d982b0f0 (diff)
parenta8835cd8b33903440f372ed66f4e3b49745ea68f (diff)
downloadinfinitytier-4a0280686c7a74b58a060375ffce385554d90040.tar.gz
infinitytier-4a0280686c7a74b58a060375ffce385554d90040.zip
Merge branch 'adamierymenko-dev' into android-jni
Diffstat (limited to 'windows/WebUIWrapper/Form1.cs')
-rw-r--r--windows/WebUIWrapper/Form1.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/windows/WebUIWrapper/Form1.cs b/windows/WebUIWrapper/Form1.cs
new file mode 100644
index 00000000..40d5da9d
--- /dev/null
+++ b/windows/WebUIWrapper/Form1.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+
+namespace WebUIWrapper
+{
+ public partial class Form1 : Form
+ {
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ 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();
+ }
+ if ((authToken == null)||(authToken.Length <= 0))
+ {
+ MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One");
+ this.Close();
+ }
+ 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
+ {
+ }
+ try
+ {
+ TcpClient tc = new TcpClient();
+ try
+ {
+ tc.Connect("127.0.0.1", port);
+ tc.Close();
+ }
+ catch
+ {
+ MessageBox.Show("ZeroTier One service does not appear to be running at local port " + port.ToString(),"ZeroTier One");
+ this.Close();
+ return;
+ }
+ webContainer.Navigate("http://127.0.0.1:" + port.ToString() + "/index.html?authToken=" + authToken);
+ }
+ catch
+ {
+ MessageBox.Show("Unable to open service control panel.", "ZeroTier One");
+ this.Close();
+ }
+ }
+ }
+}