From 9d2f5bd4b12ef79e16090d4fe2a64e85f4facf14 Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Mon, 30 Aug 2021 13:37:05 +0530 Subject: [PATCH 1/5] adding snooze service timeout notification option --- DesktopEdge/Views/Screens/MainMenu.xaml.cs | 27 +++++++++++++++++++ .../DataStructures/DataStructures.cs | 15 +++++++++++ .../ServiceClient/DataClient.cs | 25 +++++++++++++++++ service/ziti-tunnel/dto/dtos.go | 1 + service/ziti-tunnel/service/ipc.go | 15 +++++++++++ service/ziti-tunnel/service/state.go | 8 ++++++ 6 files changed, 91 insertions(+) diff --git a/DesktopEdge/Views/Screens/MainMenu.xaml.cs b/DesktopEdge/Views/Screens/MainMenu.xaml.cs index 806534c3..6d003150 100644 --- a/DesktopEdge/Views/Screens/MainMenu.xaml.cs +++ b/DesktopEdge/Views/Screens/MainMenu.xaml.cs @@ -536,6 +536,33 @@ namespace ZitiDesktopEdge { } } + /// + /// Save the snooze notification information to the properties and queue for update. + /// + async private void SnoozeNotification() { + logger.Info("snooze service timeout notification..."); + DataClient client = (DataClient)Application.Current.Properties["ServiceClient"]; + try { + var snoozeNotificationVar = false; // Boolean.Parse(Snooze.Text); + + var r = await client.SnoozeNotificationPayloadAsync(snoozeNotificationVar); + if (r.Code != 0) { + this.OnShowBlurb?.Invoke("Error: " + r.Error); + logger.Debug("ERROR: {0} : {1}", r.Message, r.Error); + } else { + this.OnShowBlurb?.Invoke("Frequency Saved"); + this.CloseFrequency(); + } + logger.Info("Got response from snooze service timeout notitification task : {0}", r); + } catch (DataStructures.ServiceException se) { + this.OnShowBlurb?.Invoke("Error: " + se.Message); + logger.Error(se, "service exception in snooze service timeout notitification check: {0}", se.Message); + } catch (Exception ex) { + this.OnShowBlurb?.Invoke("Error: " + ex.Message); + logger.Error(ex, "unexpected error in snooze service timeout notitification check: {0}", ex.Message); + } + } + /// /// Show the Edit Modal and blur the background /// diff --git a/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs b/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs index 0bcb05f0..12447ba5 100644 --- a/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs +++ b/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs @@ -530,4 +530,19 @@ namespace ZitiDesktopEdge.DataStructures { public NotificationFrequencyPayload Payload { get; set; } } + public class SnoozeNotificationPayload { + public bool SnoozeNotification { get; set; } + } + + public class SnoozeNotificationFunction : ServiceFunction { + public SnoozeNotificationFunction(bool snoozeNotification) { + this.Function = "SnoozeNotification"; + this.Payload = new SnoozeNotificationPayload() { + SnoozeNotification = snoozeNotification + }; + } + + public SnoozeNotificationPayload Payload { get; set; } + } + } diff --git a/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs b/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs index d5bbac14..52d45e0f 100644 --- a/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs +++ b/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs @@ -449,6 +449,31 @@ namespace ZitiDesktopEdge.ServiceClient { return resp; } + + async public Task SnoozeNotificationPayloadAsync(bool snooze) { + SvcResponse resp = null; + try { + + SnoozeNotificationFunction snoozeNotificationPayload = new SnoozeNotificationFunction(snooze); + + await sendAsync(snoozeNotificationPayload); + resp = await readAsync(ipcReader); + Logger.Debug("snooze notification payload is sent to the ziti tunnel"); + } catch (Exception ex) { + //almost certainly a problem with the pipe - recreate the pipe... + //setupPipe(); + //throw; + Logger.Error(ex, "Unexpected error"); + CommunicationError(ex); + throw ex; + } + if (resp?.Code != 0) { + Logger.Warn("failed to enable/diable the snooze notification option. {0} {1}", resp.Message, resp.Error); + throw new ServiceException("Failed to enable/diable the snooze notification option", resp.Code, "Un expected error."); + } + return resp; + } + async public Task debugAsync() { try { await sendAsync(new ServiceFunction() { Function = "Debug" }); diff --git a/service/ziti-tunnel/dto/dtos.go b/service/ziti-tunnel/dto/dtos.go index 657a5a47..f67eb66c 100644 --- a/service/ziti-tunnel/dto/dtos.go +++ b/service/ziti-tunnel/dto/dtos.go @@ -133,6 +133,7 @@ type TunnelStatus struct { Status string AddDns bool NotificationFrequency int + SnoozeNotification bool } type ServiceVersion struct { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 7b76aa54..9069b196 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -585,6 +585,9 @@ func serveIpc(conn net.Conn) { case "UpdateFrequency": notificationFreq := cmd.Payload["NotificationFrequency"].(float64) updateNotificationFrequency(enc, int(notificationFreq)) + case "SnoozeNotification": + snoozeFreq := cmd.Payload["SnoozeNotification"].(bool) + snoozeNotification(enc, snoozeFreq) case "Debug": dbg() respond(enc, dto.Response{ @@ -1236,7 +1239,12 @@ func broadcastNotification() { } if len(cleanNotifications) > 0 { + if rts.state.SnoozeNotification { + log.Debugf("Notification Snoozed. Notification message: %v", cleanNotifications) + return + } log.Debugf("Sending notification message to UI %v", cleanNotifications) + rts.BroadcastEvent(cziti.TunnelNotificationEvent{ Op: "notification", Notification: cleanNotifications, @@ -1400,3 +1408,10 @@ func updateNotificationFrequency(out *json.Encoder, notificationFreq int) { respond(out, dto.Response{Message: "Notification frequency is set", Code: SUCCESS, Error: "", Payload: ""}) } + +func snoozeNotification(out *json.Encoder, snooze bool) { + if snooze != rts.state.SnoozeNotification { + rts.SnoozeNotification(snooze) + } + respond(out, dto.Response{Message: "Snooze Notification frequency option is set", Code: SUCCESS, Error: "", Payload: ""}) +} diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index efddaa95..d6410f4e 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -127,6 +127,7 @@ func (t *RuntimeState) ToStatus(onlyInitialized bool) dto.TunnelStatus { TunIpv4Mask: t.state.TunIpv4Mask, AddDns: t.state.AddDns, NotificationFrequency: t.state.NotificationFrequency, + SnoozeNotification: t.state.SnoozeNotification, } i := 0 @@ -569,3 +570,10 @@ func (t *RuntimeState) UpdateNotificationFrequency(notificationFreq int) error { return nil } + +func (t *RuntimeState) SnoozeNotification(snooze bool) { + log.Infof("Set Snooze notification to: %t", snooze) + rts.state.SnoozeNotification = snooze + rts.SaveState() + +} From 6388cc88b4a6cd803a5d2c3076a5d7d95a40ba0f Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Mon, 30 Aug 2021 21:43:23 +0530 Subject: [PATCH 2/5] notification after mfa --- service/ziti-tunnel/dto/dtos.go | 1 + service/ziti-tunnel/service/ipc.go | 26 +++++++++++++++++++++++--- service/ziti-tunnel/service/state.go | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/service/ziti-tunnel/dto/dtos.go b/service/ziti-tunnel/dto/dtos.go index f67eb66c..eb3707b8 100644 --- a/service/ziti-tunnel/dto/dtos.go +++ b/service/ziti-tunnel/dto/dtos.go @@ -90,6 +90,7 @@ type Identity struct { MfaMaxTimeoutRem int32 MfaLastUpdatedTime time.Time ServiceUpdatedTime time.Time + Notified bool } type Metrics struct { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 9069b196..e21061ee 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -127,6 +127,7 @@ func SubMain(ops chan string, changes chan<- svc.Status, winEvents <-chan Window } } } + broadcastNotification(true) case <-shutdownDelay: log.Tracef("Exiting windows power events loop") return @@ -1140,6 +1141,12 @@ func handleBulkServiceChange(sc cziti.BulkServiceChange) { } rts.BroadcastEvent(m) + id := rts.Find(sc.Fingerprint) + if id != nil && !id.Notified { + broadcastNotification(true) + rts.SetNotified(id.FingerPrint, true) + } + } func addUnit(count int, unit string) (result string) { @@ -1193,17 +1200,26 @@ func handleEvents(isInitialized chan struct{}) { // notification message case <-notificationFrequency.C: - broadcastNotification() + broadcastNotification(false) } } } -func broadcastNotification() { +func broadcastNotification(adhoc bool) { + changedNotifiedStatus := false cleanNotifications := make([]cziti.NotificationMessage, 0) for _, id := range rts.ids { + if !id.Notified { + rts.SetNotified(id.FingerPrint, true) + changedNotifiedStatus = true + } else if id.Notified && adhoc { + continue + } + if id.CId == nil || !id.CId.MfaRefreshNeeded() { continue } + notificationMessage := "" var notificationMinTimeout int32 = 0 @@ -1238,6 +1254,10 @@ func broadcastNotification() { } } + if changedNotifiedStatus && adhoc { + ResetFrequency(rts.state.NotificationFrequency) + } + if len(cleanNotifications) > 0 { if rts.state.SnoozeNotification { log.Debugf("Notification Snoozed. Notification message: %v", cleanNotifications) @@ -1356,7 +1376,7 @@ func authMfa(out *json.Encoder, fingerprint string, code string) { if result == nil { // respond with auth success message immediately respond(out, dto.Response{Message: "AuthMFA complete", Code: SUCCESS, Error: "", Payload: fingerprint}) - + rts.SetNotified(fingerprint, false) id.CId.UpdateMFATime() } else { respondWithError(out, fmt.Sprintf("AuthMFA failed. the supplied code [%s] was not valid: %s", code, result), 1, result) diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index d6410f4e..cc6bc98b 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -556,6 +556,14 @@ func (t *RuntimeState) UpdateMfa(fingerprint string, mfaEnabled bool, mfaNeeded } } +func (t *RuntimeState) SetNotified(fingerprint string, notified bool) { + id := t.Find(fingerprint) + + if id != nil { + id.Notified = notified + } +} + func (t *RuntimeState) UpdateNotificationFrequency(notificationFreq int) error { log.Infof("setting notification frequency : %d", notificationFreq) From 96d3786a8800638089092fb035551340eaddb3ae Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Mon, 30 Aug 2021 22:27:19 +0530 Subject: [PATCH 3/5] broadcast message after mfa re-login --- service/ziti-tunnel/service/ipc.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index e21061ee..1a9e77fc 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -1144,7 +1144,6 @@ func handleBulkServiceChange(sc cziti.BulkServiceChange) { id := rts.Find(sc.Fingerprint) if id != nil && !id.Notified { broadcastNotification(true) - rts.SetNotified(id.FingerPrint, true) } } @@ -1209,6 +1208,11 @@ func broadcastNotification(adhoc bool) { changedNotifiedStatus := false cleanNotifications := make([]cziti.NotificationMessage, 0) for _, id := range rts.ids { + + if id.CId == nil || !id.CId.MfaRefreshNeeded() { + continue + } + if !id.Notified { rts.SetNotified(id.FingerPrint, true) changedNotifiedStatus = true @@ -1216,10 +1220,6 @@ func broadcastNotification(adhoc bool) { continue } - if id.CId == nil || !id.CId.MfaRefreshNeeded() { - continue - } - notificationMessage := "" var notificationMinTimeout int32 = 0 @@ -1378,6 +1378,7 @@ func authMfa(out *json.Encoder, fingerprint string, code string) { respond(out, dto.Response{Message: "AuthMFA complete", Code: SUCCESS, Error: "", Payload: fingerprint}) rts.SetNotified(fingerprint, false) id.CId.UpdateMFATime() + broadcastNotification(true) } else { respondWithError(out, fmt.Sprintf("AuthMFA failed. the supplied code [%s] was not valid: %s", code, result), 1, result) } From 3b01f99fbd59b3f4e8162094a12b53aed879fa27 Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Tue, 31 Aug 2021 11:03:26 +0530 Subject: [PATCH 4/5] update release notes --- release-notes.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/release-notes.md b/release-notes.md index ebbc2544..6dc848b9 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,18 @@ +# Release 1.10.2 + +## What's New +* none + +## Other changes: +* [#430](https://github.com/openziti/desktop-edge-win/issues/430) Snooze service timeout Notification. + - Send notification if WDE receives the service updates with timeout that is less than 5 minutes + +## Bugs fixed: +* none + +## Dependency Updates +* none + # Release 1.10.1 ## What's New From a209e6844bbc340241fb5426b691233ab67a52bc Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Wed, 1 Sep 2021 11:25:02 +0530 Subject: [PATCH 5/5] reverting the snooze logic from tunnel --- DesktopEdge/Views/Screens/MainMenu.xaml.cs | 26 ------------------- .../DataStructures/DataStructures.cs | 14 ---------- .../ServiceClient/DataClient.cs | 24 ----------------- service/ziti-tunnel/dto/dtos.go | 1 - service/ziti-tunnel/service/ipc.go | 13 ---------- service/ziti-tunnel/service/state.go | 7 ----- 6 files changed, 85 deletions(-) diff --git a/DesktopEdge/Views/Screens/MainMenu.xaml.cs b/DesktopEdge/Views/Screens/MainMenu.xaml.cs index 6d003150..4c75c3f2 100644 --- a/DesktopEdge/Views/Screens/MainMenu.xaml.cs +++ b/DesktopEdge/Views/Screens/MainMenu.xaml.cs @@ -536,32 +536,6 @@ namespace ZitiDesktopEdge { } } - /// - /// Save the snooze notification information to the properties and queue for update. - /// - async private void SnoozeNotification() { - logger.Info("snooze service timeout notification..."); - DataClient client = (DataClient)Application.Current.Properties["ServiceClient"]; - try { - var snoozeNotificationVar = false; // Boolean.Parse(Snooze.Text); - - var r = await client.SnoozeNotificationPayloadAsync(snoozeNotificationVar); - if (r.Code != 0) { - this.OnShowBlurb?.Invoke("Error: " + r.Error); - logger.Debug("ERROR: {0} : {1}", r.Message, r.Error); - } else { - this.OnShowBlurb?.Invoke("Frequency Saved"); - this.CloseFrequency(); - } - logger.Info("Got response from snooze service timeout notitification task : {0}", r); - } catch (DataStructures.ServiceException se) { - this.OnShowBlurb?.Invoke("Error: " + se.Message); - logger.Error(se, "service exception in snooze service timeout notitification check: {0}", se.Message); - } catch (Exception ex) { - this.OnShowBlurb?.Invoke("Error: " + ex.Message); - logger.Error(ex, "unexpected error in snooze service timeout notitification check: {0}", ex.Message); - } - } /// /// Show the Edit Modal and blur the background diff --git a/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs b/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs index 12447ba5..85152ce3 100644 --- a/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs +++ b/ZitiDesktopEdge.Client/DataStructures/DataStructures.cs @@ -530,19 +530,5 @@ namespace ZitiDesktopEdge.DataStructures { public NotificationFrequencyPayload Payload { get; set; } } - public class SnoozeNotificationPayload { - public bool SnoozeNotification { get; set; } - } - - public class SnoozeNotificationFunction : ServiceFunction { - public SnoozeNotificationFunction(bool snoozeNotification) { - this.Function = "SnoozeNotification"; - this.Payload = new SnoozeNotificationPayload() { - SnoozeNotification = snoozeNotification - }; - } - - public SnoozeNotificationPayload Payload { get; set; } - } } diff --git a/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs b/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs index 52d45e0f..378344c9 100644 --- a/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs +++ b/ZitiDesktopEdge.Client/ServiceClient/DataClient.cs @@ -450,30 +450,6 @@ namespace ZitiDesktopEdge.ServiceClient { } - async public Task SnoozeNotificationPayloadAsync(bool snooze) { - SvcResponse resp = null; - try { - - SnoozeNotificationFunction snoozeNotificationPayload = new SnoozeNotificationFunction(snooze); - - await sendAsync(snoozeNotificationPayload); - resp = await readAsync(ipcReader); - Logger.Debug("snooze notification payload is sent to the ziti tunnel"); - } catch (Exception ex) { - //almost certainly a problem with the pipe - recreate the pipe... - //setupPipe(); - //throw; - Logger.Error(ex, "Unexpected error"); - CommunicationError(ex); - throw ex; - } - if (resp?.Code != 0) { - Logger.Warn("failed to enable/diable the snooze notification option. {0} {1}", resp.Message, resp.Error); - throw new ServiceException("Failed to enable/diable the snooze notification option", resp.Code, "Un expected error."); - } - return resp; - } - async public Task debugAsync() { try { await sendAsync(new ServiceFunction() { Function = "Debug" }); diff --git a/service/ziti-tunnel/dto/dtos.go b/service/ziti-tunnel/dto/dtos.go index f67eb66c..657a5a47 100644 --- a/service/ziti-tunnel/dto/dtos.go +++ b/service/ziti-tunnel/dto/dtos.go @@ -133,7 +133,6 @@ type TunnelStatus struct { Status string AddDns bool NotificationFrequency int - SnoozeNotification bool } type ServiceVersion struct { diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 9069b196..951ac149 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -585,9 +585,6 @@ func serveIpc(conn net.Conn) { case "UpdateFrequency": notificationFreq := cmd.Payload["NotificationFrequency"].(float64) updateNotificationFrequency(enc, int(notificationFreq)) - case "SnoozeNotification": - snoozeFreq := cmd.Payload["SnoozeNotification"].(bool) - snoozeNotification(enc, snoozeFreq) case "Debug": dbg() respond(enc, dto.Response{ @@ -1239,10 +1236,6 @@ func broadcastNotification() { } if len(cleanNotifications) > 0 { - if rts.state.SnoozeNotification { - log.Debugf("Notification Snoozed. Notification message: %v", cleanNotifications) - return - } log.Debugf("Sending notification message to UI %v", cleanNotifications) rts.BroadcastEvent(cziti.TunnelNotificationEvent{ @@ -1409,9 +1402,3 @@ func updateNotificationFrequency(out *json.Encoder, notificationFreq int) { } -func snoozeNotification(out *json.Encoder, snooze bool) { - if snooze != rts.state.SnoozeNotification { - rts.SnoozeNotification(snooze) - } - respond(out, dto.Response{Message: "Snooze Notification frequency option is set", Code: SUCCESS, Error: "", Payload: ""}) -} diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index d6410f4e..a808cb77 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -127,7 +127,6 @@ func (t *RuntimeState) ToStatus(onlyInitialized bool) dto.TunnelStatus { TunIpv4Mask: t.state.TunIpv4Mask, AddDns: t.state.AddDns, NotificationFrequency: t.state.NotificationFrequency, - SnoozeNotification: t.state.SnoozeNotification, } i := 0 @@ -571,9 +570,3 @@ func (t *RuntimeState) UpdateNotificationFrequency(notificationFreq int) error { return nil } -func (t *RuntimeState) SnoozeNotification(snooze bool) { - log.Infof("Set Snooze notification to: %t", snooze) - rts.state.SnoozeNotification = snooze - rts.SaveState() - -}