mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
ui: Display server configuration on status page
This commit is contained in:
@@ -71,21 +71,31 @@ func RootMonitorMailbox(w http.ResponseWriter, req *http.Request, ctx *web.Conte
|
||||
|
||||
// RootStatus serves the Inbucket status page
|
||||
func RootStatus(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
||||
// Get flash messages, save session
|
||||
errorFlash := ctx.Session.Flashes("errors")
|
||||
if err = ctx.Session.Save(req, w); err != nil {
|
||||
return err
|
||||
root := ctx.RootConfig
|
||||
retPeriod := ""
|
||||
if root.Storage.RetentionPeriod > 0 {
|
||||
retPeriod = root.Storage.RetentionPeriod.String()
|
||||
}
|
||||
// Render template
|
||||
return web.RenderTemplate("root/status.html", w, map[string]interface{}{
|
||||
"ctx": ctx,
|
||||
"errorFlash": errorFlash,
|
||||
"version": config.Version,
|
||||
"buildDate": config.BuildDate,
|
||||
"smtpListener": ctx.RootConfig.SMTP.Addr,
|
||||
"pop3Listener": ctx.RootConfig.POP3.Addr,
|
||||
"webListener": ctx.RootConfig.Web.Addr,
|
||||
"smtpConfig": ctx.RootConfig.SMTP,
|
||||
"storageConfig": ctx.RootConfig.Storage,
|
||||
})
|
||||
|
||||
return web.RenderJSON(w,
|
||||
&jsonServerConfig{
|
||||
Version: config.Version,
|
||||
BuildDate: config.BuildDate,
|
||||
POP3Listener: root.POP3.Addr,
|
||||
WebListener: root.Web.Addr,
|
||||
SMTPConfig: jsonSMTPConfig{
|
||||
Addr: root.SMTP.Addr,
|
||||
DefaultAccept: root.SMTP.DefaultAccept,
|
||||
AcceptDomains: root.SMTP.AcceptDomains,
|
||||
RejectDomains: root.SMTP.RejectDomains,
|
||||
DefaultStore: root.SMTP.DefaultStore,
|
||||
StoreDomains: root.SMTP.StoreDomains,
|
||||
DiscardDomains: root.SMTP.DiscardDomains,
|
||||
},
|
||||
StorageConfig: jsonStorageConfig{
|
||||
MailboxMsgCap: root.Storage.MailboxMsgCap,
|
||||
StoreType: root.Storage.Type,
|
||||
RetentionPeriod: retPeriod,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
26
pkg/webui/status_json.go
Normal file
26
pkg/webui/status_json.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package webui
|
||||
|
||||
type jsonServerConfig struct {
|
||||
Version string `json:"version"`
|
||||
BuildDate string `json:"build-date"`
|
||||
POP3Listener string `json:"pop3-listener"`
|
||||
WebListener string `json:"web-listener"`
|
||||
SMTPConfig jsonSMTPConfig `json:"smtp-config"`
|
||||
StorageConfig jsonStorageConfig `json:"storage-config"`
|
||||
}
|
||||
|
||||
type jsonSMTPConfig struct {
|
||||
Addr string `json:"addr"`
|
||||
DefaultAccept bool `json:"default-accept"`
|
||||
AcceptDomains []string `json:"accept-domains"`
|
||||
RejectDomains []string `json:"reject-domains"`
|
||||
DefaultStore bool `json:"default-store"`
|
||||
StoreDomains []string `json:"store-domains"`
|
||||
DiscardDomains []string `json:"discard-domains"`
|
||||
}
|
||||
|
||||
type jsonStorageConfig struct {
|
||||
MailboxMsgCap int `json:"mailbox-msg-cap"`
|
||||
StoreType string `json:"store-type"`
|
||||
RetentionPeriod string `json:"retention-period"`
|
||||
}
|
||||
Reference in New Issue
Block a user