diff --git a/config/config.go b/config/config.go index 9d1bdf1..9e8c270 100644 --- a/config/config.go +++ b/config/config.go @@ -33,13 +33,15 @@ type POP3Config struct { // WebConfig contains the HTTP server configuration type WebConfig struct { - IP4address net.IP - IP4port int - TemplateDir string - TemplateCache bool - PublicDir string - GreetingFile string - CookieAuthKey string + IP4address net.IP + IP4port int + TemplateDir string + TemplateCache bool + PublicDir string + GreetingFile string + CookieAuthKey string + MonitorVisible bool + MonitorHistory int } // DataStoreConfig contains the mail store configuration @@ -130,6 +132,8 @@ func LoadConfig(filename string) error { requireOption(messages, "web", "template.dir") requireOption(messages, "web", "template.cache") requireOption(messages, "web", "public.dir") + requireOption(messages, "web", "monitor.visible") + requireOption(messages, "web", "monitor.history") requireOption(messages, "datastore", "path") requireOption(messages, "datastore", "retention.minutes") requireOption(messages, "datastore", "retention.sleep.millis") @@ -349,6 +353,19 @@ func parseWebConfig() error { } webConfig.GreetingFile = str + option = "monitor.visible" + flag, err = Config.Bool(section, option) + if err != nil { + return fmt.Errorf("Failed to parse [%v]%v: '%v'", section, option, err) + } + webConfig.MonitorVisible = flag + + option = "monitor.history" + webConfig.MonitorHistory, err = Config.Int(section, option) + if err != nil { + return fmt.Errorf("Failed to parse [%v]%v: '%v'", section, option, err) + } + option = "cookie.auth.key" if Config.HasOption(section, option) { str, err = Config.String(section, option) diff --git a/etc/devel.conf b/etc/devel.conf index 2549705..5e7e536 100644 --- a/etc/devel.conf +++ b/etc/devel.conf @@ -91,6 +91,18 @@ greeting.file=%(install.dir)s/themes/greeting.html # and previous sessions will be invalidated. cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/etc/docker/defaults/inbucket.conf b/etc/docker/defaults/inbucket.conf index 5fb6192..a7aafed 100644 --- a/etc/docker/defaults/inbucket.conf +++ b/etc/docker/defaults/inbucket.conf @@ -93,6 +93,18 @@ greeting.file=/con/configuration/greeting.html # and previous sessions will be invalidated. #cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/etc/homebrew/inbucket.conf b/etc/homebrew/inbucket.conf index 6281583..dd09fef 100644 --- a/etc/homebrew/inbucket.conf +++ b/etc/homebrew/inbucket.conf @@ -93,6 +93,18 @@ greeting.file=%(themes.dir)s/greeting.html # and previous sessions will be invalidated. cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/etc/inbucket.conf b/etc/inbucket.conf index e086f87..6918d9e 100644 --- a/etc/inbucket.conf +++ b/etc/inbucket.conf @@ -91,6 +91,18 @@ greeting.file=%(install.dir)s/themes/greeting.html # and previous sessions will be invalidated. #cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/etc/unix-sample.conf b/etc/unix-sample.conf index 07b8144..cdb21c3 100644 --- a/etc/unix-sample.conf +++ b/etc/unix-sample.conf @@ -91,6 +91,18 @@ greeting.file=%(install.dir)s/themes/greeting.html # and previous sessions will be invalidated. #cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/etc/win-sample.conf b/etc/win-sample.conf index fbbfbe2..0227176 100644 --- a/etc/win-sample.conf +++ b/etc/win-sample.conf @@ -91,6 +91,18 @@ greeting.file=%(install.dir)s\themes\greeting.html # and previous sessions will be invalidated. #cookie.auth.key=secret-inbucket-session-cookie-key +# Enable or disable the live message monitor tab for the web UI. This will let +# anybody see all messages delivered to Inbucket. This setting has no impact +# on the availability of the underlying WebSocket. +monitor.visible=true + +# How many historical message headers should be cached for display by new +# monitor connections. It does not limit the number of messages displayed by +# the browser once the monitor is open; all freshly received messages will be +# appended to the on screen list. This setting also affects the underlying +# API/WebSocket. +monitor.history=30 + ############################################################################# [datastore] diff --git a/httpd/context.go b/httpd/context.go index 318430e..52abfc6 100644 --- a/httpd/context.go +++ b/httpd/context.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/gorilla/sessions" + "github.com/jhillyerd/inbucket/config" "github.com/jhillyerd/inbucket/msghub" "github.com/jhillyerd/inbucket/smtpd" ) @@ -16,6 +17,7 @@ type Context struct { Session *sessions.Session DataStore smtpd.DataStore MsgHub *msghub.Hub + WebConfig config.WebConfig IsJSON bool } @@ -59,6 +61,7 @@ func NewContext(req *http.Request) (*Context, error) { Session: sess, DataStore: DataStore, MsgHub: msgHub, + WebConfig: webConfig, IsJSON: headerMatch(req, "Accept", "application/json"), } return ctx, err diff --git a/inbucket.go b/inbucket.go index 506ace4..d737e5d 100644 --- a/inbucket.go +++ b/inbucket.go @@ -97,7 +97,7 @@ func main() { } // Create message hub - msgHub := msghub.New(rootCtx, 30) + msgHub := msghub.New(rootCtx, config.GetWebConfig().MonitorHistory) // Grab our datastore ds := smtpd.DefaultFileDataStore() diff --git a/themes/bootstrap/templates/_base.html b/themes/bootstrap/templates/_base.html index 83c5e42..114e1ec 100644 --- a/themes/bootstrap/templates/_base.html +++ b/themes/bootstrap/templates/_base.html @@ -48,7 +48,9 @@ {{end}} + {{if .ctx.WebConfig.MonitorVisible}} + {{end}}