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
|
|
|
)
|
|
|
|
|
2025-06-22 15:03:55 +12:00
|
|
|
// AppInfo returns some basic details about the running app including the latest release (unless disabled).
|
2024-11-09 12:33:16 +13:00
|
|
|
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
|
|
|
// WebUIConfig returns configuration settings for the web UI.
|
2023-07-30 17:04:06 +12:00
|
|
|
func WebUIConfig(w http.ResponseWriter, _ *http.Request) {
|
2025-06-22 15:03:55 +12:00
|
|
|
// swagger:route GET /api/v1/webui application WebUIConfigurationResponse
|
2023-04-21 12:17:14 +12:00
|
|
|
//
|
|
|
|
// # 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
|
|
|
|
|
2025-06-22 15:03:55 +12:00
|
|
|
conf := webUIConfigurationResponse{}
|
2023-04-21 12:17:14 +12:00
|
|
|
|
2025-06-22 15:03:55 +12:00
|
|
|
conf.Body.Label = config.Label
|
|
|
|
conf.Body.MessageRelay.Enabled = config.ReleaseEnabled
|
2023-04-21 12:17:14 +12:00
|
|
|
if config.ReleaseEnabled {
|
2025-06-22 15:03:55 +12:00
|
|
|
conf.Body.MessageRelay.SMTPServer = fmt.Sprintf("%s:%d", config.SMTPRelayConfig.Host, config.SMTPRelayConfig.Port)
|
|
|
|
conf.Body.MessageRelay.ReturnPath = config.SMTPRelayConfig.ReturnPath
|
|
|
|
conf.Body.MessageRelay.AllowedRecipients = config.SMTPRelayConfig.AllowedRecipients
|
|
|
|
conf.Body.MessageRelay.BlockedRecipients = config.SMTPRelayConfig.BlockedRecipients
|
|
|
|
conf.Body.MessageRelay.OverrideFrom = config.SMTPRelayConfig.OverrideFrom
|
|
|
|
conf.Body.MessageRelay.PreserveMessageIDs = config.SMTPRelayConfig.PreserveMessageIDs
|
2025-06-07 11:38:25 +12:00
|
|
|
|
2024-03-12 17:07:25 +13:00
|
|
|
// DEPRECATED 2024/03/12
|
2025-06-22 15:03:55 +12:00
|
|
|
conf.Body.MessageRelay.RecipientAllowlist = config.SMTPRelayConfig.AllowedRecipients
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|
|
|
|
|
2025-06-22 15:03:55 +12:00
|
|
|
conf.Body.SpamAssassin = config.EnableSpamAssassin != ""
|
|
|
|
conf.Body.ChaosEnabled = chaos.Enabled
|
|
|
|
conf.Body.DuplicatesIgnored = config.IgnoreDuplicateIDs
|
|
|
|
conf.Body.HideDeleteAllButton = config.HideDeleteAllButton
|
2023-07-30 17:04:06 +12:00
|
|
|
|
2023-04-21 12:17:14 +12:00
|
|
|
w.Header().Add("Content-Type", "application/json")
|
2025-06-22 15:03:55 +12:00
|
|
|
if err := json.NewEncoder(w).Encode(conf.Body); err != nil {
|
2024-05-05 12:25:26 +12:00
|
|
|
httpError(w, err.Error())
|
|
|
|
}
|
2023-04-21 12:17:14 +12:00
|
|
|
}
|