Release v2.11.1
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const DEFAULT_ACCOUNT_EMAIL_TEMPLATES = {
|
||||
verificationSubject: 'Verify your Pulse Signage email address',
|
||||
verificationBody: 'Hello [[display_name]]!\n\nConfirm this email address:\n\n[[action_button]]\n\nThis link expires in 30 minutes.',
|
||||
resetSubject: 'Reset your Pulse Signage password',
|
||||
resetBody: 'Hello [[display_name]]!\n\nUse this link to choose a new password:\n\n[[action_button]]\n\nThis link expires in 30 minutes.'
|
||||
};
|
||||
|
||||
function renderAccountEmailTemplate(subject, body, variables) {
|
||||
const values = variables || {};
|
||||
const replaceVariables = function (value) {
|
||||
return String(value || '').replace(/\[\[([a-z_]+)\]\]/g, function (_match, key) {
|
||||
return Object.prototype.hasOwnProperty.call(values, key) ? String(values[key]) : _match;
|
||||
});
|
||||
};
|
||||
const renderedSubject = replaceVariables(subject);
|
||||
const renderedText = replaceVariables(body);
|
||||
const plainText = renderedText.replace(/\[(?:b|i|u)\]([\s\S]*?)\[\/(?:b|i|u)\]/gi, '$1');
|
||||
const escapedBody = renderedText.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/\[b\]([\s\S]*?)\[\/b\]/gi, '<strong>$1</strong>').replace(/\[i\]([\s\S]*?)\[\/i\]/gi, '<em>$1</em>').replace(/\[u\]([\s\S]*?)\[\/u\]/gi, '<u>$1</u>');
|
||||
const actionLabel = String(values.action_label || 'Continue').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
const actionUrl = values.url ? String(values.url).replace(/&/g, '&').replace(/"/g, '"') : '';
|
||||
const actionAlignment = values.action_alignment === 'left' || values.action_alignment === 'right' ? values.action_alignment : 'center';
|
||||
const actionButton = actionUrl ? '<a href="' + actionUrl + '" style="display:inline-block;background:#111827;color:#ffffff;padding:12px 22px;text-decoration:none;border-radius:4px;font-weight:600;">' + actionLabel + '</a>' : '';
|
||||
const actionBlock = actionButton ? '<div style="margin:24px 0;text-align:' + actionAlignment + ';">' + actionButton + '</div>' : '';
|
||||
const plainLink = actionUrl ? '<a href="' + actionUrl + '">' + actionUrl + '</a>' : '';
|
||||
const hasButtonPlaceholder = escapedBody.indexOf('[[action_button]]') !== -1;
|
||||
const hasUrlPlaceholder = String(body || '').indexOf('[[url]]') !== -1;
|
||||
const bodyWithAction = hasButtonPlaceholder
|
||||
? escapedBody.replace(/\[\[action_button\]\]/g, actionBlock)
|
||||
: hasUrlPlaceholder
|
||||
? escapedBody.split(actionUrl).join(actionBlock + plainLink)
|
||||
: escapedBody.replace(/\[\[action_link\]\]/g, plainLink).replace(actionUrl, plainLink);
|
||||
const bodyHtml = bodyWithAction.split(/\r?\n(?:[ \t]*\r?\n)+/).map(function (paragraph) {
|
||||
const paragraphHtml = paragraph.replace(/\r?\n/g, '<br>');
|
||||
if (paragraphHtml.indexOf(actionBlock) !== -1 && actionBlock) {
|
||||
return paragraphHtml.split(actionBlock).map(function (part, index, parts) {
|
||||
const text = part ? '<p style="margin:0 0 16px;">' + part + '</p>' : '';
|
||||
return text + (index < parts.length - 1 ? actionBlock : '');
|
||||
}).join('');
|
||||
}
|
||||
return paragraphHtml ? '<p style="margin:0 0 16px;">' + paragraphHtml + '</p>' : '';
|
||||
}).join('');
|
||||
const html = '<!doctype html><html><body style="margin:0;background:#f4f4f5;font-family:Arial,sans-serif;color:#27364b;"><div style="padding:24px 12px;"><div style="max-width:560px;margin:0 auto;text-align:center;color:#111827;font-size:20px;font-weight:700;padding:0 0 16px;">Pulse Signage</div><div style="max-width:560px;margin:0 auto;background:#ffffff;padding:32px;border-radius:4px;text-align:left;">' + bodyHtml + '</div></div></body></html>';
|
||||
return { subject: renderedSubject, text: plainText, html: html };
|
||||
}
|
||||
|
||||
module.exports = { DEFAULT_ACCOUNT_EMAIL_TEMPLATES, renderAccountEmailTemplate };
|
||||
+150
-23
@@ -13,6 +13,7 @@ const TOKEN_URL_MAX_LENGTH = 1024;
|
||||
const TOKEN_RESPONSE_PATH_MAX_LENGTH = 255;
|
||||
const TOKEN_HEADER_PREFIX_MAX_LENGTH = 64;
|
||||
const tokenCache = new Map();
|
||||
const tokenRequests = new Map();
|
||||
|
||||
function normalizeUpdateIntervalUnit(value) {
|
||||
const unit = String(value || '').trim().toLowerCase();
|
||||
@@ -59,7 +60,7 @@ function buildAuthHeaders(source) {
|
||||
|
||||
async function fetchApiSourcesData(pool) {
|
||||
const [apiSources] = await pool.query(
|
||||
'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources ORDER BY modified_at DESC, id DESC'
|
||||
'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_refresh_url, token_refresh_request_body_json, token_refresh_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources ORDER BY modified_at DESC, id DESC'
|
||||
);
|
||||
|
||||
return { apiSources: apiSources };
|
||||
@@ -67,7 +68,7 @@ async function fetchApiSourcesData(pool) {
|
||||
|
||||
async function fetchApiSourcesPage(pool, page, pageSize, searchTerm, sortKey, sortDirection) {
|
||||
const paged = await fetchPagedRows(pool, {
|
||||
selectSql: 'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources ORDER BY modified_at DESC, id DESC',
|
||||
selectSql: 'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_refresh_url, token_refresh_request_body_json, token_refresh_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources ORDER BY modified_at DESC, id DESC',
|
||||
countSql: 'SELECT COUNT(*) AS count FROM i_api_sources',
|
||||
searchColumns: ['name', 'api_url', 'last_pull_error'],
|
||||
searchTerm: searchTerm,
|
||||
@@ -91,7 +92,7 @@ async function fetchApiSourcesPage(pool, page, pageSize, searchTerm, sortKey, so
|
||||
|
||||
async function fetchApiSourceById(pool, id) {
|
||||
const [rows] = await pool.query(
|
||||
'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources WHERE id = ?',
|
||||
'SELECT id, name, api_url, request_method, request_body_json, auth_method, auth_username, auth_password, auth_bearer_token, auth_header_name, auth_header_value, token_url, token_request_body_json, token_response_path, token_refresh_url, token_refresh_request_body_json, token_refresh_response_path, token_header_name, token_header_prefix, items_path, enabled, update_interval_value, update_interval_unit, last_pulled_at, last_pull_error, last_response_status, last_response_content_type, last_response_json, created_at, modified_at, created_by, modified_by FROM i_api_sources WHERE id = ?',
|
||||
[id]
|
||||
);
|
||||
|
||||
@@ -184,6 +185,9 @@ function getTokenCacheKey(source) {
|
||||
source && (source.token_url || source.tokenUrl) || '',
|
||||
source && (source.token_request_body_json || source.tokenRequestBodyJson) || '',
|
||||
source && (source.token_response_path || source.tokenResponsePath) || 'access_token',
|
||||
source && (source.token_refresh_url || source.tokenRefreshUrl) || '',
|
||||
source && (source.token_refresh_request_body_json || source.tokenRefreshRequestBodyJson) || '',
|
||||
source && (source.token_refresh_response_path || source.tokenRefreshResponsePath) || 'refresh_token',
|
||||
source && (source.token_header_name || source.tokenHeaderName) || 'Authorization',
|
||||
source && (source.token_header_prefix || source.tokenHeaderPrefix) || 'Bearer'
|
||||
]);
|
||||
@@ -193,11 +197,118 @@ function clearCachedToken(source) {
|
||||
tokenCache.delete(getTokenCacheKey(source));
|
||||
}
|
||||
|
||||
async function fetchLoginToken(source) {
|
||||
function replaceRefreshToken(value, refreshToken) {
|
||||
if (typeof value === 'string') {
|
||||
return value.split('{{refresh_token}}').join(refreshToken);
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(function (item) {
|
||||
return replaceRefreshToken(item, refreshToken);
|
||||
});
|
||||
}
|
||||
if (value && typeof value === 'object') {
|
||||
return Object.keys(value).reduce(function (result, key) {
|
||||
result[key] = replaceRefreshToken(value[key], refreshToken);
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function resolveTokenExpiry(parsed, token) {
|
||||
const expiresIn = Number(parsed && (parsed.expires_in || parsed.expiresIn));
|
||||
if (Number.isFinite(expiresIn) && expiresIn > 0) {
|
||||
return { lifetimeMs: expiresIn * 1000 };
|
||||
}
|
||||
|
||||
const explicitExpiry = parsed && (parsed.expires_at || parsed.expiresAt);
|
||||
if (explicitExpiry !== undefined && explicitExpiry !== null) {
|
||||
const expiryNumber = Number(explicitExpiry);
|
||||
const expiryMs = Number.isFinite(expiryNumber)
|
||||
? (expiryNumber < 100000000000 ? expiryNumber * 1000 : expiryNumber)
|
||||
: Date.parse(String(explicitExpiry));
|
||||
if (Number.isFinite(expiryMs) && expiryMs > Date.now()) {
|
||||
return { expiresAt: expiryMs };
|
||||
}
|
||||
}
|
||||
|
||||
const tokenParts = String(token).split('.');
|
||||
if (tokenParts.length === 3) {
|
||||
try {
|
||||
const payload = JSON.parse(Buffer.from(tokenParts[1], 'base64url').toString('utf8'));
|
||||
const expiryMs = Number(payload.exp) * 1000;
|
||||
if (Number.isFinite(expiryMs) && expiryMs > Date.now()) {
|
||||
return { expiresAt: expiryMs };
|
||||
}
|
||||
} catch (_error) {
|
||||
// Opaque tokens do not contain a readable JWT expiry.
|
||||
}
|
||||
}
|
||||
|
||||
return { lifetimeMs: 300000 };
|
||||
}
|
||||
|
||||
function cacheTokenResponse(source, parsed, previousRefreshToken) {
|
||||
const tokenPath = source.token_response_path || source.tokenResponsePath || 'access_token';
|
||||
const token = resolveResponsePath(parsed, tokenPath);
|
||||
if (token === undefined || token === null || String(token).trim() === '') {
|
||||
throw new Error('Token response did not contain a token at the configured path.');
|
||||
}
|
||||
|
||||
const refreshPath = source.token_refresh_response_path || source.tokenRefreshResponsePath || 'refresh_token';
|
||||
const responseRefreshToken = resolveResponsePath(parsed, refreshPath);
|
||||
const refreshToken = responseRefreshToken === undefined || responseRefreshToken === null || String(responseRefreshToken).trim() === ''
|
||||
? previousRefreshToken
|
||||
: String(responseRefreshToken);
|
||||
const expiry = resolveTokenExpiry(parsed, token);
|
||||
const expiresAt = expiry.expiresAt || Date.now() + Math.max(1000, expiry.lifetimeMs - Math.min(60000, expiry.lifetimeMs * 0.1));
|
||||
const record = { value: String(token), refreshToken: refreshToken, expiresAt: expiresAt };
|
||||
tokenCache.set(getTokenCacheKey(source), record);
|
||||
return record;
|
||||
}
|
||||
|
||||
async function parseTokenResponse(response, source, previousRefreshToken) {
|
||||
if (!response.ok) {
|
||||
return null;
|
||||
}
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(String(response.bodyText || '').trim());
|
||||
} catch (_error) {
|
||||
throw new Error('Token response was not valid JSON.');
|
||||
}
|
||||
return cacheTokenResponse(source, parsed, previousRefreshToken);
|
||||
}
|
||||
|
||||
async function refreshLoginToken(source, cached) {
|
||||
const refreshUrl = source.token_refresh_url || source.tokenRefreshUrl || source.token_url || source.tokenUrl;
|
||||
if (!cached || !cached.refreshToken) {
|
||||
return null;
|
||||
}
|
||||
const configuredBody = parseJsonRequestBody(source.token_refresh_request_body_json || source.tokenRefreshRequestBodyJson, 'Refresh request body');
|
||||
const refreshBody = configuredBody === undefined
|
||||
? { grant_type: 'refresh_token', refresh_token: cached.refreshToken }
|
||||
: replaceRefreshToken(configuredBody, cached.refreshToken);
|
||||
const response = await loadUrlText(refreshUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(refreshBody)
|
||||
});
|
||||
return parseTokenResponse(response, source, cached.refreshToken);
|
||||
}
|
||||
|
||||
async function fetchLoginTokenUncached(source) {
|
||||
const cacheKey = getTokenCacheKey(source);
|
||||
const cached = tokenCache.get(cacheKey);
|
||||
if (cached && cached.expiresAt > Date.now()) {
|
||||
return cached.value;
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (cached && cached.refreshToken) {
|
||||
const refreshed = await refreshLoginToken(source, cached);
|
||||
if (refreshed) {
|
||||
return refreshed;
|
||||
}
|
||||
}
|
||||
|
||||
const tokenUrl = source.token_url || source.tokenUrl;
|
||||
@@ -208,29 +319,25 @@ async function fetchLoginToken(source) {
|
||||
headers: tokenHeaders,
|
||||
body: tokenBody === undefined ? undefined : JSON.stringify(tokenBody)
|
||||
});
|
||||
if (!response.ok) {
|
||||
const record = await parseTokenResponse(response, source, cached && cached.refreshToken);
|
||||
if (!record) {
|
||||
throw new Error(`Unable to obtain API token (${response.statusCode}).`);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(String(response.bodyText || '').trim());
|
||||
} catch (_error) {
|
||||
throw new Error('Token response was not valid JSON.');
|
||||
async function fetchLoginToken(source) {
|
||||
const cacheKey = getTokenCacheKey(source);
|
||||
const cached = tokenCache.get(cacheKey);
|
||||
if (cached && cached.expiresAt > Date.now()) {
|
||||
return cached.value;
|
||||
}
|
||||
|
||||
const tokenPath = source.token_response_path || source.tokenResponsePath || 'access_token';
|
||||
const token = resolveResponsePath(parsed, tokenPath);
|
||||
if (token === undefined || token === null || String(token).trim() === '') {
|
||||
throw new Error('Token response did not contain a token at the configured path.');
|
||||
if (!tokenRequests.has(cacheKey)) {
|
||||
tokenRequests.set(cacheKey, fetchLoginTokenUncached(source).finally(function () {
|
||||
tokenRequests.delete(cacheKey);
|
||||
}));
|
||||
}
|
||||
|
||||
const expiresIn = Number(parsed && (parsed.expires_in || parsed.expiresIn));
|
||||
const lifetimeMs = Number.isFinite(expiresIn) && expiresIn > 0
|
||||
? Math.max(30000, expiresIn * 1000 - 60000)
|
||||
: 300000;
|
||||
tokenCache.set(cacheKey, { value: String(token), expiresAt: Date.now() + lifetimeMs });
|
||||
return String(token);
|
||||
return (await tokenRequests.get(cacheKey)).value;
|
||||
}
|
||||
|
||||
async function buildRequestHeaders(source) {
|
||||
@@ -310,6 +417,9 @@ function buildApiSourcePayload(req, existingApiSource) {
|
||||
const tokenUrl = validateMaxLength(readBodyValue('token_url', readBodyValue('tokenUrl', fallback.token_url || '')) || '', TOKEN_URL_MAX_LENGTH, 'API token URL');
|
||||
const tokenRequestBodyJson = validateMaxLength(readBodyValue('token_request_body_json', readBodyValue('tokenRequestBodyJson', fallback.token_request_body_json || '')) || '', REQUEST_BODY_MAX_LENGTH, 'Login request body');
|
||||
const tokenResponsePath = validateMaxLength(readBodyValue('token_response_path', readBodyValue('tokenResponsePath', fallback.token_response_path || 'access_token')) || 'access_token', TOKEN_RESPONSE_PATH_MAX_LENGTH, 'Token response path');
|
||||
const tokenRefreshUrl = validateMaxLength(readBodyValue('token_refresh_url', readBodyValue('tokenRefreshUrl', fallback.token_refresh_url || '')) || '', TOKEN_URL_MAX_LENGTH, 'API refresh URL');
|
||||
const tokenRefreshRequestBodyJson = validateMaxLength(readBodyValue('token_refresh_request_body_json', readBodyValue('tokenRefreshRequestBodyJson', fallback.token_refresh_request_body_json || '')) || '', REQUEST_BODY_MAX_LENGTH, 'Refresh request body');
|
||||
const tokenRefreshResponsePath = validateMaxLength(readBodyValue('token_refresh_response_path', readBodyValue('tokenRefreshResponsePath', fallback.token_refresh_response_path || 'refresh_token')) || 'refresh_token', TOKEN_RESPONSE_PATH_MAX_LENGTH, 'Refresh token response path');
|
||||
const tokenHeaderName = validateMaxLength(readBodyValue('token_header_name', readBodyValue('tokenHeaderName', fallback.token_header_name || 'Authorization')) || 'Authorization', AUTH_MAX_LENGTH, 'Token header name');
|
||||
const tokenHeaderPrefix = validateMaxLength(readBodyValue('token_header_prefix', readBodyValue('tokenHeaderPrefix', fallback.token_header_prefix || 'Bearer')) || '', TOKEN_HEADER_PREFIX_MAX_LENGTH, 'Token prefix');
|
||||
const itemsPath = validateMaxLength(readBodyValue('items_path', readBodyValue('itemsPath', fallback.items_path || '')) || '', ITEMS_PATH_MAX_LENGTH, 'API source items path');
|
||||
@@ -369,6 +479,7 @@ function buildApiSourcePayload(req, existingApiSource) {
|
||||
|
||||
parseJsonRequestBody(requestBodyJson, 'API request body');
|
||||
parseJsonRequestBody(tokenRequestBodyJson, 'Login request body');
|
||||
parseJsonRequestBody(tokenRefreshRequestBodyJson, 'Refresh request body');
|
||||
|
||||
if (authMethod === 'token_login') {
|
||||
if (!tokenUrl) {
|
||||
@@ -393,6 +504,19 @@ function buildApiSourcePayload(req, existingApiSource) {
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenRefreshUrl) {
|
||||
try {
|
||||
const refreshParsedUrl = new URL(tokenRefreshUrl);
|
||||
if (refreshParsedUrl.protocol !== 'http:' && refreshParsedUrl.protocol !== 'https:') {
|
||||
throw new Error('invalid protocol');
|
||||
}
|
||||
} catch (_error) {
|
||||
const error = new Error('Enter a valid API refresh URL.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: name,
|
||||
apiUrl: parsedUrl.toString(),
|
||||
@@ -407,6 +531,9 @@ function buildApiSourcePayload(req, existingApiSource) {
|
||||
tokenUrl: tokenUrl,
|
||||
tokenRequestBodyJson: tokenRequestBodyJson,
|
||||
tokenResponsePath: tokenResponsePath,
|
||||
tokenRefreshUrl: tokenRefreshUrl,
|
||||
tokenRefreshRequestBodyJson: tokenRefreshRequestBodyJson,
|
||||
tokenRefreshResponsePath: tokenRefreshResponsePath,
|
||||
tokenHeaderName: tokenHeaderName,
|
||||
tokenHeaderPrefix: tokenHeaderPrefix,
|
||||
itemsPath: itemsPath,
|
||||
|
||||
@@ -21,8 +21,30 @@ const SETTING_DEFINITIONS = [
|
||||
{ key: 'security.login_max_attempts', type: 'integer', min: 1, defaultValue: 5 },
|
||||
{ key: 'security.login_lockout_minutes', type: 'integer', min: 1, defaultValue: 15 },
|
||||
{ key: 'security.login_rate_limit_scope', type: 'enum', values: ['both', 'username', 'ip'], defaultValue: 'both' },
|
||||
{ key: 'security.allow_admin_email_verification_bypass', type: 'boolean', defaultValue: true },
|
||||
{ key: 'email.smtp_enabled', type: 'boolean', defaultValue: false },
|
||||
{ key: 'email.smtp_host', type: 'string', defaultValue: '' },
|
||||
{ key: 'email.smtp_port', type: 'integer', min: 1, defaultValue: 587 },
|
||||
{ key: 'email.smtp_security', type: 'enum', values: ['none', 'starttls', 'tls'], defaultValue: 'starttls' },
|
||||
{ key: 'email.smtp_username', type: 'string', defaultValue: '' },
|
||||
{ key: 'email.smtp_password', type: 'string', defaultValue: '' },
|
||||
{ key: 'email.from_address', type: 'string', defaultValue: '' },
|
||||
{ key: 'email.from_name', type: 'string', defaultValue: 'Pulse Signage' },
|
||||
{ key: 'email.verification_subject', type: 'string', defaultValue: 'Verify your Pulse Signage email address' },
|
||||
{ key: 'email.verification_body', type: 'string', defaultValue: 'Hello [[display_name]]!\n\nConfirm this email address:\n\n[[action_button]]\n\nThis link expires in 30 minutes.' },
|
||||
{ key: 'email.reset_subject', type: 'string', defaultValue: 'Reset your Pulse Signage password' },
|
||||
{ key: 'email.reset_body', type: 'string', defaultValue: 'Hello [[display_name]]!\n\nUse this link to choose a new password:\n\n[[action_button]]\n\nThis link expires in 30 minutes.' },
|
||||
{ key: 'email.verification_button_alignment', type: 'enum', values: ['left', 'center', 'right'], defaultValue: 'center' },
|
||||
{ key: 'email.verification_button_text', type: 'string', defaultValue: 'Verify email address' },
|
||||
{ key: 'email.reset_button_alignment', type: 'enum', values: ['left', 'center', 'right'], defaultValue: 'center' },
|
||||
{ key: 'email.reset_button_text', type: 'string', defaultValue: 'Reset password' },
|
||||
{ key: 'email.invitation_subject', type: 'string', defaultValue: 'You have been invited to Pulse Signage' },
|
||||
{ key: 'email.invitation_body', type: 'string', defaultValue: 'Hello [[display_name]]!\n\nYou have been invited to create a Pulse Signage account.\n\n[[action_button]]\n\nThis invitation expires in 24 hours.' },
|
||||
{ key: 'email.invitation_button_alignment', type: 'enum', values: ['left', 'center', 'right'], defaultValue: 'center' },
|
||||
{ key: 'email.invitation_button_text', type: 'string', defaultValue: 'Accept invitation' },
|
||||
{ key: 'audit.enabled', type: 'boolean', defaultValue: true },
|
||||
{ key: 'audit.categories', type: 'string_array', defaultValue: ['authentication', 'security', 'sessions', 'users', 'roles', 'system-settings'] },
|
||||
{ key: 'audit.screen_control_commands', type: 'string_array', defaultValue: [] },
|
||||
{ key: 'audit.include_request_metadata', type: 'boolean', defaultValue: true },
|
||||
{ key: 'audit.retention_days', type: 'integer', min: 0, defaultValue: 180 },
|
||||
{ key: 'uploads.image_max_bytes', type: 'integer', min: 1, defaultValue: 100 * 1024 * 1024 },
|
||||
|
||||
+25
-2
@@ -15,7 +15,9 @@ const AUDIT_EVENT_CATEGORIES = Object.freeze({
|
||||
CANVAS_SIZES: 'canvas-sizes',
|
||||
API_SOURCES: 'api-sources',
|
||||
RSS_FEEDS: 'rss-feeds',
|
||||
TIMETABLES: 'timetables'
|
||||
TIMETABLES: 'timetables',
|
||||
WEATHER: 'weather',
|
||||
SCREEN_CONTROLS: 'screen-controls'
|
||||
});
|
||||
const AUDIT_CATEGORY_KEYS = Object.freeze(Object.values(AUDIT_EVENT_CATEGORIES));
|
||||
const AUDIT_CATEGORY_LABELS = Object.freeze({
|
||||
@@ -33,7 +35,18 @@ const AUDIT_CATEGORY_LABELS = Object.freeze({
|
||||
'canvas-sizes': 'Canvas Sizes',
|
||||
'api-sources': 'API Sources',
|
||||
'rss-feeds': 'RSS Feeds',
|
||||
timetables: 'Timetables'
|
||||
timetables: 'Timetables',
|
||||
weather: 'Weather',
|
||||
'screen-controls': 'Screen Controls'
|
||||
});
|
||||
const SCREEN_CONTROL_COMMAND_KEYS = Object.freeze(['pause', 'blackout', 'reload', 'navigation', 'moveclient', 'setclientname']);
|
||||
const SCREEN_CONTROL_COMMAND_LABELS = Object.freeze({
|
||||
pause: 'Pause / Resume',
|
||||
blackout: 'Blackout / Restore',
|
||||
reload: 'Reload',
|
||||
navigation: 'Forward / Back',
|
||||
moveclient: 'Move client',
|
||||
setclientname: 'Rename client'
|
||||
});
|
||||
const { fetchAppSettings } = require('./app-settings');
|
||||
|
||||
@@ -101,6 +114,14 @@ async function recordRequestAuditEvent(pool, req, event) {
|
||||
if (!settings['audit.enabled'] || !enabledCategories.includes(category)) {
|
||||
return;
|
||||
}
|
||||
if (category === 'screen-controls') {
|
||||
const command = String(event && event.eventType || '').replace(/^screen-control\./, '').trim().toLowerCase();
|
||||
const commandGroup = command === 'previous' || command === 'next' ? 'navigation' : command;
|
||||
const enabledCommands = Array.isArray(settings['audit.screen_control_commands']) ? settings['audit.screen_control_commands'] : [];
|
||||
if (!enabledCommands.includes(commandGroup)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const metadata = settings['audit.include_request_metadata'] ? getRequestMetadata(req) : {};
|
||||
await recordAuditEvent(pool, Object.assign({}, event, metadata));
|
||||
} catch (error) {
|
||||
@@ -113,6 +134,8 @@ module.exports = {
|
||||
AUDIT_EVENT_CATEGORIES,
|
||||
AUDIT_CATEGORY_KEYS,
|
||||
AUDIT_CATEGORY_LABELS,
|
||||
SCREEN_CONTROL_COMMAND_KEYS,
|
||||
SCREEN_CONTROL_COMMAND_LABELS,
|
||||
getRequestMetadata,
|
||||
buildAuditChanges,
|
||||
recordAuditEvent,
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// SMTP delivery for account notifications.
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
function getSmtpConfig(settings) {
|
||||
return {
|
||||
enabled: Boolean(settings['email.smtp_enabled']),
|
||||
host: String(settings['email.smtp_host'] || '').trim(),
|
||||
port: Number(settings['email.smtp_port']) || 587,
|
||||
security: String(settings['email.smtp_security'] || 'starttls'),
|
||||
username: String(settings['email.smtp_username'] || '').trim(),
|
||||
password: String(settings['email.smtp_password'] || ''),
|
||||
fromAddress: String(settings['email.from_address'] || '').trim(),
|
||||
fromName: String(settings['email.from_name'] || '').trim()
|
||||
};
|
||||
}
|
||||
|
||||
function createMailTransport(settings) {
|
||||
const config = getSmtpConfig(settings);
|
||||
if (!config.enabled || !config.host || !config.fromAddress) {
|
||||
return null;
|
||||
}
|
||||
return nodemailer.createTransport({
|
||||
host: config.host,
|
||||
port: config.port,
|
||||
secure: config.security === 'tls',
|
||||
requireTLS: config.security === 'starttls',
|
||||
auth: config.username ? { user: config.username, pass: config.password } : undefined
|
||||
});
|
||||
}
|
||||
|
||||
async function sendAccountEmail(settings, message) {
|
||||
const transport = createMailTransport(settings);
|
||||
if (!transport) {
|
||||
throw new Error('Email delivery is not configured.');
|
||||
}
|
||||
const config = getSmtpConfig(settings);
|
||||
return transport.sendMail(Object.assign({}, message, {
|
||||
from: config.fromName ? '"' + config.fromName.replace(/"/g, '') + '" <' + config.fromAddress + '>' : config.fromAddress,
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports = { getSmtpConfig, createMailTransport, sendAccountEmail };
|
||||
Reference in New Issue
Block a user