From befadf054eafca7eb3f8b8a1f3bc5a1ae8c09a4c Mon Sep 17 00:00:00 2001 From: Mary Lincy Dcouto Date: Fri, 6 Aug 2021 13:10:36 +0530 Subject: [PATCH] sending installation notification to UI when user restarts UI or ziti tunnel --- ZitiUpdateService/UpdateService.cs | 34 ++++++++++++++++++++------ ZitiUpdateService/utils/CustomTimer.cs | 3 +++ service/cziti/mfa.go | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ZitiUpdateService/UpdateService.cs b/ZitiUpdateService/UpdateService.cs index 14b9fceb..d0081c16 100644 --- a/ZitiUpdateService/UpdateService.cs +++ b/ZitiUpdateService/UpdateService.cs @@ -85,6 +85,7 @@ namespace ZitiUpdateService { private SvcResponse TriggerUpdate() { SvcResponse r = new SvcResponse(); + r.Message = "Initiating Update Check"; checkUpdateImmediately(); return r; } @@ -493,6 +494,12 @@ namespace ZitiUpdateService { }; await writer.WriteLineAsync(JsonConvert.SerializeObject(status)); await writer.FlushAsync(); + if (_installationReminder != null) { + TimerState state = _installationReminder.State; + InstallationNotificationEvent notificationMsg = logAndNotifyInstallationUpdates(state.zdeInstallerInfo, true); + await writer.WriteLineAsync(JsonConvert.SerializeObject(notificationMsg)); + await writer.FlushAsync(); + } } #pragma warning disable 1998 //This async method lacks 'await' @@ -674,6 +681,7 @@ namespace ZitiUpdateService { if (info.IsCritical) { info.TimeRemaining = 0; + info.InstallTime = DateTime.Now; NotifyInstallationUpdates(info, 0, ""); installZDE(fileDestination, filename); } else if (!info.IsCritical && _installationReminder == null) { @@ -699,12 +707,7 @@ namespace ZitiUpdateService { } if (_installationReminder != null) { - info.TimeRemaining = _installationReminder.DueTime.TotalMilliseconds / 1000; // converting to seconds - info.InstallTime = DateTime.Now.AddMilliseconds(_installationReminder.DueTime.TotalMilliseconds); - Logger.Info("Installation of ZDE version {0} will be initiated in {1} seconds, approximately at {2}", info.Version, info.TimeRemaining, info.InstallTime); - if (info.TimeRemaining > 0 && (info.TimeRemaining / 1000) < 1 ) { - NotifyInstallationUpdates(info, 0, ""); - } + logAndNotifyInstallationUpdates(info, false); } } } catch (Exception ex) { @@ -722,6 +725,16 @@ namespace ZitiUpdateService { semaphore.Release(); } + private InstallationNotificationEvent logAndNotifyInstallationUpdates(Checkers.ZDEInstallerInfo info, bool newClient) { + info.TimeRemaining = _installationReminder.DueTime.TotalMilliseconds / 1000; // converting to seconds + info.InstallTime = DateTime.Now.AddMilliseconds(_installationReminder.DueTime.TotalMilliseconds); + Logger.Info("Installation of ZDE version {0} will be initiated in {1} seconds, approximately at {2}", info.Version, info.TimeRemaining, info.InstallTime); + if (newClient || (info.TimeRemaining > 0 && (info.TimeRemaining / 1000) < 1)) { + return NotifyInstallationUpdates(info, 0, ""); + } + return null; + } + private void installZDE(string fileDestination, string filename) { Logger.Info("package is in {0} - moving to install phase", fileDestination); @@ -886,6 +899,10 @@ namespace ZitiUpdateService { dnsProbeTimer.Start(); Logger.Info("DNS Probe enabled"); } + if (_installationReminder != null) { + TimerState state = _installationReminder.State; + logAndNotifyInstallationUpdates(state.zdeInstallerInfo, true); + } } private void Svc_OnClientDisconnected(object sender, object e) { @@ -931,7 +948,7 @@ namespace ZitiUpdateService { } } - private void NotifyInstallationUpdates(Checkers.ZDEInstallerInfo info, int code, string error) { + private InstallationNotificationEvent NotifyInstallationUpdates(Checkers.ZDEInstallerInfo info, int code, string error) { try { InstallationNotificationEvent installationNotificationEvent = new InstallationNotificationEvent() { Code = code, @@ -946,10 +963,11 @@ namespace ZitiUpdateService { }; EventRegistry.SendEventToConsumers(installationNotificationEvent); Logger.Debug("The installation updates for version {0} is sent to the events pipe...", info.Version); + return installationNotificationEvent; } catch (Exception e) { Logger.Error("The notification for the installation updates for version {0} has failed", info.Version); } - + return null; } } diff --git a/ZitiUpdateService/utils/CustomTimer.cs b/ZitiUpdateService/utils/CustomTimer.cs index 6b7c9344..d1818957 100644 --- a/ZitiUpdateService/utils/CustomTimer.cs +++ b/ZitiUpdateService/utils/CustomTimer.cs @@ -15,6 +15,7 @@ namespace ZitiUpdateService.Utils { private DateTime _next; private DateTime _lastTickTime; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private TimerState _state; public CustomTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period) { _timer = new Timer(Callback, state, dueTime, period); @@ -22,6 +23,7 @@ namespace ZitiUpdateService.Utils { _period = period; _next = DateTime.Now.Add(dueTime); _lastTickTime = DateTime.Now; + _state = (TimerState)state; } private void Callback(object state) { @@ -32,6 +34,7 @@ namespace ZitiUpdateService.Utils { public TimeSpan Period => _period; public DateTime Next => _next; public TimeSpan DueTime => _next - DateTime.Now; + public TimerState State => _state; public bool Change(TimeSpan dueTime, TimeSpan period) { _period = period; _next = DateTime.Now.Add(dueTime); diff --git a/service/cziti/mfa.go b/service/cziti/mfa.go index ed515491..54be8fe9 100644 --- a/service/cziti/mfa.go +++ b/service/cziti/mfa.go @@ -303,5 +303,5 @@ func ziti_mfa_cb_remove_go(_ C.ziti_context, status C.int, cFingerprint *C.char) func EndpointStateChanged(id *ZIdentity, woken bool, unlocked bool) { C.ziti_endpoint_state_change(id.czctx, C.bool(woken), C.bool(unlocked)) - log.Debugf("Endpoint status changed for id %s - woken %t, unlocked %t", id.Name, woken, unlocked) + log.Debugf("Endpoint status changed for id %s:%s - woken %t, unlocked %t", id.Name, id.Fingerprint, woken, unlocked) }