Files
wekan/server/methods/lockoutSettings.js
T
Lauri Ojansivu e413cd4720 The Sandstorm .spk leaves out every login method but Sandstorm's, and FerretDB's other database handlers.
A grain has one login (Sandstorm's), one database (FerretDB on SQLite) and one
mailbox (the grain's own address), but the .spk carried every login package
WeKan has and a FerretDB with the PostgreSQL, MySQL and SAP HANA handlers.

releases/sandstorm-slim-spk.sh, used by sandstorm.yml, release-all.yml's
build-sandstorm job and build.sh's "Make the .spk package", builds with the
package profile of releases/sandstorm-slim.mjs - accounts-password, 2FA,
passwordless, lockout, OAuth2/OIDC, CAS, LDAP, SAML and the seven social
logins removed from a copy of .meteor/packages for that one build, then
restored - trims the bundle for a linux/x64 grain, verifies none of those
packages got in and packs with spk pack (meteor-spk pack rebuilds and would
undo the trim). sandstorm-src/build-deps.sh builds FerretDB from source with
ferretdb_no_postgresql,ferretdb_no_mysql.

Under Sandstorm the Admin Panel hides the E-mail, Login, Locked users, SAML,
LDAP, OAuth2, CAS, Header login, OAuth providers and Passwordless panes,
Attachments / Database migration, the Email-to-card IMAP and webhook settings,
the New user button and the password fields; a hidden pane opened by URL lands
on the first visible one. POST /users/login and /users/register answer 404
sandstorm-sso-only, database migration is refused and the IMAP/webhook
settings are not stored. Without accounts-password the server creates
Accounts.emailTemplates with the package's defaults and marks useraccounts
initialised, which otherwise stopped the first grain.

Against wekan-12.63-sandstorm.spk, built from the same source: 181,307,364
instead of 185,271,476 bytes (-3.8 MiB, -2.1 %), unpacked 26.7 MiB smaller.
Docker, Snap and the bundles build from the full package list, and a test fails
if that list is slimmed. Tested on a local Sandstorm 0.308: a grain starts, a
board, a list and a card are created, and the removed options are not shown.
tests/sandstormSlim.test.cjs and tests/playwright/specs/sandstorm-slim.e2e.js
pin it. Design: docs/Platforms/FOSS/Container/Sandstorm/Smaller-wekan-spk.md.

Thanks to xet7 !
2026-10-23 19:34:34 +03:00

59 lines
2.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
// Absent from the Sandstorm .spk (releases/sandstorm-slim.mjs), so asked for
// only when the package is in the build.
const AccountsLockout = Package['wekan-accounts-lockout']
? require('meteor/wekan-accounts-lockout').AccountsLockout
: null;
import { ReactiveCache } from '/imports/reactiveCache';
import LockoutSettings from '/models/lockoutSettings';
// The lockout reporter (and why it names the TARGET): server/lib/lockoutReporter.js.
import { reportLockout } from '/server/lib/lockoutReporter';
Meteor.methods({
async reloadAccountsLockout() {
// Check if user has admin rights
const userId = this.userId;
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user');
}
const user = await ReactiveCache.getUser(userId);
if (!user || !user.isAdmin) {
throw new Meteor.Error('error-not-allowed', 'Not allowed');
}
// No password login, so nothing to lock out (the Sandstorm .spk).
if (!AccountsLockout) return false;
try {
// Get configurations from database
const knownUsersConfig = {
failuresBeforeLockout: (await LockoutSettings.findOneAsync('known-failuresBeforeLockout'))?.value || 3,
lockoutPeriod: (await LockoutSettings.findOneAsync('known-lockoutPeriod'))?.value || 60,
failureWindow: (await LockoutSettings.findOneAsync('known-failureWindow'))?.value || 15
};
const unknownUsersConfig = {
failuresBeforeLockout: (await LockoutSettings.findOneAsync('unknown-failuresBeforeLockout'))?.value || 3,
lockoutPeriod: (await LockoutSettings.findOneAsync('unknown-lockoutPeriod'))?.value || 60,
failureWindow: (await LockoutSettings.findOneAsync('unknown-failureWindow'))?.value || 15
};
// Initialize the AccountsLockout with configuration
const accountsLockout = new AccountsLockout({
knownUsers: knownUsersConfig,
unknownUsers: unknownUsersConfig,
onLockout: reportLockout,
});
// Start the accounts lockout mechanism
accountsLockout.startup();
return true;
} catch (error) {
console.error('Failed to reload accounts lockout:', error);
throw new Meteor.Error('error-reloading-settings', 'Error reloading settings');
}
}
});