diff --git a/DesktopEdge/Assets/Images/Success.png b/DesktopEdge/Assets/Images/Success.png new file mode 100644 index 00000000..d9532ab4 Binary files /dev/null and b/DesktopEdge/Assets/Images/Success.png differ diff --git a/DesktopEdge/MainMenu.xaml b/DesktopEdge/MainMenu.xaml index e6fc069e..36ba6a25 100644 --- a/DesktopEdge/MainMenu.xaml +++ b/DesktopEdge/MainMenu.xaml @@ -58,6 +58,16 @@ + + + + + + + + + + @@ -71,7 +81,8 @@ - + + diff --git a/DesktopEdge/MainMenu.xaml.cs b/DesktopEdge/MainMenu.xaml.cs index 397b93b4..04204d7c 100644 --- a/DesktopEdge/MainMenu.xaml.cs +++ b/DesktopEdge/MainMenu.xaml.cs @@ -10,6 +10,9 @@ using System.Reflection; using System.Web; using System.Net.Mail; using System.IO; +using System.Net; +using Newtonsoft.Json.Linq; +using System.Threading.Tasks; namespace ZitiDesktopEdge { @@ -21,12 +24,18 @@ namespace ZitiDesktopEdge public delegate void AttachementChanged(bool attached); public event AttachementChanged OnAttachmentChange; + public delegate void LogLevelChanged(string level); + public event LogLevelChanged OnLogLevelChanged; public string menuState = "Main"; public string licenseData = "it's open source."; + public string LogLevel = ""; + private string _updateUrl = "https://api.github.com/repos/openziti/desktop-edge-win/releases/latest"; + private string _downloadUrl = ""; public MainMenu() { InitializeComponent(); LicensesItems.Text = licenseData; + CheckUpdates(); } private void HideMenu(object sender, MouseButtonEventArgs e) { @@ -39,6 +48,10 @@ namespace ZitiDesktopEdge Application.Current.Shutdown(); } + private void DoUpdate(object sender, MouseButtonEventArgs e) { + System.Diagnostics.Process.Start(_downloadUrl); + } + private void ShowAbout(object sender, MouseButtonEventArgs e) { menuState = "About"; UpdateState(); @@ -64,6 +77,39 @@ namespace ZitiDesktopEdge menuState = "UILogs"; UpdateState(); } + private void SetLogLevel(object sender, MouseButtonEventArgs e) { + menuState = "LogLevel"; + UpdateState(); + } + + private void CheckUpdates() { + HttpWebRequest httpWebRequest = WebRequest.CreateHttp(_updateUrl); + httpWebRequest.Method = "GET"; + httpWebRequest.ContentType = "application/json"; + httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"; + HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); + StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()); + string result = streamReader.ReadToEnd(); + JObject json = JObject.Parse(result); + string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + string serverVersion = json.Property("tag_name").Value.ToString() + ".0"; + + Version installed = new Version(currentVersion); + Version published = new Version(serverVersion); + int compare = installed.CompareTo(published); + if (compare<0) { + UpdateAvailable.Content = "An Upgrade is available, click to download"; + UpdateAvailable.Visibility = Visibility.Visible; + } else if (compare>0) { + UpdateAvailable.Content = "Your version is newer than the released version"; + UpdateAvailable.Visibility = Visibility.Visible; + } + JArray assets = JArray.Parse(json.Property("assets").Value.ToString()); + foreach (JObject asset in assets.Children()) { + _downloadUrl = asset.Property("browser_download_url").Value.ToString(); + break; + } + } private void UpdateState() { MainItems.Visibility = Visibility.Collapsed; @@ -75,6 +121,7 @@ namespace ZitiDesktopEdge LicensesItems.Visibility = Visibility.Collapsed; LogsItems.Visibility = Visibility.Collapsed; ConfigItems.Visibility = Visibility.Collapsed; + LogLevelItems.Visibility = Visibility.Collapsed; if (menuState == "About") { MenuTitle.Content = "About"; @@ -82,8 +129,15 @@ namespace ZitiDesktopEdge AboutItems.Visibility = Visibility.Visible; BackArrow.Visibility = Visibility.Visible; - ZitiDesktopEdge.ServiceClient.TunnelStatus s = (ZitiDesktopEdge.ServiceClient.TunnelStatus)Application.Current.Properties["CurrentTunnelStatus"]; - string version = $"{s.ServiceVersion.Version}@{s.ServiceVersion.Revision}"; + string version = ""; + try { + ServiceClient.TunnelStatus s = (ServiceClient.TunnelStatus)Application.Current.Properties["CurrentTunnelStatus"]; + version = $"{s.ServiceVersion.Version}@{s.ServiceVersion.Revision}"; + } catch (Exception e) { +#if DEBUG + Debug.WriteLine(e.ToString()); +#endif + } // Interface Version VersionInfo.Content = "App: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()+" Service: "+ version; @@ -107,6 +161,12 @@ namespace ZitiDesktopEdge LogsItems.Text = UILog.GetLogs(); LogsItems.Visibility = Visibility.Visible; BackArrow.Visibility = Visibility.Visible; + } else if (menuState == "LogLevel") { + ResetLevels(); + + MenuTitle.Content = "Set Log Level"; + LogLevelItems.Visibility = Visibility.Visible; + BackArrow.Visibility = Visibility.Visible; } else if (menuState=="Config") { MenuTitle.Content = "Tunnel Configuration"; ConfigItems.Visibility = Visibility.Visible; @@ -213,5 +273,32 @@ namespace ZitiDesktopEdge OnAttachmentChange(true); } } + + private void ResetLevels() { + if (this.LogLevel == "") this.LogLevel = "error"; + LogVerbose.IsSelected = false; + LogDebug.IsSelected = false; + LogInfo.IsSelected = false; + LogError.IsSelected = false; + LogFatal.IsSelected = false; + LogWarn.IsSelected = false; + LogTrace.IsSelected = false; + if (this.LogLevel == "verbose") LogVerbose.IsSelected = true; + else if (this.LogLevel == "debug") LogDebug.IsSelected = true; + else if (this.LogLevel == "info") LogInfo.IsSelected = true; + else if (this.LogLevel == "error") LogError.IsSelected = true; + else if (this.LogLevel == "fatal") LogFatal.IsSelected = true; + else if (this.LogLevel == "warn") LogWarn.IsSelected = true; + else if (this.LogLevel == "trace") LogTrace.IsSelected = true; + } + + private void SetLevel(object sender, MouseButtonEventArgs e) { + SubOptionItem item = (SubOptionItem)sender; + this.LogLevel = item.Label.ToLower(); + if (OnLogLevelChanged != null) { + OnLogLevelChanged(this.LogLevel); + } + ResetLevels(); + } } } diff --git a/DesktopEdge/MainWindow.xaml.cs b/DesktopEdge/MainWindow.xaml.cs index 1e93941d..ec61e71c 100644 --- a/DesktopEdge/MainWindow.xaml.cs +++ b/DesktopEdge/MainWindow.xaml.cs @@ -65,7 +65,6 @@ namespace ZitiDesktopEdge { LaunchOrInstall(); SetNotifyIcon("white"); - InitializeComponent(); } private void MainWindow_Activated(object sender, EventArgs e) { @@ -127,6 +126,7 @@ namespace ZitiDesktopEdge { Application.Current.Properties.Add("ServiceClient", serviceClient); Application.Current.Properties.Add("Identities", new List()); MainMenu.OnAttachmentChange += AttachmentChanged; + MainMenu.OnLogLevelChanged += LogLevelChanged; IdentityMenu.OnError += IdentityMenu_OnError; try { @@ -141,6 +141,10 @@ namespace ZitiDesktopEdge { IdentityMenu.OnForgot += IdentityForgotten; } + private void LogLevelChanged(string level) { + serviceClient.SetLogLevel(level); + } + private void IdentityMenu_OnError(string message) { ShowError("Identity Error", message); } @@ -247,7 +251,7 @@ namespace ZitiDesktopEdge { SetCantDisplay("Version mismatch!", "The version of the Service is not compatible"); return; } - + this.MainMenu.LogLevel = e.Status.LogLevel; InitializeTimer((int)e.Status.Duration); LoadStatusFromService(e.Status); LoadIdentities(false); @@ -395,6 +399,7 @@ namespace ZitiDesktopEdge { try { Identity createdId = serviceClient.AddIdentity(System.IO.Path.GetFileName(jwtDialog.FileName), false, fileContent); ServiceClient.Client client = (ServiceClient.Client)Application.Current.Properties["ServiceClient"]; + client.IdentityOnOff(createdId.FingerPrint, true); if (createdId != null) { identities.Add(ZitiIdentity.FromClient(createdId)); diff --git a/DesktopEdge/Properties/AssemblyInfo.cs b/DesktopEdge/Properties/AssemblyInfo.cs index 9155285a..73575b2d 100644 --- a/DesktopEdge/Properties/AssemblyInfo.cs +++ b/DesktopEdge/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.2.7.0")] +[assembly: AssemblyFileVersion("1.2.7.0")] diff --git a/DesktopEdge/ServiceClient/ClientImpl.cs b/DesktopEdge/ServiceClient/ClientImpl.cs index 901c7078..e2cb9c03 100644 --- a/DesktopEdge/ServiceClient/ClientImpl.cs +++ b/DesktopEdge/ServiceClient/ClientImpl.cs @@ -390,6 +390,18 @@ namespace ZitiDesktopEdge.ServiceClient } } + public void SetLogLevel(string level) { + try { + send(new SetLogLevelFunction(level)); + SvcResponse resp = read(ipcReader); + return; + } catch (IOException ioe) { + //almost certainly a problem with the pipe - recreate the pipe... + //setupPipe(); + throw ioe; + } + } + public void SetLogLevel(LogLevelEnum level) { try diff --git a/DesktopEdge/ServiceClient/DataStructures.cs b/DesktopEdge/ServiceClient/DataStructures.cs index cc464fde..d4e163d6 100644 --- a/DesktopEdge/ServiceClient/DataStructures.cs +++ b/DesktopEdge/ServiceClient/DataStructures.cs @@ -198,23 +198,25 @@ namespace ZitiDesktopEdge.ServiceClient public void Dump(System.IO.TextWriter writer) { - writer.WriteLine($"Tunnel Active: {Active}"); - writer.WriteLine($" ServiceVersion : {ServiceVersion}"); - writer.WriteLine($" LogLevel : {LogLevel}"); - writer.WriteLine($" EvaluatedLogLevel: {EvaluateLogLevel()}"); - foreach (Identity id in Identities) - { - writer.WriteLine($" FingerPrint: {id.FingerPrint}"); - writer.WriteLine($" Name : {id.Name}"); - writer.WriteLine($" Active : {id.Active}"); - writer.WriteLine($" Status : {id.Status}"); - writer.WriteLine($" Services:"); - foreach (Service s in id?.Services) - { - writer.WriteLine($" Name: {s.Name} HostName: {s.InterceptHost} Port: {s.InterceptPort}"); + try { + writer.WriteLine($"Tunnel Active: {Active}"); + writer.WriteLine($" LogLevel : {LogLevel}"); + writer.WriteLine($" EvaluatedLogLevel: {EvaluateLogLevel()}"); + foreach (Identity id in Identities) { + writer.WriteLine($" FingerPrint: {id.FingerPrint}"); + writer.WriteLine($" Name : {id.Name}"); + writer.WriteLine($" Active : {id.Active}"); + writer.WriteLine($" Status : {id.Status}"); + writer.WriteLine($" Services:"); + foreach (Service s in id.Services) { + writer.WriteLine($" Name: {s.Name} HostName: {s.InterceptHost} Port: {s.InterceptPort}"); + } + writer.WriteLine("============================================="); } - writer.WriteLine("============================================="); - } + } catch (Exception e) { + if (writer!=null) writer.WriteLine(e.ToString()); + } + } public LogLevelEnum EvaluateLogLevel() diff --git a/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml b/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml new file mode 100644 index 00000000..07088256 --- /dev/null +++ b/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml.cs b/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml.cs new file mode 100644 index 00000000..8a4467e8 --- /dev/null +++ b/DesktopEdge/Views/ItemRenderers/SubOptionItem.xaml.cs @@ -0,0 +1,50 @@ +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 ZitiDesktopEdge { + /// + /// Interaction logic for MenuItem.xaml + /// + public partial class SubOptionItem : UserControl { + + private string _label = ""; + private bool _isSelected = false; + + public string Label { + get { + return _label; + } + set { + this._label = value; + MainLabel.Content = this._label; + } + } + + public bool IsSelected { + get { + return _isSelected; + } + set { + this._isSelected = value; + if (this._isSelected) SelectedCheck.Visibility = Visibility.Visible; + else SelectedCheck.Visibility = Visibility.Collapsed; + } + } + + public SubOptionItem() { + InitializeComponent(); + } + } +} diff --git a/DesktopEdge/ZitiDesktopEdge.csproj b/DesktopEdge/ZitiDesktopEdge.csproj index d745cd13..76aca7dd 100644 --- a/DesktopEdge/ZitiDesktopEdge.csproj +++ b/DesktopEdge/ZitiDesktopEdge.csproj @@ -34,7 +34,7 @@ Ziti true 0 - 1.2.1.%2a + 1.2.7.%2a false true true @@ -147,6 +147,9 @@ RegistrationScreen.xaml + + SubOptionItem.xaml + SubMenuItem.xaml @@ -201,6 +204,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -353,5 +360,8 @@ + + + \ No newline at end of file