From e40e6292f56451a25528c153585ba0aaf63b59f1 Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Mon, 17 May 2021 14:59:20 +0200 Subject: [PATCH] Allow manual updates even if automatic ones are disabled --- updates/api.go | 2 +- updates/config.go | 31 +++++++++++++++++-------------- updates/main.go | 8 ++++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/updates/api.go b/updates/api.go index d4cf9fad..59edc460 100644 --- a/updates/api.go +++ b/updates/api.go @@ -14,7 +14,7 @@ func registerAPIEndpoints() error { Write: api.PermitUser, BelongsTo: module, ActionFunc: func(_ *api.Request) (msg string, err error) { - if err := TriggerUpdate(); err != nil { + if err := TriggerUpdate(true); err != nil { return "", err } return "triggered update check", nil diff --git a/updates/config.go b/updates/config.go index 169584c7..f282a5d3 100644 --- a/updates/config.go +++ b/updates/config.go @@ -86,6 +86,21 @@ func initConfig() { previousDevMode = devMode() } +func createWarningNotification() { + notifications.NotifyWarn( + updatesDisabledNotificationID, + "Automatic Updates Disabled", + "Automatic updates are disabled through configuration. Please note that this is potentially dangerous, as this also affects security updates as well as the filter lists and threat intelligence feeds.", + notifications.Action{ + Text: "Change", + Type: notifications.ActionTypeOpenSetting, + Payload: ¬ifications.ActionTypeOpenSettingPayload{ + Key: enableUpdatesKey, + }, + }, + ).AttachToModule(module) +} + func updateRegistryConfig(_ context.Context, _ interface{}) error { changed := false @@ -112,24 +127,12 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error { if updatesCurrentlyEnabled { module.Resolve("") - if err := TriggerUpdate(); err != nil { + if err := TriggerUpdate(false); err != nil { log.Warningf("updates: failed to trigger update: %s", err) } log.Infof("updates: automatic updates are now enabled") } else { - notifications.NotifyWarn( - updatesDisabledNotificationID, - "Automatic Updates Disabled", - "Automatic updates are disabled through configuration. Please note that this is potentially dangerous, as this also affects security updates as well as the filter lists and threat intelligence feeds.", - notifications.Action{ - ID: "change", - Text: "Change", - Type: notifications.ActionTypeOpenSetting, - Payload: ¬ifications.ActionTypeOpenSettingPayload{ - Key: enableUpdatesKey, - }, - }, - ).AttachToModule(module) + createWarningNotification() log.Warningf("updates: automatic updates are now disabled") } } diff --git a/updates/main.go b/updates/main.go index 673369f3..86ad65b6 100644 --- a/updates/main.go +++ b/updates/main.go @@ -195,6 +195,10 @@ func start() error { registry.SelectVersions() module.TriggerEvent(VersionUpdateEvent, nil) + if !updatesCurrentlyEnabled { + createWarningNotification() + } + // Initialize the version export - this requires the registry to be set up. err = initVersionExport() if err != nil { @@ -228,7 +232,7 @@ func start() error { } // TriggerUpdate queues the update task to execute ASAP. -func TriggerUpdate() error { +func TriggerUpdate(force bool) error { switch { case !module.OnlineSoon(): return fmt.Errorf("updates module is disabled") @@ -236,7 +240,7 @@ func TriggerUpdate() error { case !module.Online(): updateASAP = true - case !enableUpdates(): + case !force && !enableUpdates(): return fmt.Errorf("automatic updating is disabled") default: