diff --git a/ZitiConsoleApp/Program.cs b/ZitiConsoleApp/Program.cs deleted file mode 100644 index 8fbdbf97..00000000 --- a/ZitiConsoleApp/Program.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.IO; -using System.Net; -using System.Xml; -using System.Text; - -namespace ZitiConsoleApp { - class Program { - - private static string _versionUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/maven-metadata.xml"; - private static string _serviceUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/${version}/ziti-tunnel-win-${version}.zip"; - - static void Main(string[] args) { - var request = WebRequest.Create(_versionUrl) as HttpWebRequest; - var response = request.GetResponse(); - - Stream receiveStream = response.GetResponseStream(); - StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); - - var result = readStream.ReadToEnd(); - - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(result); - - XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/release"); - string version = node.InnerText; - Console.WriteLine(version); - - string remoteService = _serviceUrl.Replace("${version}", version); - Console.WriteLine(remoteService); - } - } -} diff --git a/ZitiConsoleApp/ZitiConsoleApp.csproj b/ZitiConsoleApp/ZitiConsoleApp.csproj deleted file mode 100644 index 052b6d93..00000000 --- a/ZitiConsoleApp/ZitiConsoleApp.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - netcoreapp3.1 - Debug;Release;Releases - - - diff --git a/ZitiTunneler/IdentityItem.xaml.cs b/ZitiTunneler/IdentityItem.xaml.cs index 514d1c2b..0569c7e1 100644 --- a/ZitiTunneler/IdentityItem.xaml.cs +++ b/ZitiTunneler/IdentityItem.xaml.cs @@ -22,7 +22,7 @@ namespace ZitiTunneler { public delegate void Click(ZitiIdentity identity); public event Click OnClick; - private ZitiIdentity _identity; + public ZitiIdentity _identity; public ZitiIdentity Identity { get { return _identity; @@ -64,14 +64,10 @@ namespace ZitiTunneler { ToggleStatus.Content = "DISABLED"; // MessageBox.Show("jeremy - update the identity and services here. When disabled there will be no services, service count: " + id?.Services?.Count()); } - } - catch(ServiceClient.ServiceException se) - { + } catch(ServiceClient.ServiceException se) { MessageBox.Show("Unexpected error 5 the toggle needs to be rolled back!!! jeremy!", se.Message); MessageBox.Show(se.AdditionalInfo, se.Message); - } - catch (Exception ex) - { + } catch (Exception ex) { MessageBox.Show("Unexpected error 5 the toggle needs to be rolled back!!! jeremy!", ex.Message); } } diff --git a/ZitiTunneler/MainMenu.xaml b/ZitiTunneler/MainMenu.xaml index 92ecd1a5..4c36e7f5 100644 --- a/ZitiTunneler/MainMenu.xaml +++ b/ZitiTunneler/MainMenu.xaml @@ -53,11 +53,11 @@ - - + + @@ -66,11 +66,10 @@ - + - - + diff --git a/ZitiTunneler/MainMenu.xaml.cs b/ZitiTunneler/MainMenu.xaml.cs index 008233f7..ec1c812e 100644 --- a/ZitiTunneler/MainMenu.xaml.cs +++ b/ZitiTunneler/MainMenu.xaml.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System; using System.Threading; using System.Management.Automation; +using ZitiTunneler.Models; namespace ZitiTunneler { @@ -55,6 +56,10 @@ namespace ZitiTunneler menuState = "Logs"; UpdateState(); } + private void ShowUILogs(object sender, MouseButtonEventArgs e) { + menuState = "UILogs"; + UpdateState(); + } private void UpdateState() { MainItems.Visibility = Visibility.Collapsed; @@ -82,10 +87,16 @@ namespace ZitiTunneler BackArrow.Visibility = Visibility.Visible; } else if (menuState=="Logs") { ServiceClient.Client client = (ServiceClient.Client)Application.Current.Properties["ServiceClient"]; - MenuTitle.Content = "Application Logs"; + MenuTitle.Content = "Service Logs"; LogsItems.Text = client.GetLogs(); LogsItems.Visibility = Visibility.Visible; BackArrow.Visibility = Visibility.Visible; + } else if (menuState == "UILogs") { + ServiceClient.Client client = (ServiceClient.Client)Application.Current.Properties["ServiceClient"]; + MenuTitle.Content = "Application Logs"; + LogsItems.Text = UILog.GetLogs(); + LogsItems.Visibility = Visibility.Visible; + BackArrow.Visibility = Visibility.Visible; } else if (menuState=="Config") { MenuTitle.Content = "Tunnel Configuration"; ConfigItems.Visibility = Visibility.Visible; @@ -103,7 +114,7 @@ namespace ZitiTunneler } private void GoBack(object sender, MouseButtonEventArgs e) { - if (menuState=="Config"||menuState=="Logs") { + if (menuState=="Config"||menuState=="Logs"||menuState=="UILogs") { menuState = "Advanced"; } else if (menuState=="Licenses") { menuState = "About"; diff --git a/ZitiTunneler/MainWindow.xaml b/ZitiTunneler/MainWindow.xaml index de557717..d2f1c26a 100644 --- a/ZitiTunneler/MainWindow.xaml +++ b/ZitiTunneler/MainWindow.xaml @@ -12,7 +12,72 @@ ClipToBounds="False" Icon="Assets/Images/icon.png" AllowsTransparency="True" Closing="Window_Closing" - WindowStyle="None" Loaded="MainWindow1_Loaded" Background="#000F0F23"> + WindowStyle="None" Loaded="MainWindow1_Loaded" Deactivated="MainUI_Deactivated" Activated="MainUI_Activated" Background="#000F0F23"> + + + + + + @@ -153,6 +218,30 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/ZitiTunneler/MainWindow.xaml.cs b/ZitiTunneler/MainWindow.xaml.cs index 5f5d484a..ef3a22e1 100644 --- a/ZitiTunneler/MainWindow.xaml.cs +++ b/ZitiTunneler/MainWindow.xaml.cs @@ -14,6 +14,8 @@ using System.Diagnostics; using System.Security.Principal; using System.Net; using System.Windows.Controls; +using System.Threading.Tasks; +using System.Threading; namespace ZitiTunneler { @@ -30,6 +32,7 @@ namespace ZitiTunneler { private int _right = 75; private int _bottom = 0; private double _maxHeight = 800d; + private string _serviceVersion = "0.0.8"; private string[] suffixes = { "bps", "kbps", "mbps", "gbps", "tbps", "pbps" }; private List identities { @@ -46,7 +49,8 @@ namespace ZitiTunneler { if (ctl.Status!=ServiceControllerStatus.Running) { try { ctl.Start(); - } catch /*ignored for now (Exception e)*/ { + } catch (Exception e) { + UILog.Log(e.Message); SetCantDisplay(); } } @@ -65,6 +69,8 @@ namespace ZitiTunneler { notifyIcon.Visible = true; LaunchOrInstall(); + + MainMenu.ServiceVersion.Content = _serviceVersion; SetNotifyIcon("white"); InitializeComponent(); } @@ -208,15 +214,8 @@ namespace ZitiTunneler { if (e.Action == "added") { ZitiService zs = new ZitiService(e.Service.Name, e.Service.HostName, e.Service.Port); var svc = found.Services.Find(s => s.Name == zs.Name); - - if (svc == null) - { - found.Services.Add(zs); - } - else - { - Debug.WriteLine("the service named " + zs.Name + " is already accounted for on this identity."); - } + if (svc == null) found.Services.Add(zs); + else Debug.WriteLine("the service named " + zs.Name + " is already accounted for on this identity."); } else { Debug.WriteLine("removing the service named: " + e.Service.Name); found.Services.RemoveAll(s => s.Name == e.Service.Name); @@ -229,8 +228,7 @@ namespace ZitiTunneler { { if (e == null) return; //just skip it for now... Debug.WriteLine($"==== TunnelStatusEvent: "); - this.Dispatcher.Invoke(() => - { + this.Dispatcher.Invoke(() => { InitializeTimer((int)e.Status.Duration); LoadStatusFromService(e.Status); LoadIdentities(); @@ -240,7 +238,7 @@ namespace ZitiTunneler { private void IdentityForgotten(ZitiIdentity forgotten) { ZitiIdentity idToRemove = null; foreach (var id in identities) { - if(id.Fingerprint == forgotten.Fingerprint) { + if (id.Fingerprint == forgotten.Fingerprint) { idToRemove = id; break; } @@ -302,10 +300,8 @@ namespace ZitiTunneler { private void updateViewWithIdentity(Identity id) { var zid = ZitiIdentity.FromClient(id); - foreach (var i in identities) - { - if(i.Fingerprint == zid.Fingerprint) - { + foreach (var i in identities) { + if (i.Fingerprint == zid.Fingerprint) { identities.Remove(i); break; } @@ -328,6 +324,11 @@ namespace ZitiTunneler { IdentityMenu.SetHeight(this.Height-160); for (int i=0; i { }), System.Windows.Threading.DispatcherPriority.ContextIdle); + DoConnect(); + HideLoad(); + } + + private void DoConnect() { + try { + serviceClient.SetTunnelState(true); + SetNotifyIcon("green"); + ConnectButton.Visibility = Visibility.Collapsed; + DisconnectButton.Visibility = Visibility.Visible; + + for (int i = 0; i < identities.Count; i++) { + serviceClient.IdentityOnOff(identities[i].Fingerprint, true); + } + for (int i = 0; i < IdList.Children.Count; i++) { + IdentityItem item = IdList.Children[i] as IdentityItem; + item.isOn = true; + item._identity.IsEnabled = true; + item.RefreshUI(); + } + } catch (ServiceException se) { + ShowError(se.AdditionalInfo, se.Message); + } catch (Exception ex) { + ShowError("Unexpected Error", "Code 3:" + ex.Message); + } + } private void Disconnect(object sender, RoutedEventArgs e) { + ShowLoad(); try { ConnectedTime.Content = "00:00:00"; _timer.Stop(); @@ -414,11 +432,31 @@ namespace ZitiTunneler { SetNotifyIcon("white"); ConnectButton.Visibility = Visibility.Visible; DisconnectButton.Visibility = Visibility.Collapsed; + for (int i = 0; i < identities.Count; i++) { + serviceClient.IdentityOnOff(identities[i].Fingerprint, false); + } + for (int i = 0; i < IdList.Children.Count; i++) { + IdentityItem item = IdList.Children[i] as IdentityItem; + item.isOn = false; + item._identity.IsEnabled = false; + item.RefreshUI(); + } } catch (ServiceException se) { ShowError(se.AdditionalInfo, se.Message); } catch (Exception ex) { ShowError("Unexpected Error", "Code 4:"+ex.Message); } + HideLoad(); + } + + private void ShowLoad() { + LoadProgress.IsIndeterminate = true; + LoadingScreen.Visibility = Visibility.Visible; + } + + private void HideLoad() { + LoadingScreen.Visibility = Visibility.Collapsed; + LoadProgress.IsIndeterminate = false; } private void FormFadeOut_Completed(object sender, EventArgs e) { @@ -446,5 +484,13 @@ namespace ZitiTunneler { private void CloseApp(object sender, MouseButtonEventArgs e) { Application.Current.Shutdown(); } + + private void MainUI_Deactivated(object sender, EventArgs e) { + this.WindowState = WindowState.Minimized; + } + + private void MainUI_Activated(object sender, EventArgs e) { + this.WindowState = WindowState.Normal; + } } } diff --git a/ZitiTunneler/Models/UILog.cs b/ZitiTunneler/Models/UILog.cs new file mode 100644 index 00000000..4fbe77b2 --- /dev/null +++ b/ZitiTunneler/Models/UILog.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.IO; + +namespace ZitiTunneler.Models { + public class UILog { + + private static string _logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "NetFoundry" ,"Logs", "Log.log"); + public static void Log(string message) { + try { + File.WriteAllText(_logDirectory, message); + } catch (Exception e) { + Console.WriteLine(e.Message); + } + } + + public static string GetLogs() { + return File.ReadAllText(_logDirectory); + } + } +} diff --git a/ZitiTunneler/ZitiTunneler.csproj b/ZitiTunneler/ZitiTunneler.csproj index 4d75f041..4976fa17 100644 --- a/ZitiTunneler/ZitiTunneler.csproj +++ b/ZitiTunneler/ZitiTunneler.csproj @@ -81,7 +81,7 @@ bin\Releases\ - Assets\Images\icon.ico + ziti.ico @@ -132,6 +132,7 @@ MainMenu.xaml + ServiceInfo.xaml @@ -333,9 +334,14 @@ false - + + + + + + \ No newline at end of file diff --git a/ZitiTunneler/ziti.ico b/ZitiTunneler/ziti.ico new file mode 100644 index 00000000..141e513d Binary files /dev/null and b/ZitiTunneler/ziti.ico differ diff --git a/ZitiUpdateService/UpdateService.cs b/ZitiUpdateService/UpdateService.cs index f8a9262f..fe0c1444 100644 --- a/ZitiUpdateService/UpdateService.cs +++ b/ZitiUpdateService/UpdateService.cs @@ -23,13 +23,13 @@ namespace ZitiUpdateService { private bool _isNew = true; /// private int _majorVersion = 1; private string _versionUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/maven-metadata.xml"; - private string _serviceUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/${version}/ziti-tunnel-win-${version}.zip"; + private string _serviceUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/0.0.8-SNAPSHOT/ziti-tunnel-win-0.0.8-SNAPSHOT.zip"; private System.Timers.Timer _checkTimer = new System.Timers.Timer(); private System.Timers.Timer _updateTimer = new System.Timers.Timer(); private string _rootDirectory = ""; private string _logDirectory = ""; private bool _isJustStopped = true; - private string _versionType = "release"; + private string _versionType = "latest"; ServiceController controller; public UpdateService() { @@ -37,8 +37,12 @@ namespace ZitiUpdateService { } protected override void OnStart(string[] args) { - if (ConfigurationManager.AppSettings.Get("UpdateUrl")!=null) _versionUrl = ConfigurationManager.AppSettings.Get("UpdateUrl"); - if (ConfigurationManager.AppSettings.Get("Version") !=null) _versionType = ConfigurationManager.AppSettings.Get("Version"); + try { + if (ConfigurationManager.AppSettings.Get("UpdateUrl") != null) _versionUrl = ConfigurationManager.AppSettings.Get("UpdateUrl"); + if (ConfigurationManager.AppSettings.Get("Version") != null) _versionType = ConfigurationManager.AppSettings.Get("Version"); + } catch (Exception e) { + Log(e.ToString()); + } _rootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "NetFoundry"); if (!Directory.Exists(_rootDirectory)) Directory.CreateDirectory(_rootDirectory); _logDirectory = Path.Combine(_rootDirectory, "Logs"); @@ -97,7 +101,7 @@ namespace ZitiUpdateService { xmlDoc.LoadXml(result); XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/"+ _versionType); string version = node.InnerText; - Log("Version Checked: " + version+" on "+_version); + Log("Version Checked: " + version+" on "+_version+" from "+_versionType); if (version != _version) { StopZiti(); UpdateServiceFiles(); @@ -135,9 +139,9 @@ namespace ZitiUpdateService { var result = readStream.ReadToEnd(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(result); - XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/release"); + XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/"+_versionType); string version = node.InnerText; - Log("Got Version: " + version); + Log("Got Version: " + version+" from "+_versionType); string remoteService = _serviceUrl.Replace("${version}", version); @@ -152,6 +156,7 @@ namespace ZitiUpdateService { } } WebClient webClient = new WebClient(); + Log("Get From: "+remoteService); webClient.DownloadFile(remoteService, Path.Combine(_rootDirectory, "Service") + @"\windows-tunneler.zip"); Log("Zip Downloaded"); ZipFile.ExtractToDirectory(Path.Combine(_rootDirectory, "Service") + @"\windows-tunneler.zip", Path.Combine(_rootDirectory, "Service"));