mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 13:44:37 +03:00
improve webserver, add domain redirects (aliases), add tests and admin page ui to manage the config
- make builtin http handlers serve on specific domains, such as for mta-sts, so e.g. /.well-known/mta-sts.txt isn't served on all domains. - add logging of a few more fields in access logging. - small tweaks/bug fixes in webserver request handling. - add config option for redirecting entire domains to another (common enough). - split httpserver metric into two: one for duration until writing header (i.e. performance of server), another for duration until full response is sent to client (i.e. performance as perceived by users). - add admin ui, a new page for managing the configs. after making changes and hitting "save", the changes take effect immediately. the page itself doesn't look very well-designed (many input fields, makes it look messy). i have an idea to improve it (explained in admin.html as todo) by making the layout look just like the config file. not urgent though. i've already changed my websites/webapps over. the idea of adding a webserver is to take away a (the) reason for folks to want to complicate their mox setup by running an other webserver on the same machine. i think the current webserver implementation can already serve most common use cases. with a few more tweaks (feedback needed!) we should be able to get to 95% of the use cases. the reverse proxy can take care of the remaining 5%. nevertheless, a next step is still to change the quickstart to make it easier for folks to run with an existing webserver, with existing tls certs/keys. that's how this relates to issue #5.
This commit is contained in:
@ -198,11 +198,12 @@ func (c *Config) AccountDestination(addr string) (accDests AccountDestination, o
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Config) WebHandlers() (l []config.WebHandler) {
|
||||
func (c *Config) WebServer() (r map[dns.Domain]dns.Domain, l []config.WebHandler) {
|
||||
c.withDynamicLock(func() {
|
||||
r = c.Dynamic.WebDNSDomainRedirects
|
||||
l = c.Dynamic.WebHandlers
|
||||
})
|
||||
return l
|
||||
return r, l
|
||||
}
|
||||
|
||||
func (c *Config) allowACMEHosts() {
|
||||
@ -245,6 +246,9 @@ func (c *Config) allowACMEHosts() {
|
||||
}
|
||||
|
||||
if l.WebserverHTTPS.Enabled {
|
||||
for from := range c.Dynamic.WebDNSDomainRedirects {
|
||||
hostnames[from] = struct{}{}
|
||||
}
|
||||
for _, wh := range c.Dynamic.WebHandlers {
|
||||
hostnames[wh.DNSDomain] = struct{}{}
|
||||
}
|
||||
@ -678,11 +682,13 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
|
||||
}
|
||||
checkMailboxNormf(static.Postmaster.Mailbox, "postmaster mailbox")
|
||||
|
||||
var haveSTSListener bool
|
||||
var haveSTSListener, haveWebserverListener bool
|
||||
for _, l := range static.Listeners {
|
||||
if l.MTASTSHTTPS.Enabled {
|
||||
haveSTSListener = true
|
||||
break
|
||||
}
|
||||
if l.WebserverHTTP.Enabled || l.WebserverHTTPS.Enabled {
|
||||
haveWebserverListener = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -991,6 +997,29 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
|
||||
}
|
||||
|
||||
// Check webserver configs.
|
||||
if (len(c.WebDomainRedirects) > 0 || len(c.WebHandlers) > 0) && !haveWebserverListener {
|
||||
addErrorf("WebDomainRedirects or WebHandlers configured but no listener with WebserverHTTP or WebserverHTTPS enabled")
|
||||
}
|
||||
|
||||
c.WebDNSDomainRedirects = map[dns.Domain]dns.Domain{}
|
||||
for from, to := range c.WebDomainRedirects {
|
||||
fromdom, err := dns.ParseDomain(from)
|
||||
if err != nil {
|
||||
addErrorf("parsing domain for redirect %s: %v", from, err)
|
||||
}
|
||||
todom, err := dns.ParseDomain(to)
|
||||
if err != nil {
|
||||
addErrorf("parsing domain for redirect %s: %v", to, err)
|
||||
} else if fromdom == todom {
|
||||
addErrorf("will not redirect domain %s to itself", todom)
|
||||
}
|
||||
var zerodom dns.Domain
|
||||
if _, ok := c.WebDNSDomainRedirects[fromdom]; ok && fromdom != zerodom {
|
||||
addErrorf("duplicate redirect domain %s", from)
|
||||
}
|
||||
c.WebDNSDomainRedirects[fromdom] = todom
|
||||
}
|
||||
|
||||
for i := range c.WebHandlers {
|
||||
wh := &c.WebHandlers[i]
|
||||
|
||||
|
Reference in New Issue
Block a user