2023-04-21 12:17:14 +12:00
|
|
|
package apiv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/axllent/mailpit/config"
|
2025-01-25 12:17:15 +13:00
|
|
|
"github.com/axllent/mailpit/internal/smtpd/chaos"
|
2024-11-09 12:33:16 +13:00
|
|
|
"github.com/axllent/mailpit/internal/stats"
|
2023-04-21 12:17:14 +12:00
|
|
|
)
|
|
|
|
|
2024-11-09 12:33:16 +13:00
|
|
|
// Application information
|
|
|
|
// swagger:response AppInfoResponse
|
|
|
|
type appInfoResponse struct {
|
|
|
|
// Application information
|
|
|
|
//
|
|
|
|
// in: body
|
|
|
|
Body stats.AppInformation
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppInfo returns some basic details about the running app, and latest release.
|
|
|
|
func AppInfo(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
// swagger:route GET /api/v1/info application AppInformation
|
|
|
|
//
|
|
|
|
// # Get application information
|
|
|
|
//
|
|
|
|
// Returns basic runtime information, message totals and latest release version.
|
|
|
|
//
|
|
|
|
// Produces:
|
|
|
|
// - application/json
|
|
|
|
//
|
|
|
|
// Schemes: http, https
|
|
|
|
//
|
|
|
|
// Responses:
|
|
|
|
// 200: AppInfoResponse
|
|
|
|
// 400: ErrorResponse
|
|
|
|
|
|
|
|
w.Header().Add("Content-Type", "application/json")
|
|
|
|
if err := json.NewEncoder(w).Encode(stats.Load()); err != nil {
|
|
|
|
httpError(w, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 12:17:14 +12:00
|
|
|
// Response includes global web UI settings
|
|
|
|
//
|
|
|
|
// swagger:model WebUIConfiguration
|
|
|
|
type webUIConfiguration struct {
|
2024-06-21 16:54:33 +12:00
|
|
|
// Optional label to identify this Mailpit instance
|
|
|
|
Label string
|
2023-04-21 12:17:14 +12:00
|
|
|
// 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
|
2024-03-12 17:07:25 +13:00
|
|
|
// Only allow relaying to these recipients (regex)
|
|
|
|
AllowedRecipients string
|
2024-07-14 15:04:36 +12:00
|
|
|
// Block relaying to these recipients (regex)
|
|
|
|
BlockedRecipients string
|
2025-01-26 00:22:57 +13:00
|
|
|
// Overrides the "From" address for all relayed messages
|
|
|
|
OverrideFrom string
|
2024-03-12 17:07:25 +13:00
|
|
|
// DEPRECATED 2024/03/12
|
|
|
|
// swagger:ignore
|
2023-05-05 05:28:00 +02:00
|
|
|
RecipientAllowlist string
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|
2023-07-30 17:04:06 +12:00
|
|
|
|
2024-01-20 12:05:56 +13:00
|
|
|
// Whether SpamAssassin is enabled
|
|
|
|
SpamAssassin bool
|
2024-01-23 16:11:11 +13:00
|
|
|
|
2025-01-25 12:17:15 +13:00
|
|
|
// Whether Chaos support is enabled at runtime
|
|
|
|
ChaosEnabled bool
|
|
|
|
|
2024-01-23 16:11:11 +13:00
|
|
|
// Whether messages with duplicate IDs are ignored
|
|
|
|
DuplicatesIgnored bool
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|
|
|
|
|
2024-11-09 12:33:16 +13:00
|
|
|
// Web UI configuration response
|
|
|
|
// swagger:response WebUIConfigurationResponse
|
|
|
|
type webUIConfigurationResponse struct {
|
|
|
|
// Web UI configuration settings
|
|
|
|
//
|
|
|
|
// in: body
|
|
|
|
Body webUIConfiguration
|
|
|
|
}
|
|
|
|
|
2023-04-21 12:17:14 +12:00
|
|
|
// WebUIConfig returns configuration settings for the web UI.
|
2023-07-30 17:04:06 +12:00
|
|
|
func WebUIConfig(w http.ResponseWriter, _ *http.Request) {
|
2023-04-21 12:17:14 +12:00
|
|
|
// swagger:route GET /api/v1/webui application WebUIConfiguration
|
|
|
|
//
|
|
|
|
// # Get web UI configuration
|
|
|
|
//
|
|
|
|
// Returns configuration settings for the web UI.
|
2023-07-12 17:22:48 +12:00
|
|
|
// Intended for web UI only!
|
2023-04-21 12:17:14 +12:00
|
|
|
//
|
|
|
|
// Produces:
|
2024-11-09 12:33:16 +13:00
|
|
|
// - application/json
|
2023-04-21 12:17:14 +12:00
|
|
|
//
|
|
|
|
// Schemes: http, https
|
|
|
|
//
|
|
|
|
// Responses:
|
2024-11-09 12:33:16 +13:00
|
|
|
// 200: WebUIConfigurationResponse
|
|
|
|
// 400: ErrorResponse
|
|
|
|
|
2023-04-21 12:17:14 +12:00
|
|
|
conf := webUIConfiguration{}
|
|
|
|
|
2024-06-21 16:54:33 +12:00
|
|
|
conf.Label = config.Label
|
2023-04-21 12:17:14 +12:00
|
|
|
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
|
2024-03-12 17:07:25 +13:00
|
|
|
conf.MessageRelay.AllowedRecipients = config.SMTPRelayConfig.AllowedRecipients
|
2024-07-14 15:04:36 +12:00
|
|
|
conf.MessageRelay.BlockedRecipients = config.SMTPRelayConfig.BlockedRecipients
|
2025-01-26 00:22:57 +13:00
|
|
|
conf.MessageRelay.OverrideFrom = config.SMTPRelayConfig.OverrideFrom
|
2024-03-12 17:07:25 +13:00
|
|
|
// DEPRECATED 2024/03/12
|
|
|
|
conf.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.AllowedRecipients
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|
|
|
|
|
2024-01-20 12:05:56 +13:00
|
|
|
conf.SpamAssassin = config.EnableSpamAssassin != ""
|
2025-01-25 12:17:15 +13:00
|
|
|
conf.ChaosEnabled = chaos.Enabled
|
2024-01-23 16:11:11 +13:00
|
|
|
conf.DuplicatesIgnored = config.IgnoreDuplicateIDs
|
2023-07-30 17:04:06 +12:00
|
|
|
|
2023-04-21 12:17:14 +12:00
|
|
|
w.Header().Add("Content-Type", "application/json")
|
2024-05-05 12:25:26 +12:00
|
|
|
if err := json.NewEncoder(w).Encode(conf); err != nil {
|
|
|
|
httpError(w, err.Error())
|
|
|
|
}
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|