emailengine-app 2.79.9 → 2.80.1

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 (146) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +73 -0
  3. package/README.md +6 -0
  4. package/config/default.toml +5 -1
  5. package/data/google-crawlers.json +1 -1
  6. package/encrypt.js +43 -0
  7. package/lib/account/account-state.js +62 -0
  8. package/lib/account.js +34 -2
  9. package/lib/api-routes/account-routes.js +101 -1
  10. package/lib/api-routes/blocklist-routes.js +24 -0
  11. package/lib/api-routes/delivery-test-routes.js +6 -0
  12. package/lib/api-routes/gateway-routes.js +30 -0
  13. package/lib/api-routes/index.js +1 -1
  14. package/lib/api-routes/license-routes.js +10 -0
  15. package/lib/api-routes/mcp-oauth-routes.js +3 -3
  16. package/lib/api-routes/mcp-routes.js +39 -21
  17. package/lib/api-routes/oauth2-app-routes.js +38 -1
  18. package/lib/api-routes/outbox-routes.js +6 -0
  19. package/lib/api-routes/permission-map.js +208 -43
  20. package/lib/api-routes/pubsub-routes.js +8 -0
  21. package/lib/api-routes/route-helpers.js +58 -11
  22. package/lib/api-routes/settings-routes.js +67 -6
  23. package/lib/api-routes/stats-routes.js +6 -0
  24. package/lib/api-routes/template-routes.js +21 -0
  25. package/lib/api-routes/token-routes.js +34 -2
  26. package/lib/api-routes/webhook-route-routes.js +13 -0
  27. package/lib/autodetect-imap-settings.js +349 -47
  28. package/lib/cert-handler.js +62 -0
  29. package/lib/consts.js +50 -6
  30. package/lib/db.js +12 -0
  31. package/lib/egress-fetch.js +21 -9
  32. package/lib/email-client/base-client.js +238 -67
  33. package/lib/email-client/credential-errors.js +122 -0
  34. package/lib/email-client/gmail/gmail-api.js +2 -1
  35. package/lib/email-client/gmail-client.js +70 -64
  36. package/lib/email-client/imap/connection-errors.js +52 -0
  37. package/lib/email-client/imap/listing-diff.js +47 -6
  38. package/lib/email-client/imap/login-failure.js +52 -0
  39. package/lib/email-client/imap/mailbox.js +457 -379
  40. package/lib/email-client/imap/subconnection.js +17 -12
  41. package/lib/email-client/imap/sync-operations.js +46 -59
  42. package/lib/email-client/imap-client.js +139 -101
  43. package/lib/email-client/message-builder.js +11 -11
  44. package/lib/email-client/outlook/graph-api.js +2 -1
  45. package/lib/email-client/outlook-client.js +219 -106
  46. package/lib/enum-descriptions.js +12 -2
  47. package/lib/imap-proxy-auth.js +58 -3
  48. package/lib/imapproxy/imap-server.js +53 -62
  49. package/lib/lua/h-del-if-equals.lua +39 -0
  50. package/lib/lua/h-set-if-equals.lua +39 -0
  51. package/lib/mcp/oauth.js +46 -8
  52. package/lib/mcp/protocol.js +78 -35
  53. package/lib/mcp/tools.js +53 -17
  54. package/lib/privileged-settings.js +147 -0
  55. package/lib/routes-ui.js +4 -34
  56. package/lib/schemas.js +92 -16
  57. package/lib/security-headers.js +15 -0
  58. package/lib/settings.js +13 -0
  59. package/lib/tls/catalog.js +428 -0
  60. package/lib/tls/context.js +302 -0
  61. package/lib/tls/der.js +223 -0
  62. package/lib/tls/listeners.js +62 -0
  63. package/lib/tls/provision.js +555 -0
  64. package/lib/tls/self-signed.js +282 -0
  65. package/lib/tls/status.js +480 -0
  66. package/lib/tls/store.js +667 -0
  67. package/lib/token-permission-view.js +252 -102
  68. package/lib/token-permissions.js +176 -26
  69. package/lib/tokens.js +7 -6
  70. package/lib/tools.js +73 -27
  71. package/lib/ui-routes/account-routes.js +43 -30
  72. package/lib/ui-routes/admin-config-routes.js +63 -22
  73. package/lib/ui-routes/admin-entities-routes.js +23 -13
  74. package/lib/ui-routes/auth-routes.js +16 -1
  75. package/lib/ui-routes/internals-routes.js +3 -5
  76. package/lib/ui-routes/mcp-consent-routes.js +72 -31
  77. package/lib/ui-routes/network-config-routes.js +54 -45
  78. package/lib/ui-routes/tls-config-routes.js +628 -0
  79. package/lib/utils/mailbox-path.js +51 -0
  80. package/lib/utils/severity.js +31 -0
  81. package/package.json +12 -12
  82. package/sbom.json +1 -1
  83. package/server.js +23 -1
  84. package/static/css/flyonui.css +1 -1
  85. package/static/css/src/app.tailwind.css +11 -0
  86. package/static/js/app.js +34 -0
  87. package/static/js/public.js +6 -2
  88. package/static/js/ui.js +97 -61
  89. package/static/licenses.html +341 -1252
  90. package/translations/messages.pot +62 -56
  91. package/views/account/login-redirect.hbs +22 -0
  92. package/views/account/passkeys.hbs +2 -2
  93. package/views/accounts/account.hbs +2 -2
  94. package/views/accounts/browse.hbs +1 -1
  95. package/views/accounts/edit.hbs +1 -1
  96. package/views/accounts/register/imap-server.hbs +1 -1
  97. package/views/config/ai.hbs +1 -1
  98. package/views/config/branding.hbs +2 -2
  99. package/views/config/document-store/chat.hbs +1 -1
  100. package/views/config/document-store/index.hbs +1 -1
  101. package/views/config/imap-proxy.hbs +1 -4
  102. package/views/config/license.hbs +1 -1
  103. package/views/config/mcp.hbs +88 -52
  104. package/views/config/network.hbs +1 -1
  105. package/views/config/oauth/app.hbs +2 -2
  106. package/views/config/service.hbs +1 -1
  107. package/views/config/smtp.hbs +1 -4
  108. package/views/config/tls-upload.hbs +81 -0
  109. package/views/config/tls.hbs +593 -0
  110. package/views/config/webhooks.hbs +2 -2
  111. package/views/internals/index.hbs +1 -1
  112. package/views/layout/app.hbs +6 -6
  113. package/views/layout/login.hbs +5 -5
  114. package/views/layout/main.hbs +2 -2
  115. package/views/layout/prompt.hbs +3 -3
  116. package/views/layout/public.hbs +1 -1
  117. package/views/mcp/authorize.hbs +47 -45
  118. package/views/partials/ace_assets.hbs +1 -1
  119. package/views/partials/add_account_modal.hbs +1 -1
  120. package/views/partials/filter_editor_js.hbs +2 -2
  121. package/views/partials/gateway_js.hbs +1 -1
  122. package/views/partials/mcp_access_levels.hbs +16 -9
  123. package/views/partials/mcp_tool_count.hbs +15 -14
  124. package/views/partials/oauth_form.hbs +1 -1
  125. package/views/partials/public_theme_init.hbs +1 -1
  126. package/views/partials/side_menu.hbs +1 -0
  127. package/views/partials/template_form.hbs +1 -1
  128. package/views/partials/theme_init.hbs +1 -1
  129. package/views/partials/tls_security_card.hbs +25 -53
  130. package/views/partials/ui/alert-banner.hbs +3 -2
  131. package/views/partials/ui/badge.hbs +6 -2
  132. package/views/partials/ui/btn.hbs +5 -2
  133. package/views/partials/webhooks_editor_functions.hbs +1 -1
  134. package/views/reference/index.hbs +1 -1
  135. package/views/reference/redirect.hbs +1 -1
  136. package/views/reference/tag.hbs +1 -1
  137. package/views/reference/token.hbs +1 -1
  138. package/views/templates/template.hbs +1 -1
  139. package/views/tokens/new.hbs +175 -74
  140. package/views/unsubscribe.hbs +1 -1
  141. package/views/webhooks/webhook.hbs +1 -1
  142. package/workers/api.js +102 -142
  143. package/workers/imap-proxy.js +4 -1
  144. package/workers/smtp.js +51 -44
  145. package/views/partials/tls_security_js.hbs +0 -64
  146. package/views/partials/tls_security_modal.hbs +0 -22
@@ -0,0 +1,593 @@
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 tables below it agree. The request action posts with
3
+ fetch (uiPostJson), which is why it sits outside the settings forms 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. Each listener presents one certificate by default and answers a client that asks for another configured
16
+ name with the certificate for that name. Certificates can be ordered from Let's Encrypt, uploaded, supplied through
17
+ the environment, or generated here as a self-signed fallback so a listener always starts.</p>
18
+
19
+ {{#if acme.staging}}
20
+ {{#> ui/alert-banner variant="warning" icon="icon-[tabler--flask]" title="Staging certificate authority"}}
21
+ <div>This instance is pointed at the Let's Encrypt staging directory (<code>{{acme.directoryUrl}}</code>). Certificates
22
+ it issues are signed by a root nobody trusts, so every client will refuse them. Clear
23
+ <code>EENGINE_ACME_DIRECTORY_URL</code> to go back to production.</div>
24
+ {{/ui/alert-banner}}
25
+ {{/if}}
26
+
27
+ {{!-- Listeners first: what clients actually get is the reason to open this page. One row per
28
+ listener, with the certificate it presents by default as a dropdown. Saved with the button
29
+ rather than on change: every save reloads the listeners, and a wrong default is what a
30
+ client sees on its next handshake. --}}
31
+ <form method="post" action="/admin/config/tls/listeners">
32
+ {{!-- no id: the layout already renders the #crumb element the scripts read --}}
33
+ <input type="hidden" name="crumb" value="{{crumb}}" />
34
+
35
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-listeners">
36
+ <div class="card-header">
37
+ <h6 class="card-title text-primary">Listeners</h6>
38
+ </div>
39
+ <div class="px-6 pt-4 text-sm text-base-content/70">The default certificate is presented to a client that names
40
+ no host, and for every name it covers. Other configured names are served their own certificate, from the
41
+ table below.</div>
42
+ <div class="overflow-x-auto">
43
+ <table class="table ee-table-wrap table-fixed min-w-[56rem]">
44
+ <thead>
45
+ <tr>
46
+ <th class="w-52">Listener</th>
47
+ <th>Default certificate</th>
48
+ <th class="w-80">Serving now</th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+ {{#each listeners}}
53
+ <tr data-listener="{{this.key}}">
54
+ <td class="align-top">
55
+ <div class="font-medium">{{this.name}}</div>
56
+ <div class="mt-1 flex flex-wrap items-center gap-1">
57
+ {{#if this.state}}
58
+ {{> ui/state-badge label=this.state dataType=this.key}}
59
+ {{/if}}
60
+ {{#if this.serving.label}}
61
+ {{> ui/badge label=this.serving.label.text variant=this.serving.label.type title=this.serving.label.title soft=true}}
62
+ {{/if}}
63
+ </div>
64
+ </td>
65
+ <td class="align-top">
66
+ {{> ui/setting-ref name=this.settingKey class="whitespace-nowrap"}}
67
+ <select id="tlsDefault-{{this.key}}" name="{{this.settingKey}}" class="select max-w-md"
68
+ data-tls-default="{{this.key}}">
69
+ {{#each this.options}}
70
+ <option value="{{this.id}}" {{#if this.selected}}selected{{/if}}>{{this.label}}{{#if this.covers}}
71
+ ({{this.covers}}){{/if}}</option>
72
+ {{/each}}
73
+ </select>
74
+ {{#equals this.selection "missing"}}
75
+ <span class="helper-text text-warning">{{this.missingLabel}} (<code>{{this.requested}}</code>)
76
+ no longer exists, so this listener presents the automatic choice. Save to make that the
77
+ setting.</span>
78
+ {{/equals}}
79
+ </td>
80
+ <td class="align-top text-sm">
81
+ {{#if this.serving.certificate}}
82
+ <div>Presenting {{this.serving.certificate.label}}{{#if this.serving.certificate.validToIso}}, valid
83
+ until <span class="local-time"
84
+ data-time="{{this.serving.certificate.validToIso}}">{{this.serving.certificate.validToIso}}</span>{{/if}}.
85
+ </div>
86
+ {{else if this.hint}}
87
+ <div class="text-base-content/70">{{this.hint}}{{#if this.needsSetup}} Turn it on from the <a
88
+ href="{{this.configuredAt}}" class="link link-animated">{{this.name}}</a> page.{{/if}}</div>
89
+ {{else}}
90
+ <div class="text-base-content/70">
91
+ {{#if this.tlsEnabled}}
92
+ Serving HTTPS (<code>EENGINE_API_TLS</code> is set); the listener has not reported a certificate
93
+ yet.
94
+ {{else}}
95
+ Serving plain HTTP, the default. Put a reverse proxy in front for HTTPS, or set
96
+ <code>EENGINE_API_TLS=true</code> to have EmailEngine serve it with the certificates on this
97
+ page.
98
+ {{/if}}
99
+ </div>
100
+ {{/if}}
101
+ </td>
102
+ </tr>
103
+ {{/each}}
104
+ </tbody>
105
+ </table>
106
+ </div>
107
+ <div class="card-footer border-base-content/10 border-t px-6 py-4">
108
+ {{> ui/btn label="Save Changes" type="submit" icon="icon-[tabler--settings]" id="tls-listeners-save"}}
109
+ </div>
110
+ </div>
111
+ </form>
112
+
113
+ {{!-- One row per name. The Service URL's own name comes from the General page and cannot be
114
+ removed here; the others are added from the input in the header and removed from the row menu.
115
+ Both post immediately, the way every other list on the admin surface is edited. --}}
116
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-hostnames">
117
+ <div class="card-header flex flex-wrap items-center justify-between gap-3">
118
+ <h6 class="card-title text-primary">Hostnames</h6>
119
+ <form method="post" action="/admin/config/tls/hostnames" class="flex items-center gap-2 w-full sm:w-auto">
120
+ <input type="hidden" name="crumb" value="{{crumb}}" />
121
+ <input type="text" class="input input-sm min-w-0 grow sm:grow-0 sm:w-72" id="tlsAddHostname" name="hostname"
122
+ placeholder="Add a hostname, e.g. imap.example.com" aria-label="Hostname to add" required
123
+ data-lpignore="true" autocomplete="off" />
124
+ {{> ui/btn label="Add" type="submit" variant="primary" style="soft" size="sm" icon="icon-[tabler--plus]"
125
+ id="tlsAddHostnameBtn"}}
126
+ </form>
127
+ </div>
128
+
129
+ {{#if certificates}}
130
+ {{!-- Fixed layout, so the line under a row wraps inside the card instead of widening the table;
131
+ the minimum width keeps the columns readable on a phone, where the wrapper scrolls. --}}
132
+ <div class="overflow-x-auto">
133
+ <table class="table ee-table-wrap table-fixed min-w-[52rem]">
134
+ <thead>
135
+ <tr>
136
+ <th>Hostname</th>
137
+ <th class="w-36">Status</th>
138
+ <th class="w-56">Certificate</th>
139
+ <th class="w-32">Expires</th>
140
+ <th class="w-40 text-end"><span class="sr-only">Actions</span></th>
141
+ </tr>
142
+ </thead>
143
+ <tbody>
144
+ {{#each certificates}}
145
+ <tr data-hostname-row="{{this.hostname}}">
146
+ <td>
147
+ <div class="font-mono break-words">{{this.hostname}}</div>
148
+ {{#if this.isServiceHostname}}
149
+ <div class="text-base-content/60 text-xs">Service URL</div>
150
+ {{/if}}
151
+ {{#unless this.acmeEligible}}
152
+ <div class="text-base-content/60 text-xs">Not a public name, so Let's Encrypt can not validate
153
+ it</div>
154
+ {{/unless}}
155
+ </td>
156
+ <td>
157
+ {{!-- the wrapper keeps the badge on one line: the page script rewrites the
158
+ badge's own class list on a live update --}}
159
+ <div class="whitespace-nowrap">
160
+ {{> ui/badge label=this.label.text variant=this.label.type title=this.label.title
161
+ dataName="cert-badge" dataValue=this.hostname}}
162
+ </div>
163
+ </td>
164
+ <td>
165
+ {{#if this.certificate}}
166
+ <a href="#tls-certificates" class="link link-animated">{{this.certificate.label}}</a>
167
+ {{else}}
168
+ <span class="text-base-content/60">None yet</span>
169
+ {{/if}}
170
+ {{!-- A listener whose default, or whose own environment material, covers this
171
+ name presents that instead. Said here, on the row, rather than left for
172
+ the operator to derive from three tables. --}}
173
+ {{#each this.servedBy}}
174
+ <div class="text-base-content/60 text-xs" data-served-by="{{this.key}}">{{this.name}} presents
175
+ {{this.label}}</div>
176
+ {{/each}}
177
+ </td>
178
+ <td>
179
+ {{#if this.certificate.validToIso}}
180
+ <div><span class="local-time" data-time="{{this.certificate.validToIso}}">{{this.certificate.validToIso}}</span></div>
181
+ <div class="text-base-content/60 text-xs"><span class="relative-time" data-time="{{this.certificate.validToIso}}"></span></div>
182
+ {{/if}}
183
+ </td>
184
+ <td class="text-end">
185
+ <div class="flex items-center justify-end gap-1 whitespace-nowrap">
186
+ {{#if this.wanted}}
187
+ {{> ui/btn label="Request" variant="primary" style="soft" size="sm" icon="icon-[tabler--refresh]"
188
+ class="tls-request-btn" id=""}}
189
+ {{/if}}
190
+ {{#> ui/row-actions label="Certificate actions" deleteModal=(when this.isServiceHostname "" "#removeHostname")
191
+ deleteId=this.hostname deleteName=this.hostname deleteLabel="Remove hostname"}}
192
+ {{!-- static first item on purpose: a block that opens with a condition can
193
+ lose its whole content to the partial-block pitfall --}}
194
+ <li><button type="button" class="dropdown-item" data-overlay="#certDetails{{@index}}">Details</button></li>
195
+ {{#if this.acmeEligible}}
196
+ <li><button type="button" class="dropdown-item tls-preflight-btn">Check reachability</button></li>
197
+ {{/if}}
198
+ {{#if this.canRequest}}
199
+ {{#unless this.wanted}}
200
+ <li><button type="button" class="dropdown-item tls-request-btn">Renew now</button></li>
201
+ {{/unless}}
202
+ {{/if}}
203
+ {{#equals this.certificate.source "acme"}}
204
+ <li><button type="button" class="dropdown-item text-error list-delete-btn"
205
+ data-delete-modal="#removeIssued" data-delete-id="{{this.hostname}}"
206
+ data-delete-name="{{this.hostname}}">Remove issued certificate</button></li>
207
+ {{/equals}}
208
+ {{/ui/row-actions}}
209
+ </div>
210
+ </td>
211
+ </tr>
212
+ {{!-- The one line under a name: why the last order failed, why a request was declined,
213
+ or that one is under way. The page script fills it for reachability checks and
214
+ live order progress too, so a name never grows a second alert. --}}
215
+ <tr class="{{#unless this.reason}}hidden{{/unless}}" data-cert-reason-row="{{this.hostname}}">
216
+ <td colspan="5" class="pt-0">
217
+ <div class="alert alert-soft alert-{{when this.reason.variant this.reason.variant "info"}} block break-words text-sm py-2"
218
+ data-cert-reason="{{this.hostname}}">{{this.reason.message}}</div>
219
+ </td>
220
+ </tr>
221
+ {{/each}}
222
+ </tbody>
223
+ </table>
224
+ </div>
225
+ {{else}}
226
+ <div class="card-body">
227
+ {{#> ui/empty-state icon="icon-[tabler--certificate-off]" title="No hostname is configured"}}
228
+ Set the <a href="/admin/config/service#settingsServiceUrl" class="link link-animated">Service URL</a> or add a
229
+ hostname above. Until then a TLS listener serves a self-signed certificate for <code>localhost</code>.
230
+ {{/ui/empty-state}}
231
+ </div>
232
+ {{/if}}
233
+ </div>
234
+
235
+ {{!-- Every certificate the instance holds, one row each, whatever it came from: the material a
236
+ listener's environment variables supply, the uploaded certificate, each issued one, and the
237
+ self-signed fallback. "Used by" is which listeners present it by default. --}}
238
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-certificates">
239
+ <div class="card-header flex flex-wrap items-center justify-between gap-3">
240
+ <h6 class="card-title text-primary">Certificates</h6>
241
+ {{> ui/btn label=(when manual "Replace uploaded certificate" "Upload a certificate") variant="primary" style="soft"
242
+ size="sm" href="/admin/config/tls/upload" icon="icon-[tabler--upload]" id="tls-upload-link"}}
243
+ </div>
244
+ <div class="overflow-x-auto">
245
+ <table class="table ee-table-wrap table-fixed min-w-[56rem]">
246
+ <thead>
247
+ <tr>
248
+ <th>Certificate</th>
249
+ <th class="w-52">Covers</th>
250
+ <th class="w-32">Status</th>
251
+ <th class="w-32">Expires</th>
252
+ <th class="w-44">Used by</th>
253
+ <th class="w-28 text-end"><span class="sr-only">Actions</span></th>
254
+ </tr>
255
+ </thead>
256
+ <tbody>
257
+ {{#each catalog}}
258
+ <tr data-certificate-row="{{this.id}}">
259
+ <td>
260
+ <div class="font-medium">{{this.label}}</div>
261
+ {{#if this.detail}}
262
+ <div class="text-base-content/60 text-xs font-mono break-all">{{this.detail}}</div>
263
+ {{else if this.certificate}}
264
+ <div class="text-base-content/60 text-xs font-mono break-all">{{this.certificate.subject}}</div>
265
+ {{/if}}
266
+ {{#equals this.source "self-signed"}}
267
+ {{#if this.certificate}}
268
+ <div class="flex items-start gap-2 mt-1">
269
+ <span class="text-base-content/60 text-xs shrink-0">SHA-256</span>
270
+ <code class="text-xs break-all min-w-0" id="selfSignedFingerprint">{{this.certificate.fingerprint256}}</code>
271
+ {{> ui/copy-btn target="selfSignedFingerprint" small=true btnClass="btn-text"}}
272
+ </div>
273
+ {{/if}}
274
+ {{/equals}}
275
+ </td>
276
+ <td>
277
+ {{#if this.certificate}}
278
+ <div class="font-mono text-sm break-words">{{#each this.certificate.altNames}}{{this}}{{#unless @last}},
279
+ {{/unless}}{{/each}}</div>
280
+ {{else}}
281
+ <span class="text-base-content/60">Every configured name, generated on first use</span>
282
+ {{/if}}
283
+ </td>
284
+ <td>
285
+ <div class="whitespace-nowrap">
286
+ {{> ui/badge label=this.status.text variant=this.status.type title=this.status.title}}
287
+ </div>
288
+ </td>
289
+ <td>
290
+ {{#if this.certificate.validToIso}}
291
+ <div><span class="local-time" data-time="{{this.certificate.validToIso}}">{{this.certificate.validToIso}}</span></div>
292
+ <div class="text-base-content/60 text-xs"><span class="relative-time" data-time="{{this.certificate.validToIso}}"></span></div>
293
+ {{/if}}
294
+ </td>
295
+ <td>
296
+ {{#if this.usedBy}}
297
+ <div class="flex flex-wrap gap-1">
298
+ {{#each this.usedBy}}
299
+ {{> ui/badge label=this.label variant="neutral" soft=true dataName="used-by" dataValue=this.key}}
300
+ {{/each}}
301
+ </div>
302
+ {{else}}
303
+ <span class="text-base-content/60 text-sm">No listener presents it by default</span>
304
+ {{/if}}
305
+ </td>
306
+ <td class="text-end">
307
+ <div class="flex items-center justify-end gap-1 whitespace-nowrap">
308
+ {{#> ui/row-actions label="Certificate actions"}}
309
+ {{!-- static first item on purpose: a block that opens with a condition can
310
+ lose its whole content to the partial-block pitfall --}}
311
+ <li><button type="button" class="dropdown-item" data-overlay="#catalogDetails{{@index}}">Details</button></li>
312
+ {{#equals this.source "manual"}}
313
+ <li><a class="dropdown-item" href="/admin/config/tls/upload">Replace</a></li>
314
+ <li><button type="button" class="dropdown-item text-error" data-overlay="#removeUploaded"
315
+ id="tls-remove-uploaded">Remove</button></li>
316
+ {{/equals}}
317
+ {{#equals this.source "acme"}}
318
+ <li><button type="button" class="dropdown-item text-error list-delete-btn"
319
+ data-delete-modal="#removeIssued" data-delete-id="{{this.hostname}}"
320
+ data-delete-name="{{this.hostname}}">Remove issued certificate</button></li>
321
+ {{/equals}}
322
+ {{#equals this.source "self-signed"}}
323
+ <li><button type="button" class="dropdown-item" data-overlay="#regenerateSelfSigned"
324
+ id="tls-regenerate-self-signed">{{#if this.certificate}}Regenerate{{else}}Generate now{{/if}}</button></li>
325
+ {{/equals}}
326
+ {{#equals this.source "env"}}
327
+ <li><span class="dropdown-item text-base-content/60">Managed outside EmailEngine</span></li>
328
+ {{/equals}}
329
+ {{/ui/row-actions}}
330
+ </div>
331
+ </td>
332
+ </tr>
333
+ {{/each}}
334
+ </tbody>
335
+ </table>
336
+ </div>
337
+ </div>
338
+
339
+ {{> ui/env-managed-alert}}
340
+
341
+ <form method="post" action="/admin/config/tls">
342
+ {{!-- no id: the layout already renders the #crumb element the scripts read --}}
343
+ <input type="hidden" name="crumb" value="{{crumb}}" />
344
+
345
+ <div class="card bg-base-100 shadow-md mb-6" id="tls-source">
346
+ <div class="card-header">
347
+ <h6 class="card-title text-primary">Certificate source</h6>
348
+ </div>
349
+ {{!-- The setting selects which stored sources a name is resolved from, not which one is
350
+ used, so each option says what gets served: in Let's Encrypt mode an uploaded
351
+ certificate still wins for the names it covers. A default a listener was set to
352
+ present is presented in every mode - it is a choice, like environment material. --}}
353
+ <div class="card-body space-y-4">
354
+ <div>
355
+ {{> ui/setting-ref name="tlsProvisioning"}}
356
+ {{> ui/radio id="tlsProvisioningAcme" name="tlsProvisioning" value="acme" label="Let's Encrypt (recommended)"
357
+ selected=values.tlsProvisioning hint="Ordered and renewed for every public name. An uploaded certificate
358
+ still wins for the names it covers."}}
359
+ </div>
360
+ <div>
361
+ {{> ui/radio id="tlsProvisioningManual" name="tlsProvisioning" value="manual" label="Uploaded certificate only"
362
+ selected=values.tlsProvisioning hint="Nothing is ordered. Names the upload does not cover get the
363
+ self-signed fallback."}}
364
+ </div>
365
+ <div>
366
+ {{> ui/radio id="tlsProvisioningSelfSigned" name="tlsProvisioning" value="self-signed" label="Self-signed only"
367
+ selected=values.tlsProvisioning hint="For an instance the internet can not reach. Clients must pin the
368
+ fingerprint or be told to accept the certificate."}}
369
+ </div>
370
+ </div>
371
+ <div class="card-footer border-base-content/10 border-t px-6 py-4">
372
+ {{> ui/btn label="Save Changes" type="submit" icon="icon-[tabler--settings]"}}
373
+ </div>
374
+ </div>
375
+ </form>
376
+
377
+ {{#> ui/details summary="How certificates are chosen" class="card bg-base-100 shadow-md mb-6"}}
378
+ <p class="mb-2">Each listener presents its <strong>default certificate</strong> to a client that names no host, and for
379
+ every name that certificate covers. A client asking for another configured name is answered with the first
380
+ certificate in the table above that covers the name and that the source setting admits; a name nothing covers gets
381
+ the self-signed fallback. With the default left on <em>Automatic</em>, a listener presents the material from its own
382
+ TLS environment variables (<code>EENGINE_SMTP_TLS_CERT</code>, <code>EENGINE_IMAPPROXY_TLS_CERT</code>,
383
+ <code>EENGINE_API_TLS_CERT</code>) when they are set, and otherwise the certificate for the Service URL hostname. A
384
+ default chosen by hand is presented whatever the source setting says.</p>
385
+ <p class="mb-2">EmailEngine answers the Let's Encrypt <code>http-01</code> challenge itself, at
386
+ <code>/.well-known/acme-challenge/</code>. For that to work, the hostname has to resolve to this machine and a
387
+ request to <strong>port 80</strong> for that name has to reach EmailEngine, directly or through a reverse proxy.
388
+ Nothing else is needed; the certificate is renewed on its own well before it expires. <em>Check reachability</em>
389
+ in a hostname's menu makes exactly that request against this instance's own public name, so a missing DNS record
390
+ or a port 80 that goes somewhere else is reported right away instead of as an opaque ACME error minutes later.</p>
391
+ <p>Certificate authority: <code>{{acme.directoryUrl}}</code> (account <code>{{acme.environment}}</code>).</p>
392
+ {{/ui/details}}
393
+
394
+ {{!-- One details dialog per row, so the tables stay narrow. Keyed by position: a hostname is not
395
+ a valid id, and the rows are few. --}}
396
+ {{#*inline "certificateDetails"}}
397
+ <dl class="ee-dl">
398
+ <dt>Certificate</dt>
399
+ <dd>{{this.label}}{{#if this.detail}} <span class="text-base-content/60 font-mono text-xs">{{this.detail}}</span>{{/if}}</dd>
400
+ <dt>Subject</dt>
401
+ <dd class="break-all">{{this.subject}}</dd>
402
+ <dt>Issuer</dt>
403
+ <dd class="break-all">{{this.issuer}}</dd>
404
+ <dt>Covers</dt>
405
+ <dd class="font-mono text-sm break-all">{{#each this.altNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}</dd>
406
+ <dt>Valid from</dt>
407
+ <dd><span class="local-date-time" data-time="{{this.validFromIso}}">{{this.validFromIso}}</span></dd>
408
+ <dt>Valid until</dt>
409
+ <dd><span class="local-date-time" data-time="{{this.validToIso}}">{{this.validToIso}}</span></dd>
410
+ <dt>SHA-256 fingerprint</dt>
411
+ <dd>
412
+ <div class="flex items-start gap-2">
413
+ <code class="text-xs break-all min-w-0" id="{{fingerprintId}}">{{this.fingerprint256}}</code>
414
+ {{> ui/copy-btn target=fingerprintId small=true btnClass="btn-text"}}
415
+ </div>
416
+ </dd>
417
+ <dt>Chain</dt>
418
+ <dd>{{ngettext '%d certificate' '%d certificates' this.chainLength}}</dd>
419
+ </dl>
420
+ {{/inline}}
421
+
422
+ {{#each certificates}}
423
+ {{#> ui/modal id=(concat "certDetails" @index) title=this.hostname}}
424
+ <div class="modal-body">
425
+ {{#if this.certificate}}
426
+ {{> certificateDetails this.certificate fingerprintId=(concat "certFingerprint" @index)}}
427
+ {{else}}
428
+ <p class="text-base-content/60 mb-0">No certificate is stored for this name yet.</p>
429
+ {{/if}}
430
+ </div>
431
+ {{/ui/modal}}
432
+ {{/each}}
433
+
434
+ {{#each catalog}}
435
+ {{#> ui/modal id=(concat "catalogDetails" @index) title=this.label}}
436
+ <div class="modal-body">
437
+ {{#if this.certificate}}
438
+ {{> certificateDetails this.certificate fingerprintId=(concat "catalogFingerprint" @index)}}
439
+ {{else}}
440
+ <p class="text-base-content/60 mb-0">Not generated yet. It is generated for every configured name the first time a
441
+ listener needs it, or from its row menu.</p>
442
+ {{/if}}
443
+ </div>
444
+ {{/ui/modal}}
445
+ {{/each}}
446
+
447
+ {{#> ui/delete-modal id="removeHostname" noun="hostname" action="/admin/config/tls/hostnames/delete" fieldName="hostname"}}
448
+ Stop serving a certificate for <strong class="delete-target-name"></strong>? An already issued certificate is kept and
449
+ used again if the name is added back.
450
+ {{/ui/delete-modal}}
451
+
452
+ {{#> ui/confirm-modal id="removeIssued" title="Remove issued certificate" action="/admin/config/tls/delete"
453
+ fieldName="certificate" fieldClass="delete-target-id" submitLabel="Remove certificate"}}
454
+ Remove the Let's Encrypt certificate stored for <strong class="delete-target-name"></strong>? The name falls back to the
455
+ self-signed certificate until a new one is ordered. A listener set to present this certificate presents its automatic
456
+ choice until it is set to another.
457
+ {{/ui/confirm-modal}}
458
+
459
+ {{#> ui/confirm-modal id="removeUploaded" title="Remove uploaded certificate" action="/admin/config/tls/delete"
460
+ fieldName="certificate" fieldValue="manual" submitLabel="Remove certificate"}}
461
+ Remove the uploaded certificate? Every name it covers falls back to whatever the selected source provides. A listener
462
+ set to present it presents its automatic choice until it is set to another.
463
+ {{/ui/confirm-modal}}
464
+
465
+ {{#> ui/confirm-modal id="regenerateSelfSigned" title="Self-signed certificate" action="/admin/config/tls/delete"
466
+ fieldName="certificate" fieldValue="self-signed" submitVariant="primary" submitIcon="icon-[tabler--refresh]"
467
+ submitLabel=(when selfSigned "Regenerate" "Generate")}}
468
+ {{#if selfSigned}}
469
+ Generate a new self-signed certificate for every configured name? Clients that pinned the current fingerprint will have
470
+ to pin the new one.
471
+ {{else}}
472
+ Generate a self-signed certificate for every configured name now, instead of the first time a listener needs one?
473
+ {{/if}}
474
+ {{/ui/confirm-modal}}
475
+
476
+ <script data-cfasync="false" nonce="{{cspNonce}}">
477
+ document.addEventListener('DOMContentLoaded', () => {
478
+
479
+ // The one line under a hostname row. Every message about a name lands here, so a name
480
+ // never accumulates a stack of alerts.
481
+ const showReason = (hostname, type, text) => {
482
+ let row = document.querySelector(`[data-cert-reason-row="${CSS.escape(hostname)}"]`);
483
+ let elm = row && row.querySelector('[data-cert-reason]');
484
+ if (!elm) {
485
+ return;
486
+ }
487
+ row.classList.remove('hidden');
488
+ elm.classList.remove('alert-info', 'alert-success', 'alert-warning', 'alert-error');
489
+ elm.classList.add(`alert-${type}`);
490
+ elm.textContent = text;
491
+ };
492
+
493
+ const rowHostname = elm => {
494
+ let row = elm.closest('[data-hostname-row]');
495
+ return row && row.dataset.hostnameRow;
496
+ };
497
+
498
+ for (let btn of document.querySelectorAll('.tls-preflight-btn')) {
499
+ btn.addEventListener('click', () => {
500
+ let hostname = rowHostname(btn);
501
+ showReason(hostname, 'info', `Checking whether ${hostname} reaches this server...`);
502
+
503
+ uiBusyAction(btn, uiPostJson('/admin/config/tls/preflight', { hostname }).then(data => {
504
+ showReason(hostname, data && data.success ? 'success' : 'error', (data && (data.message || data.error)) || 'The check failed');
505
+ }).catch(err => {
506
+ showReason(hostname, 'error', err.message);
507
+ }));
508
+ });
509
+ }
510
+
511
+ // One name reports on its own line; the page-level action reports as a toast and then
512
+ // marks every name it queued.
513
+ const requestCertificates = (btn, hostname) => {
514
+ if (hostname) {
515
+ showReason(hostname, 'info', `Requesting a certificate for ${hostname}...`);
516
+ }
517
+
518
+ uiBusyAction(btn, uiPostJson('/admin/config/tls/request', hostname ? { hostname } : {}).then(data => {
519
+ if (hostname) {
520
+ if (!data || !data.success) {
521
+ showReason(hostname, 'error', (data && data.error) || 'The request failed');
522
+ }
523
+ return;
524
+ }
525
+
526
+ uiToastResult(data, 'Requesting certificates', 'The request failed');
527
+ for (let name of (data && data.hostnames) || []) {
528
+ showReason(name, 'info', `Requesting a certificate for ${name}...`);
529
+ }
530
+ }).catch(err => {
531
+ if (hostname) {
532
+ showReason(hostname, 'error', err.message);
533
+ } else {
534
+ showToast(err.message, 'alert-triangle');
535
+ }
536
+ }));
537
+ };
538
+
539
+ for (let btn of document.querySelectorAll('.tls-request-btn')) {
540
+ btn.addEventListener('click', () => requestCertificates(btn, rowHostname(btn)));
541
+ }
542
+
543
+ let requestAll = document.getElementById('tls-request-all');
544
+ if (requestAll) {
545
+ requestAll.addEventListener('click', () => requestCertificates(requestAll, null));
546
+ }
547
+
548
+ // One table for both the message and the badge, so a state cannot be coloured one way in
549
+ // the reason line and another on the badge. Mirrors STATUS_VARIANTS in lib/tls/status.js,
550
+ // which paints the same states on a full render.
551
+ const STATES = {
552
+ valid: { variant: 'success', badge: 'Valid' },
553
+ failed: { variant: 'error', badge: 'Failed' },
554
+ // The certificate is still usable and still being served; it is the renewal that did
555
+ // not happen, so this is a warning rather than a failure
556
+ renewalFailed: { variant: 'warning', badge: 'Renewal failed' },
557
+ // A declined request explains itself; the badge it leaves behind is whatever the row had
558
+ skipped: { variant: 'info', badge: null }
559
+ };
560
+
561
+ // Provisioning runs in the background, so progress arrives over the change feed the rest
562
+ // of the admin UI already listens on rather than by holding this request open.
563
+ document.addEventListener('ee:change', e => {
564
+ let data = e.detail;
565
+ if (!data || data.type !== 'tlsCertificateState' || !data.payload || !data.payload.hostname) {
566
+ return;
567
+ }
568
+
569
+ let hostname = data.payload.hostname;
570
+ let state = data.payload.state;
571
+ let paint = STATES[state] || { variant: 'info', badge: 'Requesting' };
572
+
573
+ showReason(hostname, paint.variant, data.payload.message || state);
574
+
575
+ if (state === 'valid') {
576
+ // The row shows source, expiry and the details dialog, none of which this event
577
+ // carries, so repainting the badge here would only be undone a moment later.
578
+ // Reloading is both simpler and more honest than patching three fields.
579
+ setTimeout(() => window.location.reload(), 1500);
580
+ return;
581
+ }
582
+
583
+ let badge = document.querySelector(`[data-cert-badge="${CSS.escape(hostname)}"]`);
584
+ if (badge && paint.badge) {
585
+ badge.className = `badge badge-${paint.variant}`;
586
+ badge.textContent = paint.badge;
587
+ // The title carries the reason; leaving the old one behind is how a badge ends up
588
+ // saying one thing and explaining another.
589
+ badge.title = data.payload.message || paint.badge;
590
+ }
591
+ });
592
+ });
593
+ </script>
@@ -267,9 +267,9 @@ class="mb-1"}}
267
267
  </form>
268
268
 
269
269
  {{> ace_assets}}
270
- <script src="/static/js/ace/ext-language_tools.js"></script>
270
+ <script data-cfasync="false" src="/static/js/ace/ext-language_tools.js"></script>
271
271
 
272
- <script nonce="{{cspNonce}}">
272
+ <script data-cfasync="false" nonce="{{cspNonce}}">
273
273
  document.addEventListener('DOMContentLoaded', () => {
274
274
 
275
275
  const sendTestPayload = async () => {
@@ -163,7 +163,7 @@ submitLabel="Download Snapshot" submitVariant="info"}}
163
163
  Generate a memory snapshot for debugging? This may briefly affect thread performance.
164
164
  {{/ui/confirm-modal}}
165
165
 
166
- <script nonce="{{cspNonce}}">
166
+ <script data-cfasync="false" nonce="{{cspNonce}}">
167
167
  document.addEventListener('DOMContentLoaded', () => {
168
168
  for (let elm of document.querySelectorAll('.kill-thread-btn')) {
169
169
  elm.addEventListener('click', e => {
@@ -334,12 +334,12 @@
334
334
  </div>
335
335
  <!-- End of content column -->
336
336
 
337
- <script src="/static/js/flyonui.js"></script>
338
- <script src="/static/js/ui.js"></script>
337
+ <script data-cfasync="false" src="/static/js/flyonui.js"></script>
338
+ <script data-cfasync="false" src="/static/js/ui.js"></script>
339
339
 
340
- <script src="/static/js/highlight.min.js"></script>
340
+ <script data-cfasync="false" src="/static/js/highlight.min.js"></script>
341
341
 
342
- <script src="/static/js/app.js"></script>
342
+ <script data-cfasync="false" src="/static/js/app.js"></script>
343
343
 
344
344
  {{!-- global #crumb element for page scripts that post with fetch();
345
345
  must render unconditionally - converted pages rely on it instead of
@@ -352,7 +352,7 @@
352
352
  Provisioning a trial license, please wait <span class="loading loading-spinner loading-sm align-middle"></span>
353
353
  </div>
354
354
  {{/ui/modal}}
355
- <script nonce="{{cspNonce}}">
355
+ <script data-cfasync="false" nonce="{{cspNonce}}">
356
356
  document.addEventListener('DOMContentLoaded', () => {
357
357
  let trialBtn = document.getElementById('start-trial-btn');
358
358
  if (!trialBtn) {
@@ -392,7 +392,7 @@
392
392
 
393
393
  {{#if updateBrowserInfo}}
394
394
  <input type="hidden" id="browser-info-crumb" value="{{crumb}}" />
395
- <script nonce="{{cspNonce}}">
395
+ <script data-cfasync="false" nonce="{{cspNonce}}">
396
396
  document.addEventListener('DOMContentLoaded', () => {
397
397
  let sendBrowserInfo = async () => {
398
398
  let timezone = false;