2023-04-21 02:17:14 +02:00
|
|
|
package apiv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/axllent/mailpit/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Response includes global web UI settings
|
|
|
|
//
|
|
|
|
// swagger:model WebUIConfiguration
|
|
|
|
type webUIConfiguration struct {
|
|
|
|
// Message Relay information
|
|
|
|
MessageRelay struct {
|
|
|
|
// Whether message relaying (release) is enabled
|
|
|
|
Enabled bool
|
|
|
|
// The configured SMTP server address
|
|
|
|
SMTPServer string
|
|
|
|
// Enforced Return-Path (if set) for relay bounces
|
|
|
|
ReturnPath string
|
2023-05-05 05:28:00 +02:00
|
|
|
// Allowlist of accepted recipients
|
|
|
|
RecipientAllowlist string
|
2023-04-21 02:17:14 +02:00
|
|
|
}
|
2023-07-30 07:04:06 +02:00
|
|
|
|
|
|
|
// Whether the HTML check has been globally disabled
|
|
|
|
DisableHTMLCheck bool
|
2023-04-21 02:17:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// WebUIConfig returns configuration settings for the web UI.
|
2023-07-30 07:04:06 +02:00
|
|
|
func WebUIConfig(w http.ResponseWriter, _ *http.Request) {
|
2023-04-21 02:17:14 +02:00
|
|
|
// swagger:route GET /api/v1/webui application WebUIConfiguration
|
|
|
|
//
|
|
|
|
// # Get web UI configuration
|
|
|
|
//
|
|
|
|
// Returns configuration settings for the web UI.
|
2023-07-12 07:22:48 +02:00
|
|
|
// Intended for web UI only!
|
2023-04-21 02:17:14 +02:00
|
|
|
//
|
|
|
|
// Produces:
|
|
|
|
// - application/json
|
|
|
|
//
|
|
|
|
// Schemes: http, https
|
|
|
|
//
|
|
|
|
// Responses:
|
|
|
|
// 200: WebUIConfigurationResponse
|
|
|
|
// default: ErrorResponse
|
|
|
|
conf := webUIConfiguration{}
|
|
|
|
|
|
|
|
conf.MessageRelay.Enabled = config.ReleaseEnabled
|
|
|
|
if config.ReleaseEnabled {
|
|
|
|
conf.MessageRelay.SMTPServer = fmt.Sprintf("%s:%d", config.SMTPRelayConfig.Host, config.SMTPRelayConfig.Port)
|
|
|
|
conf.MessageRelay.ReturnPath = config.SMTPRelayConfig.ReturnPath
|
2023-05-05 05:28:00 +02:00
|
|
|
conf.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.RecipientAllowlist
|
2023-04-21 02:17:14 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 07:04:06 +02:00
|
|
|
conf.DisableHTMLCheck = config.DisableHTMLCheck
|
|
|
|
|
2023-04-21 02:17:14 +02:00
|
|
|
bytes, _ := json.Marshal(conf)
|
|
|
|
|
|
|
|
w.Header().Add("Content-Type", "application/json")
|
|
|
|
_, _ = w.Write(bytes)
|
|
|
|
}
|