diff --git a/firewall/prompt.go b/firewall/prompt.go index da8110dc..8a3b835e 100644 --- a/firewall/prompt.go +++ b/firewall/prompt.go @@ -93,16 +93,28 @@ func createPrompt(ctx context.Context, conn *network.Connection, pkt packet.Pack return } + // Reference relevant data for save function + localProfile := conn.Process().Profile().LocalProfile() + entity := conn.Entity + + // Create new notification. n = ¬ifications.Notification{ - EventID: nID, - Type: notifications.Prompt, - EventData: conn.Entity, - Expires: expires, + EventID: nID, + Type: notifications.Prompt, + Title: "Connection Prompt", + Category: "Privacy Filter", + EventData: &promptData{ + Entity: entity, + Profile: promptProfile{ + Source: string(localProfile.Source), + ID: localProfile.ID, + LinkedPath: localProfile.LinkedPath, + }, + }, + Expires: expires, } // Set action function. - localProfile := conn.Process().Profile().LocalProfile() - entity := conn.Entity n.SetActionFunction(func(_ context.Context, n *notifications.Notification) error { return saveResponse( localProfile, diff --git a/nameserver/takeover.go b/nameserver/takeover.go index 51da9830..7609c6a0 100644 --- a/nameserver/takeover.go +++ b/nameserver/takeover.go @@ -47,10 +47,16 @@ func checkForConflictingService() error { // wait for a short duration for the other service to shut down time.Sleep(10 * time.Millisecond) - notifications.NotifyInfo( - "namserver-stopped-conflicting-service", - fmt.Sprintf("Portmaster stopped a conflicting name service (pid %d) to gain required system integration.", pid), - ) + notifications.Notify(¬ifications.Notification{ + EventID: "namserver:stopped-conflicting-service", + Type: notifications.Info, + Title: "Conflicting DNS Service", + Category: "Secure DNS", + Message: fmt.Sprintf( + "The Portmaster stopped a conflicting name service (pid %d) to gain required system integration.", + pid, + ), + }) // restart via service-worker logic return fmt.Errorf("%w: stopped conflicting name service with pid %d", modules.ErrRestartNow, pid) diff --git a/netenv/online-status.go b/netenv/online-status.go index 5edbc0a4..3d31f8bd 100644 --- a/netenv/online-status.go +++ b/netenv/online-status.go @@ -213,16 +213,6 @@ func setCaptivePortal(portalURL *url.URL) { return } - // notify - cleanUpPortalNotification() - defer func() { - // TODO: add "open" button - captivePortalNotification = notifications.NotifyInfo( - "netenv:captive-portal:"+captivePortal.Domain, - "Portmaster detected a captive portal at "+captivePortal.Domain, - ) - }() - // set captivePortal = &CaptivePortal{ URL: portalURL.String(), @@ -234,6 +224,22 @@ func setCaptivePortal(portalURL *url.URL) { } else { captivePortal.Domain = portalURL.Hostname() } + + // notify + cleanUpPortalNotification() + // TODO: add "open" button + captivePortalNotification = notifications.Notify(¬ifications.Notification{ + EventID: fmt.Sprintf( + "netenv:captive-portal:%s", captivePortal.Domain, + ), + Type: notifications.Info, + Title: "Captive Portal", + Category: "Core", + Message: fmt.Sprintf( + "Portmaster detected a captive portal at %s", + captivePortal.Domain, + ), + }) } func cleanUpPortalNotification() { diff --git a/status/threat.go b/status/threat.go index 4b70bfab..c30013e5 100644 --- a/status/threat.go +++ b/status/threat.go @@ -45,15 +45,17 @@ type ThreatPayload struct { // // Once you're done, delete the threat // threat.Delete().Publish() // -func NewThreat(id, msg string) *Threat { +func NewThreat(id, title, msg string) *Threat { t := &Threat{ Notification: ¬ifications.Notification{ - EventID: id, - Message: msg, - Type: notifications.Warning, - State: notifications.Active, + EventID: id, + Type: notifications.Warning, + Title: title, + Category: "Threat", + Message: msg, }, } + t.threatData().Started = time.Now().Unix() return t diff --git a/updates/upgrader.go b/updates/upgrader.go index cde189e7..2ab67786 100644 --- a/updates/upgrader.go +++ b/updates/upgrader.go @@ -99,18 +99,30 @@ func upgradeCoreNotify() error { // check for new version if info.GetInfo().Version != pmCoreUpdate.Version() { - n := notifications.NotifyInfo( - "updates:core-update-available", - fmt.Sprintf(":tada: Update to **Portmaster v%s** is available! Please restart the Portmaster to apply the update.", pmCoreUpdate.Version()), - notifications.Action{ - ID: "restart", - Text: "Restart", + n := notifications.Notify(¬ifications.Notification{ + EventID: "updates:core-update-available", + Type: notifications.Info, + Title: fmt.Sprintf( + "Portmaster Update v%s", + pmCoreUpdate.Version(), + ), + Category: "Core", + Message: fmt.Sprintf( + `:tada: Update to **Portmaster v%s** is available! +Please restart the Portmaster to apply the update.`, + pmCoreUpdate.Version(), + ), + AvailableActions: []*notifications.Action{ + { + ID: "restart", + Text: "Restart", + }, + { + ID: "later", + Text: "Not now", + }, }, - notifications.Action{ - ID: "later", - Text: "Not now", - }, - ) + }) n.SetActionFunction(upgradeCoreNotifyActionHandler) log.Debugf("updates: new portmaster version available, sending notification to user") @@ -246,10 +258,18 @@ func warnOnIncorrectParentPath() { if !strings.HasPrefix(absPath, root) { log.Warningf("detected unexpected path %s for portmaster-start", absPath) - notifications.NotifyWarn( - "updates:unsupported-parent", - fmt.Sprintf("The portmaster has been launched by an unexpected %s binary at %s. Please configure your system to use the binary at %s as this version will be kept up to date automatically.", expectedFileName, absPath, filepath.Join(root, expectedFileName)), - ) + notifications.Notify(¬ifications.Notification{ + EventID: "updates:unsupported-parent", + Type: notifications.Warning, + Title: "Unsupported Launcher", + Category: "Core", + Message: fmt.Sprintf( + "The portmaster has been launched by an unexpected %s binary at %s. Please configure your system to use the binary at %s as this version will be kept up to date automatically.", + expectedFileName, + absPath, + filepath.Join(root, expectedFileName), + ), + }) } }