strapi-plugin-magic-sessionmanager 4.8.0 → 4.9.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.
- package/CHANGELOG.md +90 -5
- package/README.md +379 -641
- package/dist/admin/Analytics-dyJmyxO-.mjs +418 -0
- package/dist/admin/Analytics-lVDnHBYp.js +420 -0
- package/dist/admin/App-CdgiY_Y7.js +1896 -0
- package/dist/admin/App-Cgf_CSjw.mjs +1894 -0
- package/dist/admin/License-1XUfQty5.js +443 -0
- package/dist/admin/License-C4WSYoqY.mjs +443 -0
- package/dist/admin/OnlineUsersWidget-DJC4V1KS.mjs +255 -0
- package/dist/admin/OnlineUsersWidget-DMPtuIpm.js +274 -0
- package/dist/admin/SectionCard-BlWv8CRt.js +54 -0
- package/dist/admin/SectionCard-D51bv4Hi.mjs +55 -0
- package/dist/admin/Settings-0QsyY7fe.js +3570 -0
- package/dist/admin/Settings-DgeuUiMF.mjs +3568 -0
- package/dist/admin/de-BFKoGEVT.js +544 -0
- package/dist/admin/de-j0oZH9Pz.mjs +544 -0
- package/dist/admin/en-UY4Tb5tE.mjs +544 -0
- package/dist/admin/en-s7Ksdkcg.js +544 -0
- package/dist/admin/es-07OGMe_5.js +544 -0
- package/dist/admin/es-DGBcZwQy.mjs +544 -0
- package/dist/admin/fr-B6-DWhGO.mjs +544 -0
- package/dist/admin/fr-ETj_2UBY.js +544 -0
- package/dist/admin/index-Ck19e8qw.mjs +1760 -0
- package/dist/admin/index-D-Nr0TCm.js +1761 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/maskSensitiveValue-BWcSjow7.js +9 -0
- package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +10 -0
- package/dist/admin/pt-C7PwrQtV.js +544 -0
- package/dist/admin/pt-YMRLm9gx.mjs +544 -0
- package/dist/server/index.js +1092 -463
- package/dist/server/index.mjs +1092 -463
- package/package.json +10 -1
- package/pics/analytics.png +0 -0
- package/pics/dashboard-dark.png +0 -0
- package/pics/dashboard.png +0 -0
- package/pics/dashboardsessionmodal.png +0 -0
- package/pics/mobile-dashboard.png +0 -0
- package/pics/mobile-session.png +0 -0
- package/pics/sessioninfopanel.png +0 -0
- package/pics/settings1.png +0 -0
- package/pics/settings2.png +0 -0
- package/pics/widget.png +0 -0
- package/scripts/geoip-updater.cjs +35 -24
- package/dist/admin/Analytics-CaRlu5ad.js +0 -332
- package/dist/admin/Analytics-THqDbNX0.mjs +0 -330
- package/dist/admin/App-AbZwLHtF.js +0 -1263
- package/dist/admin/App-hSh7guii.mjs +0 -1261
- package/dist/admin/FormField-C8kIT2NE.mjs +0 -59
- package/dist/admin/FormField-b5KBvkrj.js +0 -60
- package/dist/admin/License-BXBVwUVu.mjs +0 -299
- package/dist/admin/License-CABdPwnd.js +0 -301
- package/dist/admin/OnlineUsersWidget-BnWFj9IM.mjs +0 -230
- package/dist/admin/OnlineUsersWidget-CPFAACSb.js +0 -230
- package/dist/admin/PluginPageLayout-BPFMcgrx.mjs +0 -42
- package/dist/admin/PluginPageLayout-DmNzMdqu.js +0 -43
- package/dist/admin/Settings-B4DNdeKx.js +0 -2152
- package/dist/admin/Settings-C4RsJosh.mjs +0 -2150
- package/dist/admin/de-AwIFTd9i.mjs +0 -450
- package/dist/admin/de-D23nmqnl.js +0 -450
- package/dist/admin/en-C5iYQ0mC.js +0 -450
- package/dist/admin/en-D6QEGeRh.mjs +0 -450
- package/dist/admin/es-CIXnsG-p.js +0 -435
- package/dist/admin/es-CnFfVdKw.mjs +0 -435
- package/dist/admin/fr-BglXE-W4.js +0 -435
- package/dist/admin/fr-DefoR7uH.mjs +0 -435
- package/dist/admin/index-BFVITQ-o.mjs +0 -624
- package/dist/admin/index-DlMm-NyK.js +0 -625
- package/dist/admin/maskSensitiveValue-1uGWmrfG.mjs +0 -20
- package/dist/admin/maskSensitiveValue-B9vhxPad.js +0 -19
- package/dist/admin/pt-J5sf7jiY.js +0 -435
- package/dist/admin/pt-TODwvNQA.mjs +0 -435
|
@@ -0,0 +1,3568 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback, createContext, useContext, useMemo, useId, Fragment, useRef, useEffect, useLayoutEffect } from "react";
|
|
3
|
+
import { Field, Typography, Switch, Box, TextInput, Flex, Button, Link, SingleSelect, SingleSelectOption, Accordion, Alert, Badge, Radio, Dialog, Tag, Combobox, ComboboxOption, NumberInput, Divider, Tabs, Textarea, Checkbox } from "@strapi/design-system";
|
|
4
|
+
import { ConfirmDialog, useNotification, useFetchClient, useQueryParams, Page, Form, Blocker, useForm } from "@strapi/strapi/admin";
|
|
5
|
+
import { EyeStriked, Eye, Key, Duplicate, Cross, Plus, Trash, Check } from "@strapi/icons";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { H as ReadableParagraphs, b as getTranslation, n as logSafeAdminError, R as ReadableText, I as EqualGrid, o as PersistentAlert, P as PropertyList, J as formatSessionDate, C as ConfirmAction, K as refocusIfLost, m as pluginId, L as requireSuccessfulMutation, z as PageShell } from "./index-Ck19e8qw.mjs";
|
|
8
|
+
import { useIntl } from "react-intl";
|
|
9
|
+
import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
|
|
10
|
+
import { m as maskSensitiveValue } from "./maskSensitiveValue-lLRhN_S7.mjs";
|
|
11
|
+
const SETTINGS_TAB_IDS = Object.freeze([
|
|
12
|
+
"sessions",
|
|
13
|
+
"login-protection",
|
|
14
|
+
"location-data",
|
|
15
|
+
"alerts",
|
|
16
|
+
"data-retention"
|
|
17
|
+
]);
|
|
18
|
+
const DEFAULT_SETTINGS_TAB = "sessions";
|
|
19
|
+
const SETTINGS_TAB_LABELS = Object.freeze({
|
|
20
|
+
sessions: ["settings.config.tab.sessions", "Sessions"],
|
|
21
|
+
"login-protection": ["settings.config.tab.loginProtection", "Login protection"],
|
|
22
|
+
"location-data": ["settings.config.tab.locationData", "Location data"],
|
|
23
|
+
alerts: ["settings.config.tab.alerts", "Alerts"],
|
|
24
|
+
"data-retention": ["settings.config.tab.dataRetention", "Data and retention"]
|
|
25
|
+
});
|
|
26
|
+
const SETTINGS_TAB_FIELDS = Object.freeze({
|
|
27
|
+
sessions: [
|
|
28
|
+
"inactivityTimeout",
|
|
29
|
+
"maxSessionAgeDays",
|
|
30
|
+
"lastSeenRateLimit",
|
|
31
|
+
"cleanupInterval",
|
|
32
|
+
"cleanupUseDbDirect",
|
|
33
|
+
"strictSessionEnforcement",
|
|
34
|
+
"sessionCreationGraceMs"
|
|
35
|
+
],
|
|
36
|
+
"login-protection": [
|
|
37
|
+
"maxFailedLogins",
|
|
38
|
+
"trustedProxies",
|
|
39
|
+
"blockSuspiciousSessions",
|
|
40
|
+
"geoLookupFailureMode",
|
|
41
|
+
"enableGeofencing",
|
|
42
|
+
"allowedCountries",
|
|
43
|
+
"blockedCountries"
|
|
44
|
+
],
|
|
45
|
+
"location-data": [
|
|
46
|
+
"enableGeolocation",
|
|
47
|
+
"enableSecurityScoring",
|
|
48
|
+
"geoIpProvider",
|
|
49
|
+
"geoIpDatabasePath"
|
|
50
|
+
],
|
|
51
|
+
alerts: [
|
|
52
|
+
"enableEmailAlerts",
|
|
53
|
+
"alertOnSuspiciousLogin",
|
|
54
|
+
"alertOnNewLocation",
|
|
55
|
+
"alertOnVpnProxy",
|
|
56
|
+
"emailTemplates",
|
|
57
|
+
"enableWebhooks",
|
|
58
|
+
"discordWebhookUrl",
|
|
59
|
+
"slackWebhookUrl"
|
|
60
|
+
],
|
|
61
|
+
"data-retention": ["retentionDays"]
|
|
62
|
+
});
|
|
63
|
+
const PRESERVED_SETTINGS_KEYS = Object.freeze([
|
|
64
|
+
"rateLimitWriteMax",
|
|
65
|
+
"rateLimitReadMax",
|
|
66
|
+
"rateLimitWindowSeconds"
|
|
67
|
+
]);
|
|
68
|
+
const SETTINGS_FIELD_LABELS = Object.freeze({
|
|
69
|
+
inactivityTimeout: ["settings.config.sessions.inactivity.label", "Inactivity timeout"],
|
|
70
|
+
maxSessionAgeDays: ["settings.config.sessions.maxAge.label", "Maximum session age"],
|
|
71
|
+
lastSeenRateLimit: [
|
|
72
|
+
"settings.config.sessions.lastSeen.label",
|
|
73
|
+
'Update "Last active" at most every'
|
|
74
|
+
],
|
|
75
|
+
cleanupInterval: ["settings.config.sessions.idleCheck.label", "Run idle check every"],
|
|
76
|
+
cleanupUseDbDirect: ["settings.config.sessions.idleMethod.label", "Idle check method"],
|
|
77
|
+
strictSessionEnforcement: ["settings.config.token.check.label", "Strict token check"],
|
|
78
|
+
sessionCreationGraceMs: ["settings.config.token.grace.label", "Grace period after sign-in"],
|
|
79
|
+
maxFailedLogins: ["settings.config.failed.lockout.label", "Temporary IP lockout after"],
|
|
80
|
+
trustedProxies: ["settings.config.clientIp.trustProxy.label", "Trust proxy headers"],
|
|
81
|
+
blockSuspiciousSessions: [
|
|
82
|
+
"settings.config.suspicious.reject.label",
|
|
83
|
+
"Reject suspicious sign-ins"
|
|
84
|
+
],
|
|
85
|
+
geoLookupFailureMode: [
|
|
86
|
+
"settings.config.suspicious.failureMode.label",
|
|
87
|
+
"If the location cannot be determined"
|
|
88
|
+
],
|
|
89
|
+
enableGeofencing: ["settings.config.countries.enable.label", "Use country rules"],
|
|
90
|
+
allowedCountries: ["settings.config.countries.list.label", "Countries"],
|
|
91
|
+
blockedCountries: ["settings.config.countries.list.label", "Countries"],
|
|
92
|
+
enableGeolocation: ["settings.config.lookup.enable.label", "IP location lookup"],
|
|
93
|
+
enableSecurityScoring: ["settings.config.lookup.scoring.label", "Security scoring"],
|
|
94
|
+
geoIpProvider: ["settings.config.provider.label", "Provider"],
|
|
95
|
+
geoIpDatabasePath: ["settings.config.database.fileName.label", "Database file name"],
|
|
96
|
+
enableEmailAlerts: ["settings.config.email.enable.label", "Send security emails"],
|
|
97
|
+
alertOnSuspiciousLogin: ["settings.config.email.suspicious.label", "Suspicious sign-in"],
|
|
98
|
+
alertOnNewLocation: ["settings.config.email.newCountry.label", "Sign-in from a new country"],
|
|
99
|
+
alertOnVpnProxy: ["settings.config.email.vpnProxy.label", "VPN or proxy"],
|
|
100
|
+
emailTemplates: ["settings.config.email.templates.field", "Email templates"],
|
|
101
|
+
enableWebhooks: ["settings.config.webhooks.enable.label", "Send team notifications"],
|
|
102
|
+
discordWebhookUrl: ["settings.config.webhooks.discord.label", "Discord webhook URL"],
|
|
103
|
+
slackWebhookUrl: ["settings.config.webhooks.slack.label", "Slack webhook URL"],
|
|
104
|
+
retentionDays: ["settings.config.retention.keep.label", "Keep ended sessions for"]
|
|
105
|
+
});
|
|
106
|
+
const SELECT_PRESETS = Object.freeze({
|
|
107
|
+
inactivityTimeout: Object.freeze([5, 10, 15, 30, 60, 120]),
|
|
108
|
+
maxSessionAgeDays: Object.freeze([1, 7, 14, 30, 60, 90, 180, 365]),
|
|
109
|
+
lastSeenRateLimit: Object.freeze([10, 30, 60, 120, 300]),
|
|
110
|
+
cleanupInterval: Object.freeze([15, 30, 60, 120]),
|
|
111
|
+
sessionCreationGraceMs: Object.freeze([0, 2e3, 5e3, 1e4, 3e4]),
|
|
112
|
+
retentionDays: Object.freeze([7, 30, 60, 90, 180, 365, -1])
|
|
113
|
+
});
|
|
114
|
+
function resolveSettingsTab(value) {
|
|
115
|
+
const candidate = Array.isArray(value) ? value[0] : value;
|
|
116
|
+
return SETTINGS_TAB_IDS.includes(candidate) ? candidate : DEFAULT_SETTINGS_TAB;
|
|
117
|
+
}
|
|
118
|
+
function buildTabSearch(search, tab) {
|
|
119
|
+
const params = new URLSearchParams(typeof search === "string" ? search : "");
|
|
120
|
+
params.set("tab", resolveSettingsTab(tab));
|
|
121
|
+
return `?${params.toString()}`;
|
|
122
|
+
}
|
|
123
|
+
function fieldHasError(errors, field) {
|
|
124
|
+
return Object.keys(errors || {}).some((path) => path === field || path.startsWith(`${field}.`));
|
|
125
|
+
}
|
|
126
|
+
function tabHasFieldErrors(errors, tab) {
|
|
127
|
+
return (SETTINGS_TAB_FIELDS[tab] || []).some((field) => fieldHasError(errors, field));
|
|
128
|
+
}
|
|
129
|
+
function getErrorTab(errors) {
|
|
130
|
+
return SETTINGS_TAB_IDS.find((tab) => tabHasFieldErrors(errors, tab));
|
|
131
|
+
}
|
|
132
|
+
function buildSelectOptions(presets, current) {
|
|
133
|
+
const options = presets.map((value) => ({ value, custom: false }));
|
|
134
|
+
const number = typeof current === "number" ? current : Number.parseInt(String(current ?? ""), 10);
|
|
135
|
+
if (Number.isInteger(number) && !presets.includes(number)) {
|
|
136
|
+
options.push({ value: number, custom: true });
|
|
137
|
+
}
|
|
138
|
+
return options;
|
|
139
|
+
}
|
|
140
|
+
function buildSavePayload(draft, saved) {
|
|
141
|
+
const payload = { ...draft || {} };
|
|
142
|
+
for (const key of PRESERVED_SETTINGS_KEYS) {
|
|
143
|
+
if (saved && Object.prototype.hasOwnProperty.call(saved, key)) payload[key] = saved[key];
|
|
144
|
+
}
|
|
145
|
+
return payload;
|
|
146
|
+
}
|
|
147
|
+
function usesLocalDatabase(provider) {
|
|
148
|
+
return provider === void 0 || provider === null || provider === "" || provider === "auto" || provider === "local-mmdb";
|
|
149
|
+
}
|
|
150
|
+
function getRevealScrollDelta(listRect, tabRect) {
|
|
151
|
+
if (!listRect || !tabRect) return 0;
|
|
152
|
+
if (tabRect.left < listRect.left - 0.5) return Math.round(tabRect.left - listRect.left);
|
|
153
|
+
if (tabRect.right > listRect.right + 0.5) return Math.round(tabRect.right - listRect.right);
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
const FieldFrame = styled.div`
|
|
157
|
+
width: 100%;
|
|
158
|
+
min-width: 0;
|
|
159
|
+
|
|
160
|
+
& > div {
|
|
161
|
+
width: 100%;
|
|
162
|
+
min-width: 0;
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
const FieldControl = styled.div`
|
|
166
|
+
width: 100%;
|
|
167
|
+
min-width: 0;
|
|
168
|
+
|
|
169
|
+
& > * {
|
|
170
|
+
width: 100% !important;
|
|
171
|
+
max-width: 100%;
|
|
172
|
+
min-width: 0;
|
|
173
|
+
box-sizing: border-box;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
[role='combobox'] {
|
|
177
|
+
width: 100%;
|
|
178
|
+
max-width: 100%;
|
|
179
|
+
min-width: 0;
|
|
180
|
+
box-sizing: border-box;
|
|
181
|
+
justify-content: space-between;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
input,
|
|
185
|
+
textarea {
|
|
186
|
+
width: 100%;
|
|
187
|
+
max-width: 100%;
|
|
188
|
+
min-width: 0;
|
|
189
|
+
box-sizing: border-box;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* A placeholder longer than a phone-width input ends in an ellipsis
|
|
193
|
+
instead of being cut mid-word. */
|
|
194
|
+
input {
|
|
195
|
+
text-overflow: ellipsis;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* The DS Combobox input is only 24 px tall inside its 40 px frame. It
|
|
199
|
+
grows to the 32 px touch target; negative margins keep the frame. */
|
|
200
|
+
input[role='combobox'] {
|
|
201
|
+
min-height: ${({ theme }) => theme.spaces[7]};
|
|
202
|
+
margin-block: -${({ theme }) => theme.spaces[1]};
|
|
203
|
+
}
|
|
204
|
+
`;
|
|
205
|
+
const SuffixRow = styled.div`
|
|
206
|
+
display: grid;
|
|
207
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
208
|
+
align-items: center;
|
|
209
|
+
gap: ${({ theme }) => theme.spaces[2]};
|
|
210
|
+
width: 100%;
|
|
211
|
+
min-width: 0;
|
|
212
|
+
`;
|
|
213
|
+
const FieldHint = styled.div`
|
|
214
|
+
width: 100%;
|
|
215
|
+
min-width: 0;
|
|
216
|
+
max-width: 72ch;
|
|
217
|
+
margin-top: ${({ theme }) => theme.spaces[2]};
|
|
218
|
+
|
|
219
|
+
& > p {
|
|
220
|
+
line-height: 1.6;
|
|
221
|
+
text-wrap: pretty;
|
|
222
|
+
}
|
|
223
|
+
`;
|
|
224
|
+
const FormField = ({
|
|
225
|
+
id,
|
|
226
|
+
name = id,
|
|
227
|
+
label,
|
|
228
|
+
description,
|
|
229
|
+
error,
|
|
230
|
+
required = false,
|
|
231
|
+
suffix,
|
|
232
|
+
action,
|
|
233
|
+
children
|
|
234
|
+
}) => {
|
|
235
|
+
const control = /* @__PURE__ */ jsx(FieldControl, { children });
|
|
236
|
+
return /* @__PURE__ */ jsx(FieldFrame, { children: /* @__PURE__ */ jsxs(
|
|
237
|
+
Field.Root,
|
|
238
|
+
{
|
|
239
|
+
id,
|
|
240
|
+
name,
|
|
241
|
+
hint: description,
|
|
242
|
+
error: error || void 0,
|
|
243
|
+
required,
|
|
244
|
+
children: [
|
|
245
|
+
/* @__PURE__ */ jsx(Field.Label, { children: label }),
|
|
246
|
+
suffix || action ? /* @__PURE__ */ jsxs(SuffixRow, { children: [
|
|
247
|
+
control,
|
|
248
|
+
suffix ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", id: `${id}-suffix`, children: suffix }) : action
|
|
249
|
+
] }) : control,
|
|
250
|
+
description || error ? /* @__PURE__ */ jsxs(FieldHint, { children: [
|
|
251
|
+
/* @__PURE__ */ jsx(Field.Hint, {}),
|
|
252
|
+
/* @__PURE__ */ jsx(Field.Error, {})
|
|
253
|
+
] }) : null
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
) });
|
|
257
|
+
};
|
|
258
|
+
const SettingsRowCard = styled(Box)`
|
|
259
|
+
display: grid;
|
|
260
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
261
|
+
align-items: start;
|
|
262
|
+
gap: ${({ theme }) => theme.spaces[4]};
|
|
263
|
+
width: 100%;
|
|
264
|
+
min-width: 0;
|
|
265
|
+
|
|
266
|
+
/* The DS Switch is 24 px tall, below the 32 px touch target on phones.
|
|
267
|
+
Transparent top and bottom borders grow its hit area to 32 px; the track
|
|
268
|
+
is painted only inside them (background-clip) with the same pill radius,
|
|
269
|
+
and negative margins keep the row height and the switch position. */
|
|
270
|
+
& [role='switch'] {
|
|
271
|
+
height: ${({ theme }) => theme.spaces[7]};
|
|
272
|
+
border-block: ${({ theme }) => theme.spaces[1]} solid transparent;
|
|
273
|
+
border-radius: 1.2rem / 1.6rem;
|
|
274
|
+
background-clip: padding-box;
|
|
275
|
+
margin-block: -${({ theme }) => theme.spaces[1]};
|
|
276
|
+
}
|
|
277
|
+
`;
|
|
278
|
+
const SettingsCopy = styled.div`
|
|
279
|
+
display: flex;
|
|
280
|
+
flex-direction: column;
|
|
281
|
+
align-items: flex-start;
|
|
282
|
+
gap: ${({ theme }) => theme.spaces[1]};
|
|
283
|
+
width: 100%;
|
|
284
|
+
min-width: 0;
|
|
285
|
+
overflow-wrap: break-word;
|
|
286
|
+
`;
|
|
287
|
+
const SettingsToggleRow = ({
|
|
288
|
+
id,
|
|
289
|
+
title,
|
|
290
|
+
description,
|
|
291
|
+
checked,
|
|
292
|
+
onChange,
|
|
293
|
+
disabled = false,
|
|
294
|
+
children
|
|
295
|
+
}) => {
|
|
296
|
+
const titleId = `${id}-title`;
|
|
297
|
+
const descriptionId = `${id}-description`;
|
|
298
|
+
return /* @__PURE__ */ jsxs(
|
|
299
|
+
SettingsRowCard,
|
|
300
|
+
{
|
|
301
|
+
padding: 4,
|
|
302
|
+
background: "neutral0",
|
|
303
|
+
borderColor: "neutral150",
|
|
304
|
+
hasRadius: true,
|
|
305
|
+
"data-settings-toggle-row": "",
|
|
306
|
+
children: [
|
|
307
|
+
/* @__PURE__ */ jsxs(SettingsCopy, { children: [
|
|
308
|
+
/* @__PURE__ */ jsx(
|
|
309
|
+
Typography,
|
|
310
|
+
{
|
|
311
|
+
id: titleId,
|
|
312
|
+
variant: "omega",
|
|
313
|
+
fontWeight: "bold",
|
|
314
|
+
textColor: disabled ? "neutral600" : "neutral800",
|
|
315
|
+
tag: "p",
|
|
316
|
+
children: title
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
description ? /* @__PURE__ */ jsx(
|
|
320
|
+
ReadableParagraphs,
|
|
321
|
+
{
|
|
322
|
+
id: descriptionId,
|
|
323
|
+
text: description,
|
|
324
|
+
variant: "pi",
|
|
325
|
+
textColor: "neutral600",
|
|
326
|
+
tag: "p"
|
|
327
|
+
}
|
|
328
|
+
) : null,
|
|
329
|
+
children
|
|
330
|
+
] }),
|
|
331
|
+
/* @__PURE__ */ jsx(
|
|
332
|
+
Switch,
|
|
333
|
+
{
|
|
334
|
+
id,
|
|
335
|
+
"aria-label": title,
|
|
336
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
337
|
+
checked,
|
|
338
|
+
onCheckedChange: onChange,
|
|
339
|
+
disabled,
|
|
340
|
+
visibleLabels: false
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
};
|
|
347
|
+
const ENCRYPTION_KEY_ENV_NAME = "SESSION_ENCRYPTION_KEY";
|
|
348
|
+
const ENCRYPTION_KEY_BYTES = 32;
|
|
349
|
+
const HEX = "0123456789abcdef";
|
|
350
|
+
function generateEncryptionKey(randomSource = globalThis.crypto) {
|
|
351
|
+
if (!randomSource || typeof randomSource.getRandomValues !== "function") {
|
|
352
|
+
throw new Error("secure_random_unavailable");
|
|
353
|
+
}
|
|
354
|
+
const bytes = new Uint8Array(ENCRYPTION_KEY_BYTES);
|
|
355
|
+
randomSource.getRandomValues(bytes);
|
|
356
|
+
let key = "";
|
|
357
|
+
for (const byte of bytes) key += HEX[byte >> 4] + HEX[byte & 15];
|
|
358
|
+
return key;
|
|
359
|
+
}
|
|
360
|
+
function formatEnvLine(name, value) {
|
|
361
|
+
const text = String(value ?? "");
|
|
362
|
+
if (/[\r\n]/.test(text)) throw new TypeError("env_value_must_be_single_line");
|
|
363
|
+
const quote = ['"', "'", "`"].find((candidate) => !text.includes(candidate));
|
|
364
|
+
if (!quote) throw new TypeError("env_value_contains_all_quote_styles");
|
|
365
|
+
return `${name}=${quote}${text}${quote}`;
|
|
366
|
+
}
|
|
367
|
+
const RevealToggle = styled(Field.Action)`
|
|
368
|
+
display: inline-flex;
|
|
369
|
+
align-items: center;
|
|
370
|
+
justify-content: center;
|
|
371
|
+
min-width: ${({ theme }) => theme.spaces[7]};
|
|
372
|
+
min-height: ${({ theme }) => theme.spaces[7]};
|
|
373
|
+
margin: -${({ theme }) => theme.spaces[2]};
|
|
374
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
375
|
+
/* The DS action inherits black; the icon follows the theme instead. */
|
|
376
|
+
color: ${({ theme }) => theme.colors.neutral600};
|
|
377
|
+
|
|
378
|
+
&:hover {
|
|
379
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
380
|
+
}
|
|
381
|
+
`;
|
|
382
|
+
const SecretTextInput = ({
|
|
383
|
+
value,
|
|
384
|
+
onChange,
|
|
385
|
+
showLabel,
|
|
386
|
+
hideLabel,
|
|
387
|
+
revealedType = "text",
|
|
388
|
+
readOnly = false,
|
|
389
|
+
disabled = false,
|
|
390
|
+
placeholder,
|
|
391
|
+
name,
|
|
392
|
+
revealed: controlledRevealed,
|
|
393
|
+
onRevealedChange
|
|
394
|
+
}) => {
|
|
395
|
+
const [localRevealed, setLocalRevealed] = useState(false);
|
|
396
|
+
const revealed = controlledRevealed ?? localRevealed;
|
|
397
|
+
const toggle = () => {
|
|
398
|
+
const next = !revealed;
|
|
399
|
+
if (controlledRevealed === void 0) setLocalRevealed(next);
|
|
400
|
+
onRevealedChange?.(next);
|
|
401
|
+
};
|
|
402
|
+
return /* @__PURE__ */ jsx(
|
|
403
|
+
TextInput,
|
|
404
|
+
{
|
|
405
|
+
name,
|
|
406
|
+
type: revealed ? revealedType : "password",
|
|
407
|
+
value,
|
|
408
|
+
readOnly,
|
|
409
|
+
disabled,
|
|
410
|
+
placeholder,
|
|
411
|
+
autoComplete: "off",
|
|
412
|
+
spellCheck: false,
|
|
413
|
+
onChange: (event) => onChange?.(event.target.value),
|
|
414
|
+
endAction: /* @__PURE__ */ jsx(
|
|
415
|
+
RevealToggle,
|
|
416
|
+
{
|
|
417
|
+
label: revealed ? hideLabel : showLabel,
|
|
418
|
+
"aria-pressed": revealed,
|
|
419
|
+
onClick: toggle,
|
|
420
|
+
children: revealed ? /* @__PURE__ */ jsx(EyeStriked, { "aria-hidden": true, focusable: false }) : /* @__PURE__ */ jsx(Eye, { "aria-hidden": true, focusable: false })
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
);
|
|
425
|
+
};
|
|
426
|
+
function useSettingsTranslate() {
|
|
427
|
+
const { formatMessage, locale } = useIntl();
|
|
428
|
+
const t = useCallback(
|
|
429
|
+
(id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values),
|
|
430
|
+
[formatMessage]
|
|
431
|
+
);
|
|
432
|
+
const tError = useCallback(
|
|
433
|
+
(descriptor) => descriptor ? t(descriptor.messageId, descriptor.defaultMessage, descriptor.values) : void 0,
|
|
434
|
+
[t]
|
|
435
|
+
);
|
|
436
|
+
return { t, tError, locale };
|
|
437
|
+
}
|
|
438
|
+
const EnvPreview = styled(Box)`
|
|
439
|
+
overflow-wrap: anywhere;
|
|
440
|
+
|
|
441
|
+
code {
|
|
442
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
443
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
444
|
+
}
|
|
445
|
+
`;
|
|
446
|
+
const useEncryptionKeyDraft = () => {
|
|
447
|
+
const [encryptionKey, setEncryptionKey] = useState("");
|
|
448
|
+
const [showEncryptionKey, setShowEncryptionKey] = useState(false);
|
|
449
|
+
return { encryptionKey, setEncryptionKey, showEncryptionKey, setShowEncryptionKey };
|
|
450
|
+
};
|
|
451
|
+
const EncryptionKeyCard = ({ draft, copyValue, notify }) => {
|
|
452
|
+
const { t } = useSettingsTranslate();
|
|
453
|
+
const { encryptionKey, setEncryptionKey, showEncryptionKey, setShowEncryptionKey } = draft;
|
|
454
|
+
const handleGenerate = () => {
|
|
455
|
+
try {
|
|
456
|
+
setEncryptionKey(generateEncryptionKey());
|
|
457
|
+
setShowEncryptionKey(false);
|
|
458
|
+
notify({
|
|
459
|
+
type: "success",
|
|
460
|
+
message: t(
|
|
461
|
+
"notifications.success.keyGenerated",
|
|
462
|
+
"Encryption key generated. It stays hidden until you show it."
|
|
463
|
+
)
|
|
464
|
+
});
|
|
465
|
+
} catch (error) {
|
|
466
|
+
logSafeAdminError("settings.generateEncryptionKey", error);
|
|
467
|
+
notify({
|
|
468
|
+
type: "danger",
|
|
469
|
+
message: t("notifications.error.keyGenerate", "This browser cannot generate a secure key.")
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, "data-encryption-key-tool": "", children: [
|
|
474
|
+
/* @__PURE__ */ jsx(
|
|
475
|
+
FormField,
|
|
476
|
+
{
|
|
477
|
+
id: "session-encryption-key",
|
|
478
|
+
name: "sessionEncryptionKey",
|
|
479
|
+
label: t("settings.config.token.key.label", "Token encryption key"),
|
|
480
|
+
description: t(
|
|
481
|
+
"settings.config.token.key.hint",
|
|
482
|
+
"Session Manager encrypts stored tokens with this environment variable. Not needed in Strapi's refresh-token mode. Nothing is saved here."
|
|
483
|
+
),
|
|
484
|
+
children: /* @__PURE__ */ jsx(
|
|
485
|
+
SecretTextInput,
|
|
486
|
+
{
|
|
487
|
+
name: "sessionEncryptionKey",
|
|
488
|
+
value: encryptionKey,
|
|
489
|
+
readOnly: true,
|
|
490
|
+
placeholder: t(
|
|
491
|
+
"settings.config.token.key.placeholder",
|
|
492
|
+
"Select Generate key to create a key."
|
|
493
|
+
),
|
|
494
|
+
revealed: showEncryptionKey,
|
|
495
|
+
onRevealedChange: setShowEncryptionKey,
|
|
496
|
+
showLabel: t("settings.security.encryption.showKey", "Show key"),
|
|
497
|
+
hideLabel: t("settings.security.encryption.hideKey", "Hide key")
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
}
|
|
501
|
+
),
|
|
502
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
503
|
+
/* @__PURE__ */ jsx(
|
|
504
|
+
Button,
|
|
505
|
+
{
|
|
506
|
+
variant: "secondary",
|
|
507
|
+
startIcon: /* @__PURE__ */ jsx(Key, { "aria-hidden": true, focusable: false }),
|
|
508
|
+
onClick: handleGenerate,
|
|
509
|
+
children: t("settings.config.token.key.generate", "Generate key")
|
|
510
|
+
}
|
|
511
|
+
),
|
|
512
|
+
/* @__PURE__ */ jsx(
|
|
513
|
+
Button,
|
|
514
|
+
{
|
|
515
|
+
variant: "secondary",
|
|
516
|
+
startIcon: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true, focusable: false }),
|
|
517
|
+
onClick: () => copyValue(
|
|
518
|
+
formatEnvLine(ENCRYPTION_KEY_ENV_NAME, encryptionKey),
|
|
519
|
+
t(
|
|
520
|
+
"settings.config.token.key.copied",
|
|
521
|
+
"Copied. Add it to your server environment and restart Strapi."
|
|
522
|
+
),
|
|
523
|
+
"settings.copyEncryptionKeyEnv"
|
|
524
|
+
),
|
|
525
|
+
disabled: !encryptionKey,
|
|
526
|
+
children: t("settings.security.encryption.copyEnv", "Copy for .env")
|
|
527
|
+
}
|
|
528
|
+
)
|
|
529
|
+
] }),
|
|
530
|
+
encryptionKey ? /* @__PURE__ */ jsx(EnvPreview, { padding: 4, background: "neutral100", borderColor: "neutral200", hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
531
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", tag: "div", children: t("settings.security.encryption.envLabel", "Add to .env file:") }),
|
|
532
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", tag: "p", children: /* @__PURE__ */ jsx("code", { "data-env-preview": "", children: formatEnvLine(
|
|
533
|
+
ENCRYPTION_KEY_ENV_NAME,
|
|
534
|
+
showEncryptionKey ? encryptionKey : maskSensitiveValue(encryptionKey)
|
|
535
|
+
) }) })
|
|
536
|
+
] }) }) : null
|
|
537
|
+
] });
|
|
538
|
+
};
|
|
539
|
+
const TabLink = styled(Link)`
|
|
540
|
+
min-height: ${({ theme }) => theme.spaces[6]};
|
|
541
|
+
align-items: center;
|
|
542
|
+
`;
|
|
543
|
+
const SettingsNavigationContext = createContext({ selectTab: () => {
|
|
544
|
+
} });
|
|
545
|
+
const SettingsNavigationProvider = SettingsNavigationContext.Provider;
|
|
546
|
+
const useSettingsNavigation = () => useContext(SettingsNavigationContext);
|
|
547
|
+
const SettingsTabLink = ({ tab, children }) => {
|
|
548
|
+
const { selectTab } = useSettingsNavigation();
|
|
549
|
+
const search = typeof window === "undefined" ? "" : window.location.search;
|
|
550
|
+
return /* @__PURE__ */ jsx(
|
|
551
|
+
TabLink,
|
|
552
|
+
{
|
|
553
|
+
href: buildTabSearch(search, tab),
|
|
554
|
+
onClick: (event) => {
|
|
555
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0)
|
|
556
|
+
return;
|
|
557
|
+
event.preventDefault();
|
|
558
|
+
selectTab(tab);
|
|
559
|
+
},
|
|
560
|
+
children
|
|
561
|
+
}
|
|
562
|
+
);
|
|
563
|
+
};
|
|
564
|
+
function useOptionLabels() {
|
|
565
|
+
const { t } = useSettingsTranslate();
|
|
566
|
+
return useMemo(() => {
|
|
567
|
+
const minutes = (count) => t("settings.config.unit.minutes", "{count} min", { count });
|
|
568
|
+
const seconds = (count) => t("settings.config.unit.seconds", "{count} s", { count });
|
|
569
|
+
const days = (count) => t("settings.config.unit.days", "{count, plural, one {# day} other {# days}}", { count });
|
|
570
|
+
return {
|
|
571
|
+
minutes,
|
|
572
|
+
seconds,
|
|
573
|
+
days,
|
|
574
|
+
graceMs: (ms) => ms === 0 ? t("settings.config.option.off", "Off") : seconds(Math.round(ms / 100) / 10),
|
|
575
|
+
retentionDays: (value) => value === -1 ? t("settings.config.option.forever", "Forever") : days(value),
|
|
576
|
+
custom: (value) => t("settings.config.option.custom", "{value} (custom)", { value })
|
|
577
|
+
};
|
|
578
|
+
}, [t]);
|
|
579
|
+
}
|
|
580
|
+
const IntroText = ({ children }) => /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral600", tag: "p", children });
|
|
581
|
+
const RequiresNotice = ({ tab, children }) => /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", "data-requires": "", children: tab ? /* @__PURE__ */ jsx(SettingsTabLink, { tab, children }) : children });
|
|
582
|
+
const RequiresGeolocation = () => {
|
|
583
|
+
const { t } = useSettingsTranslate();
|
|
584
|
+
return /* @__PURE__ */ jsx(RequiresNotice, { tab: "location-data", children: t("settings.config.requires.geolocation", "Requires IP location lookup") });
|
|
585
|
+
};
|
|
586
|
+
const AdvancedTrigger = styled(Accordion.Trigger)`
|
|
587
|
+
&&:focus-visible {
|
|
588
|
+
outline: 2px solid ${({ theme }) => theme.colors.primary600};
|
|
589
|
+
outline-offset: -2px;
|
|
590
|
+
}
|
|
591
|
+
`;
|
|
592
|
+
const AdvancedSection = ({ label, hasError = false, disabled = false, children }) => {
|
|
593
|
+
const { t } = useSettingsTranslate();
|
|
594
|
+
const itemValue = useId();
|
|
595
|
+
const [open, setOpen] = useState("");
|
|
596
|
+
const [hadError, setHadError] = useState(false);
|
|
597
|
+
if (hasError !== hadError) {
|
|
598
|
+
setHadError(hasError);
|
|
599
|
+
if (hasError) setOpen(itemValue);
|
|
600
|
+
}
|
|
601
|
+
return /* @__PURE__ */ jsx(Accordion.Root, { value: open, onValueChange: setOpen, "data-advanced-section": "", children: /* @__PURE__ */ jsxs(Accordion.Item, { value: itemValue, disabled: disabled && !hasError, children: [
|
|
602
|
+
/* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(AdvancedTrigger, { children: label || t("settings.config.advanced", "Advanced") }) }),
|
|
603
|
+
/* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: { initial: 4, medium: 6 }, children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 6, children }) }) })
|
|
604
|
+
] }) });
|
|
605
|
+
};
|
|
606
|
+
const PresetSelect = ({
|
|
607
|
+
id,
|
|
608
|
+
name,
|
|
609
|
+
label,
|
|
610
|
+
description,
|
|
611
|
+
error,
|
|
612
|
+
value,
|
|
613
|
+
presets,
|
|
614
|
+
format,
|
|
615
|
+
onChange,
|
|
616
|
+
disabled = false
|
|
617
|
+
}) => {
|
|
618
|
+
const { custom } = useOptionLabels();
|
|
619
|
+
const options = buildSelectOptions(presets, value);
|
|
620
|
+
return /* @__PURE__ */ jsx(FormField, { id, name, label, description, error, children: /* @__PURE__ */ jsx(
|
|
621
|
+
SingleSelect,
|
|
622
|
+
{
|
|
623
|
+
value: String(value),
|
|
624
|
+
disabled,
|
|
625
|
+
onChange: (next) => onChange(Number.parseInt(next, 10)),
|
|
626
|
+
children: options.map((option) => /* @__PURE__ */ jsx(SingleSelectOption, { value: String(option.value), children: option.custom ? custom(format(option.value)) : format(option.value) }, option.value))
|
|
627
|
+
}
|
|
628
|
+
) });
|
|
629
|
+
};
|
|
630
|
+
const Terms = styled.dl`
|
|
631
|
+
display: grid;
|
|
632
|
+
grid-template-columns: minmax(0, 1fr);
|
|
633
|
+
gap: ${({ theme }) => theme.spaces[1]} ${({ theme }) => theme.spaces[6]};
|
|
634
|
+
margin: 0;
|
|
635
|
+
min-width: 0;
|
|
636
|
+
|
|
637
|
+
/* The term column takes its natural width, but never more than 45% of
|
|
638
|
+
the list: a long term ('403 "Login temporarily unavailable"') wraps
|
|
639
|
+
instead of squeezing the descriptions into a narrow column. */
|
|
640
|
+
${({ theme }) => theme.breakpoints.small} {
|
|
641
|
+
grid-template-columns: fit-content(45%) minmax(0, 1fr);
|
|
642
|
+
row-gap: ${({ theme }) => theme.spaces[3]};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
dt,
|
|
646
|
+
dd {
|
|
647
|
+
margin: 0;
|
|
648
|
+
min-width: 0;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
dd + dt {
|
|
652
|
+
margin-top: ${({ theme }) => theme.spaces[2]};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
${({ theme }) => theme.breakpoints.small} {
|
|
656
|
+
dd + dt {
|
|
657
|
+
margin-top: 0;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
code {
|
|
662
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
663
|
+
}
|
|
664
|
+
`;
|
|
665
|
+
const TermList = ({ items, label, code = false }) => /* @__PURE__ */ jsx(Terms, { "aria-label": label, "data-term-list": "", children: items.map((item) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
666
|
+
/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx(
|
|
667
|
+
Typography,
|
|
668
|
+
{
|
|
669
|
+
variant: "omega",
|
|
670
|
+
fontWeight: code ? void 0 : "semiBold",
|
|
671
|
+
textColor: "neutral800",
|
|
672
|
+
children: code ? /* @__PURE__ */ jsx("code", { children: item.term }) : item.term
|
|
673
|
+
}
|
|
674
|
+
) }),
|
|
675
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral700", children: item.description }) })
|
|
676
|
+
] }, item.id)) });
|
|
677
|
+
const REJECTION_REASONS = [
|
|
678
|
+
["logout", "settings.config.rejected.reason.logout", "The user signed out."],
|
|
679
|
+
[
|
|
680
|
+
"manual",
|
|
681
|
+
"settings.config.rejected.reason.manual",
|
|
682
|
+
"Ended from the Strapi admin, or by the user from another of their devices."
|
|
683
|
+
],
|
|
684
|
+
[
|
|
685
|
+
"idle",
|
|
686
|
+
"settings.config.rejected.reason.idle",
|
|
687
|
+
"Not used for longer than the inactivity timeout."
|
|
688
|
+
],
|
|
689
|
+
["expired", "settings.config.rejected.reason.expired", "Reached the maximum session age."],
|
|
690
|
+
[
|
|
691
|
+
"blocked",
|
|
692
|
+
"settings.config.rejected.reason.blocked",
|
|
693
|
+
"Ended because the user account was blocked."
|
|
694
|
+
]
|
|
695
|
+
];
|
|
696
|
+
const formatReasonCodes = (locale) => {
|
|
697
|
+
const codes = REJECTION_REASONS.map(([code]) => code);
|
|
698
|
+
try {
|
|
699
|
+
return new Intl.ListFormat(locale || "en", { style: "long", type: "disjunction" }).format(
|
|
700
|
+
codes
|
|
701
|
+
);
|
|
702
|
+
} catch {
|
|
703
|
+
return codes.join(", ");
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
const SessionsTab = ({ form }) => {
|
|
707
|
+
const { t, locale } = useSettingsTranslate();
|
|
708
|
+
const units = useOptionLabels();
|
|
709
|
+
const encryptionKeyDraft = useEncryptionKeyDraft();
|
|
710
|
+
const { settings, handleChange, relaxedWarningDismissed, setRelaxedWarningDismissed } = form;
|
|
711
|
+
const lastSeenTooSlow = Number(settings.lastSeenRateLimit) * 2 > Number(settings.inactivityTimeout) * 60;
|
|
712
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
713
|
+
/* @__PURE__ */ jsx(IntroText, { children: t(
|
|
714
|
+
"settings.config.sessions.intro",
|
|
715
|
+
"These rules decide when an end user's session ends. They are checked on every request the user makes."
|
|
716
|
+
) }),
|
|
717
|
+
/* @__PURE__ */ jsxs(
|
|
718
|
+
SectionCard,
|
|
719
|
+
{
|
|
720
|
+
title: t("settings.config.sessions.lifetime.title", "Session lifetime"),
|
|
721
|
+
subtitle: t(
|
|
722
|
+
"settings.config.sessions.lifetime.intro",
|
|
723
|
+
"A session ends when it is unused for too long or reaches its maximum age."
|
|
724
|
+
),
|
|
725
|
+
children: [
|
|
726
|
+
/* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
|
|
727
|
+
/* @__PURE__ */ jsx(
|
|
728
|
+
PresetSelect,
|
|
729
|
+
{
|
|
730
|
+
id: "inactivity-timeout",
|
|
731
|
+
name: "inactivityTimeout",
|
|
732
|
+
label: t("settings.config.sessions.inactivity.label", "Inactivity timeout"),
|
|
733
|
+
description: t(
|
|
734
|
+
"settings.config.sessions.inactivity.hint",
|
|
735
|
+
"A session unused for this long becomes idle and ends as 'Timed out' on its next request or at the next idle check. Also decides who counts as online."
|
|
736
|
+
),
|
|
737
|
+
value: settings.inactivityTimeout,
|
|
738
|
+
presets: SELECT_PRESETS.inactivityTimeout,
|
|
739
|
+
format: units.minutes,
|
|
740
|
+
onChange: (value) => handleChange("inactivityTimeout", value)
|
|
741
|
+
}
|
|
742
|
+
),
|
|
743
|
+
/* @__PURE__ */ jsx(
|
|
744
|
+
PresetSelect,
|
|
745
|
+
{
|
|
746
|
+
id: "max-session-age",
|
|
747
|
+
name: "maxSessionAgeDays",
|
|
748
|
+
label: t("settings.config.sessions.maxAge.label", "Maximum session age"),
|
|
749
|
+
description: t(
|
|
750
|
+
"settings.config.sessions.maxAge.hint",
|
|
751
|
+
"Counted from sign-in, regardless of activity. Applied on the session's next request; until then the session can still show as active or idle."
|
|
752
|
+
),
|
|
753
|
+
value: settings.maxSessionAgeDays,
|
|
754
|
+
presets: SELECT_PRESETS.maxSessionAgeDays,
|
|
755
|
+
format: units.days,
|
|
756
|
+
onChange: (value) => handleChange("maxSessionAgeDays", value)
|
|
757
|
+
}
|
|
758
|
+
)
|
|
759
|
+
] }),
|
|
760
|
+
/* @__PURE__ */ jsx(AdvancedSection, { children: /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
|
|
761
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
762
|
+
/* @__PURE__ */ jsx(
|
|
763
|
+
PresetSelect,
|
|
764
|
+
{
|
|
765
|
+
id: "last-seen-rate-limit",
|
|
766
|
+
name: "lastSeenRateLimit",
|
|
767
|
+
label: t(
|
|
768
|
+
"settings.config.sessions.lastSeen.label",
|
|
769
|
+
'Update "Last active" at most every'
|
|
770
|
+
),
|
|
771
|
+
description: t(
|
|
772
|
+
"settings.config.sessions.lastSeen.hint",
|
|
773
|
+
"Lower values make 'Last active' and idle detection more precise but write to the database more often."
|
|
774
|
+
),
|
|
775
|
+
value: settings.lastSeenRateLimit,
|
|
776
|
+
presets: SELECT_PRESETS.lastSeenRateLimit,
|
|
777
|
+
format: units.seconds,
|
|
778
|
+
onChange: (value) => handleChange("lastSeenRateLimit", value)
|
|
779
|
+
}
|
|
780
|
+
),
|
|
781
|
+
lastSeenTooSlow ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "warning700", tag: "p", "aria-live": "polite", children: t(
|
|
782
|
+
"settings.config.sessions.lastSeen.warning",
|
|
783
|
+
"This is not clearly shorter than the inactivity timeout, so sessions in use can show as idle."
|
|
784
|
+
) }) : null
|
|
785
|
+
] }),
|
|
786
|
+
/* @__PURE__ */ jsx(
|
|
787
|
+
PresetSelect,
|
|
788
|
+
{
|
|
789
|
+
id: "cleanup-interval",
|
|
790
|
+
name: "cleanupInterval",
|
|
791
|
+
label: t("settings.config.sessions.idleCheck.label", "Run idle check every"),
|
|
792
|
+
description: t(
|
|
793
|
+
"settings.config.sessions.idleCheck.hint",
|
|
794
|
+
"The idle check ends idle sessions as 'Timed out'. It deletes nothing. It also runs once at server start."
|
|
795
|
+
),
|
|
796
|
+
value: settings.cleanupInterval,
|
|
797
|
+
presets: SELECT_PRESETS.cleanupInterval,
|
|
798
|
+
format: units.minutes,
|
|
799
|
+
onChange: (value) => handleChange("cleanupInterval", value)
|
|
800
|
+
}
|
|
801
|
+
),
|
|
802
|
+
/* @__PURE__ */ jsx(
|
|
803
|
+
FormField,
|
|
804
|
+
{
|
|
805
|
+
id: "cleanup-strategy",
|
|
806
|
+
name: "cleanupUseDbDirect",
|
|
807
|
+
label: t("settings.config.sessions.idleMethod.label", "Idle check method"),
|
|
808
|
+
description: t(
|
|
809
|
+
"settings.config.sessions.idleMethod.hint",
|
|
810
|
+
"Direct SQL is faster but skips lifecycle hooks. Ignored when Strapi's refresh-token mode is on."
|
|
811
|
+
),
|
|
812
|
+
children: /* @__PURE__ */ jsxs(
|
|
813
|
+
SingleSelect,
|
|
814
|
+
{
|
|
815
|
+
value: settings.cleanupUseDbDirect ? "db" : "document-service",
|
|
816
|
+
onChange: (value) => handleChange("cleanupUseDbDirect", value === "db"),
|
|
817
|
+
children: [
|
|
818
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "document-service", children: t("settings.general.cleanupMode.ds", "Document Service") }),
|
|
819
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "db", children: t("settings.general.cleanupMode.db", "Direct SQL") })
|
|
820
|
+
]
|
|
821
|
+
}
|
|
822
|
+
)
|
|
823
|
+
}
|
|
824
|
+
)
|
|
825
|
+
] }) })
|
|
826
|
+
]
|
|
827
|
+
}
|
|
828
|
+
),
|
|
829
|
+
/* @__PURE__ */ jsxs(
|
|
830
|
+
SectionCard,
|
|
831
|
+
{
|
|
832
|
+
title: t("settings.config.token.title", "Token check"),
|
|
833
|
+
subtitle: t(
|
|
834
|
+
"settings.config.token.intro",
|
|
835
|
+
"Decides what happens to a token that Session Manager has no record for. Ended, expired and revoked sessions and blocked users are always rejected."
|
|
836
|
+
),
|
|
837
|
+
action: /* @__PURE__ */ jsx(
|
|
838
|
+
Badge,
|
|
839
|
+
{
|
|
840
|
+
backgroundColor: settings.strictSessionEnforcement ? "success100" : "neutral150",
|
|
841
|
+
textColor: settings.strictSessionEnforcement ? "success700" : "neutral700",
|
|
842
|
+
children: settings.strictSessionEnforcement ? t("settings.config.token.strict", "Strict") : t("settings.config.token.relaxed", "Relaxed")
|
|
843
|
+
}
|
|
844
|
+
),
|
|
845
|
+
children: [
|
|
846
|
+
/* @__PURE__ */ jsx(
|
|
847
|
+
SettingsToggleRow,
|
|
848
|
+
{
|
|
849
|
+
id: "strict-session-enforcement",
|
|
850
|
+
title: t("settings.config.token.check.label", "Strict token check"),
|
|
851
|
+
description: t(
|
|
852
|
+
"settings.config.token.check.hint",
|
|
853
|
+
"Rejects tokens without a session record and requests where the check itself fails."
|
|
854
|
+
),
|
|
855
|
+
checked: settings.strictSessionEnforcement,
|
|
856
|
+
onChange: (checked) => handleChange("strictSessionEnforcement", checked)
|
|
857
|
+
}
|
|
858
|
+
),
|
|
859
|
+
!settings.strictSessionEnforcement && !relaxedWarningDismissed && /* @__PURE__ */ jsx(
|
|
860
|
+
Alert,
|
|
861
|
+
{
|
|
862
|
+
variant: "warning",
|
|
863
|
+
closeLabel: t("common.close", "Close"),
|
|
864
|
+
onClose: () => setRelaxedWarningDismissed(true),
|
|
865
|
+
title: t("settings.config.token.relaxed", "Relaxed"),
|
|
866
|
+
children: t(
|
|
867
|
+
"settings.config.token.relaxedWarning",
|
|
868
|
+
"Tokens without a session record are accepted. If the check itself fails, up to 10 requests per minute are still allowed."
|
|
869
|
+
)
|
|
870
|
+
}
|
|
871
|
+
),
|
|
872
|
+
/* @__PURE__ */ jsx(AdvancedSection, { children: /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
|
|
873
|
+
/* @__PURE__ */ jsx(
|
|
874
|
+
PresetSelect,
|
|
875
|
+
{
|
|
876
|
+
id: "session-creation-grace-period",
|
|
877
|
+
name: "sessionCreationGraceMs",
|
|
878
|
+
label: t("settings.config.token.grace.label", "Grace period after sign-in"),
|
|
879
|
+
description: t(
|
|
880
|
+
"settings.config.token.grace.hint",
|
|
881
|
+
"Accepts a new token for a few seconds while its session record is being created. Only for tokens without a session record. Not used when Strapi's refresh-token mode (jwtManagement: 'refresh') is on."
|
|
882
|
+
),
|
|
883
|
+
value: settings.sessionCreationGraceMs ?? 5e3,
|
|
884
|
+
presets: SELECT_PRESETS.sessionCreationGraceMs,
|
|
885
|
+
format: units.graceMs,
|
|
886
|
+
onChange: (value) => handleChange("sessionCreationGraceMs", value)
|
|
887
|
+
}
|
|
888
|
+
),
|
|
889
|
+
/* @__PURE__ */ jsx(
|
|
890
|
+
EncryptionKeyCard,
|
|
891
|
+
{
|
|
892
|
+
draft: encryptionKeyDraft,
|
|
893
|
+
copyValue: form.copyValue,
|
|
894
|
+
notify: form.notify
|
|
895
|
+
}
|
|
896
|
+
)
|
|
897
|
+
] }) })
|
|
898
|
+
]
|
|
899
|
+
}
|
|
900
|
+
),
|
|
901
|
+
/* @__PURE__ */ jsxs(
|
|
902
|
+
SectionCard,
|
|
903
|
+
{
|
|
904
|
+
title: t("settings.config.rejected.title", "When a session is rejected"),
|
|
905
|
+
subtitle: t(
|
|
906
|
+
"settings.config.rejected.intro",
|
|
907
|
+
"What your app receives when a request uses an ended session."
|
|
908
|
+
),
|
|
909
|
+
children: [
|
|
910
|
+
/* @__PURE__ */ jsx(
|
|
911
|
+
ReadableParagraphs,
|
|
912
|
+
{
|
|
913
|
+
variant: "omega",
|
|
914
|
+
textColor: "neutral700",
|
|
915
|
+
tag: "p",
|
|
916
|
+
text: t(
|
|
917
|
+
"settings.config.rejected.body",
|
|
918
|
+
"The response is 401 with the header {header} and the reason: {reasons}.",
|
|
919
|
+
{ header: "X-Session-Terminated-Reason", reasons: formatReasonCodes(locale) }
|
|
920
|
+
)
|
|
921
|
+
}
|
|
922
|
+
),
|
|
923
|
+
/* @__PURE__ */ jsx(
|
|
924
|
+
TermList,
|
|
925
|
+
{
|
|
926
|
+
code: true,
|
|
927
|
+
label: t("settings.config.rejected.title", "When a session is rejected"),
|
|
928
|
+
items: REJECTION_REASONS.map(([code, id, defaultMessage]) => ({
|
|
929
|
+
id: code,
|
|
930
|
+
term: code,
|
|
931
|
+
description: t(id, defaultMessage)
|
|
932
|
+
}))
|
|
933
|
+
}
|
|
934
|
+
)
|
|
935
|
+
]
|
|
936
|
+
}
|
|
937
|
+
)
|
|
938
|
+
] });
|
|
939
|
+
};
|
|
940
|
+
function areSettingsEqual(left, right) {
|
|
941
|
+
if (Object.is(left, right)) return true;
|
|
942
|
+
if (left === null || right === null || typeof left !== "object" || typeof right !== "object") {
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
946
|
+
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => areSettingsEqual(value, right[index]));
|
|
947
|
+
}
|
|
948
|
+
const leftKeys = Object.keys(left).sort();
|
|
949
|
+
const rightKeys = Object.keys(right).sort();
|
|
950
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(
|
|
951
|
+
(key, index) => key === rightKeys[index] && areSettingsEqual(left[key], right[key])
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
const TEMPLATE_KEYS = Object.freeze(["suspiciousLogin", "newLocation", "vpnProxy"]);
|
|
955
|
+
const TEMPLATE_LIMITS = Object.freeze({ subject: 200, html: 1e4, text: 5e3 });
|
|
956
|
+
const TEMPLATE_VARIABLE_DEFINITIONS = Object.freeze({
|
|
957
|
+
"{{user.email}}": {
|
|
958
|
+
messageId: "settings.email.templates.variable.userEmail",
|
|
959
|
+
defaultMessage: "User email address"
|
|
960
|
+
},
|
|
961
|
+
"{{user.username}}": {
|
|
962
|
+
messageId: "settings.email.templates.variable.username",
|
|
963
|
+
defaultMessage: "Username"
|
|
964
|
+
},
|
|
965
|
+
"{{session.loginTime}}": {
|
|
966
|
+
messageId: "settings.email.templates.variable.loginTime",
|
|
967
|
+
defaultMessage: "Login time"
|
|
968
|
+
},
|
|
969
|
+
"{{session.ipAddress}}": {
|
|
970
|
+
messageId: "settings.email.templates.variable.ipAddress",
|
|
971
|
+
defaultMessage: "IP address"
|
|
972
|
+
},
|
|
973
|
+
"{{geo.city}}": {
|
|
974
|
+
messageId: "settings.email.templates.variable.city",
|
|
975
|
+
defaultMessage: "City (if available)"
|
|
976
|
+
},
|
|
977
|
+
"{{geo.country}}": {
|
|
978
|
+
messageId: "settings.email.templates.variable.country",
|
|
979
|
+
defaultMessage: "Country (if available)"
|
|
980
|
+
},
|
|
981
|
+
"{{geo.timezone}}": {
|
|
982
|
+
messageId: "settings.email.templates.variable.timezone",
|
|
983
|
+
defaultMessage: "Time zone (if available)"
|
|
984
|
+
},
|
|
985
|
+
"{{session.userAgent}}": {
|
|
986
|
+
messageId: "settings.email.templates.variable.userAgent",
|
|
987
|
+
defaultMessage: "Browser and device"
|
|
988
|
+
},
|
|
989
|
+
"{{reason.isVpn}}": {
|
|
990
|
+
messageId: "settings.email.templates.variable.isVpn",
|
|
991
|
+
defaultMessage: "VPN detected (true or false)"
|
|
992
|
+
},
|
|
993
|
+
"{{reason.isProxy}}": {
|
|
994
|
+
messageId: "settings.email.templates.variable.isProxy",
|
|
995
|
+
defaultMessage: "Proxy detected (true or false)"
|
|
996
|
+
},
|
|
997
|
+
"{{reason.isThreat}}": {
|
|
998
|
+
messageId: "settings.email.templates.variable.isThreat",
|
|
999
|
+
defaultMessage: "Threat detected (true or false)"
|
|
1000
|
+
},
|
|
1001
|
+
"{{reason.securityScore}}": {
|
|
1002
|
+
messageId: "settings.email.templates.variable.securityScore",
|
|
1003
|
+
defaultMessage: "Security score (0 to 100)"
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
const TEMPLATE_VARIABLES = Object.freeze({
|
|
1007
|
+
suspiciousLogin: [
|
|
1008
|
+
"{{user.email}}",
|
|
1009
|
+
"{{user.username}}",
|
|
1010
|
+
"{{session.loginTime}}",
|
|
1011
|
+
"{{session.ipAddress}}",
|
|
1012
|
+
"{{geo.city}}",
|
|
1013
|
+
"{{geo.country}}",
|
|
1014
|
+
"{{geo.timezone}}",
|
|
1015
|
+
"{{session.userAgent}}",
|
|
1016
|
+
"{{reason.isVpn}}",
|
|
1017
|
+
"{{reason.isProxy}}",
|
|
1018
|
+
"{{reason.isThreat}}",
|
|
1019
|
+
"{{reason.securityScore}}"
|
|
1020
|
+
],
|
|
1021
|
+
newLocation: [
|
|
1022
|
+
"{{user.email}}",
|
|
1023
|
+
"{{user.username}}",
|
|
1024
|
+
"{{session.loginTime}}",
|
|
1025
|
+
"{{session.ipAddress}}",
|
|
1026
|
+
"{{geo.city}}",
|
|
1027
|
+
"{{geo.country}}",
|
|
1028
|
+
"{{geo.timezone}}",
|
|
1029
|
+
"{{session.userAgent}}"
|
|
1030
|
+
],
|
|
1031
|
+
vpnProxy: [
|
|
1032
|
+
"{{user.email}}",
|
|
1033
|
+
"{{user.username}}",
|
|
1034
|
+
"{{session.loginTime}}",
|
|
1035
|
+
"{{session.ipAddress}}",
|
|
1036
|
+
"{{geo.city}}",
|
|
1037
|
+
"{{geo.country}}",
|
|
1038
|
+
"{{session.userAgent}}",
|
|
1039
|
+
"{{reason.isVpn}}",
|
|
1040
|
+
"{{reason.isProxy}}"
|
|
1041
|
+
]
|
|
1042
|
+
});
|
|
1043
|
+
const TEMPLATE_PREVIEW_VALUES = Object.freeze({
|
|
1044
|
+
"{{user.email}}": "jane.doe@example.com",
|
|
1045
|
+
"{{user.username}}": "jane.doe",
|
|
1046
|
+
"{{session.loginTime}}": "2026-11-06 09:41 UTC",
|
|
1047
|
+
"{{session.ipAddress}}": "203.0.113.42",
|
|
1048
|
+
"{{geo.city}}": "Berlin",
|
|
1049
|
+
"{{geo.country}}": "Germany",
|
|
1050
|
+
"{{geo.timezone}}": "Europe/Berlin",
|
|
1051
|
+
"{{session.userAgent}}": "Firefox 132 on macOS",
|
|
1052
|
+
"{{reason.isVpn}}": "true",
|
|
1053
|
+
"{{reason.isProxy}}": "false",
|
|
1054
|
+
"{{reason.isThreat}}": "false",
|
|
1055
|
+
"{{reason.securityScore}}": "35"
|
|
1056
|
+
});
|
|
1057
|
+
function updateEmailTemplate(templates, templateKey, field, value) {
|
|
1058
|
+
return { ...templates, [templateKey]: { ...templates[templateKey], [field]: value } };
|
|
1059
|
+
}
|
|
1060
|
+
function findTemplateVariables(template, templateKey) {
|
|
1061
|
+
const available = TEMPLATE_VARIABLES[templateKey] || [];
|
|
1062
|
+
const source = typeof template === "string" ? template : "";
|
|
1063
|
+
return {
|
|
1064
|
+
found: available.filter((variable) => source.includes(variable)),
|
|
1065
|
+
total: available.length
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
const escapeHtml = (value) => String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1069
|
+
const HTML_SPACE = /[\t\n\f\r ]/;
|
|
1070
|
+
const ASCII_LETTER = /[A-Za-z]/;
|
|
1071
|
+
const isActiveAttribute = (name) => /^on/i.test(name) || name.toLowerCase() === "srcdoc";
|
|
1072
|
+
const readTag = (raw, start) => {
|
|
1073
|
+
const isEnd = raw[start + 1] === "/";
|
|
1074
|
+
let j = start + (isEnd ? 2 : 1);
|
|
1075
|
+
const nameStart = j;
|
|
1076
|
+
while (j < raw.length && !HTML_SPACE.test(raw[j]) && raw[j] !== "/" && raw[j] !== ">") j += 1;
|
|
1077
|
+
const name = raw.slice(nameStart, j);
|
|
1078
|
+
let tag = `<${isEnd ? "/" : ""}${name}`;
|
|
1079
|
+
for (; ; ) {
|
|
1080
|
+
let separator = "";
|
|
1081
|
+
while (j < raw.length && (HTML_SPACE.test(raw[j]) || raw[j] === "/")) separator += raw[j++];
|
|
1082
|
+
if (j >= raw.length) return null;
|
|
1083
|
+
if (raw[j] === ">") return { tag: `${tag}${separator}>`, name: name.toLowerCase(), end: j + 1 };
|
|
1084
|
+
const attributeStart = j;
|
|
1085
|
+
j += 1;
|
|
1086
|
+
while (j < raw.length && !HTML_SPACE.test(raw[j]) && !["/", ">", "="].includes(raw[j])) j += 1;
|
|
1087
|
+
const attributeName = raw.slice(attributeStart, j);
|
|
1088
|
+
let k = j;
|
|
1089
|
+
while (k < raw.length && HTML_SPACE.test(raw[k])) k += 1;
|
|
1090
|
+
if (raw[k] === "=") {
|
|
1091
|
+
k += 1;
|
|
1092
|
+
while (k < raw.length && HTML_SPACE.test(raw[k])) k += 1;
|
|
1093
|
+
if (k >= raw.length) return null;
|
|
1094
|
+
if (raw[k] === '"' || raw[k] === "'") {
|
|
1095
|
+
const close = raw.indexOf(raw[k], k + 1);
|
|
1096
|
+
if (close === -1) return null;
|
|
1097
|
+
j = close + 1;
|
|
1098
|
+
} else if (raw[k] === ">") {
|
|
1099
|
+
j = k;
|
|
1100
|
+
} else {
|
|
1101
|
+
while (k < raw.length && !HTML_SPACE.test(raw[k]) && raw[k] !== ">") k += 1;
|
|
1102
|
+
if (k >= raw.length) return null;
|
|
1103
|
+
j = k;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (!isActiveAttribute(attributeName)) {
|
|
1107
|
+
tag += `${separator || " "}${raw.slice(attributeStart, j)}`;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
const stripActiveHtml = (raw) => {
|
|
1112
|
+
let out = "";
|
|
1113
|
+
let i = 0;
|
|
1114
|
+
while (i < raw.length) {
|
|
1115
|
+
const lt = raw.indexOf("<", i);
|
|
1116
|
+
if (lt === -1) return out + raw.slice(i);
|
|
1117
|
+
out += raw.slice(i, lt);
|
|
1118
|
+
i = lt;
|
|
1119
|
+
const next = raw[i + 1] || "";
|
|
1120
|
+
if (raw.startsWith("<!--", i)) {
|
|
1121
|
+
const shortEnd = raw.startsWith("<!-->", i) ? 5 : raw.startsWith("<!--->", i) ? 6 : 0;
|
|
1122
|
+
if (shortEnd) {
|
|
1123
|
+
out += raw.slice(i, i + shortEnd);
|
|
1124
|
+
i += shortEnd;
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
const ends = [raw.indexOf("-->", i + 4), raw.indexOf("--!>", i + 4)].filter(
|
|
1128
|
+
(index) => index !== -1
|
|
1129
|
+
);
|
|
1130
|
+
if (!ends.length) return out;
|
|
1131
|
+
const end = Math.min(...ends);
|
|
1132
|
+
const close = raw.indexOf(">", end) + 1;
|
|
1133
|
+
out += raw.slice(i, close);
|
|
1134
|
+
i = close;
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
const isTag = ASCII_LETTER.test(next) || next === "/" && ASCII_LETTER.test(raw[i + 2] || "");
|
|
1138
|
+
if (!isTag) {
|
|
1139
|
+
if (next === "!" || next === "?" || next === "/") {
|
|
1140
|
+
const close = raw.indexOf(">", i);
|
|
1141
|
+
if (close === -1) return out;
|
|
1142
|
+
out += raw.slice(i, close + 1);
|
|
1143
|
+
i = close + 1;
|
|
1144
|
+
} else {
|
|
1145
|
+
out += "<";
|
|
1146
|
+
i += 1;
|
|
1147
|
+
}
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1150
|
+
const parsed = readTag(raw, i);
|
|
1151
|
+
if (!parsed) return out;
|
|
1152
|
+
i = parsed.end;
|
|
1153
|
+
if (parsed.name === "script" && !parsed.tag.startsWith("</")) {
|
|
1154
|
+
const closing = /<\/script[\t\n\f\r />]/i.exec(raw.slice(i));
|
|
1155
|
+
if (!closing) return out;
|
|
1156
|
+
const close = raw.indexOf(">", i + closing.index);
|
|
1157
|
+
if (close === -1) return out;
|
|
1158
|
+
i = close + 1;
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
if (parsed.name === "script") continue;
|
|
1162
|
+
out += parsed.tag;
|
|
1163
|
+
}
|
|
1164
|
+
return out;
|
|
1165
|
+
};
|
|
1166
|
+
function renderTemplatePreview(template, { html = false } = {}) {
|
|
1167
|
+
const raw = typeof template === "string" ? template : "";
|
|
1168
|
+
const source = html ? stripActiveHtml(raw) : raw;
|
|
1169
|
+
return source.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (match, name) => {
|
|
1170
|
+
const value = TEMPLATE_PREVIEW_VALUES[`{{${name}}}`];
|
|
1171
|
+
if (value === void 0) return match;
|
|
1172
|
+
return html ? escapeHtml(value) : value;
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
const getDefaultTemplates = () => ({
|
|
1176
|
+
suspiciousLogin: {
|
|
1177
|
+
subject: "[ALERT] Suspicious Login Alert - Session Manager",
|
|
1178
|
+
html: `
|
|
1179
|
+
<html>
|
|
1180
|
+
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
|
|
1181
|
+
<div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f9fafb; border-radius: 10px;">
|
|
1182
|
+
<h2 style="color: #dc2626;">[ALERT] Suspicious Login Detected</h2>
|
|
1183
|
+
<p>A potentially suspicious login was detected for your account.</p>
|
|
1184
|
+
|
|
1185
|
+
<div style="background: white; padding: 15px; border-radius: 8px; margin: 20px 0;">
|
|
1186
|
+
<h3 style="margin-top: 0;">Account Information:</h3>
|
|
1187
|
+
<ul>
|
|
1188
|
+
<li><strong>Email:</strong> {{user.email}}</li>
|
|
1189
|
+
<li><strong>Username:</strong> {{user.username}}</li>
|
|
1190
|
+
</ul>
|
|
1191
|
+
|
|
1192
|
+
<h3>Login Details:</h3>
|
|
1193
|
+
<ul>
|
|
1194
|
+
<li><strong>Time:</strong> {{session.loginTime}}</li>
|
|
1195
|
+
<li><strong>IP Address:</strong> {{session.ipAddress}}</li>
|
|
1196
|
+
<li><strong>Location:</strong> {{geo.city}}, {{geo.country}}</li>
|
|
1197
|
+
<li><strong>Timezone:</strong> {{geo.timezone}}</li>
|
|
1198
|
+
<li><strong>Device:</strong> {{session.userAgent}}</li>
|
|
1199
|
+
</ul>
|
|
1200
|
+
|
|
1201
|
+
<h3 style="color: #dc2626;">Security Alert:</h3>
|
|
1202
|
+
<ul>
|
|
1203
|
+
<li>VPN Detected: {{reason.isVpn}}</li>
|
|
1204
|
+
<li>Proxy Detected: {{reason.isProxy}}</li>
|
|
1205
|
+
<li>Threat Detected: {{reason.isThreat}}</li>
|
|
1206
|
+
<li>Security Score: {{reason.securityScore}}/100</li>
|
|
1207
|
+
</ul>
|
|
1208
|
+
</div>
|
|
1209
|
+
|
|
1210
|
+
<p>If this was you, you can safely ignore this email. If you don't recognize this activity, please secure your account immediately.</p>
|
|
1211
|
+
|
|
1212
|
+
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;"/>
|
|
1213
|
+
<p style="color: #666; font-size: 12px;">This is an automated security notification from Magic Session Manager.</p>
|
|
1214
|
+
</div>
|
|
1215
|
+
</body>
|
|
1216
|
+
</html>`,
|
|
1217
|
+
text: `[ALERT] Suspicious Login Detected
|
|
1218
|
+
|
|
1219
|
+
A potentially suspicious login was detected for your account.
|
|
1220
|
+
|
|
1221
|
+
Account: {{user.email}}
|
|
1222
|
+
Username: {{user.username}}
|
|
1223
|
+
|
|
1224
|
+
Login Details:
|
|
1225
|
+
- Time: {{session.loginTime}}
|
|
1226
|
+
- IP: {{session.ipAddress}}
|
|
1227
|
+
- Location: {{geo.city}}, {{geo.country}}
|
|
1228
|
+
|
|
1229
|
+
Security: VPN={{reason.isVpn}}, Proxy={{reason.isProxy}}, Threat={{reason.isThreat}}, Score={{reason.securityScore}}/100`
|
|
1230
|
+
},
|
|
1231
|
+
newLocation: {
|
|
1232
|
+
subject: "[LOCATION] New Location Login Detected",
|
|
1233
|
+
html: `
|
|
1234
|
+
<html>
|
|
1235
|
+
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
|
|
1236
|
+
<div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f0f9ff; border-radius: 10px;">
|
|
1237
|
+
<h2 style="color: #0284c7;">[LOCATION] Login from New Location</h2>
|
|
1238
|
+
<p>Your account was accessed from a new location.</p>
|
|
1239
|
+
|
|
1240
|
+
<div style="background: white; padding: 15px; border-radius: 8px; margin: 20px 0;">
|
|
1241
|
+
<h3 style="margin-top: 0;">Account:</h3>
|
|
1242
|
+
<p><strong>{{user.email}}</strong></p>
|
|
1243
|
+
|
|
1244
|
+
<h3>New Location Details:</h3>
|
|
1245
|
+
<ul>
|
|
1246
|
+
<li><strong>Time:</strong> {{session.loginTime}}</li>
|
|
1247
|
+
<li><strong>Location:</strong> {{geo.city}}, {{geo.country}}</li>
|
|
1248
|
+
<li><strong>IP Address:</strong> {{session.ipAddress}}</li>
|
|
1249
|
+
<li><strong>Device:</strong> {{session.userAgent}}</li>
|
|
1250
|
+
</ul>
|
|
1251
|
+
</div>
|
|
1252
|
+
|
|
1253
|
+
<p>If this was you, no action is needed. If you don't recognize this login, please secure your account.</p>
|
|
1254
|
+
|
|
1255
|
+
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;"/>
|
|
1256
|
+
<p style="color: #666; font-size: 12px;">Magic Session Manager notification</p>
|
|
1257
|
+
</div>
|
|
1258
|
+
</body>
|
|
1259
|
+
</html>`,
|
|
1260
|
+
text: `[LOCATION] Login from New Location
|
|
1261
|
+
|
|
1262
|
+
Your account was accessed from a new location.
|
|
1263
|
+
|
|
1264
|
+
Account: {{user.email}}
|
|
1265
|
+
|
|
1266
|
+
New Location Details:
|
|
1267
|
+
- Time: {{session.loginTime}}
|
|
1268
|
+
- Location: {{geo.city}}, {{geo.country}}
|
|
1269
|
+
- IP Address: {{session.ipAddress}}
|
|
1270
|
+
- Device: {{session.userAgent}}
|
|
1271
|
+
|
|
1272
|
+
If this was you, no action is needed.`
|
|
1273
|
+
},
|
|
1274
|
+
vpnProxy: {
|
|
1275
|
+
subject: "[WARNING] VPN/Proxy Login Detected",
|
|
1276
|
+
html: `
|
|
1277
|
+
<html>
|
|
1278
|
+
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
|
|
1279
|
+
<div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fffbeb; border-radius: 10px;">
|
|
1280
|
+
<h2 style="color: #d97706;">[WARNING] VPN/Proxy Detected</h2>
|
|
1281
|
+
<p>A login from a VPN or proxy service was detected on your account.</p>
|
|
1282
|
+
|
|
1283
|
+
<div style="background: white; padding: 15px; border-radius: 8px; margin: 20px 0;">
|
|
1284
|
+
<h3 style="margin-top: 0;">Account:</h3>
|
|
1285
|
+
<p><strong>{{user.email}}</strong></p>
|
|
1286
|
+
|
|
1287
|
+
<h3>Login Details:</h3>
|
|
1288
|
+
<ul>
|
|
1289
|
+
<li><strong>Time:</strong> {{session.loginTime}}</li>
|
|
1290
|
+
<li><strong>IP Address:</strong> {{session.ipAddress}}</li>
|
|
1291
|
+
<li><strong>Location:</strong> {{geo.city}}, {{geo.country}}</li>
|
|
1292
|
+
<li><strong>Device:</strong> {{session.userAgent}}</li>
|
|
1293
|
+
<li><strong>VPN:</strong> {{reason.isVpn}}</li>
|
|
1294
|
+
<li><strong>Proxy:</strong> {{reason.isProxy}}</li>
|
|
1295
|
+
</ul>
|
|
1296
|
+
</div>
|
|
1297
|
+
|
|
1298
|
+
<p>VPN/Proxy usage may indicate suspicious activity. If this was you, you can safely ignore this email.</p>
|
|
1299
|
+
|
|
1300
|
+
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;"/>
|
|
1301
|
+
<p style="color: #666; font-size: 12px;">Magic Session Manager notification</p>
|
|
1302
|
+
</div>
|
|
1303
|
+
</body>
|
|
1304
|
+
</html>`,
|
|
1305
|
+
text: `[WARNING] VPN/Proxy Detected
|
|
1306
|
+
|
|
1307
|
+
A login from a VPN or proxy service was detected on your account.
|
|
1308
|
+
|
|
1309
|
+
Account: {{user.email}}
|
|
1310
|
+
|
|
1311
|
+
Login Details:
|
|
1312
|
+
- Time: {{session.loginTime}}
|
|
1313
|
+
- IP Address: {{session.ipAddress}}
|
|
1314
|
+
- Location: {{geo.city}}, {{geo.country}}
|
|
1315
|
+
- VPN: {{reason.isVpn}}, Proxy: {{reason.isProxy}}`
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
function fillMissingTemplates(templates) {
|
|
1319
|
+
const defaults = getDefaultTemplates();
|
|
1320
|
+
const source = templates && typeof templates === "object" ? templates : {};
|
|
1321
|
+
return Object.fromEntries(
|
|
1322
|
+
TEMPLATE_KEYS.map((key) => {
|
|
1323
|
+
const stored = source[key] && typeof source[key] === "object" ? source[key] : {};
|
|
1324
|
+
return [
|
|
1325
|
+
key,
|
|
1326
|
+
{
|
|
1327
|
+
subject: stored.subject || defaults[key].subject,
|
|
1328
|
+
html: stored.html || defaults[key].html,
|
|
1329
|
+
text: stored.text || defaults[key].text
|
|
1330
|
+
}
|
|
1331
|
+
];
|
|
1332
|
+
})
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
const SETTINGS_DEFAULTS = Object.freeze({
|
|
1336
|
+
inactivityTimeout: 15,
|
|
1337
|
+
cleanupInterval: 30,
|
|
1338
|
+
lastSeenRateLimit: 30,
|
|
1339
|
+
retentionDays: 90,
|
|
1340
|
+
maxSessionAgeDays: 30,
|
|
1341
|
+
sessionCreationGraceMs: 5e3,
|
|
1342
|
+
cleanupUseDbDirect: false,
|
|
1343
|
+
strictSessionEnforcement: false,
|
|
1344
|
+
trustedProxies: false,
|
|
1345
|
+
enableGeolocation: true,
|
|
1346
|
+
enableSecurityScoring: true,
|
|
1347
|
+
blockSuspiciousSessions: false,
|
|
1348
|
+
maxFailedLogins: 5,
|
|
1349
|
+
enableEmailAlerts: false,
|
|
1350
|
+
alertOnSuspiciousLogin: true,
|
|
1351
|
+
alertOnNewLocation: true,
|
|
1352
|
+
alertOnVpnProxy: true,
|
|
1353
|
+
enableWebhooks: false,
|
|
1354
|
+
discordWebhookUrl: "",
|
|
1355
|
+
slackWebhookUrl: "",
|
|
1356
|
+
enableGeofencing: false,
|
|
1357
|
+
allowedCountries: [],
|
|
1358
|
+
blockedCountries: [],
|
|
1359
|
+
geoIpProvider: "auto",
|
|
1360
|
+
geoIpDatabasePath: "",
|
|
1361
|
+
geoLookupFailureMode: "auto"
|
|
1362
|
+
});
|
|
1363
|
+
const MAX_FAILED_LOGINS_RANGE = Object.freeze({ min: 0, max: 100 });
|
|
1364
|
+
const WEBHOOK_HOSTS = Object.freeze({
|
|
1365
|
+
discordWebhookUrl: ["discord.com", "discordapp.com"],
|
|
1366
|
+
slackWebhookUrl: ["hooks.slack.com"]
|
|
1367
|
+
});
|
|
1368
|
+
const GEOIP_DATABASE_FILENAMES = Object.freeze([
|
|
1369
|
+
"GeoLite2-City.mmdb",
|
|
1370
|
+
"GeoLite2-Country.mmdb",
|
|
1371
|
+
"GeoIP2-City.mmdb",
|
|
1372
|
+
"GeoIP2-Country.mmdb"
|
|
1373
|
+
]);
|
|
1374
|
+
function normalizeSettings(loaded) {
|
|
1375
|
+
if (!loaded || typeof loaded !== "object" || Array.isArray(loaded)) {
|
|
1376
|
+
throw new Error("Invalid settings response");
|
|
1377
|
+
}
|
|
1378
|
+
return {
|
|
1379
|
+
...SETTINGS_DEFAULTS,
|
|
1380
|
+
...loaded,
|
|
1381
|
+
allowedCountries: Array.isArray(loaded.allowedCountries) ? loaded.allowedCountries : [],
|
|
1382
|
+
blockedCountries: Array.isArray(loaded.blockedCountries) ? loaded.blockedCountries : [],
|
|
1383
|
+
emailTemplates: fillMissingTemplates(loaded.emailTemplates)
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
const message = (messageId, defaultMessage, values) => ({ messageId, defaultMessage, values });
|
|
1387
|
+
function isAllowedWebhookUrl(value, hosts) {
|
|
1388
|
+
if (typeof value !== "string" || !value.trim()) return true;
|
|
1389
|
+
try {
|
|
1390
|
+
const parsed = new URL(value.trim());
|
|
1391
|
+
if (parsed.protocol !== "https:") return false;
|
|
1392
|
+
return hosts.some((host) => parsed.hostname === host || parsed.hostname.endsWith(`.${host}`));
|
|
1393
|
+
} catch {
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
function validateMaxFailedLogins(value) {
|
|
1398
|
+
const { min, max } = MAX_FAILED_LOGINS_RANGE;
|
|
1399
|
+
if (value === void 0 || value === null || value === "") {
|
|
1400
|
+
return message("settings.validation.required", "Enter a value.");
|
|
1401
|
+
}
|
|
1402
|
+
const number = Number(value);
|
|
1403
|
+
if (!Number.isInteger(number) || number < min || number > max) {
|
|
1404
|
+
return message("settings.validation.range", "Enter a whole number from {min} to {max}.", {
|
|
1405
|
+
min,
|
|
1406
|
+
max
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
return null;
|
|
1410
|
+
}
|
|
1411
|
+
function validateCountryCode(code, list = []) {
|
|
1412
|
+
const value = typeof code === "string" ? code.trim().toUpperCase() : "";
|
|
1413
|
+
if (!value) return null;
|
|
1414
|
+
if (!/^[A-Z]{2}$/.test(value)) {
|
|
1415
|
+
return message(
|
|
1416
|
+
"settings.validation.countryCode",
|
|
1417
|
+
"Enter a two-letter ISO code, for example JP."
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
if (list.includes(value)) {
|
|
1421
|
+
return message("settings.validation.countryDuplicate", "{country} is already in the list.", {
|
|
1422
|
+
country: value
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
function validateSettings(settings) {
|
|
1428
|
+
const errors = {};
|
|
1429
|
+
const source = settings || {};
|
|
1430
|
+
const maxFailed = validateMaxFailedLogins(source.maxFailedLogins);
|
|
1431
|
+
if (maxFailed) errors.maxFailedLogins = maxFailed;
|
|
1432
|
+
if (!isAllowedWebhookUrl(source.discordWebhookUrl, WEBHOOK_HOSTS.discordWebhookUrl)) {
|
|
1433
|
+
errors.discordWebhookUrl = message(
|
|
1434
|
+
"settings.validation.webhookDiscord",
|
|
1435
|
+
"Enter an https address on discord.com or discordapp.com."
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
if (!isAllowedWebhookUrl(source.slackWebhookUrl, WEBHOOK_HOSTS.slackWebhookUrl)) {
|
|
1439
|
+
errors.slackWebhookUrl = message(
|
|
1440
|
+
"settings.validation.webhookSlack",
|
|
1441
|
+
"Enter an https address on hooks.slack.com."
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
const filename = typeof source.geoIpDatabasePath === "string" ? source.geoIpDatabasePath.trim() : "";
|
|
1445
|
+
if (filename && !GEOIP_DATABASE_FILENAMES.includes(filename)) {
|
|
1446
|
+
errors.geoIpDatabasePath = message(
|
|
1447
|
+
"settings.validation.geoIpFilename",
|
|
1448
|
+
"Use one of these filenames: {names}.",
|
|
1449
|
+
{
|
|
1450
|
+
names: GEOIP_DATABASE_FILENAMES.join(", ")
|
|
1451
|
+
}
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
const templates = source.emailTemplates || {};
|
|
1455
|
+
for (const key of TEMPLATE_KEYS) {
|
|
1456
|
+
for (const [field, max] of Object.entries(TEMPLATE_LIMITS)) {
|
|
1457
|
+
const value = templates[key]?.[field];
|
|
1458
|
+
if (typeof value === "string" && value.length > max) {
|
|
1459
|
+
errors[`emailTemplates.${key}.${field}`] = message(
|
|
1460
|
+
"settings.validation.maxLength",
|
|
1461
|
+
"Use at most {max} characters (currently {count}).",
|
|
1462
|
+
{ max, count: value.length }
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return errors;
|
|
1468
|
+
}
|
|
1469
|
+
function getAdjustedFields(submitted, stored, previous) {
|
|
1470
|
+
const source = submitted || {};
|
|
1471
|
+
return Object.keys(source).filter(
|
|
1472
|
+
(key) => !areSettingsEqual(source[key], stored?.[key]) && (previous === void 0 || !areSettingsEqual(source[key], previous?.[key]))
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
const COUNTRIES = [
|
|
1476
|
+
{ code: "DE", name: "Germany", flag: "🇩🇪" },
|
|
1477
|
+
{ code: "AT", name: "Austria", flag: "🇦🇹" },
|
|
1478
|
+
{ code: "CH", name: "Switzerland", flag: "🇨🇭" },
|
|
1479
|
+
{ code: "US", name: "United States", flag: "🇺🇸" },
|
|
1480
|
+
{ code: "CA", name: "Canada", flag: "🇨🇦" },
|
|
1481
|
+
{ code: "MX", name: "Mexico", flag: "🇲🇽" },
|
|
1482
|
+
{ code: "GB", name: "United Kingdom", flag: "🇬🇧" },
|
|
1483
|
+
{ code: "IE", name: "Ireland", flag: "🇮🇪" },
|
|
1484
|
+
{ code: "FR", name: "France", flag: "🇫🇷" },
|
|
1485
|
+
{ code: "IT", name: "Italy", flag: "🇮🇹" },
|
|
1486
|
+
{ code: "ES", name: "Spain", flag: "🇪🇸" },
|
|
1487
|
+
{ code: "PT", name: "Portugal", flag: "🇵🇹" },
|
|
1488
|
+
{ code: "NL", name: "Netherlands", flag: "🇳🇱" },
|
|
1489
|
+
{ code: "BE", name: "Belgium", flag: "🇧🇪" },
|
|
1490
|
+
{ code: "LU", name: "Luxembourg", flag: "🇱🇺" },
|
|
1491
|
+
{ code: "SE", name: "Sweden", flag: "🇸🇪" },
|
|
1492
|
+
{ code: "NO", name: "Norway", flag: "🇳🇴" },
|
|
1493
|
+
{ code: "DK", name: "Denmark", flag: "🇩🇰" },
|
|
1494
|
+
{ code: "FI", name: "Finland", flag: "🇫🇮" },
|
|
1495
|
+
{ code: "PL", name: "Poland", flag: "🇵🇱" },
|
|
1496
|
+
{ code: "CZ", name: "Czech Republic", flag: "🇨🇿" },
|
|
1497
|
+
{ code: "SK", name: "Slovakia", flag: "🇸🇰" },
|
|
1498
|
+
{ code: "HU", name: "Hungary", flag: "🇭🇺" },
|
|
1499
|
+
{ code: "RO", name: "Romania", flag: "🇷🇴" },
|
|
1500
|
+
{ code: "BG", name: "Bulgaria", flag: "🇧🇬" },
|
|
1501
|
+
{ code: "GR", name: "Greece", flag: "🇬🇷" },
|
|
1502
|
+
{ code: "HR", name: "Croatia", flag: "🇭🇷" },
|
|
1503
|
+
{ code: "SI", name: "Slovenia", flag: "🇸🇮" },
|
|
1504
|
+
{ code: "EE", name: "Estonia", flag: "🇪🇪" },
|
|
1505
|
+
{ code: "LV", name: "Latvia", flag: "🇱🇻" },
|
|
1506
|
+
{ code: "LT", name: "Lithuania", flag: "🇱🇹" },
|
|
1507
|
+
{ code: "IS", name: "Iceland", flag: "🇮🇸" },
|
|
1508
|
+
{ code: "TR", name: "Turkey", flag: "🇹🇷" },
|
|
1509
|
+
{ code: "RU", name: "Russia", flag: "🇷🇺" },
|
|
1510
|
+
{ code: "UA", name: "Ukraine", flag: "🇺🇦" },
|
|
1511
|
+
{ code: "BR", name: "Brazil", flag: "🇧🇷" },
|
|
1512
|
+
{ code: "AR", name: "Argentina", flag: "🇦🇷" },
|
|
1513
|
+
{ code: "CL", name: "Chile", flag: "🇨🇱" },
|
|
1514
|
+
{ code: "CO", name: "Colombia", flag: "🇨🇴" },
|
|
1515
|
+
{ code: "AU", name: "Australia", flag: "🇦🇺" },
|
|
1516
|
+
{ code: "NZ", name: "New Zealand", flag: "🇳🇿" },
|
|
1517
|
+
{ code: "JP", name: "Japan", flag: "🇯🇵" },
|
|
1518
|
+
{ code: "KR", name: "South Korea", flag: "🇰🇷" },
|
|
1519
|
+
{ code: "CN", name: "China", flag: "🇨🇳" },
|
|
1520
|
+
{ code: "HK", name: "Hong Kong", flag: "🇭🇰" },
|
|
1521
|
+
{ code: "TW", name: "Taiwan", flag: "🇹🇼" },
|
|
1522
|
+
{ code: "SG", name: "Singapore", flag: "🇸🇬" },
|
|
1523
|
+
{ code: "IN", name: "India", flag: "🇮🇳" },
|
|
1524
|
+
{ code: "ID", name: "Indonesia", flag: "🇮🇩" },
|
|
1525
|
+
{ code: "TH", name: "Thailand", flag: "🇹🇭" },
|
|
1526
|
+
{ code: "VN", name: "Vietnam", flag: "🇻🇳" },
|
|
1527
|
+
{ code: "PH", name: "Philippines", flag: "🇵🇭" },
|
|
1528
|
+
{ code: "MY", name: "Malaysia", flag: "🇲🇾" },
|
|
1529
|
+
{ code: "AE", name: "United Arab Emirates", flag: "🇦🇪" },
|
|
1530
|
+
{ code: "SA", name: "Saudi Arabia", flag: "🇸🇦" },
|
|
1531
|
+
{ code: "IL", name: "Israel", flag: "🇮🇱" },
|
|
1532
|
+
{ code: "EG", name: "Egypt", flag: "🇪🇬" },
|
|
1533
|
+
{ code: "ZA", name: "South Africa", flag: "🇿🇦" },
|
|
1534
|
+
{ code: "NG", name: "Nigeria", flag: "🇳🇬" },
|
|
1535
|
+
{ code: "KE", name: "Kenya", flag: "🇰🇪" },
|
|
1536
|
+
{ code: "MA", name: "Morocco", flag: "🇲🇦" }
|
|
1537
|
+
];
|
|
1538
|
+
const normalizeCountryCode = (raw) => {
|
|
1539
|
+
if (typeof raw !== "string") return null;
|
|
1540
|
+
const up = raw.trim().toUpperCase();
|
|
1541
|
+
if (!/^[A-Z]{2}$/.test(up)) return null;
|
|
1542
|
+
return up;
|
|
1543
|
+
};
|
|
1544
|
+
const getCountryName = (code, locale = "en") => {
|
|
1545
|
+
const match = COUNTRIES.find((c) => c.code === code);
|
|
1546
|
+
if (!match) return "";
|
|
1547
|
+
try {
|
|
1548
|
+
return new Intl.DisplayNames([locale], { type: "region" }).of(code) || match.name;
|
|
1549
|
+
} catch {
|
|
1550
|
+
return match.name;
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
const formatCountry = (code, locale = "en", { withFlag = false } = {}) => {
|
|
1554
|
+
if (!code) return "";
|
|
1555
|
+
const match = COUNTRIES.find((c) => c.code === code);
|
|
1556
|
+
if (!match) return code;
|
|
1557
|
+
const label = `${getCountryName(code, locale)} (${match.code})`;
|
|
1558
|
+
return withFlag ? `${match.flag} ${label}` : label;
|
|
1559
|
+
};
|
|
1560
|
+
const getCountryOptions = (locale = "en", exclude = []) => {
|
|
1561
|
+
let collator;
|
|
1562
|
+
try {
|
|
1563
|
+
collator = new Intl.Collator(locale);
|
|
1564
|
+
} catch {
|
|
1565
|
+
collator = new Intl.Collator("en");
|
|
1566
|
+
}
|
|
1567
|
+
return COUNTRIES.filter((country) => !exclude.includes(country.code)).map((country) => ({ code: country.code, label: formatCountry(country.code, locale) })).sort((left, right) => collator.compare(left.label, right.label));
|
|
1568
|
+
};
|
|
1569
|
+
const getFocusIndexAfterRemoval = (removedIndex, remainingCount) => {
|
|
1570
|
+
if (remainingCount <= 0) return null;
|
|
1571
|
+
return Math.min(Math.max(removedIndex, 0), remainingCount - 1);
|
|
1572
|
+
};
|
|
1573
|
+
const inferGeofencingMode = (settings) => {
|
|
1574
|
+
if (Array.isArray(settings?.allowedCountries) && settings.allowedCountries.length > 0) {
|
|
1575
|
+
return "allowlist";
|
|
1576
|
+
}
|
|
1577
|
+
if (Array.isArray(settings?.blockedCountries) && settings.blockedCountries.length > 0) {
|
|
1578
|
+
return "blocklist";
|
|
1579
|
+
}
|
|
1580
|
+
return "allowlist";
|
|
1581
|
+
};
|
|
1582
|
+
const getGeofencingField = (mode) => mode === "blocklist" ? "blockedCountries" : "allowedCountries";
|
|
1583
|
+
const selectGeofencingMode = (currentMode, requestedMode) => {
|
|
1584
|
+
if (requestedMode !== "allowlist" && requestedMode !== "blocklist") {
|
|
1585
|
+
return { mode: currentMode, clearField: null };
|
|
1586
|
+
}
|
|
1587
|
+
if (requestedMode === currentMode) {
|
|
1588
|
+
return { mode: currentMode, clearField: null };
|
|
1589
|
+
}
|
|
1590
|
+
return {
|
|
1591
|
+
mode: requestedMode,
|
|
1592
|
+
clearField: requestedMode === "allowlist" ? "blockedCountries" : "allowedCountries"
|
|
1593
|
+
};
|
|
1594
|
+
};
|
|
1595
|
+
const getModeChangeImpact = (settings, currentMode, requestedMode) => {
|
|
1596
|
+
const { clearField } = selectGeofencingMode(currentMode, requestedMode);
|
|
1597
|
+
const list = clearField && Array.isArray(settings?.[clearField]) ? settings[clearField] : [];
|
|
1598
|
+
return { confirm: list.length > 0, clearField, count: list.length };
|
|
1599
|
+
};
|
|
1600
|
+
const NO_COUNTRIES = [];
|
|
1601
|
+
const ChipList = styled(Flex)`
|
|
1602
|
+
& button {
|
|
1603
|
+
min-width: ${({ theme }) => theme.spaces[7]};
|
|
1604
|
+
min-height: ${({ theme }) => theme.spaces[7]};
|
|
1605
|
+
justify-content: center;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
${({ theme }) => theme.breakpoints.medium} {
|
|
1609
|
+
& button {
|
|
1610
|
+
min-width: 0;
|
|
1611
|
+
min-height: 0;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
`;
|
|
1615
|
+
const CountryListEditor = ({ settings, handleChange }) => {
|
|
1616
|
+
const { t, tError, locale } = useSettingsTranslate();
|
|
1617
|
+
const modeLabelId = useId();
|
|
1618
|
+
const listLabelId = useId();
|
|
1619
|
+
const [mode, setMode] = useState(() => inferGeofencingMode(settings));
|
|
1620
|
+
const [pendingMode, setPendingMode] = useState(null);
|
|
1621
|
+
const [pickerKey, setPickerKey] = useState(0);
|
|
1622
|
+
const [manualCode, setManualCode] = useState("");
|
|
1623
|
+
const pendingFocusIndexRef = useRef(void 0);
|
|
1624
|
+
const refocusPickerRef = useRef(false);
|
|
1625
|
+
const chipListRef = useRef(null);
|
|
1626
|
+
const pickerRef = useRef(null);
|
|
1627
|
+
const modeGroupRef = useRef(null);
|
|
1628
|
+
const activeField = getGeofencingField(mode);
|
|
1629
|
+
const activeList = Array.isArray(settings[activeField]) ? settings[activeField] : NO_COUNTRIES;
|
|
1630
|
+
const options = useMemo(() => getCountryOptions(locale, activeList), [locale, activeList]);
|
|
1631
|
+
const manualError = tError(validateCountryCode(manualCode, activeList));
|
|
1632
|
+
const inferredMode = inferGeofencingMode(settings);
|
|
1633
|
+
const allowedCount = settings.allowedCountries?.length || 0;
|
|
1634
|
+
const blockedCount = settings.blockedCountries?.length || 0;
|
|
1635
|
+
const listSignature = `${inferredMode}:${allowedCount}:${blockedCount}`;
|
|
1636
|
+
const [syncedSignature, setSyncedSignature] = useState(listSignature);
|
|
1637
|
+
if (listSignature !== syncedSignature) {
|
|
1638
|
+
setSyncedSignature(listSignature);
|
|
1639
|
+
if (allowedCount > 0 || blockedCount > 0) setMode(inferredMode);
|
|
1640
|
+
}
|
|
1641
|
+
useEffect(() => {
|
|
1642
|
+
const focusIndex = pendingFocusIndexRef.current;
|
|
1643
|
+
if (focusIndex === void 0) return;
|
|
1644
|
+
pendingFocusIndexRef.current = void 0;
|
|
1645
|
+
const chips = chipListRef.current?.querySelectorAll("button") || [];
|
|
1646
|
+
if (focusIndex !== null && chips[focusIndex]) chips[focusIndex].focus();
|
|
1647
|
+
else pickerRef.current?.focus();
|
|
1648
|
+
}, [activeList.length]);
|
|
1649
|
+
useEffect(() => {
|
|
1650
|
+
if (!refocusPickerRef.current) return;
|
|
1651
|
+
refocusPickerRef.current = false;
|
|
1652
|
+
pickerRef.current?.focus();
|
|
1653
|
+
}, [pickerKey]);
|
|
1654
|
+
const applyMode = (requestedMode) => {
|
|
1655
|
+
const selection = selectGeofencingMode(mode, requestedMode);
|
|
1656
|
+
if (selection.mode === mode) return;
|
|
1657
|
+
setMode(selection.mode);
|
|
1658
|
+
if (selection.clearField) handleChange(selection.clearField, []);
|
|
1659
|
+
};
|
|
1660
|
+
const requestMode = (requestedMode) => {
|
|
1661
|
+
const impact = getModeChangeImpact(settings, mode, requestedMode);
|
|
1662
|
+
if (impact.confirm) {
|
|
1663
|
+
setPendingMode(requestedMode);
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
applyMode(requestedMode);
|
|
1667
|
+
};
|
|
1668
|
+
const focusSelectedMode = () => {
|
|
1669
|
+
if (typeof window === "undefined") return;
|
|
1670
|
+
window.requestAnimationFrame(() => {
|
|
1671
|
+
modeGroupRef.current?.querySelector('[role="radio"][data-state="checked"]')?.focus();
|
|
1672
|
+
});
|
|
1673
|
+
};
|
|
1674
|
+
const addCode = (raw) => {
|
|
1675
|
+
const code = normalizeCountryCode(raw);
|
|
1676
|
+
if (!code || activeList.includes(code)) return false;
|
|
1677
|
+
handleChange(activeField, [...activeList, code]);
|
|
1678
|
+
return true;
|
|
1679
|
+
};
|
|
1680
|
+
const removeCode = (code) => {
|
|
1681
|
+
const index = activeList.indexOf(code);
|
|
1682
|
+
const next = activeList.filter((entry) => entry !== code);
|
|
1683
|
+
handleChange(activeField, next);
|
|
1684
|
+
pendingFocusIndexRef.current = getFocusIndexAfterRemoval(index, next.length);
|
|
1685
|
+
};
|
|
1686
|
+
const pendingImpact = pendingMode ? getModeChangeImpact(settings, mode, pendingMode) : null;
|
|
1687
|
+
const modeLabels = {
|
|
1688
|
+
allowlist: t("settings.config.countries.mode.allow", "Allow only listed countries"),
|
|
1689
|
+
blocklist: t("settings.config.countries.mode.reject", "Reject listed countries")
|
|
1690
|
+
};
|
|
1691
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
|
|
1692
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
1693
|
+
/* @__PURE__ */ jsx(
|
|
1694
|
+
Typography,
|
|
1695
|
+
{
|
|
1696
|
+
id: modeLabelId,
|
|
1697
|
+
variant: "pi",
|
|
1698
|
+
fontWeight: "bold",
|
|
1699
|
+
tag: "div",
|
|
1700
|
+
textColor: "neutral800",
|
|
1701
|
+
children: t("settings.config.countries.mode.label", "Mode")
|
|
1702
|
+
}
|
|
1703
|
+
),
|
|
1704
|
+
/* @__PURE__ */ jsxs(
|
|
1705
|
+
Radio.Group,
|
|
1706
|
+
{
|
|
1707
|
+
ref: modeGroupRef,
|
|
1708
|
+
"aria-labelledby": modeLabelId,
|
|
1709
|
+
value: mode,
|
|
1710
|
+
onValueChange: requestMode,
|
|
1711
|
+
children: [
|
|
1712
|
+
/* @__PURE__ */ jsx(Radio.Item, { value: "allowlist", children: modeLabels.allowlist }),
|
|
1713
|
+
/* @__PURE__ */ jsx(Radio.Item, { value: "blocklist", children: modeLabels.blocklist })
|
|
1714
|
+
]
|
|
1715
|
+
}
|
|
1716
|
+
)
|
|
1717
|
+
] }),
|
|
1718
|
+
/* @__PURE__ */ jsx(
|
|
1719
|
+
Dialog.Root,
|
|
1720
|
+
{
|
|
1721
|
+
open: Boolean(pendingMode),
|
|
1722
|
+
onOpenChange: (open) => {
|
|
1723
|
+
if (!open) {
|
|
1724
|
+
setPendingMode(null);
|
|
1725
|
+
focusSelectedMode();
|
|
1726
|
+
}
|
|
1727
|
+
},
|
|
1728
|
+
children: /* @__PURE__ */ jsx(
|
|
1729
|
+
ConfirmDialog,
|
|
1730
|
+
{
|
|
1731
|
+
title: t("settings.config.countries.switch.title", "Switch to {mode}?", {
|
|
1732
|
+
mode: modeLabels[pendingMode] ?? ""
|
|
1733
|
+
}),
|
|
1734
|
+
variant: "danger",
|
|
1735
|
+
endAction: /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(
|
|
1736
|
+
Button,
|
|
1737
|
+
{
|
|
1738
|
+
fullWidth: true,
|
|
1739
|
+
variant: "danger",
|
|
1740
|
+
onClick: () => {
|
|
1741
|
+
applyMode(pendingMode);
|
|
1742
|
+
setPendingMode(null);
|
|
1743
|
+
focusSelectedMode();
|
|
1744
|
+
},
|
|
1745
|
+
children: t("settings.config.countries.switch.action", "Switch mode")
|
|
1746
|
+
}
|
|
1747
|
+
) }),
|
|
1748
|
+
children: t(
|
|
1749
|
+
"settings.config.countries.switch.body",
|
|
1750
|
+
"The current list of {count, plural, one {# country} other {# countries}} is cleared when you save.",
|
|
1751
|
+
{ count: pendingImpact?.count ?? 0 }
|
|
1752
|
+
)
|
|
1753
|
+
}
|
|
1754
|
+
)
|
|
1755
|
+
}
|
|
1756
|
+
),
|
|
1757
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
1758
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
1759
|
+
/* @__PURE__ */ jsx(
|
|
1760
|
+
Typography,
|
|
1761
|
+
{
|
|
1762
|
+
id: listLabelId,
|
|
1763
|
+
variant: "pi",
|
|
1764
|
+
fontWeight: "bold",
|
|
1765
|
+
tag: "div",
|
|
1766
|
+
textColor: "neutral800",
|
|
1767
|
+
children: t("settings.config.countries.list.label", "Countries")
|
|
1768
|
+
}
|
|
1769
|
+
),
|
|
1770
|
+
/* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
1771
|
+
"settings.config.countries.list.hint",
|
|
1772
|
+
"With 'Allow only listed countries', an empty list allows every country."
|
|
1773
|
+
) })
|
|
1774
|
+
] }),
|
|
1775
|
+
activeList.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("settings.geofencing.empty", "No countries configured.") }) : /* @__PURE__ */ jsx(
|
|
1776
|
+
ChipList,
|
|
1777
|
+
{
|
|
1778
|
+
ref: chipListRef,
|
|
1779
|
+
tag: "ul",
|
|
1780
|
+
gap: 2,
|
|
1781
|
+
wrap: "wrap",
|
|
1782
|
+
"aria-labelledby": listLabelId,
|
|
1783
|
+
"data-country-chips": "",
|
|
1784
|
+
children: activeList.map((code) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
1785
|
+
Tag,
|
|
1786
|
+
{
|
|
1787
|
+
icon: /* @__PURE__ */ jsx(Cross, { "aria-hidden": true, focusable: false }),
|
|
1788
|
+
label: t("settings.geofencing.removeCountry", "Remove {country}", {
|
|
1789
|
+
country: getCountryName(code, locale) || code
|
|
1790
|
+
}),
|
|
1791
|
+
onClick: () => removeCode(code),
|
|
1792
|
+
children: formatCountry(code, locale)
|
|
1793
|
+
}
|
|
1794
|
+
) }, code))
|
|
1795
|
+
}
|
|
1796
|
+
)
|
|
1797
|
+
] }),
|
|
1798
|
+
/* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 4, children: [
|
|
1799
|
+
/* @__PURE__ */ jsx(
|
|
1800
|
+
FormField,
|
|
1801
|
+
{
|
|
1802
|
+
id: "country-picker",
|
|
1803
|
+
name: "countryPicker",
|
|
1804
|
+
label: t("settings.geofencing.pick.label", "Select a country"),
|
|
1805
|
+
description: t(
|
|
1806
|
+
"settings.geofencing.pick.hint",
|
|
1807
|
+
"Choose a country to add it to the active list."
|
|
1808
|
+
),
|
|
1809
|
+
children: /* @__PURE__ */ jsx(
|
|
1810
|
+
Combobox,
|
|
1811
|
+
{
|
|
1812
|
+
ref: pickerRef,
|
|
1813
|
+
autocomplete: { type: "list", filter: "contains" },
|
|
1814
|
+
placeholder: t("settings.geofencing.pick", "Pick a country to add…"),
|
|
1815
|
+
onChange: (code) => {
|
|
1816
|
+
if (code && addCode(code)) {
|
|
1817
|
+
refocusPickerRef.current = true;
|
|
1818
|
+
setPickerKey((key) => key + 1);
|
|
1819
|
+
}
|
|
1820
|
+
},
|
|
1821
|
+
noOptionsMessage: () => t("settings.geofencing.pick.noResults", "No matching country"),
|
|
1822
|
+
children: options.map((option) => /* @__PURE__ */ jsx(ComboboxOption, { value: option.code, children: option.label }, option.code))
|
|
1823
|
+
},
|
|
1824
|
+
pickerKey
|
|
1825
|
+
)
|
|
1826
|
+
}
|
|
1827
|
+
),
|
|
1828
|
+
/* @__PURE__ */ jsx(
|
|
1829
|
+
FormField,
|
|
1830
|
+
{
|
|
1831
|
+
id: "country-code-manual",
|
|
1832
|
+
name: "countryCodeManual",
|
|
1833
|
+
label: t("settings.geofencing.manual.label", "Country code"),
|
|
1834
|
+
description: t("settings.geofencing.manual.hint", "Enter a two-letter ISO country code."),
|
|
1835
|
+
error: manualError,
|
|
1836
|
+
action: /* @__PURE__ */ jsx(
|
|
1837
|
+
Button,
|
|
1838
|
+
{
|
|
1839
|
+
variant: "secondary",
|
|
1840
|
+
size: "L",
|
|
1841
|
+
startIcon: /* @__PURE__ */ jsx(Plus, { "aria-hidden": true, focusable: false }),
|
|
1842
|
+
disabled: Boolean(manualError) || !normalizeCountryCode(manualCode),
|
|
1843
|
+
onClick: () => {
|
|
1844
|
+
if (addCode(manualCode)) setManualCode("");
|
|
1845
|
+
},
|
|
1846
|
+
children: t("settings.geofencing.add", "Add")
|
|
1847
|
+
}
|
|
1848
|
+
),
|
|
1849
|
+
children: /* @__PURE__ */ jsx(
|
|
1850
|
+
TextInput,
|
|
1851
|
+
{
|
|
1852
|
+
placeholder: t("settings.geofencing.manual", "For example, JP"),
|
|
1853
|
+
value: manualCode,
|
|
1854
|
+
maxLength: 2,
|
|
1855
|
+
autoComplete: "off",
|
|
1856
|
+
onChange: (event) => setManualCode(event.target.value.toUpperCase().slice(0, 2)),
|
|
1857
|
+
onKeyDown: (event) => {
|
|
1858
|
+
if (event.key === "Enter") {
|
|
1859
|
+
event.preventDefault();
|
|
1860
|
+
if (!manualError && addCode(manualCode)) setManualCode("");
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
)
|
|
1865
|
+
}
|
|
1866
|
+
)
|
|
1867
|
+
] })
|
|
1868
|
+
] });
|
|
1869
|
+
};
|
|
1870
|
+
const LoginProtectionTab = ({ form }) => {
|
|
1871
|
+
const { t, tError } = useSettingsTranslate();
|
|
1872
|
+
const { settings, handleChange, errors } = form;
|
|
1873
|
+
const maxFailedError = tError(errors.maxFailedLogins);
|
|
1874
|
+
const maxFailedValue = Number(settings.maxFailedLogins);
|
|
1875
|
+
const lookupOff = !settings.enableGeolocation;
|
|
1876
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
1877
|
+
/* @__PURE__ */ jsx(IntroText, { children: t(
|
|
1878
|
+
"settings.config.loginProtection.intro",
|
|
1879
|
+
"These rules check new sign-ins before they succeed. Existing sessions are not affected, and refused sign-ins are not recorded."
|
|
1880
|
+
) }),
|
|
1881
|
+
/* @__PURE__ */ jsxs(
|
|
1882
|
+
SectionCard,
|
|
1883
|
+
{
|
|
1884
|
+
title: t("settings.config.failed.title", "Failed sign-ins"),
|
|
1885
|
+
subtitle: t(
|
|
1886
|
+
"settings.config.failed.intro",
|
|
1887
|
+
"Slows down password guessing from one IP address."
|
|
1888
|
+
),
|
|
1889
|
+
children: [
|
|
1890
|
+
/* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
|
|
1891
|
+
FormField,
|
|
1892
|
+
{
|
|
1893
|
+
id: "max-failed-logins",
|
|
1894
|
+
name: "maxFailedLogins",
|
|
1895
|
+
label: t("settings.config.failed.lockout.label", "Temporary IP lockout after"),
|
|
1896
|
+
description: t(
|
|
1897
|
+
"settings.config.failed.lockout.hint",
|
|
1898
|
+
"A whole number from 0 to 100. 0 turns the lockout off."
|
|
1899
|
+
),
|
|
1900
|
+
suffix: t("settings.config.failed.lockout.suffix", "failed sign-ins"),
|
|
1901
|
+
error: maxFailedError,
|
|
1902
|
+
required: true,
|
|
1903
|
+
children: /* @__PURE__ */ jsx(
|
|
1904
|
+
NumberInput,
|
|
1905
|
+
{
|
|
1906
|
+
value: settings.maxFailedLogins,
|
|
1907
|
+
onValueChange: (value) => handleChange("maxFailedLogins", value),
|
|
1908
|
+
min: MAX_FAILED_LOGINS_RANGE.min,
|
|
1909
|
+
max: MAX_FAILED_LOGINS_RANGE.max,
|
|
1910
|
+
step: 1
|
|
1911
|
+
},
|
|
1912
|
+
form.draftVersion
|
|
1913
|
+
)
|
|
1914
|
+
}
|
|
1915
|
+
) }),
|
|
1916
|
+
!maxFailedError ? /* @__PURE__ */ jsx(
|
|
1917
|
+
Box,
|
|
1918
|
+
{
|
|
1919
|
+
padding: 3,
|
|
1920
|
+
background: maxFailedValue === 0 ? "warning100" : "neutral100",
|
|
1921
|
+
hasRadius: true,
|
|
1922
|
+
"aria-live": "polite",
|
|
1923
|
+
children: /* @__PURE__ */ jsx(
|
|
1924
|
+
ReadableParagraphs,
|
|
1925
|
+
{
|
|
1926
|
+
variant: "pi",
|
|
1927
|
+
textColor: maxFailedValue === 0 ? "warning700" : "neutral700",
|
|
1928
|
+
tag: "p",
|
|
1929
|
+
text: maxFailedValue === 0 ? t(
|
|
1930
|
+
"settings.config.failed.lockout.off",
|
|
1931
|
+
"The temporary IP lockout is off. Failed sign-ins are not limited."
|
|
1932
|
+
) : t(
|
|
1933
|
+
"settings.config.failed.lockout.preview",
|
|
1934
|
+
"After {count, plural, one {# failed sign-in} other {# failed sign-ins}} from one IP address within 15 minutes, that address is refused for 15 minutes. User accounts are not blocked. Counted per server process.",
|
|
1935
|
+
{ count: maxFailedValue }
|
|
1936
|
+
)
|
|
1937
|
+
}
|
|
1938
|
+
)
|
|
1939
|
+
}
|
|
1940
|
+
) : null
|
|
1941
|
+
]
|
|
1942
|
+
}
|
|
1943
|
+
),
|
|
1944
|
+
/* @__PURE__ */ jsx(
|
|
1945
|
+
SectionCard,
|
|
1946
|
+
{
|
|
1947
|
+
id: "client-ip-address",
|
|
1948
|
+
title: t("settings.config.clientIp.title", "Client IP address"),
|
|
1949
|
+
subtitle: t(
|
|
1950
|
+
"settings.config.clientIp.intro",
|
|
1951
|
+
"All IP-based rules depend on reading the real client address."
|
|
1952
|
+
),
|
|
1953
|
+
children: /* @__PURE__ */ jsx(
|
|
1954
|
+
SettingsToggleRow,
|
|
1955
|
+
{
|
|
1956
|
+
id: "trusted-proxies",
|
|
1957
|
+
title: t("settings.config.clientIp.trustProxy.label", "Trust proxy headers"),
|
|
1958
|
+
description: t(
|
|
1959
|
+
"settings.config.clientIp.trustProxy.hint",
|
|
1960
|
+
"Turn on only behind a proxy you control. Affects the recorded IP address, the IP lockout and location lookups."
|
|
1961
|
+
),
|
|
1962
|
+
checked: settings.trustedProxies,
|
|
1963
|
+
onChange: (checked) => handleChange("trustedProxies", checked)
|
|
1964
|
+
}
|
|
1965
|
+
)
|
|
1966
|
+
}
|
|
1967
|
+
),
|
|
1968
|
+
/* @__PURE__ */ jsxs(
|
|
1969
|
+
SectionCard,
|
|
1970
|
+
{
|
|
1971
|
+
title: t("settings.config.suspicious.title", "Suspicious sign-ins"),
|
|
1972
|
+
subtitle: t("settings.config.suspicious.intro", "Refuses new sign-ins that look risky."),
|
|
1973
|
+
children: [
|
|
1974
|
+
lookupOff ? /* @__PURE__ */ jsx(RequiresGeolocation, {}) : null,
|
|
1975
|
+
/* @__PURE__ */ jsx(
|
|
1976
|
+
SettingsToggleRow,
|
|
1977
|
+
{
|
|
1978
|
+
id: "block-suspicious-sessions",
|
|
1979
|
+
title: t("settings.config.suspicious.reject.label", "Reject suspicious sign-ins"),
|
|
1980
|
+
description: t(
|
|
1981
|
+
"settings.config.suspicious.reject.hint",
|
|
1982
|
+
"Refuses sign-ins from VPN, proxy or known threat addresses and, with security scoring on, scores below 50."
|
|
1983
|
+
),
|
|
1984
|
+
checked: settings.blockSuspiciousSessions,
|
|
1985
|
+
disabled: lookupOff,
|
|
1986
|
+
onChange: (checked) => handleChange("blockSuspiciousSessions", checked),
|
|
1987
|
+
children: settings.geoIpProvider === "local-mmdb" ? /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
1988
|
+
"settings.config.suspicious.reject.localNote",
|
|
1989
|
+
"The local database has no VPN, proxy or threat data and always scores 100, so only failed lookups can be refused."
|
|
1990
|
+
) }) : null
|
|
1991
|
+
}
|
|
1992
|
+
),
|
|
1993
|
+
/* @__PURE__ */ jsx(AdvancedSection, { hasError: fieldHasError(errors, "geoLookupFailureMode"), children: /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
|
|
1994
|
+
FormField,
|
|
1995
|
+
{
|
|
1996
|
+
id: "geoip-lookup-failure-mode",
|
|
1997
|
+
name: "geoLookupFailureMode",
|
|
1998
|
+
label: t(
|
|
1999
|
+
"settings.config.suspicious.failureMode.label",
|
|
2000
|
+
"If the location cannot be determined"
|
|
2001
|
+
),
|
|
2002
|
+
description: t(
|
|
2003
|
+
"settings.config.suspicious.failureMode.hint",
|
|
2004
|
+
"Automatic rejects only when 'Reject suspicious sign-ins' is on. A rejected sign-in gets 'Login temporarily unavailable'. With 'Reject sign-in', the Automatic provider no longer falls back to ipapi.co."
|
|
2005
|
+
),
|
|
2006
|
+
children: /* @__PURE__ */ jsxs(
|
|
2007
|
+
SingleSelect,
|
|
2008
|
+
{
|
|
2009
|
+
value: settings.geoLookupFailureMode || "auto",
|
|
2010
|
+
disabled: lookupOff,
|
|
2011
|
+
onChange: (value) => handleChange("geoLookupFailureMode", value),
|
|
2012
|
+
children: [
|
|
2013
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "auto", children: t("settings.config.suspicious.failureMode.auto", "Automatic") }),
|
|
2014
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "allow", children: t("settings.config.suspicious.failureMode.allow", "Allow sign-in") }),
|
|
2015
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "block", children: t("settings.config.suspicious.failureMode.block", "Reject sign-in") })
|
|
2016
|
+
]
|
|
2017
|
+
}
|
|
2018
|
+
)
|
|
2019
|
+
}
|
|
2020
|
+
) }) })
|
|
2021
|
+
]
|
|
2022
|
+
}
|
|
2023
|
+
),
|
|
2024
|
+
/* @__PURE__ */ jsxs(
|
|
2025
|
+
SectionCard,
|
|
2026
|
+
{
|
|
2027
|
+
title: t("settings.config.countries.title", "Country rules"),
|
|
2028
|
+
subtitle: t(
|
|
2029
|
+
"settings.config.countries.intro",
|
|
2030
|
+
"Allow or reject new sign-ins by the country of the IP address."
|
|
2031
|
+
),
|
|
2032
|
+
children: [
|
|
2033
|
+
lookupOff ? /* @__PURE__ */ jsx(RequiresGeolocation, {}) : null,
|
|
2034
|
+
/* @__PURE__ */ jsx(
|
|
2035
|
+
SettingsToggleRow,
|
|
2036
|
+
{
|
|
2037
|
+
id: "enable-geofencing",
|
|
2038
|
+
title: t("settings.config.countries.enable.label", "Use country rules"),
|
|
2039
|
+
checked: !!settings.enableGeofencing,
|
|
2040
|
+
disabled: lookupOff,
|
|
2041
|
+
onChange: (checked) => handleChange("enableGeofencing", checked)
|
|
2042
|
+
}
|
|
2043
|
+
),
|
|
2044
|
+
/* @__PURE__ */ jsx(CountryListEditor, { settings, handleChange })
|
|
2045
|
+
]
|
|
2046
|
+
}
|
|
2047
|
+
),
|
|
2048
|
+
/* @__PURE__ */ jsxs(SectionCard, { title: t("settings.config.refused.title", "Why sign-ins are refused"), children: [
|
|
2049
|
+
/* @__PURE__ */ jsx(
|
|
2050
|
+
TermList,
|
|
2051
|
+
{
|
|
2052
|
+
label: t("settings.config.refused.title", "Why sign-ins are refused"),
|
|
2053
|
+
items: [
|
|
2054
|
+
{
|
|
2055
|
+
id: "lockout",
|
|
2056
|
+
term: t("settings.config.refused.lockout.response", "429 with Retry-After"),
|
|
2057
|
+
description: t("settings.config.refused.lockout.cause", "Temporary IP lockout")
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
id: "rule",
|
|
2061
|
+
term: t("settings.config.refused.rule.response", "403"),
|
|
2062
|
+
description: t(
|
|
2063
|
+
"settings.config.refused.rule.cause",
|
|
2064
|
+
"Country rule, or suspicious address / low score"
|
|
2065
|
+
)
|
|
2066
|
+
},
|
|
2067
|
+
{
|
|
2068
|
+
id: "unavailable",
|
|
2069
|
+
term: t(
|
|
2070
|
+
"settings.config.refused.unavailable.response",
|
|
2071
|
+
'403 "Login temporarily unavailable"'
|
|
2072
|
+
),
|
|
2073
|
+
description: t(
|
|
2074
|
+
"settings.config.refused.unavailable.cause",
|
|
2075
|
+
"Location could not be determined and the rule says reject"
|
|
2076
|
+
)
|
|
2077
|
+
}
|
|
2078
|
+
]
|
|
2079
|
+
}
|
|
2080
|
+
),
|
|
2081
|
+
/* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t("settings.config.refused.noLog", "Session Manager keeps no log of refused sign-ins.") })
|
|
2082
|
+
] })
|
|
2083
|
+
] });
|
|
2084
|
+
};
|
|
2085
|
+
const BUILD_DATE_OPTIONS$1 = Object.freeze({ dateStyle: "medium" });
|
|
2086
|
+
const PathValue = ({ path }) => {
|
|
2087
|
+
const parts = String(path).split("/");
|
|
2088
|
+
return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: parts.map((part, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2089
|
+
part,
|
|
2090
|
+
index < parts.length - 1 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2091
|
+
"/",
|
|
2092
|
+
/* @__PURE__ */ jsx("wbr", {})
|
|
2093
|
+
] }) : null
|
|
2094
|
+
] }, index)) });
|
|
2095
|
+
};
|
|
2096
|
+
const GeoIpDatabaseCard = ({ form }) => {
|
|
2097
|
+
const { t, tError, locale } = useSettingsTranslate();
|
|
2098
|
+
const { settings, handleChange, errors, hasChanges, geoIp } = form;
|
|
2099
|
+
const geoIpStatus = geoIp.status;
|
|
2100
|
+
const accountIdRef = useRef(null);
|
|
2101
|
+
const saveCredentialsRef = useRef(null);
|
|
2102
|
+
const updateRef = useRef(null);
|
|
2103
|
+
const forceRef = useRef(null);
|
|
2104
|
+
const keepFocus = async (action, buttonRef) => {
|
|
2105
|
+
await action();
|
|
2106
|
+
window.requestAnimationFrame(
|
|
2107
|
+
() => window.requestAnimationFrame(() => {
|
|
2108
|
+
refocusIfLost(buttonRef.current, accountIdRef.current);
|
|
2109
|
+
})
|
|
2110
|
+
);
|
|
2111
|
+
};
|
|
2112
|
+
const lookupOff = !settings.enableGeolocation;
|
|
2113
|
+
const localDatabase = usesLocalDatabase(settings.geoIpProvider);
|
|
2114
|
+
const databaseDisabled = lookupOff || !localDatabase;
|
|
2115
|
+
const credentialSource = geoIpStatus?.credentialSource;
|
|
2116
|
+
const fromEnvironment = credentialSource === "env";
|
|
2117
|
+
const credentialSourceLabels = {
|
|
2118
|
+
env: t("settings.config.database.credentials.env", "Environment variables"),
|
|
2119
|
+
store: t("settings.config.database.credentials.store", "Stored in Strapi"),
|
|
2120
|
+
missing: t("settings.config.database.credentials.missing", "Missing")
|
|
2121
|
+
};
|
|
2122
|
+
return /* @__PURE__ */ jsxs(
|
|
2123
|
+
SectionCard,
|
|
2124
|
+
{
|
|
2125
|
+
title: t("settings.config.provider.title", "Provider and database"),
|
|
2126
|
+
action: geoIpStatus ? /* @__PURE__ */ jsx(
|
|
2127
|
+
Badge,
|
|
2128
|
+
{
|
|
2129
|
+
backgroundColor: geoIpStatus.exists ? "success100" : "neutral150",
|
|
2130
|
+
textColor: geoIpStatus.exists ? "success700" : "neutral700",
|
|
2131
|
+
children: geoIpStatus.exists ? t("settings.config.database.downloaded", "Downloaded") : t("settings.config.database.notDownloaded", "Not downloaded")
|
|
2132
|
+
}
|
|
2133
|
+
) : null,
|
|
2134
|
+
children: [
|
|
2135
|
+
lookupOff ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.geolocation", "Requires IP location lookup") }) : null,
|
|
2136
|
+
/* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
|
|
2137
|
+
FormField,
|
|
2138
|
+
{
|
|
2139
|
+
id: "geoip-provider",
|
|
2140
|
+
name: "geoIpProvider",
|
|
2141
|
+
label: t("settings.config.provider.label", "Provider"),
|
|
2142
|
+
description: t(
|
|
2143
|
+
"settings.config.provider.hint",
|
|
2144
|
+
"Automatic uses the local database, else ipapi.co unless lookup failures are set to reject. Local database keeps lookups on this server. ipapi.co sends IP addresses to that service. Off turns lookups off."
|
|
2145
|
+
),
|
|
2146
|
+
children: /* @__PURE__ */ jsxs(
|
|
2147
|
+
SingleSelect,
|
|
2148
|
+
{
|
|
2149
|
+
value: settings.geoIpProvider || "auto",
|
|
2150
|
+
disabled: lookupOff,
|
|
2151
|
+
onChange: (value) => handleChange("geoIpProvider", value),
|
|
2152
|
+
children: [
|
|
2153
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "auto", children: t("settings.config.provider.auto", "Automatic") }),
|
|
2154
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "local-mmdb", children: t("settings.config.provider.local", "Local database") }),
|
|
2155
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "ipapi", children: t("settings.config.provider.ipapi", "ipapi.co") }),
|
|
2156
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "disabled", children: t("settings.config.provider.off", "Off") })
|
|
2157
|
+
]
|
|
2158
|
+
}
|
|
2159
|
+
)
|
|
2160
|
+
}
|
|
2161
|
+
) }),
|
|
2162
|
+
!lookupOff && !localDatabase ? /* @__PURE__ */ jsx(RequiresNotice, { children: t(
|
|
2163
|
+
"settings.config.requires.localDatabase",
|
|
2164
|
+
"The database settings below require the Automatic or Local database provider."
|
|
2165
|
+
) }) : null,
|
|
2166
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
2167
|
+
geoIp.statusError && /* @__PURE__ */ jsx(
|
|
2168
|
+
PersistentAlert,
|
|
2169
|
+
{
|
|
2170
|
+
variant: "danger",
|
|
2171
|
+
closeLabel: t("common.close", "Close"),
|
|
2172
|
+
title: "",
|
|
2173
|
+
action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: geoIp.fetchStatus, children: t("settings.config.load.retry", "Try again") }),
|
|
2174
|
+
children: t("settings.config.database.statusError", "The database status could not be loaded.")
|
|
2175
|
+
}
|
|
2176
|
+
),
|
|
2177
|
+
geoIpStatus ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
2178
|
+
!geoIpStatus.exists ? /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral600", tag: "p", children: t("settings.config.database.none", "No database downloaded yet.") }) : null,
|
|
2179
|
+
/* @__PURE__ */ jsx(
|
|
2180
|
+
PropertyList,
|
|
2181
|
+
{
|
|
2182
|
+
label: t("settings.config.database.statusLabel", "Database status"),
|
|
2183
|
+
items: [
|
|
2184
|
+
{
|
|
2185
|
+
id: "edition",
|
|
2186
|
+
label: t("settings.config.database.edition", "Edition"),
|
|
2187
|
+
value: geoIpStatus.editionId
|
|
2188
|
+
},
|
|
2189
|
+
{
|
|
2190
|
+
id: "built",
|
|
2191
|
+
label: t("settings.config.database.built", "Build date"),
|
|
2192
|
+
value: formatSessionDate(
|
|
2193
|
+
geoIpStatus.metadata?.lastModified,
|
|
2194
|
+
locale,
|
|
2195
|
+
"",
|
|
2196
|
+
BUILD_DATE_OPTIONS$1
|
|
2197
|
+
)
|
|
2198
|
+
},
|
|
2199
|
+
{
|
|
2200
|
+
id: "file",
|
|
2201
|
+
label: t("settings.config.database.file", "File"),
|
|
2202
|
+
value: geoIpStatus.databasePath,
|
|
2203
|
+
render: geoIpStatus.databasePath ? /* @__PURE__ */ jsx(PathValue, { path: geoIpStatus.databasePath }) : void 0,
|
|
2204
|
+
kind: "id"
|
|
2205
|
+
},
|
|
2206
|
+
{
|
|
2207
|
+
id: "credentials",
|
|
2208
|
+
label: t("settings.config.database.credentials", "MaxMind credentials"),
|
|
2209
|
+
value: credentialSourceLabels[credentialSource]
|
|
2210
|
+
}
|
|
2211
|
+
]
|
|
2212
|
+
}
|
|
2213
|
+
)
|
|
2214
|
+
] }) : null,
|
|
2215
|
+
fromEnvironment ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), title: "", children: t(
|
|
2216
|
+
"settings.config.database.credentials.envNote",
|
|
2217
|
+
"Environment variables are set and take precedence; stored values are ignored."
|
|
2218
|
+
) }) : null,
|
|
2219
|
+
/* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
|
|
2220
|
+
/* @__PURE__ */ jsx(
|
|
2221
|
+
FormField,
|
|
2222
|
+
{
|
|
2223
|
+
id: "maxmind-account-id",
|
|
2224
|
+
name: "maxmindAccountId",
|
|
2225
|
+
label: t("settings.config.database.accountId", "MaxMind account ID"),
|
|
2226
|
+
description: t(
|
|
2227
|
+
"settings.config.database.accountId.hint",
|
|
2228
|
+
"Up to 64 characters. Environment variables take precedence."
|
|
2229
|
+
),
|
|
2230
|
+
children: /* @__PURE__ */ jsx(
|
|
2231
|
+
TextInput,
|
|
2232
|
+
{
|
|
2233
|
+
ref: accountIdRef,
|
|
2234
|
+
name: "maxmindAccountId",
|
|
2235
|
+
value: geoIp.credentials.accountId || "",
|
|
2236
|
+
autoComplete: "off",
|
|
2237
|
+
maxLength: 64,
|
|
2238
|
+
disabled: databaseDisabled,
|
|
2239
|
+
readOnly: fromEnvironment,
|
|
2240
|
+
onChange: (event) => geoIp.setCredentials((prev) => ({ ...prev, accountId: event.target.value }))
|
|
2241
|
+
}
|
|
2242
|
+
)
|
|
2243
|
+
}
|
|
2244
|
+
),
|
|
2245
|
+
/* @__PURE__ */ jsx(
|
|
2246
|
+
FormField,
|
|
2247
|
+
{
|
|
2248
|
+
id: "maxmind-license-key",
|
|
2249
|
+
name: "maxmindLicenseKey",
|
|
2250
|
+
label: t("settings.config.database.licenseKey", "MaxMind license key"),
|
|
2251
|
+
description: t(
|
|
2252
|
+
"settings.config.database.licenseKey.hint",
|
|
2253
|
+
"Up to 256 characters. The key is masked and never shown again after saving."
|
|
2254
|
+
),
|
|
2255
|
+
children: /* @__PURE__ */ jsx(
|
|
2256
|
+
TextInput,
|
|
2257
|
+
{
|
|
2258
|
+
name: "maxmindLicenseKey",
|
|
2259
|
+
type: "password",
|
|
2260
|
+
autoComplete: "new-password",
|
|
2261
|
+
maxLength: 256,
|
|
2262
|
+
disabled: databaseDisabled,
|
|
2263
|
+
readOnly: fromEnvironment,
|
|
2264
|
+
value: geoIp.credentials.licenseKey || "",
|
|
2265
|
+
onChange: (event) => geoIp.setCredentials((prev) => ({ ...prev, licenseKey: event.target.value })),
|
|
2266
|
+
placeholder: credentialSource === "store" ? t("settings.config.database.licenseKey.stored", "A license key is stored") : void 0
|
|
2267
|
+
}
|
|
2268
|
+
)
|
|
2269
|
+
}
|
|
2270
|
+
)
|
|
2271
|
+
] }),
|
|
2272
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
2273
|
+
/* @__PURE__ */ jsx(
|
|
2274
|
+
Button,
|
|
2275
|
+
{
|
|
2276
|
+
ref: saveCredentialsRef,
|
|
2277
|
+
variant: "secondary",
|
|
2278
|
+
onClick: () => keepFocus(geoIp.saveCredentials, saveCredentialsRef),
|
|
2279
|
+
loading: geoIp.savingCredentials,
|
|
2280
|
+
disabled: databaseDisabled || fromEnvironment || geoIp.savingCredentials || !geoIp.credentials.accountId || !geoIp.credentials.licenseKey,
|
|
2281
|
+
children: t("settings.config.database.saveCredentials", "Save credentials")
|
|
2282
|
+
}
|
|
2283
|
+
),
|
|
2284
|
+
credentialSource === "store" ? /* @__PURE__ */ jsx(
|
|
2285
|
+
ConfirmAction,
|
|
2286
|
+
{
|
|
2287
|
+
variant: "danger",
|
|
2288
|
+
trigger: /* @__PURE__ */ jsx(Button, { variant: "danger-light", startIcon: /* @__PURE__ */ jsx(Trash, { "aria-hidden": true, focusable: false }), children: t("settings.config.database.removeCredentials", "Remove credentials") }),
|
|
2289
|
+
title: t("settings.config.database.remove.title", "Remove stored MaxMind credentials?"),
|
|
2290
|
+
body: t(
|
|
2291
|
+
"settings.config.database.remove.body",
|
|
2292
|
+
"Updates of the GeoIP database stop working unless credentials are set as environment variables."
|
|
2293
|
+
),
|
|
2294
|
+
confirmLabel: t("settings.config.database.remove.action", "Remove"),
|
|
2295
|
+
onConfirm: geoIp.removeCredentials,
|
|
2296
|
+
fallbackFocusRef: accountIdRef
|
|
2297
|
+
}
|
|
2298
|
+
) : null
|
|
2299
|
+
] }),
|
|
2300
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
2301
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
2302
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
2303
|
+
/* @__PURE__ */ jsx(
|
|
2304
|
+
Button,
|
|
2305
|
+
{
|
|
2306
|
+
ref: updateRef,
|
|
2307
|
+
onClick: () => keepFocus(() => geoIp.updateDatabase(false), updateRef),
|
|
2308
|
+
loading: geoIp.updating,
|
|
2309
|
+
disabled: databaseDisabled || geoIp.updating || !geoIpStatus?.hasCredentials || hasChanges,
|
|
2310
|
+
children: t("settings.config.database.update", "Update database")
|
|
2311
|
+
}
|
|
2312
|
+
),
|
|
2313
|
+
/* @__PURE__ */ jsx(
|
|
2314
|
+
Button,
|
|
2315
|
+
{
|
|
2316
|
+
ref: forceRef,
|
|
2317
|
+
variant: "tertiary",
|
|
2318
|
+
onClick: () => keepFocus(() => geoIp.updateDatabase(true), forceRef),
|
|
2319
|
+
disabled: databaseDisabled || geoIp.updating || !geoIpStatus?.hasCredentials || hasChanges,
|
|
2320
|
+
children: t("settings.config.database.force", "Force download")
|
|
2321
|
+
}
|
|
2322
|
+
)
|
|
2323
|
+
] }),
|
|
2324
|
+
geoIpStatus && !geoIpStatus.hasCredentials ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.credentials", "Add MaxMind credentials first.") }) : null,
|
|
2325
|
+
hasChanges ? /* @__PURE__ */ jsx(RequiresNotice, { children: t(
|
|
2326
|
+
"settings.config.database.saveFirst",
|
|
2327
|
+
"Save your changes first, so the download uses the current settings."
|
|
2328
|
+
) }) : null
|
|
2329
|
+
] }),
|
|
2330
|
+
/* @__PURE__ */ jsx(AdvancedSection, { hasError: fieldHasError(errors, "geoIpDatabasePath"), children: /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
|
|
2331
|
+
FormField,
|
|
2332
|
+
{
|
|
2333
|
+
id: "geoip-database-filename",
|
|
2334
|
+
name: "geoIpDatabasePath",
|
|
2335
|
+
label: t("settings.config.database.fileName.label", "Database file name"),
|
|
2336
|
+
description: t(
|
|
2337
|
+
"settings.config.database.fileName.hint",
|
|
2338
|
+
"File name only, inside the plugin's GeoIP folder. Leave empty for the default."
|
|
2339
|
+
),
|
|
2340
|
+
error: tError(errors.geoIpDatabasePath),
|
|
2341
|
+
children: /* @__PURE__ */ jsx(
|
|
2342
|
+
TextInput,
|
|
2343
|
+
{
|
|
2344
|
+
name: "geoIpDatabasePath",
|
|
2345
|
+
value: settings.geoIpDatabasePath || "",
|
|
2346
|
+
disabled: databaseDisabled && !errors.geoIpDatabasePath,
|
|
2347
|
+
onChange: (event) => handleChange("geoIpDatabasePath", event.target.value),
|
|
2348
|
+
placeholder: "GeoLite2-City.mmdb",
|
|
2349
|
+
autoComplete: "off",
|
|
2350
|
+
spellCheck: false
|
|
2351
|
+
}
|
|
2352
|
+
)
|
|
2353
|
+
}
|
|
2354
|
+
) }) })
|
|
2355
|
+
]
|
|
2356
|
+
}
|
|
2357
|
+
);
|
|
2358
|
+
};
|
|
2359
|
+
const LocationDataTab = ({ form }) => {
|
|
2360
|
+
const { t } = useSettingsTranslate();
|
|
2361
|
+
const { settings, handleChange } = form;
|
|
2362
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
2363
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
2364
|
+
/* @__PURE__ */ jsx(IntroText, { children: t(
|
|
2365
|
+
"settings.config.locationData.intro",
|
|
2366
|
+
"Location and risk data power country rules, suspicious-sign-in checks and alerts. Turn the lookup off to stop all location processing."
|
|
2367
|
+
) }),
|
|
2368
|
+
/* @__PURE__ */ jsx(RequiresNotice, { tab: "login-protection", children: t(
|
|
2369
|
+
"settings.config.locationData.clientIpLink",
|
|
2370
|
+
"The client IP address source is set under Login protection › Client IP address."
|
|
2371
|
+
) })
|
|
2372
|
+
] }),
|
|
2373
|
+
/* @__PURE__ */ jsxs(SectionCard, { title: t("settings.config.lookup.title", "IP location lookup"), children: [
|
|
2374
|
+
/* @__PURE__ */ jsx(
|
|
2375
|
+
SettingsToggleRow,
|
|
2376
|
+
{
|
|
2377
|
+
id: "enable-ip-geolocation",
|
|
2378
|
+
title: t("settings.config.lookup.enable.label", "IP location lookup"),
|
|
2379
|
+
description: t(
|
|
2380
|
+
"settings.config.lookup.enable.hint",
|
|
2381
|
+
"Looks up country and city at every sign-in and for listed sessions without a location."
|
|
2382
|
+
),
|
|
2383
|
+
checked: settings.enableGeolocation,
|
|
2384
|
+
onChange: (checked) => handleChange("enableGeolocation", checked),
|
|
2385
|
+
children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", "data-privacy-note": "", children: t(
|
|
2386
|
+
"settings.config.lookup.enable.privacy",
|
|
2387
|
+
"With the Automatic or ipapi.co provider, IP addresses can be sent to ipapi.co."
|
|
2388
|
+
) })
|
|
2389
|
+
}
|
|
2390
|
+
),
|
|
2391
|
+
/* @__PURE__ */ jsx(
|
|
2392
|
+
SettingsToggleRow,
|
|
2393
|
+
{
|
|
2394
|
+
id: "enable-security-scoring",
|
|
2395
|
+
title: t("settings.config.lookup.scoring.label", "Security scoring"),
|
|
2396
|
+
description: t(
|
|
2397
|
+
"settings.config.lookup.scoring.hint",
|
|
2398
|
+
"Applies the score thresholds: below 70 triggers a suspicious-sign-in email, below 50 a rejection if enabled. Local database results always score 100."
|
|
2399
|
+
),
|
|
2400
|
+
checked: settings.enableSecurityScoring,
|
|
2401
|
+
disabled: !settings.enableGeolocation,
|
|
2402
|
+
onChange: (checked) => handleChange("enableSecurityScoring", checked),
|
|
2403
|
+
children: !settings.enableGeolocation ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.geolocation", "Requires IP location lookup") }) : null
|
|
2404
|
+
}
|
|
2405
|
+
)
|
|
2406
|
+
] }),
|
|
2407
|
+
/* @__PURE__ */ jsx(GeoIpDatabaseCard, { form })
|
|
2408
|
+
] });
|
|
2409
|
+
};
|
|
2410
|
+
const CodeTextarea = styled(Textarea)`
|
|
2411
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
2412
|
+
font-size: ${({ theme }) => theme.fontSizes[2]};
|
|
2413
|
+
white-space: pre;
|
|
2414
|
+
overflow-wrap: normal;
|
|
2415
|
+
`;
|
|
2416
|
+
const TemplateTabsFrame = styled.div`
|
|
2417
|
+
container-type: inline-size;
|
|
2418
|
+
min-width: 0;
|
|
2419
|
+
`;
|
|
2420
|
+
const TemplateTabsList = styled(Tabs.List)`
|
|
2421
|
+
width: 100%;
|
|
2422
|
+
min-width: 0;
|
|
2423
|
+
display: grid;
|
|
2424
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
2425
|
+
align-items: stretch;
|
|
2426
|
+
|
|
2427
|
+
@container (max-width: 35.99rem) {
|
|
2428
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2429
|
+
}
|
|
2430
|
+
`;
|
|
2431
|
+
const TemplateTabTrigger = styled(Tabs.Trigger)`
|
|
2432
|
+
&& {
|
|
2433
|
+
min-width: 0;
|
|
2434
|
+
overflow-wrap: break-word;
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
@container (max-width: 35.99rem) {
|
|
2438
|
+
/* The DS raises the selected tab with extra padding; stacked rows keep
|
|
2439
|
+
one height, the selection shows through colour and shadow. */
|
|
2440
|
+
&& {
|
|
2441
|
+
padding-block: ${({ theme }) => theme.spaces[3]};
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
`;
|
|
2445
|
+
const VariableGridFrame = styled.div`
|
|
2446
|
+
container-type: inline-size;
|
|
2447
|
+
min-width: 0;
|
|
2448
|
+
`;
|
|
2449
|
+
const VariableGrid = styled.div`
|
|
2450
|
+
display: grid;
|
|
2451
|
+
grid-template-columns: max-content minmax(0, 1fr);
|
|
2452
|
+
align-items: center;
|
|
2453
|
+
gap: ${({ theme }) => theme.spaces[3]};
|
|
2454
|
+
min-width: 0;
|
|
2455
|
+
|
|
2456
|
+
@container (min-width: 720px) {
|
|
2457
|
+
grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
|
|
2458
|
+
column-gap: ${({ theme }) => theme.spaces[4]};
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
/* Copy buttons are DS Tags (28 px); on phones they reach the 32 px target. */
|
|
2462
|
+
& button {
|
|
2463
|
+
min-width: ${({ theme }) => theme.spaces[7]};
|
|
2464
|
+
min-height: ${({ theme }) => theme.spaces[7]};
|
|
2465
|
+
justify-content: center;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
${({ theme }) => theme.breakpoints.medium} {
|
|
2469
|
+
& button {
|
|
2470
|
+
min-width: 0;
|
|
2471
|
+
min-height: 0;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
`;
|
|
2475
|
+
const PreviewFrame = styled.iframe`
|
|
2476
|
+
display: block;
|
|
2477
|
+
width: 100%;
|
|
2478
|
+
height: calc(${({ theme }) => theme.spaces[11]} * 7);
|
|
2479
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
2480
|
+
border-radius: ${({ theme }) => theme.borderRadius};
|
|
2481
|
+
background: ${({ theme }) => theme.colors.neutral0};
|
|
2482
|
+
`;
|
|
2483
|
+
const TEMPLATE_TAB_LABELS = {
|
|
2484
|
+
suspiciousLogin: ["settings.email.templates.tab.suspicious", "Suspicious sign-in"],
|
|
2485
|
+
newLocation: ["settings.email.templates.tab.newLocation", "New country"],
|
|
2486
|
+
vpnProxy: ["settings.email.templates.tab.vpnProxy", "VPN or proxy"]
|
|
2487
|
+
};
|
|
2488
|
+
const BlockLabel = ({ children }) => /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", tag: "div", textColor: "neutral800", children });
|
|
2489
|
+
const TemplateEditor = ({ templateKey, template, templates, handleChange, copyValue, errors }) => {
|
|
2490
|
+
const { t, tError } = useSettingsTranslate();
|
|
2491
|
+
const { toggleNotification } = useNotification();
|
|
2492
|
+
const defaults = getDefaultTemplates()[templateKey];
|
|
2493
|
+
const setField = (field, value) => {
|
|
2494
|
+
handleChange("emailTemplates", updateEmailTemplate(templates, templateKey, field, value));
|
|
2495
|
+
};
|
|
2496
|
+
const loadDefault = (field) => {
|
|
2497
|
+
handleChange(
|
|
2498
|
+
"emailTemplates",
|
|
2499
|
+
updateEmailTemplate(templates, templateKey, field, defaults[field])
|
|
2500
|
+
);
|
|
2501
|
+
toggleNotification({
|
|
2502
|
+
type: "success",
|
|
2503
|
+
message: t("notifications.success.defaultLoaded", "Default template loaded.")
|
|
2504
|
+
});
|
|
2505
|
+
};
|
|
2506
|
+
const validateVariables = () => {
|
|
2507
|
+
const validation = findTemplateVariables(template.html, templateKey);
|
|
2508
|
+
toggleNotification({
|
|
2509
|
+
type: validation.found.length > 0 ? "success" : "warning",
|
|
2510
|
+
message: validation.found.length > 0 ? t(
|
|
2511
|
+
"notifications.success.validated",
|
|
2512
|
+
"Template checked: {found} of {total} variables found.",
|
|
2513
|
+
{ found: validation.found.length, total: validation.total }
|
|
2514
|
+
) : t(
|
|
2515
|
+
"notifications.warning.noVariables",
|
|
2516
|
+
"No variables found. Add at least one variable."
|
|
2517
|
+
)
|
|
2518
|
+
});
|
|
2519
|
+
};
|
|
2520
|
+
const loadDefaultAction = (field, labelId, labelDefault) => /* @__PURE__ */ jsx(
|
|
2521
|
+
ConfirmAction,
|
|
2522
|
+
{
|
|
2523
|
+
variant: "danger-light",
|
|
2524
|
+
disabled: template[field] === defaults[field],
|
|
2525
|
+
trigger: /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "S", disabled: template[field] === defaults[field], children: t(labelId, labelDefault) }),
|
|
2526
|
+
title: t(
|
|
2527
|
+
"settings.email.templates.loadDefault.confirmTitle",
|
|
2528
|
+
"Replace this template with the default?"
|
|
2529
|
+
),
|
|
2530
|
+
body: t(
|
|
2531
|
+
"settings.email.templates.loadDefault.confirmBody",
|
|
2532
|
+
"Your edits to this template are replaced. They are only stored when you save the settings."
|
|
2533
|
+
),
|
|
2534
|
+
confirmLabel: t(labelId, labelDefault),
|
|
2535
|
+
onConfirm: () => loadDefault(field)
|
|
2536
|
+
}
|
|
2537
|
+
);
|
|
2538
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, paddingTop: 6, children: [
|
|
2539
|
+
/* @__PURE__ */ jsx(
|
|
2540
|
+
FormField,
|
|
2541
|
+
{
|
|
2542
|
+
id: `email-template-subject-${templateKey}`,
|
|
2543
|
+
name: `emailTemplateSubject-${templateKey}`,
|
|
2544
|
+
label: t("settings.email.templates.subject", "Email subject"),
|
|
2545
|
+
description: t(
|
|
2546
|
+
"settings.email.templates.subjectHint",
|
|
2547
|
+
"This subject line is used for the selected alert type."
|
|
2548
|
+
),
|
|
2549
|
+
error: tError(errors[`emailTemplates.${templateKey}.subject`]),
|
|
2550
|
+
children: /* @__PURE__ */ jsx(
|
|
2551
|
+
TextInput,
|
|
2552
|
+
{
|
|
2553
|
+
value: template.subject,
|
|
2554
|
+
onChange: (event) => setField("subject", event.target.value),
|
|
2555
|
+
placeholder: t("settings.email.templates.subjectPlaceholder", "Enter the email subject")
|
|
2556
|
+
}
|
|
2557
|
+
)
|
|
2558
|
+
}
|
|
2559
|
+
),
|
|
2560
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
2561
|
+
/* @__PURE__ */ jsx(BlockLabel, { children: t("settings.email.templates.variables", "Available variables") }),
|
|
2562
|
+
/* @__PURE__ */ jsx(VariableGridFrame, { children: /* @__PURE__ */ jsx(VariableGrid, { "data-template-variables": "", children: TEMPLATE_VARIABLES[templateKey].map((variable) => {
|
|
2563
|
+
const definition = TEMPLATE_VARIABLE_DEFINITIONS[variable];
|
|
2564
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2565
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
2566
|
+
Tag,
|
|
2567
|
+
{
|
|
2568
|
+
icon: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true, focusable: false }),
|
|
2569
|
+
label: t("settings.email.templates.copyVariable", "Copy {variable}", {
|
|
2570
|
+
variable
|
|
2571
|
+
}),
|
|
2572
|
+
onClick: () => copyValue(
|
|
2573
|
+
variable,
|
|
2574
|
+
t("notifications.success.variableCopied", "{variable} copied.", {
|
|
2575
|
+
variable
|
|
2576
|
+
}),
|
|
2577
|
+
"settings.copyTemplateVariable"
|
|
2578
|
+
),
|
|
2579
|
+
children: variable
|
|
2580
|
+
}
|
|
2581
|
+
) }),
|
|
2582
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(definition.messageId, definition.defaultMessage) })
|
|
2583
|
+
] }, variable);
|
|
2584
|
+
}) }) })
|
|
2585
|
+
] }),
|
|
2586
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
2587
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
2588
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
2589
|
+
/* @__PURE__ */ jsx(BlockLabel, { children: t("settings.email.templates.html.title", "HTML template") }),
|
|
2590
|
+
/* @__PURE__ */ jsx(Badge, { children: t("settings.email.templates.html.badge", "Main template") })
|
|
2591
|
+
] }),
|
|
2592
|
+
loadDefaultAction("html", "settings.email.templates.html.loadDefault", "Load default")
|
|
2593
|
+
] }),
|
|
2594
|
+
/* @__PURE__ */ jsx(
|
|
2595
|
+
FormField,
|
|
2596
|
+
{
|
|
2597
|
+
id: `email-template-html-${templateKey}`,
|
|
2598
|
+
name: `emailTemplateHtml-${templateKey}`,
|
|
2599
|
+
label: t("settings.email.templates.html.editorLabel", "HTML template source"),
|
|
2600
|
+
description: t(
|
|
2601
|
+
"settings.email.templates.html.description",
|
|
2602
|
+
"HTML template for email notifications. Use variables like '{{user.email}}' for dynamic content."
|
|
2603
|
+
),
|
|
2604
|
+
error: tError(errors[`emailTemplates.${templateKey}.html`]),
|
|
2605
|
+
children: /* @__PURE__ */ jsx(
|
|
2606
|
+
CodeTextarea,
|
|
2607
|
+
{
|
|
2608
|
+
rows: 18,
|
|
2609
|
+
spellCheck: false,
|
|
2610
|
+
value: template.html,
|
|
2611
|
+
onChange: (event) => setField("html", event.target.value),
|
|
2612
|
+
placeholder: t(
|
|
2613
|
+
"settings.email.templates.html.placeholder",
|
|
2614
|
+
"Enter the HTML template. Variables are replaced when the email is sent."
|
|
2615
|
+
)
|
|
2616
|
+
}
|
|
2617
|
+
)
|
|
2618
|
+
}
|
|
2619
|
+
),
|
|
2620
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
2621
|
+
/* @__PURE__ */ jsx(
|
|
2622
|
+
Button,
|
|
2623
|
+
{
|
|
2624
|
+
variant: "secondary",
|
|
2625
|
+
size: "S",
|
|
2626
|
+
startIcon: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true, focusable: false }),
|
|
2627
|
+
onClick: () => copyValue(
|
|
2628
|
+
template.html,
|
|
2629
|
+
t("notifications.success.htmlCopied", "HTML template copied."),
|
|
2630
|
+
"settings.copyHtmlTemplate"
|
|
2631
|
+
),
|
|
2632
|
+
children: t("settings.email.templates.html.copy", "Copy template")
|
|
2633
|
+
}
|
|
2634
|
+
),
|
|
2635
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "S", onClick: validateVariables, children: t("settings.email.templates.html.validate", "Validate") })
|
|
2636
|
+
] })
|
|
2637
|
+
] }),
|
|
2638
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
2639
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
2640
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
|
|
2641
|
+
/* @__PURE__ */ jsx(BlockLabel, { children: t("settings.email.templates.text.title", "Text template") }),
|
|
2642
|
+
/* @__PURE__ */ jsx(Badge, { children: t("settings.email.templates.text.badge", "Fallback") })
|
|
2643
|
+
] }),
|
|
2644
|
+
loadDefaultAction("text", "settings.email.templates.text.loadDefault", "Load default")
|
|
2645
|
+
] }),
|
|
2646
|
+
/* @__PURE__ */ jsx(
|
|
2647
|
+
FormField,
|
|
2648
|
+
{
|
|
2649
|
+
id: `email-template-text-${templateKey}`,
|
|
2650
|
+
name: `emailTemplateText-${templateKey}`,
|
|
2651
|
+
label: t("settings.email.templates.text.editorLabel", "Plain text template source"),
|
|
2652
|
+
description: t(
|
|
2653
|
+
"settings.email.templates.text.description",
|
|
2654
|
+
"Plain text version (no HTML) as fallback for older email clients"
|
|
2655
|
+
),
|
|
2656
|
+
error: tError(errors[`emailTemplates.${templateKey}.text`]),
|
|
2657
|
+
children: /* @__PURE__ */ jsx(
|
|
2658
|
+
CodeTextarea,
|
|
2659
|
+
{
|
|
2660
|
+
rows: 12,
|
|
2661
|
+
spellCheck: false,
|
|
2662
|
+
value: template.text,
|
|
2663
|
+
onChange: (event) => setField("text", event.target.value),
|
|
2664
|
+
placeholder: t(
|
|
2665
|
+
"settings.email.templates.text.placeholder",
|
|
2666
|
+
"Enter the plain text version without HTML."
|
|
2667
|
+
)
|
|
2668
|
+
}
|
|
2669
|
+
)
|
|
2670
|
+
}
|
|
2671
|
+
),
|
|
2672
|
+
/* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", children: /* @__PURE__ */ jsx(
|
|
2673
|
+
Button,
|
|
2674
|
+
{
|
|
2675
|
+
variant: "secondary",
|
|
2676
|
+
size: "S",
|
|
2677
|
+
startIcon: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true, focusable: false }),
|
|
2678
|
+
onClick: () => copyValue(
|
|
2679
|
+
template.text,
|
|
2680
|
+
t("notifications.success.textCopied", "Text template copied."),
|
|
2681
|
+
"settings.copyTextTemplate"
|
|
2682
|
+
),
|
|
2683
|
+
children: t("settings.email.templates.text.copy", "Copy template")
|
|
2684
|
+
}
|
|
2685
|
+
) })
|
|
2686
|
+
] })
|
|
2687
|
+
] });
|
|
2688
|
+
};
|
|
2689
|
+
const EmailTemplatesCard = ({ form }) => {
|
|
2690
|
+
const { t } = useSettingsTranslate();
|
|
2691
|
+
const { settings, handleChange, copyValue, errors } = form;
|
|
2692
|
+
const [activeTemplateTab, setActiveTemplateTab] = useState("suspiciousLogin");
|
|
2693
|
+
const templates = settings.emailTemplates;
|
|
2694
|
+
const active = templates[activeTemplateTab];
|
|
2695
|
+
const errorTemplate = TEMPLATE_KEYS.find(
|
|
2696
|
+
(key) => Object.keys(errors).some((path) => path.startsWith(`emailTemplates.${key}.`))
|
|
2697
|
+
);
|
|
2698
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, "data-email-templates": "", children: [
|
|
2699
|
+
/* @__PURE__ */ jsx(TemplateTabsFrame, { children: /* @__PURE__ */ jsxs(
|
|
2700
|
+
Tabs.Root,
|
|
2701
|
+
{
|
|
2702
|
+
value: activeTemplateTab,
|
|
2703
|
+
onValueChange: setActiveTemplateTab,
|
|
2704
|
+
hasError: errorTemplate,
|
|
2705
|
+
children: [
|
|
2706
|
+
/* @__PURE__ */ jsx(
|
|
2707
|
+
TemplateTabsList,
|
|
2708
|
+
{
|
|
2709
|
+
"aria-label": t("settings.config.email.templates.field", "Email templates"),
|
|
2710
|
+
children: TEMPLATE_KEYS.map((key) => /* @__PURE__ */ jsx(TemplateTabTrigger, { value: key, children: t(TEMPLATE_TAB_LABELS[key][0], TEMPLATE_TAB_LABELS[key][1]) }, key))
|
|
2711
|
+
}
|
|
2712
|
+
),
|
|
2713
|
+
TEMPLATE_KEYS.map((templateKey) => /* @__PURE__ */ jsx(Tabs.Content, { value: templateKey, children: /* @__PURE__ */ jsx(
|
|
2714
|
+
TemplateEditor,
|
|
2715
|
+
{
|
|
2716
|
+
templateKey,
|
|
2717
|
+
template: templates[templateKey],
|
|
2718
|
+
templates,
|
|
2719
|
+
handleChange,
|
|
2720
|
+
copyValue,
|
|
2721
|
+
errors
|
|
2722
|
+
}
|
|
2723
|
+
) }, templateKey))
|
|
2724
|
+
]
|
|
2725
|
+
}
|
|
2726
|
+
) }),
|
|
2727
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
2728
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
2729
|
+
/* @__PURE__ */ jsx(BlockLabel, { children: t("settings.email.templates.preview.title", "Preview") }),
|
|
2730
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
2731
|
+
"settings.email.templates.preview.subtitle",
|
|
2732
|
+
"The selected template rendered with sample data. Scripts and links are disabled."
|
|
2733
|
+
) })
|
|
2734
|
+
] }),
|
|
2735
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
2736
|
+
/* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", tag: "div", children: t("settings.email.templates.subject", "Email subject") }),
|
|
2737
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", tag: "div", children: renderTemplatePreview(active.subject) })
|
|
2738
|
+
] }),
|
|
2739
|
+
/* @__PURE__ */ jsx(
|
|
2740
|
+
PreviewFrame,
|
|
2741
|
+
{
|
|
2742
|
+
title: t("settings.email.templates.preview.frameTitle", "Email preview: {template}", {
|
|
2743
|
+
template: t(
|
|
2744
|
+
TEMPLATE_TAB_LABELS[activeTemplateTab][0],
|
|
2745
|
+
TEMPLATE_TAB_LABELS[activeTemplateTab][1]
|
|
2746
|
+
)
|
|
2747
|
+
}),
|
|
2748
|
+
sandbox: "",
|
|
2749
|
+
referrerPolicy: "no-referrer",
|
|
2750
|
+
srcDoc: renderTemplatePreview(active.html, { html: true })
|
|
2751
|
+
}
|
|
2752
|
+
)
|
|
2753
|
+
] })
|
|
2754
|
+
] });
|
|
2755
|
+
};
|
|
2756
|
+
const WEBHOOK_EVENTS = Object.freeze({
|
|
2757
|
+
suspicious: "login.suspicious",
|
|
2758
|
+
newLocation: "login.new_location",
|
|
2759
|
+
success: "login.success"
|
|
2760
|
+
});
|
|
2761
|
+
const EmailTypeGrid = styled.div`
|
|
2762
|
+
container-type: inline-size;
|
|
2763
|
+
min-width: 0;
|
|
2764
|
+
|
|
2765
|
+
& > div {
|
|
2766
|
+
display: grid;
|
|
2767
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2768
|
+
gap: ${({ theme }) => theme.spaces[4]};
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
@container (min-width: 640px) {
|
|
2772
|
+
& > div {
|
|
2773
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
`;
|
|
2777
|
+
const AlertTypeCell = ({ checked, disabled, children }) => /* @__PURE__ */ jsx(
|
|
2778
|
+
Box,
|
|
2779
|
+
{
|
|
2780
|
+
padding: 4,
|
|
2781
|
+
hasRadius: true,
|
|
2782
|
+
borderColor: checked && !disabled ? "primary600" : "neutral200",
|
|
2783
|
+
background: checked && !disabled ? "primary100" : "neutral0",
|
|
2784
|
+
height: "100%",
|
|
2785
|
+
children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children })
|
|
2786
|
+
}
|
|
2787
|
+
);
|
|
2788
|
+
const AlertsTab = ({ form }) => {
|
|
2789
|
+
const { t, tError } = useSettingsTranslate();
|
|
2790
|
+
const { settings, handleChange, errors } = form;
|
|
2791
|
+
const hintIds = { suspicious: useId(), newCountry: useId(), vpnProxy: useId() };
|
|
2792
|
+
const lookupOff = !settings.enableGeolocation;
|
|
2793
|
+
const emailTypesDisabled = lookupOff || !settings.enableEmailAlerts;
|
|
2794
|
+
const webhookFieldsDisabled = lookupOff || !settings.enableWebhooks;
|
|
2795
|
+
const templateErrors = fieldHasError(errors, "emailTemplates");
|
|
2796
|
+
const emailTypes = [
|
|
2797
|
+
{
|
|
2798
|
+
field: "alertOnSuspiciousLogin",
|
|
2799
|
+
hintId: hintIds.suspicious,
|
|
2800
|
+
label: t("settings.config.email.suspicious.label", "Suspicious sign-in"),
|
|
2801
|
+
hint: t(
|
|
2802
|
+
"settings.config.email.suspicious.hint",
|
|
2803
|
+
"VPN, proxy or threat address, or a score below 70 with scoring on."
|
|
2804
|
+
)
|
|
2805
|
+
},
|
|
2806
|
+
{
|
|
2807
|
+
field: "alertOnNewLocation",
|
|
2808
|
+
hintId: hintIds.newCountry,
|
|
2809
|
+
label: t("settings.config.email.newCountry.label", "Sign-in from a new country"),
|
|
2810
|
+
hint: t(
|
|
2811
|
+
"settings.config.email.newCountry.hint",
|
|
2812
|
+
"The country differs from all of the user's last 50 sessions. Needs at least one earlier country."
|
|
2813
|
+
)
|
|
2814
|
+
},
|
|
2815
|
+
{
|
|
2816
|
+
field: "alertOnVpnProxy",
|
|
2817
|
+
hintId: hintIds.vpnProxy,
|
|
2818
|
+
label: t("settings.config.email.vpnProxy.label", "VPN or proxy"),
|
|
2819
|
+
hint: t(
|
|
2820
|
+
"settings.config.email.vpnProxy.hint",
|
|
2821
|
+
"Needs ipapi.co data; the local database does not detect VPNs or proxies."
|
|
2822
|
+
)
|
|
2823
|
+
}
|
|
2824
|
+
];
|
|
2825
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
2826
|
+
/* @__PURE__ */ jsx(IntroText, { children: t(
|
|
2827
|
+
"settings.config.alerts.intro",
|
|
2828
|
+
"Alerts are sent only when location data is available for the sign-in."
|
|
2829
|
+
) }),
|
|
2830
|
+
lookupOff ? /* @__PURE__ */ jsxs(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), title: "", children: [
|
|
2831
|
+
t(
|
|
2832
|
+
"settings.config.alerts.lookupOff",
|
|
2833
|
+
"IP location lookup is off, so no alerts are sent."
|
|
2834
|
+
),
|
|
2835
|
+
" ",
|
|
2836
|
+
/* @__PURE__ */ jsx(SettingsTabLink, { tab: "location-data", children: t("settings.config.requires.geolocation", "Requires IP location lookup") })
|
|
2837
|
+
] }) : null,
|
|
2838
|
+
/* @__PURE__ */ jsxs(
|
|
2839
|
+
SectionCard,
|
|
2840
|
+
{
|
|
2841
|
+
title: t("settings.config.email.title", "Security emails to users"),
|
|
2842
|
+
subtitle: t(
|
|
2843
|
+
"settings.config.email.intro",
|
|
2844
|
+
"Sent to the end user's own email address, not to administrators."
|
|
2845
|
+
),
|
|
2846
|
+
children: [
|
|
2847
|
+
/* @__PURE__ */ jsx(
|
|
2848
|
+
SettingsToggleRow,
|
|
2849
|
+
{
|
|
2850
|
+
id: "enable-email-alerts",
|
|
2851
|
+
title: t("settings.config.email.enable.label", "Send security emails"),
|
|
2852
|
+
checked: settings.enableEmailAlerts,
|
|
2853
|
+
disabled: lookupOff,
|
|
2854
|
+
onChange: (checked) => handleChange("enableEmailAlerts", checked)
|
|
2855
|
+
}
|
|
2856
|
+
),
|
|
2857
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
2858
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", tag: "div", textColor: "neutral800", children: t("settings.config.email.types.label", "Send an email for") }),
|
|
2859
|
+
!lookupOff && !settings.enableEmailAlerts ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.emailAlerts", "Requires Send security emails") }) : null,
|
|
2860
|
+
/* @__PURE__ */ jsx(EmailTypeGrid, { children: /* @__PURE__ */ jsx("div", { children: emailTypes.map(({ field, hintId, label, hint }) => /* @__PURE__ */ jsxs(AlertTypeCell, { checked: settings[field], disabled: emailTypesDisabled, children: [
|
|
2861
|
+
/* @__PURE__ */ jsx(
|
|
2862
|
+
Checkbox,
|
|
2863
|
+
{
|
|
2864
|
+
checked: settings[field],
|
|
2865
|
+
disabled: emailTypesDisabled,
|
|
2866
|
+
"aria-describedby": hintId,
|
|
2867
|
+
onCheckedChange: (checked) => handleChange(field, checked === true),
|
|
2868
|
+
children: label
|
|
2869
|
+
}
|
|
2870
|
+
),
|
|
2871
|
+
/* @__PURE__ */ jsx(ReadableText, { id: hintId, variant: "pi", textColor: "neutral600", tag: "p", children: hint })
|
|
2872
|
+
] }, field)) }) })
|
|
2873
|
+
] }),
|
|
2874
|
+
/* @__PURE__ */ jsxs(
|
|
2875
|
+
AdvancedSection,
|
|
2876
|
+
{
|
|
2877
|
+
label: t("settings.config.email.templates.label", "Edit email templates"),
|
|
2878
|
+
hasError: templateErrors,
|
|
2879
|
+
disabled: emailTypesDisabled,
|
|
2880
|
+
children: [
|
|
2881
|
+
/* @__PURE__ */ jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), title: "", children: t(
|
|
2882
|
+
"settings.config.email.templates.warning",
|
|
2883
|
+
"As soon as any template has content, only your stored templates are used and empty ones are sent empty. Fill in all three, or none."
|
|
2884
|
+
) }),
|
|
2885
|
+
/* @__PURE__ */ jsx(EmailTemplatesCard, { form })
|
|
2886
|
+
]
|
|
2887
|
+
}
|
|
2888
|
+
)
|
|
2889
|
+
]
|
|
2890
|
+
}
|
|
2891
|
+
),
|
|
2892
|
+
/* @__PURE__ */ jsxs(
|
|
2893
|
+
SectionCard,
|
|
2894
|
+
{
|
|
2895
|
+
title: t("settings.config.webhooks.title", "Team notifications (webhooks)"),
|
|
2896
|
+
subtitle: t(
|
|
2897
|
+
"settings.config.webhooks.intro",
|
|
2898
|
+
"Posts every sign-in to Discord or Slack as 'suspicious', 'new country' or 'success'."
|
|
2899
|
+
),
|
|
2900
|
+
children: [
|
|
2901
|
+
/* @__PURE__ */ jsx(
|
|
2902
|
+
SettingsToggleRow,
|
|
2903
|
+
{
|
|
2904
|
+
id: "enable-webhooks",
|
|
2905
|
+
title: t("settings.config.webhooks.enable.label", "Send team notifications"),
|
|
2906
|
+
description: t(
|
|
2907
|
+
"settings.config.webhooks.enable.hint",
|
|
2908
|
+
"Event per sign-in: {suspicious}, otherwise {newLocation}, otherwise {success}.",
|
|
2909
|
+
WEBHOOK_EVENTS
|
|
2910
|
+
),
|
|
2911
|
+
checked: settings.enableWebhooks,
|
|
2912
|
+
disabled: lookupOff,
|
|
2913
|
+
onChange: (checked) => handleChange("enableWebhooks", checked)
|
|
2914
|
+
}
|
|
2915
|
+
),
|
|
2916
|
+
!lookupOff && !settings.enableWebhooks ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.webhooks", "Requires Send team notifications") }) : null,
|
|
2917
|
+
/* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
|
|
2918
|
+
/* @__PURE__ */ jsx(
|
|
2919
|
+
FormField,
|
|
2920
|
+
{
|
|
2921
|
+
id: "discord-webhook-url",
|
|
2922
|
+
name: "discordWebhookUrl",
|
|
2923
|
+
label: t("settings.config.webhooks.discord.label", "Discord webhook URL"),
|
|
2924
|
+
description: t(
|
|
2925
|
+
"settings.config.webhooks.discord.hint",
|
|
2926
|
+
"Must start with https://discord.com or https://discordapp.com. Anyone with this URL can post to your channel."
|
|
2927
|
+
),
|
|
2928
|
+
error: tError(errors.discordWebhookUrl),
|
|
2929
|
+
children: /* @__PURE__ */ jsx(
|
|
2930
|
+
SecretTextInput,
|
|
2931
|
+
{
|
|
2932
|
+
name: "discordWebhookUrl",
|
|
2933
|
+
revealedType: "url",
|
|
2934
|
+
value: settings.discordWebhookUrl || "",
|
|
2935
|
+
disabled: webhookFieldsDisabled && !errors.discordWebhookUrl,
|
|
2936
|
+
onChange: (value) => handleChange("discordWebhookUrl", value),
|
|
2937
|
+
placeholder: t(
|
|
2938
|
+
"settings.webhooks.discord.placeholder",
|
|
2939
|
+
"https://discord.com/api/webhooks/123456789/abcdefghijklmnopqrstuvwxyz..."
|
|
2940
|
+
),
|
|
2941
|
+
showLabel: t("settings.webhooks.show", "Show URL"),
|
|
2942
|
+
hideLabel: t("settings.webhooks.hide", "Hide URL")
|
|
2943
|
+
}
|
|
2944
|
+
)
|
|
2945
|
+
}
|
|
2946
|
+
),
|
|
2947
|
+
/* @__PURE__ */ jsx(
|
|
2948
|
+
FormField,
|
|
2949
|
+
{
|
|
2950
|
+
id: "slack-webhook-url",
|
|
2951
|
+
name: "slackWebhookUrl",
|
|
2952
|
+
label: t("settings.config.webhooks.slack.label", "Slack webhook URL"),
|
|
2953
|
+
description: t(
|
|
2954
|
+
"settings.config.webhooks.slack.hint",
|
|
2955
|
+
"Must start with https://hooks.slack.com. Anyone with this URL can post to your channel."
|
|
2956
|
+
),
|
|
2957
|
+
error: tError(errors.slackWebhookUrl),
|
|
2958
|
+
children: /* @__PURE__ */ jsx(
|
|
2959
|
+
SecretTextInput,
|
|
2960
|
+
{
|
|
2961
|
+
name: "slackWebhookUrl",
|
|
2962
|
+
revealedType: "url",
|
|
2963
|
+
value: settings.slackWebhookUrl || "",
|
|
2964
|
+
disabled: webhookFieldsDisabled && !errors.slackWebhookUrl,
|
|
2965
|
+
onChange: (value) => handleChange("slackWebhookUrl", value),
|
|
2966
|
+
placeholder: t(
|
|
2967
|
+
"settings.webhooks.slack.placeholder",
|
|
2968
|
+
"https://hooks.slack.com/services/XXXX/XXXX/XXXX"
|
|
2969
|
+
),
|
|
2970
|
+
showLabel: t("settings.webhooks.show", "Show URL"),
|
|
2971
|
+
hideLabel: t("settings.webhooks.hide", "Hide URL")
|
|
2972
|
+
}
|
|
2973
|
+
)
|
|
2974
|
+
}
|
|
2975
|
+
)
|
|
2976
|
+
] })
|
|
2977
|
+
]
|
|
2978
|
+
}
|
|
2979
|
+
)
|
|
2980
|
+
] });
|
|
2981
|
+
};
|
|
2982
|
+
const DangerButton = styled(Button)`
|
|
2983
|
+
flex: none;
|
|
2984
|
+
white-space: nowrap;
|
|
2985
|
+
`;
|
|
2986
|
+
const DataRetentionTab = ({ form }) => {
|
|
2987
|
+
const { t } = useSettingsTranslate();
|
|
2988
|
+
const units = useOptionLabels();
|
|
2989
|
+
const { settings, handleChange, handleCleanInactive } = form;
|
|
2990
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
2991
|
+
/* @__PURE__ */ jsx(IntroText, { children: t(
|
|
2992
|
+
"settings.config.retention.intro",
|
|
2993
|
+
"Ended sessions stay in the history until they are deleted. The tokens of deleted sessions stay revoked."
|
|
2994
|
+
) }),
|
|
2995
|
+
/* @__PURE__ */ jsx(SectionCard, { title: t("settings.config.retention.title", "History retention"), children: /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
|
|
2996
|
+
PresetSelect,
|
|
2997
|
+
{
|
|
2998
|
+
id: "session-retention-period",
|
|
2999
|
+
name: "retentionDays",
|
|
3000
|
+
label: t("settings.config.retention.keep.label", "Keep ended sessions for"),
|
|
3001
|
+
description: t(
|
|
3002
|
+
"settings.config.retention.keep.hint",
|
|
3003
|
+
"Checked once a day, the first time about 24 hours after the server starts. Open sessions are never deleted by retention. 'Forever' keeps them."
|
|
3004
|
+
),
|
|
3005
|
+
value: settings.retentionDays,
|
|
3006
|
+
presets: SELECT_PRESETS.retentionDays,
|
|
3007
|
+
format: units.retentionDays,
|
|
3008
|
+
onChange: (value) => handleChange("retentionDays", value)
|
|
3009
|
+
}
|
|
3010
|
+
) }) }),
|
|
3011
|
+
/* @__PURE__ */ jsx(
|
|
3012
|
+
SectionCard,
|
|
3013
|
+
{
|
|
3014
|
+
title: t("settings.config.deleteEnded.title", "Delete ended sessions"),
|
|
3015
|
+
tone: "danger",
|
|
3016
|
+
children: /* @__PURE__ */ jsxs(
|
|
3017
|
+
Flex,
|
|
3018
|
+
{
|
|
3019
|
+
direction: { initial: "column", small: "row" },
|
|
3020
|
+
alignItems: { initial: "flex-start", small: "center" },
|
|
3021
|
+
justifyContent: "space-between",
|
|
3022
|
+
gap: 4,
|
|
3023
|
+
"data-danger-zone": "",
|
|
3024
|
+
children: [
|
|
3025
|
+
/* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
3026
|
+
"settings.config.deleteEnded.description",
|
|
3027
|
+
"Deletes the records of all ended sessions of all users now. Open sessions, including idle ones, stay."
|
|
3028
|
+
) }),
|
|
3029
|
+
/* @__PURE__ */ jsx(
|
|
3030
|
+
ConfirmAction,
|
|
3031
|
+
{
|
|
3032
|
+
trigger: /* @__PURE__ */ jsx(
|
|
3033
|
+
DangerButton,
|
|
3034
|
+
{
|
|
3035
|
+
variant: "danger-light",
|
|
3036
|
+
startIcon: /* @__PURE__ */ jsx(Trash, { "aria-hidden": true, focusable: false }),
|
|
3037
|
+
children: t("settings.config.deleteEnded.action", "Delete ended sessions")
|
|
3038
|
+
}
|
|
3039
|
+
),
|
|
3040
|
+
title: t("settings.config.deleteEnded.confirmTitle", "Delete all ended sessions?"),
|
|
3041
|
+
body: t(
|
|
3042
|
+
"settings.config.deleteEnded.confirmBody",
|
|
3043
|
+
"The records of every ended session of every user are removed permanently from history, statistics and exports. Open sessions, including idle ones, are not affected. This cannot be undone."
|
|
3044
|
+
),
|
|
3045
|
+
confirmLabel: t("settings.config.deleteEnded.action", "Delete ended sessions"),
|
|
3046
|
+
onConfirm: handleCleanInactive
|
|
3047
|
+
}
|
|
3048
|
+
)
|
|
3049
|
+
]
|
|
3050
|
+
}
|
|
3051
|
+
)
|
|
3052
|
+
}
|
|
3053
|
+
)
|
|
3054
|
+
] });
|
|
3055
|
+
};
|
|
3056
|
+
async function copyText(value, clipboard = globalThis.navigator?.clipboard) {
|
|
3057
|
+
if (typeof value !== "string") {
|
|
3058
|
+
throw new TypeError("clipboard_value_must_be_text");
|
|
3059
|
+
}
|
|
3060
|
+
if (!clipboard || typeof clipboard.writeText !== "function") {
|
|
3061
|
+
throw new Error("clipboard_unavailable");
|
|
3062
|
+
}
|
|
3063
|
+
await clipboard.writeText(value);
|
|
3064
|
+
}
|
|
3065
|
+
const INITIAL_SETTINGS = { ...SETTINGS_DEFAULTS, emailTemplates: fillMissingTemplates({}) };
|
|
3066
|
+
const BUILD_DATE_OPTIONS = Object.freeze({ dateStyle: "medium" });
|
|
3067
|
+
const getServerMessage = (error) => {
|
|
3068
|
+
const message2 = error?.response?.data?.error?.message;
|
|
3069
|
+
return typeof message2 === "string" ? message2.trim() : "";
|
|
3070
|
+
};
|
|
3071
|
+
const formatList = (names, locale) => {
|
|
3072
|
+
try {
|
|
3073
|
+
return new Intl.ListFormat(locale || "en", { style: "long", type: "conjunction" }).format(
|
|
3074
|
+
names
|
|
3075
|
+
);
|
|
3076
|
+
} catch {
|
|
3077
|
+
return names.join(", ");
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
function useSettingsForm() {
|
|
3081
|
+
const { t, locale } = useSettingsTranslate();
|
|
3082
|
+
const { get, post, put } = useFetchClient();
|
|
3083
|
+
const { toggleNotification } = useNotification();
|
|
3084
|
+
const [loading, setLoading] = useState(true);
|
|
3085
|
+
const [loadError, setLoadError] = useState(false);
|
|
3086
|
+
const [saving, setSaving] = useState(false);
|
|
3087
|
+
const [relaxedWarningDismissed, setRelaxedWarningDismissed] = useState(false);
|
|
3088
|
+
const [draftVersion, setDraftVersion] = useState(0);
|
|
3089
|
+
const [geoIpStatus, setGeoIpStatus] = useState(null);
|
|
3090
|
+
const [geoIpStatusError, setGeoIpStatusError] = useState(false);
|
|
3091
|
+
const [geoIpCredentials, setGeoIpCredentials] = useState({ accountId: "", licenseKey: "" });
|
|
3092
|
+
const [geoIpUpdating, setGeoIpUpdating] = useState(false);
|
|
3093
|
+
const [geoIpSavingCredentials, setGeoIpSavingCredentials] = useState(false);
|
|
3094
|
+
const [settings, setSettings] = useState(INITIAL_SETTINGS);
|
|
3095
|
+
const [savedSettings, setSavedSettings] = useState(settings);
|
|
3096
|
+
const hasChanges = !areSettingsEqual(settings, savedSettings);
|
|
3097
|
+
const errors = useMemo(() => validateSettings(settings), [settings]);
|
|
3098
|
+
const errorCount = Object.keys(errors).length;
|
|
3099
|
+
const errorTab = getErrorTab(errors);
|
|
3100
|
+
const canSave = hasChanges && errorCount === 0 && !saving;
|
|
3101
|
+
const settingsRef = useRef(settings);
|
|
3102
|
+
const savedSettingsRef = useRef(savedSettings);
|
|
3103
|
+
useLayoutEffect(() => {
|
|
3104
|
+
settingsRef.current = settings;
|
|
3105
|
+
savedSettingsRef.current = savedSettings;
|
|
3106
|
+
}, [settings, savedSettings]);
|
|
3107
|
+
const copyValue = useCallback(
|
|
3108
|
+
async (value, successMessage, scope) => {
|
|
3109
|
+
try {
|
|
3110
|
+
await copyText(value);
|
|
3111
|
+
toggleNotification({ type: "success", message: successMessage });
|
|
3112
|
+
} catch (error) {
|
|
3113
|
+
logSafeAdminError(scope, error);
|
|
3114
|
+
toggleNotification({
|
|
3115
|
+
type: "danger",
|
|
3116
|
+
message: t("notifications.error.clipboard", "Could not copy to clipboard.")
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
},
|
|
3120
|
+
[t, toggleNotification]
|
|
3121
|
+
);
|
|
3122
|
+
const fetchGeoIpStatus = useCallback(async () => {
|
|
3123
|
+
setGeoIpStatus(null);
|
|
3124
|
+
setGeoIpStatusError(false);
|
|
3125
|
+
try {
|
|
3126
|
+
const response = await get(`/${pluginId}/geoip/status`);
|
|
3127
|
+
const status = response?.data?.status;
|
|
3128
|
+
if (typeof status?.exists !== "boolean" || typeof status?.hasCredentials !== "boolean") {
|
|
3129
|
+
throw new Error("Invalid GeoIP status response");
|
|
3130
|
+
}
|
|
3131
|
+
setGeoIpStatus(status);
|
|
3132
|
+
setGeoIpCredentials((prev) => ({
|
|
3133
|
+
accountId: prev.accountId || status.accountId || "",
|
|
3134
|
+
licenseKey: ""
|
|
3135
|
+
}));
|
|
3136
|
+
return status;
|
|
3137
|
+
} catch (err) {
|
|
3138
|
+
setGeoIpStatus(null);
|
|
3139
|
+
setGeoIpStatusError(true);
|
|
3140
|
+
logSafeAdminError("settings.geoIpStatus", err);
|
|
3141
|
+
return null;
|
|
3142
|
+
}
|
|
3143
|
+
}, [get]);
|
|
3144
|
+
const fetchSettings = useCallback(async () => {
|
|
3145
|
+
setLoading(true);
|
|
3146
|
+
setLoadError(false);
|
|
3147
|
+
try {
|
|
3148
|
+
const response = await get(`/${pluginId}/settings`);
|
|
3149
|
+
if (!response?.data?.settings || typeof response.data.settings !== "object" || Array.isArray(response.data.settings)) {
|
|
3150
|
+
throw new Error("Invalid settings response");
|
|
3151
|
+
}
|
|
3152
|
+
const nextSettings = normalizeSettings(response.data.settings);
|
|
3153
|
+
setSettings(nextSettings);
|
|
3154
|
+
setSavedSettings(nextSettings);
|
|
3155
|
+
await fetchGeoIpStatus();
|
|
3156
|
+
} catch (err) {
|
|
3157
|
+
logSafeAdminError("settings.load", err);
|
|
3158
|
+
setLoadError(true);
|
|
3159
|
+
} finally {
|
|
3160
|
+
setLoading(false);
|
|
3161
|
+
}
|
|
3162
|
+
}, [get, fetchGeoIpStatus]);
|
|
3163
|
+
const fetchSettingsRef = useRef(fetchSettings);
|
|
3164
|
+
useLayoutEffect(() => {
|
|
3165
|
+
fetchSettingsRef.current = fetchSettings;
|
|
3166
|
+
}, [fetchSettings]);
|
|
3167
|
+
useEffect(() => {
|
|
3168
|
+
fetchSettingsRef.current();
|
|
3169
|
+
}, []);
|
|
3170
|
+
const handleChange = useCallback((key, value) => {
|
|
3171
|
+
if (key === "strictSessionEnforcement") {
|
|
3172
|
+
setRelaxedWarningDismissed(false);
|
|
3173
|
+
}
|
|
3174
|
+
setSettings((previousSettings) => ({ ...previousSettings, [key]: value }));
|
|
3175
|
+
}, []);
|
|
3176
|
+
const handleSave = useCallback(async () => {
|
|
3177
|
+
const submitted = buildSavePayload(settingsRef.current, savedSettingsRef.current);
|
|
3178
|
+
const previous = savedSettingsRef.current;
|
|
3179
|
+
if (Object.keys(validateSettings(submitted)).length > 0) return false;
|
|
3180
|
+
setSaving(true);
|
|
3181
|
+
try {
|
|
3182
|
+
const response = await put(`/${pluginId}/settings`, submitted);
|
|
3183
|
+
if (!response?.data?.success) {
|
|
3184
|
+
throw new Error("Save failed");
|
|
3185
|
+
}
|
|
3186
|
+
const storedPayload = response.data.settings ?? (await get(`/${pluginId}/settings`))?.data?.settings;
|
|
3187
|
+
const stored = normalizeSettings(storedPayload);
|
|
3188
|
+
setSettings(stored);
|
|
3189
|
+
setSavedSettings(stored);
|
|
3190
|
+
setDraftVersion((version) => version + 1);
|
|
3191
|
+
const adjustedNames = [
|
|
3192
|
+
...new Set(
|
|
3193
|
+
getAdjustedFields(submitted, stored, previous).map((key) => SETTINGS_FIELD_LABELS[key]).filter(Boolean).map(([id, defaultMessage]) => t(id, defaultMessage))
|
|
3194
|
+
)
|
|
3195
|
+
];
|
|
3196
|
+
toggleNotification({
|
|
3197
|
+
type: adjustedNames.length > 0 ? "warning" : "success",
|
|
3198
|
+
message: adjustedNames.length > 0 ? t(
|
|
3199
|
+
"settings.config.feedback.adjusted",
|
|
3200
|
+
"Settings saved. Some values were adjusted to the allowed limits: {fields}.",
|
|
3201
|
+
{ fields: formatList(adjustedNames, locale) }
|
|
3202
|
+
) : t("notifications.success.saved", "Settings saved.")
|
|
3203
|
+
});
|
|
3204
|
+
await fetchGeoIpStatus();
|
|
3205
|
+
return true;
|
|
3206
|
+
} catch (err) {
|
|
3207
|
+
logSafeAdminError("settings.save", err);
|
|
3208
|
+
toggleNotification({
|
|
3209
|
+
type: "danger",
|
|
3210
|
+
message: t(
|
|
3211
|
+
"settings.config.feedback.saveError",
|
|
3212
|
+
"Settings could not be saved. Your changes are still in the form."
|
|
3213
|
+
)
|
|
3214
|
+
});
|
|
3215
|
+
return false;
|
|
3216
|
+
} finally {
|
|
3217
|
+
setSaving(false);
|
|
3218
|
+
}
|
|
3219
|
+
}, [get, put, t, locale, toggleNotification, fetchGeoIpStatus]);
|
|
3220
|
+
const handleReset = useCallback(() => {
|
|
3221
|
+
setSettings(savedSettingsRef.current);
|
|
3222
|
+
setRelaxedWarningDismissed(false);
|
|
3223
|
+
setDraftVersion((version) => version + 1);
|
|
3224
|
+
}, []);
|
|
3225
|
+
const handleCleanInactive = useCallback(async () => {
|
|
3226
|
+
try {
|
|
3227
|
+
const { data } = await post(`/${pluginId}/sessions/clean-inactive`);
|
|
3228
|
+
const count = Number(data?.deletedCount) || 0;
|
|
3229
|
+
toggleNotification({
|
|
3230
|
+
type: "success",
|
|
3231
|
+
message: count > 0 ? t(
|
|
3232
|
+
"settings.config.feedback.deletedEnded",
|
|
3233
|
+
"{count, plural, one {# ended session deleted.} other {# ended sessions deleted.}}",
|
|
3234
|
+
{ count }
|
|
3235
|
+
) : t("settings.config.feedback.deletedNone", "There were no ended sessions to delete.")
|
|
3236
|
+
});
|
|
3237
|
+
} catch (err) {
|
|
3238
|
+
logSafeAdminError("settings.cleanInactive", err);
|
|
3239
|
+
toggleNotification({
|
|
3240
|
+
type: "danger",
|
|
3241
|
+
message: t(
|
|
3242
|
+
"settings.config.feedback.deleteEndedError",
|
|
3243
|
+
"Ended sessions could not be deleted. Some may already be gone; reload to see the current state."
|
|
3244
|
+
)
|
|
3245
|
+
});
|
|
3246
|
+
throw err;
|
|
3247
|
+
}
|
|
3248
|
+
}, [post, t, toggleNotification]);
|
|
3249
|
+
const handleSaveGeoIpCredentials = useCallback(async () => {
|
|
3250
|
+
setGeoIpSavingCredentials(true);
|
|
3251
|
+
try {
|
|
3252
|
+
const response = await put(`/${pluginId}/geoip/credentials`, geoIpCredentials);
|
|
3253
|
+
requireSuccessfulMutation(response.data);
|
|
3254
|
+
toggleNotification({
|
|
3255
|
+
type: "success",
|
|
3256
|
+
message: t("settings.config.feedback.credentialsSaved", "Credentials saved.")
|
|
3257
|
+
});
|
|
3258
|
+
setGeoIpCredentials((prev) => ({ ...prev, licenseKey: "" }));
|
|
3259
|
+
await fetchGeoIpStatus();
|
|
3260
|
+
} catch (err) {
|
|
3261
|
+
logSafeAdminError("settings.saveGeoIpCredentials", err);
|
|
3262
|
+
toggleNotification({
|
|
3263
|
+
type: "danger",
|
|
3264
|
+
message: t(
|
|
3265
|
+
"settings.config.feedback.credentialsSaveError",
|
|
3266
|
+
"The credentials could not be saved. Please try again."
|
|
3267
|
+
)
|
|
3268
|
+
});
|
|
3269
|
+
} finally {
|
|
3270
|
+
setGeoIpSavingCredentials(false);
|
|
3271
|
+
}
|
|
3272
|
+
}, [put, geoIpCredentials, t, toggleNotification, fetchGeoIpStatus]);
|
|
3273
|
+
const handleRemoveGeoIpCredentials = useCallback(async () => {
|
|
3274
|
+
try {
|
|
3275
|
+
const response = await put(`/${pluginId}/geoip/credentials`, { clear: true });
|
|
3276
|
+
requireSuccessfulMutation(response.data);
|
|
3277
|
+
toggleNotification({
|
|
3278
|
+
type: "success",
|
|
3279
|
+
message: t("settings.config.feedback.credentialsRemoved", "Credentials removed.")
|
|
3280
|
+
});
|
|
3281
|
+
setGeoIpCredentials({ accountId: "", licenseKey: "" });
|
|
3282
|
+
await fetchGeoIpStatus();
|
|
3283
|
+
} catch (err) {
|
|
3284
|
+
logSafeAdminError("settings.removeGeoIpCredentials", err);
|
|
3285
|
+
toggleNotification({
|
|
3286
|
+
type: "danger",
|
|
3287
|
+
message: t(
|
|
3288
|
+
"settings.config.feedback.credentialsRemoveError",
|
|
3289
|
+
"The credentials could not be removed. Please try again."
|
|
3290
|
+
)
|
|
3291
|
+
});
|
|
3292
|
+
throw err;
|
|
3293
|
+
}
|
|
3294
|
+
}, [put, t, toggleNotification, fetchGeoIpStatus]);
|
|
3295
|
+
const handleUpdateGeoIpDatabase = useCallback(
|
|
3296
|
+
async (force = false) => {
|
|
3297
|
+
setGeoIpUpdating(true);
|
|
3298
|
+
try {
|
|
3299
|
+
const response = await post(`/${pluginId}/geoip/update`, { force });
|
|
3300
|
+
requireSuccessfulMutation(response.data);
|
|
3301
|
+
const status = await fetchGeoIpStatus();
|
|
3302
|
+
const result = response.data.result || {};
|
|
3303
|
+
const values = {
|
|
3304
|
+
edition: status?.editionId || "—",
|
|
3305
|
+
date: formatSessionDate(
|
|
3306
|
+
result.lastModified || status?.metadata?.lastModified,
|
|
3307
|
+
locale,
|
|
3308
|
+
"—",
|
|
3309
|
+
BUILD_DATE_OPTIONS
|
|
3310
|
+
)
|
|
3311
|
+
};
|
|
3312
|
+
toggleNotification({
|
|
3313
|
+
type: "success",
|
|
3314
|
+
message: result.changed === false ? t(
|
|
3315
|
+
"settings.config.feedback.geoipCurrent",
|
|
3316
|
+
"The GeoIP database is already up to date: {edition}, built {date}.",
|
|
3317
|
+
values
|
|
3318
|
+
) : t(
|
|
3319
|
+
"settings.config.feedback.geoipUpdated",
|
|
3320
|
+
"GeoIP database updated: {edition}, built {date}.",
|
|
3321
|
+
values
|
|
3322
|
+
)
|
|
3323
|
+
});
|
|
3324
|
+
} catch (err) {
|
|
3325
|
+
logSafeAdminError("settings.updateGeoIpDatabase", err);
|
|
3326
|
+
toggleNotification({
|
|
3327
|
+
type: "danger",
|
|
3328
|
+
message: getServerMessage(err) || t(
|
|
3329
|
+
"settings.config.feedback.geoipUpdateError",
|
|
3330
|
+
"The GeoIP database could not be updated."
|
|
3331
|
+
)
|
|
3332
|
+
});
|
|
3333
|
+
} finally {
|
|
3334
|
+
setGeoIpUpdating(false);
|
|
3335
|
+
}
|
|
3336
|
+
},
|
|
3337
|
+
[post, t, locale, toggleNotification, fetchGeoIpStatus]
|
|
3338
|
+
);
|
|
3339
|
+
return {
|
|
3340
|
+
loading,
|
|
3341
|
+
loadError,
|
|
3342
|
+
saving,
|
|
3343
|
+
settings,
|
|
3344
|
+
savedSettings,
|
|
3345
|
+
hasChanges,
|
|
3346
|
+
errors,
|
|
3347
|
+
errorCount,
|
|
3348
|
+
errorTab,
|
|
3349
|
+
canSave,
|
|
3350
|
+
relaxedWarningDismissed,
|
|
3351
|
+
setRelaxedWarningDismissed,
|
|
3352
|
+
draftVersion,
|
|
3353
|
+
copyValue,
|
|
3354
|
+
notify: toggleNotification,
|
|
3355
|
+
fetchSettings,
|
|
3356
|
+
handleChange,
|
|
3357
|
+
handleSave,
|
|
3358
|
+
handleReset,
|
|
3359
|
+
handleCleanInactive,
|
|
3360
|
+
geoIp: {
|
|
3361
|
+
status: geoIpStatus,
|
|
3362
|
+
statusError: geoIpStatusError,
|
|
3363
|
+
credentials: geoIpCredentials,
|
|
3364
|
+
setCredentials: setGeoIpCredentials,
|
|
3365
|
+
updating: geoIpUpdating,
|
|
3366
|
+
savingCredentials: geoIpSavingCredentials,
|
|
3367
|
+
fetchStatus: fetchGeoIpStatus,
|
|
3368
|
+
saveCredentials: handleSaveGeoIpCredentials,
|
|
3369
|
+
removeCredentials: handleRemoveGeoIpCredentials,
|
|
3370
|
+
updateDatabase: handleUpdateGeoIpDatabase
|
|
3371
|
+
}
|
|
3372
|
+
};
|
|
3373
|
+
}
|
|
3374
|
+
const HEADING_ID = "magic-sessionmanager-settings-title";
|
|
3375
|
+
const SettingsTabsList = styled(Tabs.List)`
|
|
3376
|
+
overflow-x: auto;
|
|
3377
|
+
overflow-y: hidden;
|
|
3378
|
+
max-width: 100%;
|
|
3379
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.neutral150};
|
|
3380
|
+
`;
|
|
3381
|
+
const SettingsTabTrigger = styled(Tabs.Trigger)`
|
|
3382
|
+
&& {
|
|
3383
|
+
flex: 0 0 auto;
|
|
3384
|
+
white-space: nowrap;
|
|
3385
|
+
}
|
|
3386
|
+
`;
|
|
3387
|
+
const SettingsTabLabel = styled.span`
|
|
3388
|
+
text-transform: none;
|
|
3389
|
+
letter-spacing: normal;
|
|
3390
|
+
font-size: ${({ theme }) => theme.fontSizes[2]};
|
|
3391
|
+
`;
|
|
3392
|
+
const TAB_PANEL_FOLD_REM = 60;
|
|
3393
|
+
const TabPanelFrame = styled.div`
|
|
3394
|
+
container-type: inline-size;
|
|
3395
|
+
min-width: 0;
|
|
3396
|
+
|
|
3397
|
+
@container (max-width: ${TAB_PANEL_FOLD_REM - 0.01}rem) {
|
|
3398
|
+
[data-equal-grid='2'] > * {
|
|
3399
|
+
grid-column: span 12;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
`;
|
|
3403
|
+
const TAB_COMPONENTS = {
|
|
3404
|
+
sessions: SessionsTab,
|
|
3405
|
+
"login-protection": LoginProtectionTab,
|
|
3406
|
+
"location-data": LocationDataTab,
|
|
3407
|
+
alerts: AlertsTab,
|
|
3408
|
+
"data-retention": DataRetentionTab
|
|
3409
|
+
};
|
|
3410
|
+
const DraftSync = ({ values }) => {
|
|
3411
|
+
const setValues = useForm("DraftSync", (state) => state.setValues);
|
|
3412
|
+
useEffect(() => {
|
|
3413
|
+
setValues(values);
|
|
3414
|
+
}, [values, setValues]);
|
|
3415
|
+
return null;
|
|
3416
|
+
};
|
|
3417
|
+
const writeTabToAddressBar = (tab) => {
|
|
3418
|
+
if (typeof window === "undefined" || !window.history?.replaceState) return;
|
|
3419
|
+
const { pathname, search, hash } = window.location;
|
|
3420
|
+
const nextSearch = buildTabSearch(search, tab);
|
|
3421
|
+
if (nextSearch === search) return;
|
|
3422
|
+
window.history.replaceState(window.history.state, "", `${pathname}${nextSearch}${hash}`);
|
|
3423
|
+
};
|
|
3424
|
+
const SettingsPage = () => {
|
|
3425
|
+
const { t } = useSettingsTranslate();
|
|
3426
|
+
const form = useSettingsForm();
|
|
3427
|
+
const [{ query }] = useQueryParams();
|
|
3428
|
+
const requestedTab = resolveSettingsTab(query?.tab);
|
|
3429
|
+
const [activeTab, setActiveTab] = useState(requestedTab);
|
|
3430
|
+
const [followedTab, setFollowedTab] = useState(requestedTab);
|
|
3431
|
+
const tabsRef = useRef(null);
|
|
3432
|
+
if (requestedTab !== followedTab) {
|
|
3433
|
+
setFollowedTab(requestedTab);
|
|
3434
|
+
setActiveTab(requestedTab);
|
|
3435
|
+
}
|
|
3436
|
+
useEffect(() => {
|
|
3437
|
+
const list = tabsRef.current?.querySelector('[role="tablist"]');
|
|
3438
|
+
const tab = list?.querySelector('[role="tab"][aria-selected="true"]');
|
|
3439
|
+
if (!list || !tab) return;
|
|
3440
|
+
const delta = getRevealScrollDelta(list.getBoundingClientRect(), tab.getBoundingClientRect());
|
|
3441
|
+
if (delta) list.scrollLeft += delta;
|
|
3442
|
+
}, [activeTab, form.loading]);
|
|
3443
|
+
const focusActiveTab = useCallback(() => {
|
|
3444
|
+
if (typeof window === "undefined") return;
|
|
3445
|
+
window.requestAnimationFrame(
|
|
3446
|
+
() => window.requestAnimationFrame(() => {
|
|
3447
|
+
tabsRef.current?.querySelector('[role="tab"][aria-selected="true"]')?.focus();
|
|
3448
|
+
})
|
|
3449
|
+
);
|
|
3450
|
+
}, []);
|
|
3451
|
+
const { handleSave } = form;
|
|
3452
|
+
const handleSaveClick = useCallback(async () => {
|
|
3453
|
+
if (await handleSave()) focusActiveTab();
|
|
3454
|
+
}, [handleSave, focusActiveTab]);
|
|
3455
|
+
const changeTab = useCallback((tab) => {
|
|
3456
|
+
const next = resolveSettingsTab(tab);
|
|
3457
|
+
setActiveTab(next);
|
|
3458
|
+
writeTabToAddressBar(next);
|
|
3459
|
+
}, []);
|
|
3460
|
+
const navigation = useMemo(
|
|
3461
|
+
() => ({
|
|
3462
|
+
selectTab: (tab) => {
|
|
3463
|
+
changeTab(tab);
|
|
3464
|
+
focusActiveTab();
|
|
3465
|
+
}
|
|
3466
|
+
}),
|
|
3467
|
+
[changeTab, focusActiveTab]
|
|
3468
|
+
);
|
|
3469
|
+
const title = t("settings.config.title", "Session Manager configuration");
|
|
3470
|
+
const subtitle = t(
|
|
3471
|
+
"settings.config.subtitle",
|
|
3472
|
+
"Applies to all end-user sessions of this Strapi instance."
|
|
3473
|
+
);
|
|
3474
|
+
if (form.loading) {
|
|
3475
|
+
return /* @__PURE__ */ jsx(Page.Loading, {});
|
|
3476
|
+
}
|
|
3477
|
+
if (form.loadError) {
|
|
3478
|
+
return /* @__PURE__ */ jsx(PageShell, { headingId: HEADING_ID, title, subtitle, children: /* @__PURE__ */ jsx(
|
|
3479
|
+
PersistentAlert,
|
|
3480
|
+
{
|
|
3481
|
+
variant: "danger",
|
|
3482
|
+
title: "",
|
|
3483
|
+
closeLabel: t("common.close", "Close"),
|
|
3484
|
+
action: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: form.fetchSettings, children: t("settings.config.load.retry", "Try again") }),
|
|
3485
|
+
children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", tag: "span", children: t(
|
|
3486
|
+
"settings.config.load.error",
|
|
3487
|
+
"Settings could not be loaded. Nothing can be saved until they load."
|
|
3488
|
+
) })
|
|
3489
|
+
}
|
|
3490
|
+
) });
|
|
3491
|
+
}
|
|
3492
|
+
return /* @__PURE__ */ jsx(
|
|
3493
|
+
PageShell,
|
|
3494
|
+
{
|
|
3495
|
+
headingId: HEADING_ID,
|
|
3496
|
+
title,
|
|
3497
|
+
subtitle,
|
|
3498
|
+
primaryAction: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
3499
|
+
/* @__PURE__ */ jsx(
|
|
3500
|
+
ConfirmAction,
|
|
3501
|
+
{
|
|
3502
|
+
variant: "danger",
|
|
3503
|
+
disabled: !form.hasChanges || form.saving,
|
|
3504
|
+
trigger: /* @__PURE__ */ jsx(Button, { variant: "secondary", disabled: !form.hasChanges || form.saving, children: t("settings.config.discard", "Discard changes") }),
|
|
3505
|
+
title: t("settings.config.discard.confirmTitle", "Discard unsaved changes?"),
|
|
3506
|
+
body: t("settings.config.discard.confirmBody", "Your changes on all tabs are lost."),
|
|
3507
|
+
confirmLabel: t("settings.config.discard.confirmAction", "Discard"),
|
|
3508
|
+
onConfirm: () => {
|
|
3509
|
+
form.handleReset();
|
|
3510
|
+
focusActiveTab();
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
),
|
|
3514
|
+
/* @__PURE__ */ jsx(
|
|
3515
|
+
Button,
|
|
3516
|
+
{
|
|
3517
|
+
onClick: handleSaveClick,
|
|
3518
|
+
loading: form.saving,
|
|
3519
|
+
startIcon: /* @__PURE__ */ jsx(Check, { "aria-hidden": true, focusable: false }),
|
|
3520
|
+
disabled: !form.canSave,
|
|
3521
|
+
children: t("settings.config.save", "Save")
|
|
3522
|
+
}
|
|
3523
|
+
)
|
|
3524
|
+
] }),
|
|
3525
|
+
children: /* @__PURE__ */ jsx(SettingsNavigationProvider, { value: navigation, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
3526
|
+
form.errorCount > 0 ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "danger", closeLabel: t("common.close", "Close"), title: "", children: t(
|
|
3527
|
+
"settings.validation.summary",
|
|
3528
|
+
"Fix {count, plural, one {# field} other {# fields}} before saving.",
|
|
3529
|
+
{ count: form.errorCount }
|
|
3530
|
+
) }) : null,
|
|
3531
|
+
/* @__PURE__ */ jsxs(
|
|
3532
|
+
Tabs.Root,
|
|
3533
|
+
{
|
|
3534
|
+
ref: tabsRef,
|
|
3535
|
+
variant: "simple",
|
|
3536
|
+
value: activeTab,
|
|
3537
|
+
onValueChange: changeTab,
|
|
3538
|
+
hasError: form.errorTab,
|
|
3539
|
+
children: [
|
|
3540
|
+
/* @__PURE__ */ jsx(
|
|
3541
|
+
SettingsTabsList,
|
|
3542
|
+
{
|
|
3543
|
+
"aria-label": t("settings.config.tabs.label", "Configuration sections"),
|
|
3544
|
+
children: SETTINGS_TAB_IDS.map((tab) => /* @__PURE__ */ jsx(SettingsTabTrigger, { value: tab, children: /* @__PURE__ */ jsx(SettingsTabLabel, { children: t(SETTINGS_TAB_LABELS[tab][0], SETTINGS_TAB_LABELS[tab][1]) }) }, tab))
|
|
3545
|
+
}
|
|
3546
|
+
),
|
|
3547
|
+
SETTINGS_TAB_IDS.map((tab) => {
|
|
3548
|
+
const TabPanel = TAB_COMPONENTS[tab];
|
|
3549
|
+
return /* @__PURE__ */ jsx(Tabs.Content, { value: tab, forceMount: true, hidden: activeTab !== tab, children: /* @__PURE__ */ jsx(TabPanelFrame, { "data-settings-tab-panel": "", children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", paddingTop: 6, children: /* @__PURE__ */ jsx(TabPanel, { form }) }) }) }, tab);
|
|
3550
|
+
}),
|
|
3551
|
+
/* @__PURE__ */ jsxs(Form, { method: "PUT", initialValues: form.savedSettings, children: [
|
|
3552
|
+
/* @__PURE__ */ jsx(DraftSync, { values: form.settings }),
|
|
3553
|
+
/* @__PURE__ */ jsx(Blocker, {})
|
|
3554
|
+
] })
|
|
3555
|
+
]
|
|
3556
|
+
}
|
|
3557
|
+
),
|
|
3558
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", "data-settings-footer": "", children: t(
|
|
3559
|
+
"settings.config.footer",
|
|
3560
|
+
"Saved in the database. Other server processes apply changes within 30 seconds."
|
|
3561
|
+
) })
|
|
3562
|
+
] }) })
|
|
3563
|
+
}
|
|
3564
|
+
);
|
|
3565
|
+
};
|
|
3566
|
+
export {
|
|
3567
|
+
SettingsPage as default
|
|
3568
|
+
};
|