|
|
@@ -1,6 +1,9 @@
|
|
|
package server
|
|
|
|
|
|
import (
|
|
|
+ "crypto/sha256"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
"io/fs"
|
|
|
"net/netip"
|
|
|
"text/template"
|
|
|
@@ -275,3 +278,87 @@ func NewConfig() *Config {
|
|
|
WebPushExpiryWarningDuration: DefaultWebPushExpiryWarningDuration,
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// configHashData is a subset of Config fields used for computing the config hash.
|
|
|
+// It excludes sensitive fields (keys, passwords, tokens) and runtime-only fields.
|
|
|
+type configHashData struct {
|
|
|
+ BaseURL string
|
|
|
+ ListenHTTP string
|
|
|
+ ListenHTTPS string
|
|
|
+ ListenUnix string
|
|
|
+ CacheDuration time.Duration
|
|
|
+ AttachmentTotalSizeLimit int64
|
|
|
+ AttachmentFileSizeLimit int64
|
|
|
+ AttachmentExpiryDuration time.Duration
|
|
|
+ KeepaliveInterval time.Duration
|
|
|
+ ManagerInterval time.Duration
|
|
|
+ DisallowedTopics []string
|
|
|
+ WebRoot string
|
|
|
+ MessageDelayMin time.Duration
|
|
|
+ MessageDelayMax time.Duration
|
|
|
+ MessageSizeLimit int
|
|
|
+ TotalTopicLimit int
|
|
|
+ VisitorSubscriptionLimit int
|
|
|
+ VisitorAttachmentTotalSizeLimit int64
|
|
|
+ VisitorAttachmentDailyBandwidthLimit int64
|
|
|
+ VisitorRequestLimitBurst int
|
|
|
+ VisitorRequestLimitReplenish time.Duration
|
|
|
+ VisitorMessageDailyLimit int
|
|
|
+ VisitorEmailLimitBurst int
|
|
|
+ VisitorEmailLimitReplenish time.Duration
|
|
|
+ EnableSignup bool
|
|
|
+ EnableLogin bool
|
|
|
+ RequireLogin bool
|
|
|
+ EnableReservations bool
|
|
|
+ EnableMetrics bool
|
|
|
+ EnablePayments bool
|
|
|
+ EnableCalls bool
|
|
|
+ EnableEmails bool
|
|
|
+ EnableWebPush bool
|
|
|
+ BillingContact string
|
|
|
+ Version string
|
|
|
+}
|
|
|
+
|
|
|
+// Hash computes a SHA-256 hash of the configuration. This is used to detect
|
|
|
+// configuration changes for the web app version check feature.
|
|
|
+func (c *Config) Hash() string {
|
|
|
+ data := configHashData{
|
|
|
+ BaseURL: c.BaseURL,
|
|
|
+ ListenHTTP: c.ListenHTTP,
|
|
|
+ ListenHTTPS: c.ListenHTTPS,
|
|
|
+ ListenUnix: c.ListenUnix,
|
|
|
+ CacheDuration: c.CacheDuration,
|
|
|
+ AttachmentTotalSizeLimit: c.AttachmentTotalSizeLimit,
|
|
|
+ AttachmentFileSizeLimit: c.AttachmentFileSizeLimit,
|
|
|
+ AttachmentExpiryDuration: c.AttachmentExpiryDuration,
|
|
|
+ KeepaliveInterval: c.KeepaliveInterval,
|
|
|
+ ManagerInterval: c.ManagerInterval,
|
|
|
+ DisallowedTopics: c.DisallowedTopics,
|
|
|
+ WebRoot: c.WebRoot,
|
|
|
+ MessageDelayMin: c.MessageDelayMin,
|
|
|
+ MessageDelayMax: c.MessageDelayMax,
|
|
|
+ MessageSizeLimit: c.MessageSizeLimit,
|
|
|
+ TotalTopicLimit: c.TotalTopicLimit,
|
|
|
+ VisitorSubscriptionLimit: c.VisitorSubscriptionLimit,
|
|
|
+ VisitorAttachmentTotalSizeLimit: c.VisitorAttachmentTotalSizeLimit,
|
|
|
+ VisitorAttachmentDailyBandwidthLimit: c.VisitorAttachmentDailyBandwidthLimit,
|
|
|
+ VisitorRequestLimitBurst: c.VisitorRequestLimitBurst,
|
|
|
+ VisitorRequestLimitReplenish: c.VisitorRequestLimitReplenish,
|
|
|
+ VisitorMessageDailyLimit: c.VisitorMessageDailyLimit,
|
|
|
+ VisitorEmailLimitBurst: c.VisitorEmailLimitBurst,
|
|
|
+ VisitorEmailLimitReplenish: c.VisitorEmailLimitReplenish,
|
|
|
+ EnableSignup: c.EnableSignup,
|
|
|
+ EnableLogin: c.EnableLogin,
|
|
|
+ RequireLogin: c.RequireLogin,
|
|
|
+ EnableReservations: c.EnableReservations,
|
|
|
+ EnableMetrics: c.EnableMetrics,
|
|
|
+ EnablePayments: c.StripeSecretKey != "",
|
|
|
+ EnableCalls: c.TwilioAccount != "",
|
|
|
+ EnableEmails: c.SMTPSenderFrom != "",
|
|
|
+ EnableWebPush: c.WebPushPublicKey != "",
|
|
|
+ BillingContact: c.BillingContact,
|
|
|
+ Version: c.Version,
|
|
|
+ }
|
|
|
+ b, _ := json.Marshal(data)
|
|
|
+ return fmt.Sprintf("%x", sha256.Sum256(b))
|
|
|
+}
|