emailengine-app 2.79.9 → 2.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +49 -0
  3. package/config/default.toml +5 -1
  4. package/data/google-crawlers.json +1 -1
  5. package/encrypt.js +43 -0
  6. package/lib/account/account-state.js +62 -0
  7. package/lib/account.js +34 -2
  8. package/lib/api-routes/account-routes.js +20 -0
  9. package/lib/api-routes/index.js +1 -1
  10. package/lib/api-routes/settings-routes.js +17 -2
  11. package/lib/autodetect-imap-settings.js +349 -47
  12. package/lib/cert-handler.js +62 -0
  13. package/lib/consts.js +50 -6
  14. package/lib/db.js +12 -0
  15. package/lib/egress-fetch.js +21 -9
  16. package/lib/email-client/base-client.js +234 -66
  17. package/lib/email-client/credential-errors.js +118 -0
  18. package/lib/email-client/gmail/gmail-api.js +2 -1
  19. package/lib/email-client/gmail-client.js +70 -64
  20. package/lib/email-client/imap/connection-errors.js +52 -0
  21. package/lib/email-client/imap/listing-diff.js +47 -6
  22. package/lib/email-client/imap/mailbox.js +457 -379
  23. package/lib/email-client/imap/subconnection.js +15 -11
  24. package/lib/email-client/imap/sync-operations.js +46 -59
  25. package/lib/email-client/imap-client.js +136 -95
  26. package/lib/email-client/message-builder.js +11 -11
  27. package/lib/email-client/outlook/graph-api.js +2 -1
  28. package/lib/email-client/outlook-client.js +219 -106
  29. package/lib/imap-proxy-auth.js +58 -3
  30. package/lib/imapproxy/imap-server.js +53 -62
  31. package/lib/lua/h-del-if-equals.lua +39 -0
  32. package/lib/lua/h-set-if-equals.lua +39 -0
  33. package/lib/routes-ui.js +4 -34
  34. package/lib/schemas.js +32 -0
  35. package/lib/security-headers.js +15 -0
  36. package/lib/tls/context.js +376 -0
  37. package/lib/tls/der.js +223 -0
  38. package/lib/tls/provision.js +555 -0
  39. package/lib/tls/self-signed.js +282 -0
  40. package/lib/tls/status.js +431 -0
  41. package/lib/tls/store.js +666 -0
  42. package/lib/tools.js +72 -27
  43. package/lib/ui-routes/account-routes.js +43 -30
  44. package/lib/ui-routes/admin-config-routes.js +22 -1
  45. package/lib/ui-routes/auth-routes.js +16 -1
  46. package/lib/ui-routes/internals-routes.js +3 -5
  47. package/lib/ui-routes/network-config-routes.js +54 -45
  48. package/lib/ui-routes/tls-config-routes.js +581 -0
  49. package/lib/utils/mailbox-path.js +51 -0
  50. package/lib/utils/severity.js +31 -0
  51. package/package.json +4 -4
  52. package/sbom.json +1 -1
  53. package/server.js +16 -0
  54. package/static/css/flyonui.css +1 -1
  55. package/static/css/src/app.tailwind.css +11 -0
  56. package/static/js/app.js +34 -0
  57. package/static/js/public.js +6 -2
  58. package/static/js/ui.js +8 -25
  59. package/static/licenses.html +328 -1257
  60. package/translations/messages.pot +87 -87
  61. package/views/account/login-redirect.hbs +22 -0
  62. package/views/config/imap-proxy.hbs +0 -3
  63. package/views/config/smtp.hbs +0 -3
  64. package/views/config/tls-upload.hbs +81 -0
  65. package/views/config/tls.hbs +492 -0
  66. package/views/partials/side_menu.hbs +1 -0
  67. package/views/partials/tls_security_card.hbs +25 -53
  68. package/views/partials/ui/alert-banner.hbs +3 -2
  69. package/views/partials/ui/badge.hbs +6 -2
  70. package/views/partials/ui/btn.hbs +5 -2
  71. package/workers/api.js +93 -134
  72. package/workers/imap-proxy.js +4 -1
  73. package/workers/smtp.js +51 -44
  74. package/views/partials/tls_security_js.hbs +0 -64
  75. package/views/partials/tls_security_modal.hbs +0 -22
@@ -0,0 +1,492 @@
1
+ {{!-- The header badge is the worst of what the listeners serve, or "TLS off" when none of them
2
+ serves TLS, so the first glance and the tiles below it agree. The request action posts with
3
+ fetch (uiPostJson), which is why it sits outside the settings form further down. The static
4
+ wrapper is deliberate: a partial block that opens with a condition can lose its content. --}}
5
+ {{#> ui/page-header title="TLS Certificates" icon="icon-[tabler--certificate]" badgeLabel=pageLabel.text
6
+ badgeVariant=pageLabel.type class="mb-1"}}
7
+ <div class="flex items-center gap-2">
8
+ {{#if anyWanted}}
9
+ {{> ui/btn label="Request certificates" variant="primary" size="sm" icon="icon-[tabler--refresh]" id="tls-request-all"}}
10
+ {{/if}}
11
+ </div>
12
+ {{/ui/page-header}}
13
+
14
+ <p class="mb-6">Certificates for the SMTP server, the IMAP proxy, and the admin interface when EmailEngine serves HTTPS
15
+ itself. They can be ordered from Let's Encrypt, uploaded, or generated here as a self-signed fallback so a
16
+ listener always starts.</p>
17
+
18
+ {{#if acme.staging}}
19
+ {{#> ui/alert-banner variant="warning" icon="icon-[tabler--flask]" title="Staging certificate authority"}}
20
+ <div>This instance is pointed at the Let's Encrypt staging directory (<code>{{acme.directoryUrl}}</code>). Certificates
21
+ it issues are signed by a root nobody trusts, so every client will refuse them. Clear
22
+ <code>EENGINE_ACME_DIRECTORY_URL</code> to go back to production.</div>
23
+ {{/ui/alert-banner}}
24
+ {{/if}}
25
+
26
+ {{!-- One tile per listener. The icon is a call-site literal so the Tailwind scanner sees it; the
27
+ tint follows the certificate the listener serves, muted when it serves none. --}}
28
+ {{#*inline "listenerTile"}}
29
+ {{#> ui/stat-card variant=(when this.serving.label.type this.serving.label.type "neutral") icon=icon title=this.name}}
30
+ <div class="text-sm" data-listener="{{this.key}}">
31
+ <div class="mb-1 flex flex-wrap items-center gap-1">
32
+ {{#if this.state}}
33
+ {{> ui/state-badge label=this.state dataType=this.key}}
34
+ {{/if}}
35
+ {{#if this.serving.label}}
36
+ {{> ui/badge label=this.serving.label.text variant=this.serving.label.type title=this.serving.label.title soft=true}}
37
+ {{/if}}
38
+ </div>
39
+ {{#if this.serving.certificate}}
40
+ <div>Serving <span class="font-mono">{{this.serving.hostname}}</span> from
41
+ {{this.serving.certificate.sourcePhrase}}{{#if this.serving.certificate.validToIso}}, valid until <span
42
+ class="local-time" data-time="{{this.serving.certificate.validToIso}}">{{this.serving.certificate.validToIso}}</span>{{/if}}.
43
+ </div>
44
+ {{else if this.hint}}
45
+ <div class="text-base-content/70">{{this.hint}}{{#if this.needsSetup}} Turn it on from the <a
46
+ href="{{this.configuredAt}}" class="link link-animated">{{this.name}}</a> page.{{/if}}</div>
47
+ {{else}}
48
+ <div class="text-base-content/70">
49
+ {{#if this.tlsEnabled}}
50
+ Serving HTTPS (<code>EENGINE_API_TLS</code> is set); the listener has not reported a certificate yet.
51
+ {{else}}
52
+ Serving plain HTTP, the default. Put a reverse proxy in front for HTTPS, or set
53
+ <code>EENGINE_API_TLS=true</code> to have EmailEngine serve it with the certificates on this page.
54
+ {{/if}}
55
+ </div>
56
+ {{/if}}
57
+ </div>
58
+ {{/ui/stat-card}}
59
+ {{/inline}}
60
+
61
+ {{!-- Listeners first: what clients actually get is the reason to open this page. --}}
62
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6" id="tls-listeners">
63
+ {{#each listeners}}
64
+ {{#equals this.key "api"}}{{> listenerTile icon="icon-[tabler--world]"}}{{/equals}}
65
+ {{#equals this.key "smtp"}}{{> listenerTile icon="icon-[tabler--server]"}}{{/equals}}
66
+ {{#equals this.key "imapProxy"}}{{> listenerTile icon="icon-[tabler--inbox]"}}{{/equals}}
67
+ {{/each}}
68
+ </div>
69
+
70
+ {{!-- One row per name. The Service URL's own name comes from the General page and cannot be
71
+ removed here; the others are added from the input in the header and removed from the row menu.
72
+ Both post immediately, the way every other list on the admin surface is edited. --}}
73
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-certificates">
74
+ <div class="card-header flex flex-wrap items-center justify-between gap-3">
75
+ <h6 class="card-title text-primary">Certificates</h6>
76
+ <form method="post" action="/admin/config/tls/hostnames" class="flex items-center gap-2 w-full sm:w-auto">
77
+ <input type="hidden" name="crumb" value="{{crumb}}" />
78
+ <input type="text" class="input input-sm min-w-0 grow sm:grow-0 sm:w-72" id="tlsAddHostname" name="hostname"
79
+ placeholder="Add a hostname, e.g. imap.example.com" aria-label="Hostname to add" required
80
+ data-lpignore="true" autocomplete="off" />
81
+ {{> ui/btn label="Add" type="submit" variant="primary" style="soft" size="sm" icon="icon-[tabler--plus]"
82
+ id="tlsAddHostnameBtn"}}
83
+ </form>
84
+ </div>
85
+
86
+ {{#if certificates}}
87
+ {{!-- Fixed layout, so the line under a row wraps inside the card instead of widening the table;
88
+ the minimum width keeps the columns readable on a phone, where the wrapper scrolls. --}}
89
+ <div class="overflow-x-auto">
90
+ <table class="table ee-table-wrap table-fixed min-w-[52rem]">
91
+ <thead>
92
+ <tr>
93
+ <th>Hostname</th>
94
+ <th class="w-36">Status</th>
95
+ <th class="w-32">Source</th>
96
+ <th class="w-32">Expires</th>
97
+ <th class="w-40 text-end"><span class="sr-only">Actions</span></th>
98
+ </tr>
99
+ </thead>
100
+ <tbody>
101
+ {{#each certificates}}
102
+ <tr data-hostname-row="{{this.hostname}}">
103
+ <td>
104
+ <div class="font-mono break-words">{{this.hostname}}</div>
105
+ {{#if this.isServiceHostname}}
106
+ <div class="text-base-content/60 text-xs">Service URL</div>
107
+ {{/if}}
108
+ {{#unless this.acmeEligible}}
109
+ <div class="text-base-content/60 text-xs">Not a public name, so Let's Encrypt can not validate
110
+ it</div>
111
+ {{/unless}}
112
+ </td>
113
+ <td>
114
+ {{!-- the wrapper keeps the badge on one line: the page script rewrites the
115
+ badge's own class list on a live update --}}
116
+ <div class="whitespace-nowrap">
117
+ {{> ui/badge label=this.label.text variant=this.label.type title=this.label.title
118
+ dataName="cert-badge" dataValue=this.hostname}}
119
+ </div>
120
+ </td>
121
+ <td>
122
+ {{#if this.certificate}}
123
+ {{this.certificate.sourceLabel}}
124
+ {{else}}
125
+ <span class="text-base-content/60">None yet</span>
126
+ {{/if}}
127
+ </td>
128
+ <td>
129
+ {{#if this.certificate.validToIso}}
130
+ <div><span class="local-time" data-time="{{this.certificate.validToIso}}">{{this.certificate.validToIso}}</span></div>
131
+ <div class="text-base-content/60 text-xs"><span class="relative-time" data-time="{{this.certificate.validToIso}}"></span></div>
132
+ {{/if}}
133
+ </td>
134
+ <td class="text-end">
135
+ <div class="flex items-center justify-end gap-1 whitespace-nowrap">
136
+ {{#if this.wanted}}
137
+ {{> ui/btn label="Request" variant="primary" style="soft" size="sm" icon="icon-[tabler--refresh]"
138
+ class="tls-request-btn" id=""}}
139
+ {{/if}}
140
+ {{#> ui/row-actions label="Certificate actions" deleteModal=(when this.isServiceHostname "" "#removeHostname")
141
+ deleteId=this.hostname deleteName=this.hostname deleteLabel="Remove hostname"}}
142
+ {{!-- static first item on purpose: a block that opens with a condition can
143
+ lose its whole content to the partial-block pitfall --}}
144
+ <li><button type="button" class="dropdown-item" data-overlay="#certDetails{{@index}}">Details</button></li>
145
+ {{#if this.acmeEligible}}
146
+ <li><button type="button" class="dropdown-item tls-preflight-btn">Check reachability</button></li>
147
+ {{/if}}
148
+ {{#if this.canRequest}}
149
+ {{#unless this.wanted}}
150
+ <li><button type="button" class="dropdown-item tls-request-btn">Renew now</button></li>
151
+ {{/unless}}
152
+ {{/if}}
153
+ {{#equals this.certificate.source "acme"}}
154
+ <li><button type="button" class="dropdown-item text-error list-delete-btn"
155
+ data-delete-modal="#removeIssued" data-delete-id="{{this.hostname}}"
156
+ data-delete-name="{{this.hostname}}">Remove issued certificate</button></li>
157
+ {{/equals}}
158
+ {{/ui/row-actions}}
159
+ </div>
160
+ </td>
161
+ </tr>
162
+ {{!-- The one line under a name: why the last order failed, why a request was declined,
163
+ or that one is under way. The page script fills it for reachability checks and
164
+ live order progress too, so a name never grows a second alert. --}}
165
+ <tr class="{{#unless this.reason}}hidden{{/unless}}" data-cert-reason-row="{{this.hostname}}">
166
+ <td colspan="5" class="pt-0">
167
+ <div class="alert alert-soft alert-{{when this.reason.variant this.reason.variant "info"}} block break-words text-sm py-2"
168
+ data-cert-reason="{{this.hostname}}">{{this.reason.message}}</div>
169
+ </td>
170
+ </tr>
171
+ {{/each}}
172
+ </tbody>
173
+ </table>
174
+ </div>
175
+ {{else}}
176
+ <div class="card-body">
177
+ {{#> ui/empty-state icon="icon-[tabler--certificate-off]" title="No hostname is configured"}}
178
+ Set the <a href="/admin/config/service#settingsServiceUrl" class="link link-animated">Service URL</a> or add a
179
+ hostname above. Until then a TLS listener serves a self-signed certificate for <code>localhost</code>.
180
+ {{/ui/empty-state}}
181
+ </div>
182
+ {{/if}}
183
+ </div>
184
+
185
+ {{> ui/env-managed-alert}}
186
+
187
+ <form method="post" action="/admin/config/tls">
188
+ {{!-- no id: the layout already renders the #crumb element the scripts read --}}
189
+ <input type="hidden" name="crumb" value="{{crumb}}" />
190
+
191
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-source">
192
+ <div class="card-header">
193
+ <h6 class="card-title text-primary">Certificate source</h6>
194
+ </div>
195
+ {{!-- The setting selects which stored sources are admitted, not which one is used, so each
196
+ option says what gets served: in Let's Encrypt mode an uploaded certificate still wins
197
+ for the names it covers. --}}
198
+ <div class="card-body space-y-4">
199
+ <div>
200
+ {{> ui/setting-ref name="tlsProvisioning"}}
201
+ {{> ui/radio id="tlsProvisioningAcme" name="tlsProvisioning" value="acme" label="Let's Encrypt (recommended)"
202
+ selected=values.tlsProvisioning hint="Ordered and renewed for every public name. An uploaded certificate
203
+ still wins for the names it covers."}}
204
+ </div>
205
+ <div>
206
+ {{> ui/radio id="tlsProvisioningManual" name="tlsProvisioning" value="manual" label="Uploaded certificate only"
207
+ selected=values.tlsProvisioning hint="Nothing is ordered. Names the upload does not cover get the
208
+ self-signed fallback."}}
209
+ </div>
210
+ <div>
211
+ {{> ui/radio id="tlsProvisioningSelfSigned" name="tlsProvisioning" value="self-signed" label="Self-signed only"
212
+ selected=values.tlsProvisioning hint="For an instance the internet can not reach. Clients must pin the
213
+ fingerprint or be told to accept the certificate."}}
214
+ </div>
215
+ </div>
216
+ <div class="card-footer border-base-content/10 border-t px-6 py-4">
217
+ {{> ui/btn label="Save Changes" type="submit" icon="icon-[tabler--settings]"}}
218
+ </div>
219
+ </div>
220
+ </form>
221
+
222
+ {{!-- Material that is not tied to one hostname: the uploaded certificate and the self-signed
223
+ fallback each have exactly one place, and the table above only names them as a source. --}}
224
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-stored">
225
+ <div class="card-header">
226
+ <h6 class="card-title text-primary">Stored certificates</h6>
227
+ </div>
228
+ <div class="overflow-x-auto">
229
+ <table class="table ee-table-wrap min-w-[40rem]">
230
+ <tbody>
231
+ <tr>
232
+ <td class="w-1/3 align-top">
233
+ <div class="font-medium">Uploaded certificate</div>
234
+ <div class="text-base-content/60 text-xs">Served for every name it covers, ahead of anything
235
+ EmailEngine obtains itself. Never renewed automatically.</div>
236
+ </td>
237
+ <td class="align-top">
238
+ {{#if manual}}
239
+ <div class="font-mono text-sm break-all">{{manual.subject}}</div>
240
+ <div class="text-sm break-words">Covers <span class="font-mono">{{#each manual.altNames}}{{this}}{{#unless
241
+ @last}}, {{/unless}}{{/each}}</span></div>
242
+ <div class="text-base-content/60 text-sm">Valid until <span class="local-time"
243
+ data-time="{{manual.validToIso}}">{{manual.validToIso}}</span> (<span class="relative-time"
244
+ data-time="{{manual.validToIso}}"></span>)</div>
245
+ {{else}}
246
+ <span class="text-base-content/60">None uploaded yet.</span>
247
+ {{/if}}
248
+ </td>
249
+ <td class="text-end align-top">
250
+ <div class="flex items-center justify-end gap-1 whitespace-nowrap">
251
+ {{#if manual}}
252
+ {{> ui/btn label="Replace" variant="neutral" style="soft" size="sm" href="/admin/config/tls/upload"
253
+ icon="icon-[tabler--upload]"}}
254
+ {{> ui/btn label="Remove" variant="error" style="text" size="sm" icon="icon-[tabler--trash]"
255
+ overlay="#removeUploaded" id="tls-remove-uploaded"}}
256
+ {{else}}
257
+ {{> ui/btn label="Upload a certificate" variant="primary" style="soft" size="sm"
258
+ href="/admin/config/tls/upload" icon="icon-[tabler--upload]"}}
259
+ {{/if}}
260
+ </div>
261
+ </td>
262
+ </tr>
263
+ <tr>
264
+ <td class="align-top">
265
+ <div class="font-medium">Self-signed fallback</div>
266
+ <div class="text-base-content/60 text-xs">Generated on this instance the first time a listener
267
+ needs one. Clients can not verify it, so pin the fingerprint or configure them to accept it.</div>
268
+ </td>
269
+ <td class="align-top">
270
+ {{#if selfSigned}}
271
+ <div class="text-sm break-words">Covers <span class="font-mono">{{#each selfSigned.altNames}}{{this}}{{#unless
272
+ @last}}, {{/unless}}{{/each}}</span></div>
273
+ <div class="text-base-content/60 text-sm">Valid until <span class="local-time"
274
+ data-time="{{selfSigned.validToIso}}">{{selfSigned.validToIso}}</span> (<span class="relative-time"
275
+ data-time="{{selfSigned.validToIso}}"></span>)</div>
276
+ <div class="flex items-start gap-2 mt-1">
277
+ <span class="text-base-content/60 text-xs shrink-0">SHA-256</span>
278
+ <code class="text-xs break-all min-w-0" id="selfSignedFingerprint">{{selfSigned.fingerprint256}}</code>
279
+ {{> ui/copy-btn target="selfSignedFingerprint" small=true btnClass="btn-text"}}
280
+ </div>
281
+ {{else}}
282
+ <span class="text-base-content/60">Not generated yet.</span>
283
+ {{/if}}
284
+ </td>
285
+ <td class="text-end align-top">
286
+ <div class="whitespace-nowrap">
287
+ {{> ui/btn label=(when selfSigned "Regenerate" "Generate") variant="neutral" style="soft" size="sm"
288
+ icon="icon-[tabler--refresh]" overlay="#regenerateSelfSigned" id="tls-regenerate-self-signed"}}
289
+ </div>
290
+ </td>
291
+ </tr>
292
+ </tbody>
293
+ </table>
294
+ </div>
295
+ </div>
296
+
297
+ {{#> ui/details summary="How automatic certificates work" class="card bg-base-100 shadow-md mb-6"}}
298
+ <p class="mb-2">EmailEngine answers the Let's Encrypt <code>http-01</code> challenge itself, at
299
+ <code>/.well-known/acme-challenge/</code>. For that to work, the hostname has to resolve to this machine and a
300
+ request to <strong>port 80</strong> for that name has to reach EmailEngine, directly or through a reverse proxy.
301
+ Nothing else is needed; the certificate is renewed on its own well before it expires.</p>
302
+ <p class="mb-2"><em>Check reachability</em> in a hostname's menu makes exactly that request against this instance's own
303
+ public name, so a missing DNS record or a port 80 that goes somewhere else is reported right away instead of as an
304
+ opaque ACME error minutes later.</p>
305
+ <p class="mb-2">Each name gets its own certificate, served by hostname (SNI). A certificate supplied through the TLS
306
+ environment variables (<code>EENGINE_SMTP_TLS_CERT</code>, <code>EENGINE_IMAPPROXY_TLS_CERT</code>,
307
+ <code>EENGINE_API_TLS_CERT</code>) is served whichever source is selected above: it is an explicit instruction from
308
+ whoever runs this instance, and EmailEngine does not overrule it.</p>
309
+ <p>Certificate authority: <code>{{acme.directoryUrl}}</code> (account <code>{{acme.environment}}</code>).</p>
310
+ {{/ui/details}}
311
+
312
+ {{!-- One details dialog per row, so the table stays five columns wide. Keyed by position: a
313
+ hostname is not a valid id, and the rows are few. --}}
314
+ {{#each certificates}}
315
+ {{#> ui/modal id=(concat "certDetails" @index) title=this.hostname}}
316
+ <div class="modal-body">
317
+ {{#if this.certificate}}
318
+ <dl class="ee-dl">
319
+ <dt>Source</dt>
320
+ <dd>{{this.certificate.sourceLabel}}</dd>
321
+ <dt>Subject</dt>
322
+ <dd class="break-all">{{this.certificate.subject}}</dd>
323
+ <dt>Issuer</dt>
324
+ <dd class="break-all">{{this.certificate.issuer}}</dd>
325
+ <dt>Covers</dt>
326
+ <dd class="font-mono text-sm break-all">{{#each this.certificate.altNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}</dd>
327
+ <dt>Valid from</dt>
328
+ <dd><span class="local-date-time" data-time="{{this.certificate.validFromIso}}">{{this.certificate.validFromIso}}</span></dd>
329
+ <dt>Valid until</dt>
330
+ <dd><span class="local-date-time" data-time="{{this.certificate.validToIso}}">{{this.certificate.validToIso}}</span></dd>
331
+ <dt>SHA-256 fingerprint</dt>
332
+ <dd>
333
+ <div class="flex items-start gap-2">
334
+ <code class="text-xs break-all min-w-0" id="certFingerprint{{@index}}">{{this.certificate.fingerprint256}}</code>
335
+ {{> ui/copy-btn target=(concat "certFingerprint" @index) small=true btnClass="btn-text"}}
336
+ </div>
337
+ </dd>
338
+ <dt>Chain</dt>
339
+ <dd>{{ngettext '%d certificate' '%d certificates' this.certificate.chainLength}}</dd>
340
+ </dl>
341
+ {{else}}
342
+ <p class="text-base-content/60 mb-0">No certificate is stored for this name yet.</p>
343
+ {{/if}}
344
+ </div>
345
+ {{/ui/modal}}
346
+ {{/each}}
347
+
348
+ {{#> ui/delete-modal id="removeHostname" noun="hostname" action="/admin/config/tls/hostnames/delete" fieldName="hostname"}}
349
+ Stop serving a certificate for <strong class="delete-target-name"></strong>? An already issued certificate is kept and
350
+ used again if the name is added back.
351
+ {{/ui/delete-modal}}
352
+
353
+ {{#> ui/confirm-modal id="removeIssued" title="Remove issued certificate" action="/admin/config/tls/delete"
354
+ fieldName="certificate" fieldClass="delete-target-id" submitLabel="Remove certificate"}}
355
+ Remove the Let's Encrypt certificate stored for <strong class="delete-target-name"></strong>? The name falls back to the
356
+ self-signed certificate until a new one is ordered.
357
+ {{/ui/confirm-modal}}
358
+
359
+ {{#> ui/confirm-modal id="removeUploaded" title="Remove uploaded certificate" action="/admin/config/tls/delete"
360
+ fieldName="certificate" fieldValue="manual" submitLabel="Remove certificate"}}
361
+ Remove the uploaded certificate? Every name it covers falls back to whatever the selected source provides.
362
+ {{/ui/confirm-modal}}
363
+
364
+ {{#> ui/confirm-modal id="regenerateSelfSigned" title="Self-signed certificate" action="/admin/config/tls/delete"
365
+ fieldName="certificate" fieldValue="self-signed" submitVariant="primary" submitIcon="icon-[tabler--refresh]"
366
+ submitLabel=(when selfSigned "Regenerate" "Generate")}}
367
+ {{#if selfSigned}}
368
+ Generate a new self-signed certificate for every configured name? Clients that pinned the current fingerprint will have
369
+ to pin the new one.
370
+ {{else}}
371
+ Generate a self-signed certificate for every configured name now, instead of the first time a listener needs one?
372
+ {{/if}}
373
+ {{/ui/confirm-modal}}
374
+
375
+ <script nonce="{{cspNonce}}">
376
+ document.addEventListener('DOMContentLoaded', () => {
377
+
378
+ // The one line under a hostname row. Every message about a name lands here, so a name
379
+ // never accumulates a stack of alerts.
380
+ const showReason = (hostname, type, text) => {
381
+ let row = document.querySelector(`[data-cert-reason-row="${CSS.escape(hostname)}"]`);
382
+ let elm = row && row.querySelector('[data-cert-reason]');
383
+ if (!elm) {
384
+ return;
385
+ }
386
+ row.classList.remove('hidden');
387
+ elm.classList.remove('alert-info', 'alert-success', 'alert-warning', 'alert-error');
388
+ elm.classList.add(`alert-${type}`);
389
+ elm.textContent = text;
390
+ };
391
+
392
+ const rowHostname = elm => {
393
+ let row = elm.closest('[data-hostname-row]');
394
+ return row && row.dataset.hostnameRow;
395
+ };
396
+
397
+ for (let btn of document.querySelectorAll('.tls-preflight-btn')) {
398
+ btn.addEventListener('click', () => {
399
+ let hostname = rowHostname(btn);
400
+ showReason(hostname, 'info', `Checking whether ${hostname} reaches this server...`);
401
+
402
+ uiBusyAction(btn, uiPostJson('/admin/config/tls/preflight', { hostname }).then(data => {
403
+ showReason(hostname, data && data.success ? 'success' : 'error', (data && (data.message || data.error)) || 'The check failed');
404
+ }).catch(err => {
405
+ showReason(hostname, 'error', err.message);
406
+ }));
407
+ });
408
+ }
409
+
410
+ // One name reports on its own line; the page-level action reports as a toast and then
411
+ // marks every name it queued.
412
+ const requestCertificates = (btn, hostname) => {
413
+ if (hostname) {
414
+ showReason(hostname, 'info', `Requesting a certificate for ${hostname}...`);
415
+ }
416
+
417
+ uiBusyAction(btn, uiPostJson('/admin/config/tls/request', hostname ? { hostname } : {}).then(data => {
418
+ if (hostname) {
419
+ if (!data || !data.success) {
420
+ showReason(hostname, 'error', (data && data.error) || 'The request failed');
421
+ }
422
+ return;
423
+ }
424
+
425
+ uiToastResult(data, 'Requesting certificates', 'The request failed');
426
+ for (let name of (data && data.hostnames) || []) {
427
+ showReason(name, 'info', `Requesting a certificate for ${name}...`);
428
+ }
429
+ }).catch(err => {
430
+ if (hostname) {
431
+ showReason(hostname, 'error', err.message);
432
+ } else {
433
+ showToast(err.message, 'alert-triangle');
434
+ }
435
+ }));
436
+ };
437
+
438
+ for (let btn of document.querySelectorAll('.tls-request-btn')) {
439
+ btn.addEventListener('click', () => requestCertificates(btn, rowHostname(btn)));
440
+ }
441
+
442
+ let requestAll = document.getElementById('tls-request-all');
443
+ if (requestAll) {
444
+ requestAll.addEventListener('click', () => requestCertificates(requestAll, null));
445
+ }
446
+
447
+ // One table for both the message and the badge, so a state cannot be coloured one way in
448
+ // the reason line and another on the badge. Mirrors STATUS_VARIANTS in lib/tls/status.js,
449
+ // which paints the same states on a full render.
450
+ const STATES = {
451
+ valid: { variant: 'success', badge: 'Valid' },
452
+ failed: { variant: 'error', badge: 'Failed' },
453
+ // The certificate is still usable and still being served; it is the renewal that did
454
+ // not happen, so this is a warning rather than a failure
455
+ renewalFailed: { variant: 'warning', badge: 'Renewal failed' },
456
+ // A declined request explains itself; the badge it leaves behind is whatever the row had
457
+ skipped: { variant: 'info', badge: null }
458
+ };
459
+
460
+ // Provisioning runs in the background, so progress arrives over the change feed the rest
461
+ // of the admin UI already listens on rather than by holding this request open.
462
+ document.addEventListener('ee:change', e => {
463
+ let data = e.detail;
464
+ if (!data || data.type !== 'tlsCertificateState' || !data.payload || !data.payload.hostname) {
465
+ return;
466
+ }
467
+
468
+ let hostname = data.payload.hostname;
469
+ let state = data.payload.state;
470
+ let paint = STATES[state] || { variant: 'info', badge: 'Requesting' };
471
+
472
+ showReason(hostname, paint.variant, data.payload.message || state);
473
+
474
+ if (state === 'valid') {
475
+ // The row shows source, expiry and the details dialog, none of which this event
476
+ // carries, so repainting the badge here would only be undone a moment later.
477
+ // Reloading is both simpler and more honest than patching three fields.
478
+ setTimeout(() => window.location.reload(), 1500);
479
+ return;
480
+ }
481
+
482
+ let badge = document.querySelector(`[data-cert-badge="${CSS.escape(hostname)}"]`);
483
+ if (badge && paint.badge) {
484
+ badge.className = `badge badge-${paint.variant}`;
485
+ badge.textContent = paint.badge;
486
+ // The title carries the reason; leaving the old one behind is how a badge ends up
487
+ // saying one thing and explaining another.
488
+ badge.title = data.payload.message || paint.badge;
489
+ }
490
+ });
491
+ });
492
+ </script>
@@ -29,6 +29,7 @@
29
29
  {{> ui/menu-item href="/admin/config/ai" label="AI Processing" active=menuConfigAi}}
30
30
  {{> ui/menu-item href="/admin/config/mcp" label="MCP" badge="Beta" active=menuConfigMcp}}
31
31
  {{> ui/menu-item href="/admin/config/network" label="Network" active=menuConfigNetwork}}
32
+ {{> ui/menu-item href="/admin/config/tls" label="TLS Certificates" active=menuConfigTls}}
32
33
  {{> ui/menu-item href="/admin/config/smtp" label="SMTP Server" active=menuConfigSmtp}}
33
34
  {{> ui/menu-item href="/admin/config/imap-proxy" label="IMAP Proxy" active=menuConfigImapProxy}}
34
35
  {{> ui/menu-item href="/admin/config/branding" label="Branding" active=menuConfigBranding}}
@@ -1,6 +1,13 @@
1
1
  {{!-- Security (TLS) card shared by the SMTP and IMAP proxy config pages.
2
- Renders inside the settings form; pair with tls_security_modal (after
3
- the form) and tls_security_js (inside the page script).
2
+ The checkbox decides whether this listener speaks TLS; which certificate
3
+ it serves is decided on /admin/config/tls and only summarized here.
4
+
5
+ It used to do both. Ticking it fired an ACME order in the foreground,
6
+ before the setting had been saved, and unticked itself when the order
7
+ failed - so the page stopped matching the stored setting, and the reason
8
+ was never shown. The listener now always has a certificate to start with
9
+ (a self-signed one if nothing better exists), which is what lets this be
10
+ an ordinary checkbox again.
4
11
  Params:
5
12
  field - the TLS-enabled setting name, also the checkbox id/name
6
13
  (smtpServerTLSEnabled / imapProxyServerTLSEnabled) --}}
@@ -12,65 +19,30 @@
12
19
  <div>
13
20
  {{> ui/setting-ref name=field}}
14
21
 
15
- {{!-- hand-rolled checkbox: the label carries the #tls-label
16
- badge whose badge-{type} class and tooltip body are
17
- repainted by paintCertData() from ui.js. Certificates can
18
- only be provisioned for a real domain (serviceDomain is
19
- false when the Service URL is unset, an IP or localhost),
20
- so without one the checkbox is disabled - except when TLS
21
- is already on, so it can still be turned off. --}}
22
22
  <div class="flex items-center gap-2">
23
- <input type="checkbox"
24
- class="checkbox checkbox-sm trigger-example-render{{#if (lookup errors field)}} is-invalid{{/if}}"
25
- id="{{field}}" {{#if certificateData}}data-certificate="{{certificateData.fingerprint}}" {{/if}}
26
- {{#if serviceDomain}}data-domain="{{serviceDomain}}" {{/if}}name="{{field}}" {{#if (lookup values
27
- field)}}checked{{/if}}
28
- {{#unless serviceDomain}}{{#unless (lookup values field)}}disabled{{/unless}}{{/unless}} />
23
+ {{> ui/checkbox id=field name=field label="Enable TLS Encryption" class="trigger-example-render"
24
+ checked=(lookup values field) error=(lookup errors field)}}
29
25
 
30
- <label class="label-text p-0" for="{{field}}">Enable TLS Encryption
31
-
32
- {{#if certificateData.label}}
33
- {{#> ui/tooltip text=certificateData.label.title}}
34
- <span id="tls-label" class="badge badge-{{eeColor certificateData.label.type}}"
35
- data-labeltype="{{certificateData.label.type}}">{{certificateData.label.text}}</span>
36
- {{/ui/tooltip}}
37
- {{/if}}
38
-
39
- </label>
26
+ {{#if tlsSummary.label}}
27
+ {{#> ui/tooltip text=tlsSummary.label.title}}
28
+ {{> ui/badge label=tlsSummary.label.text variant=tlsSummary.label.type elId="tls-label"}}
29
+ {{/ui/tooltip}}
30
+ {{/if}}
40
31
  </div>
41
32
 
42
- {{#if (lookup errors field)}}
43
- <span class="helper-text text-error">{{lookup errors field}}</span>
44
- {{/if}}
45
-
46
33
  <span class="helper-text">
47
- {{#if serviceDomain}}
48
-
49
- Certificates will be provisioned for <em>{{serviceDomain}}</em>. Change the domain in <a
50
- href="/admin/config/service#settingsServiceUrl" class="link link-animated">Service URL
51
- settings</a>.
52
-
34
+ {{#if tlsSummary.hostname}}
35
+ Clients connect to <em>{{tlsSummary.hostname}}</em>, which is served with
36
+ {{#if tlsSummary.certificate}}a {{tlsSummary.certificate.sourceLabel}} certificate{{else}}no
37
+ certificate yet{{/if}}. Manage certificates on the <a href="/admin/config/tls"
38
+ class="link link-animated">TLS Certificates</a> page.
53
39
  {{else}}
54
-
55
- Set a domain name in <a href="/admin/config/service#settingsServiceUrl"
56
- class="link link-animated">Service URL settings</a> to enable automatic TLS certificates.
57
-
40
+ No hostname is configured, so this listener serves a self-signed certificate. Set a <a
41
+ href="/admin/config/service#settingsServiceUrl" class="link link-animated">Service URL</a> and
42
+ manage certificates on the <a href="/admin/config/tls" class="link link-animated">TLS
43
+ Certificates</a> page.
58
44
  {{/if}}
59
-
60
45
  </span>
61
46
  </div>
62
-
63
47
  </div>
64
-
65
- {{#if serviceDomain}}
66
- <div class="card-footer border-base-content/10 border-t px-6 py-4">
67
- <small class="text-base-content/60">
68
- <span class="icon-[tabler--info-circle] size-4 align-text-bottom"></span>
69
- EmailEngine must be publicly accessible at <em><a href="{{serviceUrl}}" target="_blank"
70
- rel="noopener noreferrer" class="link link-animated">{{serviceUrl}}</a></em> for automatic
71
- certificates. Otherwise, a self-signed certificate will be used.
72
- </small>
73
- </div>
74
- {{/if}}
75
-
76
48
  </div>
@@ -11,13 +11,14 @@
11
11
  variant - error|warning|info|success (default error); sets alert-<variant>
12
12
  title - bold heading text (optional)
13
13
  icon - override the leading icon (default icon-[tabler--alert-triangle])
14
+ class - extra classes, e.g. "mb-4" to override the default page-level spacing (optional)
14
15
  --}}
15
- <div class="alert alert-soft alert-{{#if variant}}{{variant}}{{else}}error{{/if}} mb-6 flex items-start gap-3"
16
+ <div class="alert alert-soft alert-{{#if variant}}{{variant}}{{else}}error{{/if}}{{#unless class}} mb-6{{/unless}} flex items-start gap-3{{#if class}} {{class}}{{/if}}"
16
17
  role="alert">
17
18
  <span class="{{#if icon}}{{icon}}{{else}}icon-[tabler--alert-triangle]{{/if}} size-5 shrink-0"></span>
18
19
  <div class="min-w-0">
19
20
  {{#if title}}<div class="font-semibold">{{title}}</div>{{/if}}
20
21
  {{!-- body content; own hash params neutralized so they do not fall through into nested ui/* calls --}}
21
- {{> @partial-block variant="" title="" icon=""}}
22
+ {{> @partial-block variant="" title="" icon="" class=""}}
22
23
  </div>
23
24
  </div>
@@ -9,9 +9,13 @@
9
9
  elId - element id (optional). NOT named `id`: Handlebars merges hash params
10
10
  into the caller's context, so a partial reading `id` also inherits one
11
11
  that merely happens to be in scope - a row's id inside {{#each}}
12
+ title - native tooltip text, for a badge whose one word needs a sentence
13
+ behind it (optional)
14
+ dataName/dataValue - one data-* attribute, e.g. dataName="cert-badge", for a
15
+ page script that repaints this badge later (optional)
12
16
  class - extra classes, e.g. "state-info" hooks (optional)
13
17
  --}}
14
- <span {{#if elId}}id="{{elId}}" {{/if}}class="badge badge-{{eeColor variant}}{{#if soft}} badge-soft{{/if}}{{#if class}} {{class}}{{/if}}">
18
+ <span {{#if elId}}id="{{elId}}" {{/if}}{{#if title}}title="{{title}}" {{/if}}{{#if dataName}}data-{{dataName}}="{{dataValue}}" {{/if}}class="badge badge-{{eeColor variant}}{{#if soft}} badge-soft{{/if}}{{#if class}} {{class}}{{/if}}">
15
19
  {{~#if icon}}<span class="{{icon}} size-3.5 shrink-0"></span>{{/if~}}
16
- {{~#if label includeZero=true}}{{label}}{{else if @partial-block}}{{> @partial-block label="" variant="" soft="" icon="" id="" class=""}}{{/if~}}
20
+ {{~#if label includeZero=true}}{{label}}{{else if @partial-block}}{{> @partial-block label="" variant="" soft="" icon="" id="" elId="" title="" dataName="" dataValue="" class=""}}{{/if~}}
17
21
  </span>