Files
wekan/server/lib/systemStatus.js
T
Lauri Ojansivu eb49a4b1b6 Override every login environment variable in Admin Panel / People.
Each login method has its own section: LDAP, OAuth2 (OpenID Connect and
Oracle OIM), CAS and Header login are new or complete, and the Login pane
gets PASSWORD_LOGIN_ENABLED and ACCOUNTS_COMMON_LOGIN_EXPIRATION_IN_DAYS.
models/lib/authConfigCatalog.js lists all 103 variables; server/lib/
authConfig.js resolves each one at run time (Admin Panel value first, then
the environment variable) for the app and, through
globalThis.__wekanAuthEnv, for the wekan-ldap, wekan-oidc and
wekan-accounts-cas packages. OAuth2 and CAS service configurations and LDAP
background sync are reapplied when their settings are saved.

Passwords and client secrets (LDAP_AUTHENTIFICATION_PASSWORD, OAUTH2_SECRET)
never reach the browser: the page learns only whether one is set and where
it comes from. Other values have credentials written inside a URL masked on
the server, and a URL field refuses them.

Fixed on the way:
- The Admin Panel LDAP overrides never applied. The bridge read Settings with
  a server-side findOne(), which Meteor 3 refuses; the error was swallowed and
  the environment used. The settings are now held in an observed cache.
- LDAP Test connection never existed on the server (testConnection.js was not
  imported) and used the synchronous Meteor.user().
- PROPAGATE_OIDC_DATA=false turned the feature on.
- CAS read only the misspelled CASE_VALIDATE_URL; CAS_VALIDATE_URL now works
  and the old name still does.
- snap help named three group-filter keys snap set does not know.

Every catalog variable is now listed in the Dockerfile, the docker-compose
files, snap config and help, and start-wekan.sh/.bat; 14 were missing.
tests/authConfigCatalog.test.cjs pins resolution, secrets, input validation,
platform coverage, and - across the whole tree - that no code reads a login
variable outside the catalog or straight from process.env, and that no
server code calls the synchronous Settings.findOne() or Meteor.user().
tests/playwright/specs/admin-login-env-overrides.e2e.js drives the pages.

Thanks to xet7 !
2026-10-05 19:48:48 +03:00

141 lines
5.6 KiB
JavaScript

import RecoveryStatus from '/models/recoveryStatus';
import AttachmentMigrationStatus from '/models/attachmentMigrationStatus';
import TextMigrationStatus from '/models/textMigrationStatus';
import Cards from '/models/cards';
import { loginProblemChecks } from '/models/lib/loginProblems';
import { authEnv } from '/server/lib/authConfig';
import { buildProblemsOverview } from '/models/lib/problemsOverview';
import { brokenCardsSelector } from '/models/lib/brokenCardsRepair';
import { countRestorableListSwimlanes } from '/server/lib/restoreListSwimlanes';
import { isStatusActive } from '/models/lib/statusActive';
// Server hub for the Admin Panel / Problems "Status" overview and the
// `snap run wekan.problems` command. It PERSISTS the text-migration and
// board-repair progress (so a separate process can see "a migration/repair is in
// progress") and AGGREGATES every in-progress migration/repair plus the detected
// problems into one overview.
const TEXT_MIGRATION_ID = 'text-migration';
const BOARD_REPAIR_ID = 'board-repair';
const REPAIR_MARKER_ID = 'startup-repair-version';
async function upsertStatusDoc(id, fields) {
try {
await TextMigrationStatus.upsertAsync(
{ _id: id },
{ $set: { ...fields, _id: id, updatedAt: new Date() } },
);
} catch (error) {
console.error('[systemStatus] persist', id, error);
}
}
// Persist the MongoDB <-> SQLite text-migration progress snapshot.
export async function setTextMigrationStatus(fields) {
await upsertStatusDoc(TEXT_MIGRATION_ID, fields);
}
// Persist the server-side board data-repair progress snapshot.
export async function setBoardRepairStatus(fields) {
await upsertStatusDoc(BOARD_REPAIR_ID, fields);
}
// Version marker so the startup board-repair pass runs once per version, not on
// every boot (a full scan is expensive). Board open still repairs per board.
export async function getRepairMarkerVersion() {
const doc = await TextMigrationStatus.findOneAsync({ _id: REPAIR_MARKER_ID });
return doc && Number.isFinite(doc.version) ? doc.version : 0;
}
export async function setRepairMarkerVersion(version, summary) {
await upsertStatusDoc(REPAIR_MARKER_ID, { version, summary: summary || null });
}
function describeTextMigration(tm) {
let where = '';
if (tm.phase === 'migrating') {
where = `: ${tm.collection || ''} (${tm.collectionsDone || 0}/${tm.collectionsTotal || 0} collections)`;
} else if (tm.phase === 'repairing') {
where = `: repairing ${tm.boardsDone || 0}/${tm.boardsTotal || 0} boards`;
}
return `Database migration (${tm.direction || '?'}) — ${tm.phase || 'running'}${where}`;
}
// Everything currently in progress, as [{ kind, active, message }].
export async function getInProgress() {
const items = [];
// #6520: use isStatusActive, not the raw `running` flag, so a stale
// running:true (a completion write that lost a race with a late progress write,
// or a process killed mid-run) does not show the migration/repair "in progress"
// forever — e.g. "Board data-repair — 146/146 boards" that never clears.
const tm = await TextMigrationStatus.findOneAsync({ _id: TEXT_MIGRATION_ID });
if (isStatusActive(tm)) {
items.push({ kind: 'database-migration', active: true, message: describeTextMigration(tm) });
}
const br = await TextMigrationStatus.findOneAsync({ _id: BOARD_REPAIR_ID });
if (isStatusActive(br)) {
items.push({
kind: 'board-repair',
active: true,
message: `Board data-repair — ${br.boardsDone || 0}/${br.boardsTotal || 0} boards`,
});
}
try {
const rec = await RecoveryStatus.findOneAsync({});
if (rec && rec.active) {
items.push({ kind: 'recovery', active: true, message: rec.message || 'Data recovery / maintenance in progress' });
}
} catch (_) {}
// The cron-driven migration subsystem that wrote `cronJobStatus` docs is gone (it
// never ran and had no UI), so this no longer looks there. Leaving the check in
// would have been worse than useless: a leftover status:'running' doc from an older
// version has nothing to clear it now, so Problems would show "Migration job X
// running" forever.
try {
const att = await AttachmentMigrationStatus.findOneAsync({ $or: [{ running: true }, { status: 'running' }] });
if (att) {
items.push({ kind: 'attachment-migration', active: true, message: att.message || 'Attachment migration / repair in progress' });
}
} catch (_) {}
return items;
}
// The login-page "Must be logged in" cause checklist (detected values).
export async function getLoginProblems() {
const inProgress = await getInProgress();
return loginProblemChecks({
migrationActive: inProgress.length > 0,
migrationMessage: inProgress.map(x => x.message).join('; '),
rootUrl: process.env.ROOT_URL || '',
ldapEnabled: authEnv('LDAP_ENABLE') === 'true',
sandstorm: !!(process.env.SANDSTORM || process.env.SANDSTORM_SMTP_SEND),
});
}
// What counts as broken lives in models/lib/brokenCardsRepair.js, shared with
// the Repair button on the Summary page, so the count and the repair can never
// disagree about which cards they mean.
async function countBrokenCards() {
try {
return await Cards.find(brokenCardsSelector()).countAsync();
} catch (_) {
return 0;
}
}
// The Problems "Status" overview: everything in progress + detected problems.
export async function getProblemsOverview() {
const [inProgress, loginProblems, brokenCards, unboundLists] = await Promise.all([
getInProgress(),
getLoginProblems(),
countBrokenCards(),
countRestorableListSwimlanes(),
]);
return buildProblemsOverview({ inProgress, loginProblems, brokenCards, unboundLists });
}