emailengine-app 2.79.8 → 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 (182) hide show
  1. package/.github/dependabot.yml +22 -0
  2. package/.github/workflows/test.yml +39 -0
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +69 -0
  5. package/DOCKER_DEPLOYMENT.md +6 -7
  6. package/Dockerfile +35 -11
  7. package/config/default.toml +7 -2
  8. package/copy-static-files.sh +23 -5
  9. package/data/google-crawlers.json +1 -1
  10. package/encrypt.js +43 -0
  11. package/lib/account/account-state.js +62 -0
  12. package/lib/account.js +60 -3
  13. package/lib/api-routes/account-routes.js +20 -0
  14. package/lib/api-routes/bull-board-routes.js +3 -2
  15. package/lib/api-routes/index.js +1 -1
  16. package/lib/api-routes/route-helpers.js +8 -0
  17. package/lib/api-routes/settings-routes.js +17 -2
  18. package/lib/auth-token.js +73 -2
  19. package/lib/autodetect-imap-settings.js +379 -69
  20. package/lib/cert-handler.js +62 -0
  21. package/lib/consts.js +58 -7
  22. package/lib/db.js +12 -0
  23. package/lib/egress-fetch.js +145 -0
  24. package/lib/email-client/base-client.js +234 -66
  25. package/lib/email-client/credential-errors.js +118 -0
  26. package/lib/email-client/gmail/gmail-api.js +2 -1
  27. package/lib/email-client/gmail-client.js +70 -64
  28. package/lib/email-client/imap/connection-errors.js +52 -0
  29. package/lib/email-client/imap/listing-diff.js +47 -6
  30. package/lib/email-client/imap/mailbox.js +457 -379
  31. package/lib/email-client/imap/subconnection.js +15 -11
  32. package/lib/email-client/imap/sync-operations.js +46 -59
  33. package/lib/email-client/imap-client.js +136 -95
  34. package/lib/email-client/message-builder.js +11 -11
  35. package/lib/email-client/outlook/graph-api.js +2 -1
  36. package/lib/email-client/outlook-client.js +219 -106
  37. package/lib/export.js +35 -2
  38. package/lib/handlebars-helpers.js +129 -0
  39. package/lib/imap-proxy-auth.js +96 -21
  40. package/lib/imapproxy/imap-core/README.md +1 -0
  41. package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
  42. package/lib/imapproxy/imap-server.js +56 -66
  43. package/lib/lua/h-del-if-equals.lua +39 -0
  44. package/lib/lua/h-set-if-equals.lua +39 -0
  45. package/lib/openapi/index.js +3 -0
  46. package/lib/outbox.js +28 -3
  47. package/lib/rate-limit.js +23 -4
  48. package/lib/routes-ui.js +4 -34
  49. package/lib/schemas.js +42 -3
  50. package/lib/security-headers.js +411 -0
  51. package/lib/sentry.js +36 -4
  52. package/lib/smtp-auth.js +86 -7
  53. package/lib/tls/context.js +376 -0
  54. package/lib/tls/der.js +223 -0
  55. package/lib/tls/provision.js +555 -0
  56. package/lib/tls/self-signed.js +282 -0
  57. package/lib/tls/status.js +431 -0
  58. package/lib/tls/store.js +666 -0
  59. package/lib/tools.js +337 -147
  60. package/lib/ui-routes/account-routes.js +47 -33
  61. package/lib/ui-routes/admin-config-routes.js +22 -1
  62. package/lib/ui-routes/auth-routes.js +16 -1
  63. package/lib/ui-routes/export-routes.js +4 -0
  64. package/lib/ui-routes/internals-routes.js +3 -5
  65. package/lib/ui-routes/mcp-consent-routes.js +7 -0
  66. package/lib/ui-routes/network-config-routes.js +58 -48
  67. package/lib/ui-routes/route-helpers.js +24 -8
  68. package/lib/ui-routes/smtp-test-routes.js +7 -0
  69. package/lib/ui-routes/tls-config-routes.js +581 -0
  70. package/lib/utils/mailbox-path.js +51 -0
  71. package/lib/utils/severity.js +31 -0
  72. package/lib/webhook-egress.js +5 -0
  73. package/package.json +21 -24
  74. package/sbom.json +1 -1
  75. package/server.js +53 -36
  76. package/static/css/flyonui.css +1 -1
  77. package/static/css/src/app.tailwind.css +11 -0
  78. package/static/js/ace/css/ace.css +1462 -0
  79. package/static/js/ace/css/kuroir-1.png +0 -0
  80. package/static/js/ace/css/kuroir-2.png +0 -0
  81. package/static/js/ace/css/main-1.png +0 -0
  82. package/static/js/ace/css/main-10.svg +4 -0
  83. package/static/js/ace/css/main-11.svg +5 -0
  84. package/static/js/ace/css/main-12.svg +4 -0
  85. package/static/js/ace/css/main-13.png +0 -0
  86. package/static/js/ace/css/main-14.png +0 -0
  87. package/static/js/ace/css/main-15.png +0 -0
  88. package/static/js/ace/css/main-16.png +0 -0
  89. package/static/js/ace/css/main-17.png +0 -0
  90. package/static/js/ace/css/main-18.png +0 -0
  91. package/static/js/ace/css/main-19.png +0 -0
  92. package/static/js/ace/css/main-2.png +0 -0
  93. package/static/js/ace/css/main-20.png +0 -0
  94. package/static/js/ace/css/main-21.png +0 -0
  95. package/static/js/ace/css/main-22.png +0 -0
  96. package/static/js/ace/css/main-23.png +0 -0
  97. package/static/js/ace/css/main-24.png +0 -0
  98. package/static/js/ace/css/main-25.svg +1 -0
  99. package/static/js/ace/css/main-26.png +0 -0
  100. package/static/js/ace/css/main-3.png +0 -0
  101. package/static/js/ace/css/main-4.png +0 -0
  102. package/static/js/ace/css/main-5.svg +7 -0
  103. package/static/js/ace/css/main-6.svg +9 -0
  104. package/static/js/ace/css/main-7.svg +7 -0
  105. package/static/js/ace/css/main-8.svg +9 -0
  106. package/static/js/ace/css/main-9.svg +6 -0
  107. package/static/js/ace/css/theme/kuroir.css +78 -0
  108. package/static/js/ace/css/theme/tomorrow_night.css +128 -0
  109. package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
  110. package/static/js/ace/css/theme/xcode.css +106 -0
  111. package/static/js/ace/css/tomorrow_night-1.png +0 -0
  112. package/static/js/ace/css/tomorrow_night-2.png +0 -0
  113. package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
  114. package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
  115. package/static/js/ace/css/xcode-1.png +0 -0
  116. package/static/js/ace/css/xcode-2.png +0 -0
  117. package/static/js/app.js +34 -0
  118. package/static/js/ee-client.js +256 -102
  119. package/static/js/public.js +13 -2
  120. package/static/js/ui.js +40 -25
  121. package/static/licenses.html +393 -1282
  122. package/static/vendor/simplewebauthn/browser.min.js +2 -2
  123. package/translations/messages.pot +203 -157
  124. package/views/account/login-redirect.hbs +22 -0
  125. package/views/accounts/account.hbs +15 -37
  126. package/views/accounts/browse.hbs +3 -1
  127. package/views/accounts/edit.hbs +1 -1
  128. package/views/accounts/register/imap-server.hbs +1 -1
  129. package/views/config/ai.hbs +1 -1
  130. package/views/config/branding.hbs +2 -2
  131. package/views/config/document-store/chat.hbs +1 -1
  132. package/views/config/document-store/index.hbs +1 -1
  133. package/views/config/imap-proxy.hbs +1 -4
  134. package/views/config/license.hbs +1 -1
  135. package/views/config/mcp.hbs +1 -1
  136. package/views/config/network.hbs +14 -16
  137. package/views/config/oauth/app.hbs +2 -2
  138. package/views/config/service.hbs +1 -1
  139. package/views/config/smtp.hbs +1 -4
  140. package/views/config/tls-upload.hbs +81 -0
  141. package/views/config/tls.hbs +492 -0
  142. package/views/config/webhooks.hbs +2 -2
  143. package/views/error.hbs +4 -2
  144. package/views/internals/index.hbs +1 -1
  145. package/views/layout/app.hbs +3 -11
  146. package/views/mcp/authorize.hbs +1 -1
  147. package/views/partials/ace_assets.hbs +13 -0
  148. package/views/partials/add_account_modal.hbs +1 -1
  149. package/views/partials/address_list.hbs +4 -4
  150. package/views/partials/filter_editor_js.hbs +2 -2
  151. package/views/partials/gateway_js.hbs +1 -1
  152. package/views/partials/oauth_form.hbs +1 -1
  153. package/views/partials/public_theme_init.hbs +1 -1
  154. package/views/partials/side_menu.hbs +1 -0
  155. package/views/partials/template_form.hbs +2 -2
  156. package/views/partials/test_send.hbs +7 -4
  157. package/views/partials/theme_init.hbs +1 -1
  158. package/views/partials/tls_security_card.hbs +25 -53
  159. package/views/partials/ui/alert-banner.hbs +3 -2
  160. package/views/partials/ui/badge.hbs +6 -2
  161. package/views/partials/ui/btn.hbs +5 -2
  162. package/views/partials/ui/details.hbs +2 -2
  163. package/views/partials/webhooks_editor_functions.hbs +1 -1
  164. package/views/reference/redirect.hbs +1 -1
  165. package/views/templates/template.hbs +2 -2
  166. package/views/tokens/new.hbs +1 -1
  167. package/views/unsubscribe.hbs +1 -1
  168. package/views/webhooks/webhook.hbs +2 -2
  169. package/workers/api.js +131 -242
  170. package/workers/export.js +1 -5
  171. package/workers/imap-proxy.js +4 -1
  172. package/workers/imap.js +1 -3
  173. package/workers/smtp.js +59 -83
  174. package/workers/submit.js +6 -12
  175. package/workers/webhooks.js +6 -17
  176. package/static/front/EmailEngine_logo_horiz.png +0 -0
  177. package/static/front/EmailEngine_logo_vert.png +0 -0
  178. package/static/front/index.html +0 -57
  179. package/static/front/logo.png +0 -0
  180. package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
  181. package/views/partials/tls_security_js.hbs +0 -64
  182. 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>
@@ -266,10 +266,10 @@ class="mb-1"}}
266
266
 
267
267
  </form>
268
268
 
269
- <script src="/static/js/ace/ace.js"></script>
269
+ {{> ace_assets}}
270
270
  <script src="/static/js/ace/ext-language_tools.js"></script>
271
271
 
272
- <script>
272
+ <script nonce="{{cspNonce}}">
273
273
  document.addEventListener('DOMContentLoaded', () => {
274
274
 
275
275
  const sendTestPayload = async () => {
package/views/error.hbs CHANGED
@@ -14,9 +14,11 @@ pages, blocked access, failed form submissions without a friendlier page). --}}
14
14
  </div>
15
15
  {{/if}}
16
16
  <div class="ee-form-actions">
17
- <a href="javascript:history.back()" class="ee-btn ee-btn-neutral ee-btn-soft ee-btn-sm">
17
+ {{!-- A button rather than a javascript: link: the Content-Security-Policy on the admin
18
+ surface allows no javascript: URLs; static/js/public.js wires data-ee-back --}}
19
+ <button type="button" data-ee-back class="ee-btn ee-btn-neutral ee-btn-soft ee-btn-sm">
18
20
  <span class="ee-icon ee-icon-arrow-left"></span> {{_ "Go back" templateLocale}}
19
- </a>
21
+ </button>
20
22
  {{!-- The dashboard is an admin destination. A mailbox owner on the hosted form or a
21
23
  list recipient on an unsubscribe link has no business there, so the button only
22
24
  shows for a requester who holds an admin session, or on an instance that has no
@@ -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>
166
+ <script nonce="{{cspNonce}}">
167
167
  document.addEventListener('DOMContentLoaded', () => {
168
168
  for (let elm of document.querySelectorAll('.kill-thread-btn')) {
169
169
  elm.addEventListener('click', e => {
@@ -143,13 +143,7 @@
143
143
  <span class="bg-{{eeColor level}}/10 text-{{eeColor level}} flex size-8 shrink-0 items-center justify-center rounded-field">
144
144
  <span class="{{icon}} size-4 shrink-0"></span>
145
145
  </span>
146
- <span class="text-sm whitespace-normal">
147
- {{#if verbatim}}
148
- {{{message}}}
149
- {{else}}
150
- {{message}}
151
- {{/if}}
152
- </span>
146
+ <span class="text-sm whitespace-normal">{{message}}</span>
153
147
  </a>
154
148
  </li>
155
149
  {{/each}}
@@ -343,8 +337,6 @@
343
337
  <script src="/static/js/flyonui.js"></script>
344
338
  <script src="/static/js/ui.js"></script>
345
339
 
346
- <script src="/static/vendor/handlebars/handlebars.min-v4.7.9.js"></script>
347
-
348
340
  <script src="/static/js/highlight.min.js"></script>
349
341
 
350
342
  <script src="/static/js/app.js"></script>
@@ -360,7 +352,7 @@
360
352
  Provisioning a trial license, please wait <span class="loading loading-spinner loading-sm align-middle"></span>
361
353
  </div>
362
354
  {{/ui/modal}}
363
- <script>
355
+ <script nonce="{{cspNonce}}">
364
356
  document.addEventListener('DOMContentLoaded', () => {
365
357
  let trialBtn = document.getElementById('start-trial-btn');
366
358
  if (!trialBtn) {
@@ -400,7 +392,7 @@
400
392
 
401
393
  {{#if updateBrowserInfo}}
402
394
  <input type="hidden" id="browser-info-crumb" value="{{crumb}}" />
403
- <script>
395
+ <script nonce="{{cspNonce}}">
404
396
  document.addEventListener('DOMContentLoaded', () => {
405
397
  let sendBrowserInfo = async () => {
406
398
  let timezone = false;
@@ -115,7 +115,7 @@
115
115
  </div>
116
116
  </form>
117
117
 
118
- <script>
118
+ <script nonce="{{cspNonce}}">
119
119
  (() => {
120
120
  // The grant sentences describe the same token under each setting of the radio, so
121
121
  // whichever is showing is the one the operator is about to approve
@@ -0,0 +1,13 @@
1
+ {{!-- ACE editor assets: use this partial rather than a bare ace.js include. ACE runs in
2
+ strict-CSP mode (uiAceEnsureAssets in static/js/ui.js, which every editor goes through),
3
+ so it injects none of its own stylesheets; these are the sheets it would have injected -
4
+ the core one and the four themes uiAceThemes switches between, copied from ace-builds by
5
+ copy-static-files.sh. Linking them here rather than leaving uiAceEnsureAssets to add them
6
+ keeps the editor from painting before its stylesheet arrives. Pages that need an extension
7
+ (ext-language_tools) add it after this partial. --}}
8
+ <link rel="stylesheet" href="/static/js/ace/css/ace.css">
9
+ <link rel="stylesheet" href="/static/js/ace/css/theme/xcode.css">
10
+ <link rel="stylesheet" href="/static/js/ace/css/theme/kuroir.css">
11
+ <link rel="stylesheet" href="/static/js/ace/css/theme/tomorrow_night.css">
12
+ <link rel="stylesheet" href="/static/js/ace/css/theme/tomorrow_night_eighties.css">
13
+ <script src="/static/js/ace/ace.js"></script>
@@ -17,7 +17,7 @@
17
17
  </form>
18
18
  {{/ui/modal}}
19
19
 
20
- <script>
20
+ <script nonce="{{cspNonce}}">
21
21
  document.addEventListener('DOMContentLoaded', () => {
22
22
  let modalElm = document.getElementById('addAccount');
23
23
 
@@ -1,7 +1,7 @@
1
- {{!-- Rendered server-side on first paint AND re-compiled in the browser after
2
- an IP rescan (served via cachedTemplates.addressList, compiled with the
3
- Handlebars runtime in config/network.hbs). Keep it self-contained: no
4
- server-registered partials or helpers, plain FlyonUI markup only. --}}
1
+ {{!-- Rendered server-side on first paint AND again by POST /admin/config/network/reload
2
+ after an IP rescan (compiledFragments.addressList in lib/ui-routes/route-helpers.js,
3
+ which renders without the page's view context - so no inline scripts here, and
4
+ nothing that needs cspNonce or the locale). --}}
5
5
  {{#each addresses}}
6
6
  <tr class="hover:bg-base-200/60">
7
7
  <td>
@@ -21,7 +21,7 @@
21
21
  Render context: examplePayloadsJson, scriptEnvJson and (webhooks pages only)
22
22
  notificationTypesJson, which switches on the event-name autocompleter.
23
23
  --}}
24
- <script src="/static/js/ace/ace.js"></script>
24
+ {{> ace_assets}}
25
25
  <script src="/static/js/ace/ext-language_tools.js"></script>
26
26
 
27
27
  {{#if notificationTypesJson}}
@@ -50,7 +50,7 @@
50
50
  </div>
51
51
  {{/ui/modal}}
52
52
 
53
- <script>
53
+ <script nonce="{{cspNonce}}">
54
54
  document.addEventListener('DOMContentLoaded', () => {
55
55
 
56
56
  let scriptEnv = JSON.parse(document.getElementById('scriptEnvJson').value);