merge origin/master again - small tweaks, cleanups, etc

This commit is contained in:
dovholuknf
2020-04-21 00:02:30 -04:00
6 changed files with 143 additions and 87 deletions
+6 -4
View File
@@ -16,7 +16,7 @@ using System.Diagnostics;
using System.Windows.Navigation;
namespace ZitiTunneler
{
{
/// <summary>
/// Interaction logic for MainMenu.xaml
/// </summary>
@@ -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") {
+39 -17
View File
@@ -1,15 +1,35 @@
<Window x:Name="MainWindow1" x:Class="ZitiTunneler.MainWindow"
<Window x:Class="ZitiTunneler.MainWindow"
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"
xmlns:local="clr-namespace:ZitiTunneler"
mc:Ignorable="d"
ShowInTaskbar="True"
ShowInTaskbar="False"
x:Name="MainUI"
Title="MainWindow" Height="510"
Width="375" ResizeMode="NoResize"
Icon="Assets/Images/icon.png" AllowsTransparency="True"
Closing="Window_Closing"
WindowStyle="None" Loaded="MainWindow1_Loaded" Background="#000F0F23">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard Name="FormFade">
<DoubleAnimation Name="FormFadeAnimation" Storyboard.TargetName="MainUI" Storyboard.TargetProperty="(Window.Opacity)" From="0.0" To="1.0" Duration="0:0:.5" AutoReverse="False" RepeatBehavior="1x" />
<DoubleAnimation Name="FormGrowAnimation" Storyboard.TargetName="MainUI" Storyboard.TargetProperty="(Window.Height)" From="300" To="575" Duration="0:0:.5" AutoReverse="False" RepeatBehavior="1x" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Window.Unloaded">
<BeginStoryboard>
<Storyboard Name="FormFadeOut" Completed="FormFadeOut_Completed">
<DoubleAnimation Name="FormGrowOutAnimation" Storyboard.TargetName="MainUI" Storyboard.TargetProperty="(Window.Height)" From="575" To="200" Duration="0:0:.5" AutoReverse="False" RepeatBehavior="1x" />
<DoubleAnimation Name="FormFadeOutAnimation" Storyboard.TargetName="MainUI" Storyboard.TargetProperty="(Window.Opacity)" From="1.0" To="0.0" Duration="0:0:.5" AutoReverse="False" RepeatBehavior="1x" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Window.Resources>
<Storyboard x:Key="gridFadeInStoryBoard">
<DoubleAnimation Storyboard.TargetName="UIMain" BeginTime="0:0:0.1" Storyboard.TargetProperty="Opacity" From="0.00" To="1.00" AutoReverse="False" Duration="0:0:0.3" />
@@ -26,7 +46,7 @@
</Rectangle>
<Border Name="UIBorder" Width="375" Height="510" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="3" CornerRadius="10">
<Border.Effect>
<DropShadowEffect />
<DropShadowEffect BlurRadius="15" Direction="0" RenderingBias="Quality" ShadowDepth="2" Opacity="0.2"/>
</Border.Effect>
</Border>
<Rectangle Name="BgColor" Width="375" Height="510" Stroke="Black" RadiusY="10" RadiusX="10" ClipToBounds="True">
@@ -56,20 +76,22 @@
<Label Content="IDENTITY" FontFamily="pack://application:,,,/Assets/Fonts/#Open Sans" Foreground="White" Height="25" Margin="0,-14,0,0" FontSize="12" HorizontalAlignment="Right"></Label>
</StackPanel>
</Grid>
<Button Name="ConnectButton" Height="160" Click="Connect">
<Button.Template>
<ControlTemplate>
<Image Source="/Assets/Images/connect.png" />
</ControlTemplate>
</Button.Template>
</Button>
<Button Name="DisconnectButton" Height="160" Click="Disconnect" Visibility="Collapsed">
<Button.Template>
<ControlTemplate>
<Image Source="/Assets/Images/connected.png" />
</ControlTemplate>
</Button.Template>
</Button>
<Canvas Name="ConnectButton" Width="375" Height="160" MouseDown="Connect" Visibility="Visible">
<Grid Width="{Binding ActualWidth, ElementName=ConnectButton}" Height="180">
<Image Source="/Assets/Images/connect.png" Height="180" HorizontalAlignment="Center" />
</Grid>
</Canvas>
<Canvas Name="DisconnectButton" Width="375" Height="160" MouseDown="Disconnect" Visibility="Collapsed">
<Grid Width="{Binding ActualWidth, ElementName=DisconnectButton}" Height="180">
<Image Source="/Assets/Images/connected.png" Height="180" HorizontalAlignment="Center" />
</Grid>
<Grid Width="{Binding ActualWidth, ElementName=DisconnectButton}" Height="180">
<Label Name="ConnectedTime" HorizontalAlignment="Center" Content="00:00:00" Foreground="White" Padding="0,115,0,0"/>
</Grid>
<Grid Width="{Binding ActualWidth, ElementName=DisconnectButton}" Height="180">
<Label HorizontalAlignment="Center" Content="STOP" Foreground="White" Padding="0,130,0,0"/>
</Grid>
</Canvas>
<Grid HorizontalAlignment="Stretch" Width="Auto" Margin="0,30,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
+48 -46
View File
@@ -13,9 +13,11 @@ namespace ZitiTunneler {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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<ZitiIdentity> 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;
}
}
}
}
+29 -3
View File
@@ -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 } }";
+1
View File
@@ -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
+20 -17
View File
@@ -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