Add titles and categories to notifications

Also, add more event data to prompts.
This commit is contained in:
Daniel 2020-10-29 22:54:46 +01:00
parent 17a0c8f721
commit ed00e1fe83
5 changed files with 86 additions and 40 deletions

View file

@ -93,16 +93,28 @@ func createPrompt(ctx context.Context, conn *network.Connection, pkt packet.Pack
return return
} }
// Reference relevant data for save function
localProfile := conn.Process().Profile().LocalProfile()
entity := conn.Entity
// Create new notification.
n = &notifications.Notification{ n = &notifications.Notification{
EventID: nID, EventID: nID,
Type: notifications.Prompt, Type: notifications.Prompt,
EventData: conn.Entity, Title: "Connection Prompt",
Expires: expires, Category: "Privacy Filter",
EventData: &promptData{
Entity: entity,
Profile: promptProfile{
Source: string(localProfile.Source),
ID: localProfile.ID,
LinkedPath: localProfile.LinkedPath,
},
},
Expires: expires,
} }
// Set action function. // Set action function.
localProfile := conn.Process().Profile().LocalProfile()
entity := conn.Entity
n.SetActionFunction(func(_ context.Context, n *notifications.Notification) error { n.SetActionFunction(func(_ context.Context, n *notifications.Notification) error {
return saveResponse( return saveResponse(
localProfile, localProfile,

View file

@ -47,10 +47,16 @@ func checkForConflictingService() error {
// wait for a short duration for the other service to shut down // wait for a short duration for the other service to shut down
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
notifications.NotifyInfo( notifications.Notify(&notifications.Notification{
"namserver-stopped-conflicting-service", EventID: "namserver:stopped-conflicting-service",
fmt.Sprintf("Portmaster stopped a conflicting name service (pid %d) to gain required system integration.", pid), 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 // restart via service-worker logic
return fmt.Errorf("%w: stopped conflicting name service with pid %d", modules.ErrRestartNow, pid) return fmt.Errorf("%w: stopped conflicting name service with pid %d", modules.ErrRestartNow, pid)

View file

@ -213,16 +213,6 @@ func setCaptivePortal(portalURL *url.URL) {
return 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 // set
captivePortal = &CaptivePortal{ captivePortal = &CaptivePortal{
URL: portalURL.String(), URL: portalURL.String(),
@ -234,6 +224,22 @@ func setCaptivePortal(portalURL *url.URL) {
} else { } else {
captivePortal.Domain = portalURL.Hostname() captivePortal.Domain = portalURL.Hostname()
} }
// notify
cleanUpPortalNotification()
// TODO: add "open" button
captivePortalNotification = notifications.Notify(&notifications.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() { func cleanUpPortalNotification() {

View file

@ -45,15 +45,17 @@ type ThreatPayload struct {
// // Once you're done, delete the threat // // Once you're done, delete the threat
// threat.Delete().Publish() // threat.Delete().Publish()
// //
func NewThreat(id, msg string) *Threat { func NewThreat(id, title, msg string) *Threat {
t := &Threat{ t := &Threat{
Notification: &notifications.Notification{ Notification: &notifications.Notification{
EventID: id, EventID: id,
Message: msg, Type: notifications.Warning,
Type: notifications.Warning, Title: title,
State: notifications.Active, Category: "Threat",
Message: msg,
}, },
} }
t.threatData().Started = time.Now().Unix() t.threatData().Started = time.Now().Unix()
return t return t

View file

@ -99,18 +99,30 @@ func upgradeCoreNotify() error {
// check for new version // check for new version
if info.GetInfo().Version != pmCoreUpdate.Version() { if info.GetInfo().Version != pmCoreUpdate.Version() {
n := notifications.NotifyInfo( n := notifications.Notify(&notifications.Notification{
"updates:core-update-available", EventID: "updates:core-update-available",
fmt.Sprintf(":tada: Update to **Portmaster v%s** is available! Please restart the Portmaster to apply the update.", pmCoreUpdate.Version()), Type: notifications.Info,
notifications.Action{ Title: fmt.Sprintf(
ID: "restart", "Portmaster Update v%s",
Text: "Restart", 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) n.SetActionFunction(upgradeCoreNotifyActionHandler)
log.Debugf("updates: new portmaster version available, sending notification to user") log.Debugf("updates: new portmaster version available, sending notification to user")
@ -246,10 +258,18 @@ func warnOnIncorrectParentPath() {
if !strings.HasPrefix(absPath, root) { if !strings.HasPrefix(absPath, root) {
log.Warningf("detected unexpected path %s for portmaster-start", absPath) log.Warningf("detected unexpected path %s for portmaster-start", absPath)
notifications.NotifyWarn( notifications.Notify(&notifications.Notification{
"updates:unsupported-parent", EventID: "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)), 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),
),
})
} }
} }