diff --git a/ZitiTunneler/MainMenu.xaml.cs b/ZitiTunneler/MainMenu.xaml.cs
index 71e26e75..c00781f9 100644
--- a/ZitiTunneler/MainMenu.xaml.cs
+++ b/ZitiTunneler/MainMenu.xaml.cs
@@ -16,7 +16,7 @@ using System.Diagnostics;
using System.Windows.Navigation;
namespace ZitiTunneler
-{
+{
///
/// Interaction logic for MainMenu.xaml
///
@@ -26,7 +26,7 @@ namespace ZitiTunneler
// Clint: all these need to be wired to something
public string licenseData = "Clint, I need license data here.";
- public string logData = "Clint, I need log data here";
+
public string ip = "169.254.0.1";
public string subnet = "255.255.255.0";
public string mtu = "1600";
@@ -94,9 +94,11 @@ namespace ZitiTunneler
MenuTitle.Content = "Third Party Licenses";
LicensesItems.Visibility = Visibility.Visible;
BackArrow.Visibility = Visibility.Visible;
- } else if (menuState=="Logs") {
+ } else if (menuState=="Logs")
+ {
+ ServiceClient.Client client = (ServiceClient.Client)Application.Current.Properties["ServiceClient"];
MenuTitle.Content = "Application Logs";
- LogsItems.Text = logData;
+ LogsItems.Text = client.GetLogs();
LogsItems.Visibility = Visibility.Visible;
BackArrow.Visibility = Visibility.Visible;
} else if (menuState=="Config") {
diff --git a/ZitiTunneler/MainWindow.xaml b/ZitiTunneler/MainWindow.xaml
index e3c08c26..5a9adc11 100644
--- a/ZitiTunneler/MainWindow.xaml
+++ b/ZitiTunneler/MainWindow.xaml
@@ -1,15 +1,35 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -26,7 +46,7 @@
-
+
@@ -56,20 +76,22 @@
-
-
+
+
diff --git a/ZitiTunneler/MainWindow.xaml.cs b/ZitiTunneler/MainWindow.xaml.cs
index f6a5af86..1e44b336 100644
--- a/ZitiTunneler/MainWindow.xaml.cs
+++ b/ZitiTunneler/MainWindow.xaml.cs
@@ -13,9 +13,11 @@ namespace ZitiTunneler {
///
/// Interaction logic for MainWindow.xaml
///
- public partial class MainWindow:Window
- {
+ public partial class MainWindow:Window {
+
public System.Windows.Forms.NotifyIcon notifyIcon;
+ private DateTime _startDate;
+ private System.Windows.Forms.Timer _timer;
private ServiceClient.Client serviceClient = null;
private List identities
@@ -33,6 +35,7 @@ namespace ZitiTunneler {
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Visible = true;
notifyIcon.Click += TargetNotifyIcon_Click;
+ notifyIcon.Visible = true;
SetNotifyIcon("white");
@@ -40,14 +43,20 @@ namespace ZitiTunneler {
}
private void TargetNotifyIcon_Click(object sender, EventArgs e) {
+ this.Show();
+ this.Activate();
+ /*
if (App.Current.MainWindow.WindowState==WindowState.Minimized) {
App.Current.MainWindow.WindowState = WindowState.Normal;
App.Current.MainWindow.BringIntoView();
//this.Opacity = 1;
+ //this.Activate();
} else {
App.Current.MainWindow.WindowState = WindowState.Minimized;
+ this.Close();
//this.Opacity = 0;
}
+ */
}
private void MainWindow1_Loaded(object sender, RoutedEventArgs e) {
@@ -74,24 +83,7 @@ namespace ZitiTunneler {
private void updateViewWithIdentity(Identity id)
{
- var zid = ZitiIdentity.FromClient(id);/*new ZitiIdentity()
- {
- Name = id.Name,
- ControllerUrl = id.Config.ztAPI,
- Fingerprint = id.FingerPrint,
- EnrollmentStatus = id.Status,
- Status = id.Status,
- IsEnabled = id.Active
- };
- if (id.Services != null)
- {
- foreach (var svc in id.Services)
- {
- var zsvc = new ZitiService(svc.Name, svc.HostName + ":" + svc.Port);
- zid.Services.Add(zsvc);
- services.Add(zsvc);
- }
- }*/
+ var zid = ZitiIdentity.FromClient(id);
identities.Add(zid);
}
private void SetNotifyIcon(string iconPrefix) {
@@ -110,6 +102,8 @@ namespace ZitiTunneler {
}
UIMain.Height = 480+(identities.Count*60);
BgColor.Height = 480+(identities.Count*60);
+ FormGrowAnimation.To = UIMain.Height;
+ FormGrowOutAnimation.From = BgColor.Height;
App.Current.MainWindow.Height = 490+(identities.Count*60);
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right-this.Width-25;
@@ -131,37 +125,18 @@ namespace ZitiTunneler {
jwtDialog.Filter = "Ziti Identities (*.jwt)|*.jwt";
if (jwtDialog.ShowDialog() == true) {
string fileContent = File.ReadAllText(jwtDialog.FileName);
-
- // Jeremy!! AxedaBuddy - DUN!
- try
- {
- Identity createdId = serviceClient.AddIdentity(System.IO.Path.GetFileName(jwtDialog.FileName), false, fileContent);
- if (createdId != null)
- {
- identities.Add(ZitiIdentity.FromClient(createdId));
- MessageBox.Show("New identity added with fingerprint: " + createdId.FingerPrint);
- updateViewWithIdentity(createdId);
- }
- else
- {
- // Jeremy buddy - error popup here
- MessageBox.Show("created id was null - wtf jeremy. your fault");
- }
- }
- catch(ServiceClient.ServiceException se)
- {
- MessageBox.Show(se.AdditionalInfo, se.Message);
- }
- catch(Exception ex)
- {
- MessageBox.Show("Unexpected error", ex.Message);
- }
+ // Clint!! AxedaBuddy - What to do with the jwt file?
}
- LoadIdentities();
}
private void Connect(object sender, RoutedEventArgs e) {
SetNotifyIcon("green");
+ _startDate = DateTime.Now;
+ _timer = new System.Windows.Forms.Timer();
+ _timer.Interval = 1000;
+ _timer.Tick += OnTimedEvent;
+ _timer.Enabled = true;
+ _timer.Start();
ConnectButton.Visibility = Visibility.Collapsed;
DisconnectButton.Visibility = Visibility.Visible;
@@ -178,7 +153,20 @@ namespace ZitiTunneler {
MessageBox.Show("Unexpected error", ex.Message);
}
}
+
+ private void OnTimedEvent(object sender, EventArgs e) {
+ TimeSpan span = (DateTime.Now - _startDate);
+ int hours = span.Hours;
+ int minutes = span.Minutes;
+ int seconds = span.Seconds;
+ var hoursString = (hours>9)?hours.ToString():"0"+hours;
+ var minutesString = (minutes>9)? minutes.ToString():"0"+minutes;
+ var secondsString = (seconds>9) ? seconds.ToString() : "0"+seconds;
+ ConnectedTime.Content = hoursString+":"+minutesString+":"+secondsString;
+ }
+
private void Disconnect(object sender, RoutedEventArgs e) {
+ _timer.Stop();
SetNotifyIcon("white");
ConnectButton.Visibility = Visibility.Visible;
DisconnectButton.Visibility = Visibility.Collapsed;
@@ -196,5 +184,19 @@ namespace ZitiTunneler {
MessageBox.Show("Unexpected error", ex.Message);
}
}
+
+
+
+ private void FormFadeOut_Completed(object sender, EventArgs e) {
+ closeCompleted = true;
+ //this.Close();
+ }
+ private bool closeCompleted = false;
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
+ if (!closeCompleted) {
+ FormFadeOut.Begin();
+ e.Cancel = true;
+ }
+ }
}
}
diff --git a/ZitiTunneler/ServiceClient/ClientImpl.cs b/ZitiTunneler/ServiceClient/ClientImpl.cs
index 7605eac6..e807f22f 100644
--- a/ZitiTunneler/ServiceClient/ClientImpl.cs
+++ b/ZitiTunneler/ServiceClient/ClientImpl.cs
@@ -20,9 +20,11 @@ namespace ZitiTunneler.ServiceClient
JsonSerializer serializer = new JsonSerializer();
private object namedPipeSyncLock = new object();
- const string namedPipe = @"NetFoundry\tunneler\ipc";
+ const string ipcPipe = @"NetFoundry\tunneler\ipc";
+ const string logPipe = @"NetFoundry\tunneler\logs";
const string localPipeServer = ".";
const PipeDirection inOut = PipeDirection.InOut;
+ const int ServiceConnectTimeout = 5000;
NamedPipeClientStream pipeClient = null;
StreamWriter writer = null;
@@ -42,10 +44,10 @@ namespace ZitiTunneler.ServiceClient
{
pipeClient.Dispose();
}
- pipeClient = new NamedPipeClientStream(localPipeServer, namedPipe, inOut);
+ pipeClient = new NamedPipeClientStream(localPipeServer, ipcPipe, inOut);
writer = new StreamWriter(pipeClient);
reader = new StreamReader(pipeClient);
- pipeClient.Connect();
+ pipeClient.Connect(ServiceConnectTimeout);
}
}
@@ -136,6 +138,30 @@ namespace ZitiTunneler.ServiceClient
}
}
+ public string GetLogs()
+ {
+ NamedPipeClientStream logClient = new NamedPipeClientStream(localPipeServer, logPipe, PipeDirection.In);
+ reader = new StreamReader(logClient);
+ logClient.Connect(ServiceConnectTimeout);
+ /*
+ string line = null;
+ System.Text.StringBuilder sb = new System.Text.StringBuilder();
+ do
+ {
+ line = reader.ReadLine();
+ sb.Append(line);
+ sb.Append("\r\n");
+ Debug.WriteLine(line);
+ } while (line != null);
+ */
+ string content = reader.ReadToEnd();
+ //string content = sb.ToString();
+ //ugly hack to turn ansi escaping to not... _bleck_
+ //todo: fix this :point_up:
+ content = new System.Text.RegularExpressions.Regex(@"\x1B\[[^@-~]*[@-~]").Replace(content, "");
+ return content;
+ }
+
public void IdentityOnOff(Identity id)
{
string msg = @"{""Function"":""IdentityOnOff"", ""Payload"": { ""fingerprint"" : ""FINGERPRINTHERE"", ""onOff"" : true } }";
diff --git a/wintun-testing/winio/config/config.go b/wintun-testing/winio/config/config.go
index 36a1b28d..83002cb0 100644
--- a/wintun-testing/winio/config/config.go
+++ b/wintun-testing/winio/config/config.go
@@ -46,6 +46,7 @@ func InitLogger(level string) {
logLevel := ParseLevel(level)
logrus.SetLevel(logLevel)
+ _ = os.Remove(LogFile()) //reset the log on startup
multiWriter := io.MultiWriter(os.Stdout, &lumberjack.Logger{
Filename: LogFile(),
MaxSize: 1, // megabytes
diff --git a/wintun-testing/winio/main.go b/wintun-testing/winio/main.go
index 774667a7..acd8b5b8 100644
--- a/wintun-testing/winio/main.go
+++ b/wintun-testing/winio/main.go
@@ -5,16 +5,15 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
- "io"
- "io/ioutil"
- "net"
- "os"
-
"github.com/Microsoft/go-winio"
"github.com/michaelquigley/pfxlog"
"github.com/netfoundry/ziti-foundation/identity/identity"
idcfg "github.com/netfoundry/ziti-sdk-golang/ziti/config"
"github.com/netfoundry/ziti-sdk-golang/ziti/enroll"
+ "io"
+ "io/ioutil"
+ "net"
+ "os"
"wintun-testing/winio/config"
"wintun-testing/winio/dto"
@@ -120,9 +119,9 @@ func serveIpc(conn net.Conn) {
case "RemoveIdentity":
log.Debugf("Request received to remove an identity")
removeIdentity(enc, cmd.Payload["Fingerprint"].(string))
- case "GetLogData":
- log.Debugf("request for log data received")
- _ = enc.Encode(dto.Response{Message: "this is my message"})
+ /*case "GetLogStream":
+ log.Debugf("request for log data received")
+ getLogs(*writer);*/
case "Status":
reportStatus(enc)
case "TunnelState":
@@ -163,12 +162,19 @@ func serveLogs(conn net.Conn) {
}
r := bufio.NewReader(file)
+ wrote, err := io.Copy(w, r)
+ if err != nil{
+ log.Errorf("problem responding with log data")
+ }
+ log.Debugf("wrote %d bytes to client from logs", wrote)
+ w.Write([]byte("end of logs\n"))
+ w.Flush()
+ _ = conn.Close() //close the connection
+
err = file.Close()
if err != nil {
log.Error("error closing log file", err)
}
- io.Copy(w,r)
- _ = conn.Close() //close the connection
}
func reportStatus(out *json.Encoder) {
@@ -240,7 +246,6 @@ func newIdentity(newId dto.AddIdentity, out *json.Encoder) {
"Check the process has access to the temporary folder", COULD_NOT_WRITE_FILE, err)
return
}
- defer removeTempFile(*enrolled)
enc := json.NewEncoder(enrolled)
enc.SetEscapeHTML(false)
@@ -268,19 +273,17 @@ func newIdentity(newId dto.AddIdentity, out *json.Encoder) {
newId.Id.Status = "Enrolled"
err = enrolled.Close()
- if err != nil{
+ if err != nil {
panic(err)
}
newPath := config.Path() + newId.Id.FingerPrint + ".json"
//move the temp file to its final home after enrollment
err = os.Rename(enrolled.Name(), newPath)
- if err != nil{
+ if err != nil {
log.Errorf("unexpected issue renaming the enrollment! attempting to remove the temporary file at: %s", enrolled.Name())
- err = os.Remove(enrolled.Name()) //if this fails... we tried :(
- if err != nil {
- log.Panic(err)
- }
+ removeTempFile(*enrolled)
+ respondWithError(out, "a problem occurred while writing the identity file.", COULD_NOT_ENROLL, err)
}
//newId.Id.Active = false //set to false by default - enable the id after persisting