8 "github.com/mjl-/sconf"
10 "github.com/mjl-/mox/config"
13func cmdExample(c *cmd) {
15 c.help = `List available examples, or print a specific example.`
22 var match func() string
23 for _, ex := range examples {
26 } else if args[0] == ex.Name {
34 log.Fatalln("not found")
39var examples = []struct {
46 const webhandlers = `# Snippet of domains.conf to configure WebDomainRedirects and WebHandlers.
48# Redirect all requests for mox.example to https://www.mox.example.
50 mox.example: www.mox.example
52# Each request is matched against these handlers until one matches and serves it.
55 # Redirect all plain http requests to https, leaving path, query strings, etc
56 # intact. When the request is already to https, the destination URL would have the
57 # same scheme, host and path, causing this redirect handler to not match the
58 # request (and not cause a redirect loop) and the webserver to serve the request
59 # with a later handler.
61 Domain: www.mox.example
63 # Could leave DontRedirectPlainHTTP at false if it wasn't for this being an
64 # example for doing this redirect.
65 DontRedirectPlainHTTP: true
67 BaseURL: https://www.mox.example
69 # The name of the handler, used in logging and metrics.
71 # With ACME configured, each configured domain will automatically get a TLS
72 # certificate on first request.
73 Domain: www.mox.example
74 PathRegexp: ^/who/mjl/
77 # Requested path /who/mjl/inferno/ resolves to local web/mjl/inferno.
78 # If a directory contains an index.html, it is served when a directory is requested.
80 # With ListFiles true, if a directory does not contain an index.html, the contents are listed.
86 Domain: www.mox.example
87 PathRegexp: ^/redir/a/b/c
88 # Don't redirect from plain HTTP to HTTPS.
89 DontRedirectPlainHTTP: true
91 # Just change the domain and add query string set fragment. No change to scheme.
92 # Path will start with /redir/a/b/c (and whathever came after) because no
93 # OrigPathRegexp+ReplacePath is set.
94 BaseURL: //moxest.example?q=1#frag
95 # Default redirection is 308 - Permanent Redirect.
99 Domain: www.mox.example
102 # Replace path, leaving rest of URL intact.
103 OrigPathRegexp: ^/old/(.*)
107 Domain: www.mox.example
110 # Strip the path matched by PathRegexp before forwarding the request. So original
111 # request /app/api become just /api.
113 # URL of backend, where requests are forwarded to. The path in the URL is kept,
114 # so for incoming request URL /app/api, the outgoing request URL has path /app-v2/api.
115 # Requests are made with Go's net/http DefaultTransporter, including using
116 # HTTP_PROXY and HTTPS_PROXY environment variables.
117 URL: http://127.0.0.1:8900/app-v2/
118 # Add headers to response.
120 X-Frame-Options: deny
121 X-Content-Type-Options: nosniff
123 // Parse just so we know we have the syntax right.
124 // todo: ideally we would have a complete config file and parse it fully.
126 WebDomainRedirects map[string]string
127 WebHandlers []config.WebHandler
129 err := sconf.Parse(strings.NewReader(webhandlers), &conf)
130 xcheckf(err, "parsing webhandlers example")
137 const moxconf = `# Snippet for mox.conf, defining a transport called Example that connects on the
138# SMTP submission with TLS port 465 ("submissions), authenticating with
139# SCRAM-SHA-256-PLUS (other providers may not support SCRAM-SHA-256-PLUS, but they
140# typically do support the older CRAM-MD5).:
142# Transport are mechanisms for delivering messages. Transports can be referenced
143# from Routes in accounts, domains and the global configuration. There is always
144# an implicit/fallback delivery transport doing direct delivery with SMTP from the
145# outgoing message queue. Transports are typically only configured when using
146# smarthosts, i.e. when delivering through another SMTP server. Zero or one
147# transport methods must be set in a transport, never multiple. When using an
148# external party to send email for a domain, keep in mind you may have to add
149# their IP address to your domain's SPF record, and possibly additional DKIM
153 # Submission SMTP over a TLS connection to submit email to a remote queue.
156 # Host name to connect to and for verifying its TLS certificate.
157 Host: smtp.example.com
159 # If set, authentication credentials for the remote server. (optional)
161 Username: user@example.com
164 # Allowed authentication mechanisms. Defaults to SCRAM-SHA-256-PLUS,
165 # SCRAM-SHA-256, SCRAM-SHA-1-PLUS, SCRAM-SHA-1, CRAM-MD5. Not included by default:
166 # PLAIN. Specify the strongest mechanism known to be implemented by the server to
167 # prevent mechanism downgrade attacks. (optional)
172 const domainsconf = `# Snippet for domains.conf, specifying a route that sends through the transport:
174# Routes for delivering outgoing messages through the queue. Each delivery attempt
175# evaluates account routes, domain routes and finally these global routes. The
176# transport of the first matching route is used in the delivery attempt. If no
177# routes match, which is the default with no configured routes, messages are
178# delivered directly from the queue. (optional)
185 Transports map[string]config.Transport
188 Routes []config.Route
190 err := sconf.Parse(strings.NewReader(moxconf), &static)
191 xcheckf(err, "parsing moxconf example")
192 err = sconf.Parse(strings.NewReader(domainsconf), &dynamic)
193 xcheckf(err, "parsing domainsconf example")
194 return moxconf + "\n\n" + domainsconf