diff --git a/admin.go b/admin.go index 4111e04..f704e32 100644 --- a/admin.go +++ b/admin.go @@ -1,13 +1,43 @@ package main import ( + "bytes" + "encoding/json" "net/http" "github.com/labstack/echo" ) +type configScript struct { + RootURL string `json:"rootURL"` + UploadURI string `json:"uploadURL"` + FromEmail string `json:"fromEmail"` + Messengers []string `json:"messengers"` +} + // handleGetStats returns a collection of general statistics. func handleGetStats(c echo.Context) error { app := c.Get("app").(*App) return c.JSON(http.StatusOK, okResp{app.Runner.GetMessengerNames()}) } + +// handleGetConfigScript returns general configuration as a Javascript +// variable that can be included in an HTML page directly. +func handleGetConfigScript(c echo.Context) error { + var ( + app = c.Get("app").(*App) + out = configScript{ + RootURL: app.Constants.RootURL, + UploadURI: app.Constants.UploadURI, + FromEmail: app.Constants.FromEmail, + Messengers: app.Runner.GetMessengerNames(), + } + + b = bytes.Buffer{} + j = json.NewEncoder(&b) + ) + + b.Write([]byte(`var CONFIG = `)) + j.Encode(out) + return c.Blob(http.StatusOK, "application/javascript", b.Bytes()) +} diff --git a/campaigns.go b/campaigns.go index 5843ea3..f5a3c6b 100644 --- a/campaigns.go +++ b/campaigns.go @@ -401,12 +401,6 @@ func handleGetRunningCampaignStats(c echo.Context) error { return c.JSON(http.StatusOK, okResp{out}) } -// handleGetCampaignMessengers returns the list of registered messengers. -func handleGetCampaignMessengers(c echo.Context) error { - app := c.Get("app").(*App) - return c.JSON(http.StatusOK, okResp{app.Runner.GetMessengerNames()}) -} - // handleTestCampaign handles the sending of a campaign message to // arbitrary subscribers for testing. func handleTestCampaign(c echo.Context) error { diff --git a/config.toml.sample b/config.toml.sample index 2d3bf91..15f57f8 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -3,8 +3,8 @@ # Interface and port where the app will run its webserver. address = "0.0.0.0:9000" -# Root to the listmonk installation that'll be used in the e-mails for linking to -# images, the unsubscribe URL etc. +# Public root URL of the listmonk installation that'll be used +# in the messages for linking to images, unsubscribe page etc. root = "http://listmonk.mysite.com" # The default 'from' e-mail for outgoing e-mail campaigns. diff --git a/frontend/my/public/index.html b/frontend/my/public/index.html index 7f64787..ac8ab82 100644 --- a/frontend/my/public/index.html +++ b/frontend/my/public/index.html @@ -4,21 +4,9 @@ - + -