mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
This app runs with the audit-argument-checks package, so any Meteor method that
RECEIVES an argument it never check()s throws
"Did not check() all arguments during call to '<method>'" - the call fails
entirely, no matter what the method would have done.
problemDetailReport(area) had that defect but nothing had ever passed it an
argument, so it went unnoticed until the new Admin Panel / Problems / CPU usage
header started polling problemDetailReport('cpu') every 5 seconds and the server
log filled with the exception.
Auditing every server method for the same defect found five more that ARE called
with arguments from the client, so these features were failing outright:
- unlockUser(userId) - Admin Panel / People, unlocking a locked-out user
- runBackup(opts, storageName) - Admin Panel / Attachments, running a backup
- restoreBackup(zipPath, mode) - restoring a backup
- saveBackupSchedule(schedule) - saving the backup schedule
- migrateTextDatabase(direction) - the MongoDB <-> FerretDB text migration
and one with no current client caller, getServiceConfiguration(service), fixed
for the same reason.
Each now check()s its arguments against the types its call sites actually pass
(the two optional ones use Match.OneOf(String, null, undefined)), and the three
files that had no check import got one.
Thanks to xet7 !
76 lines
3.2 KiB
JavaScript
76 lines
3.2 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { check, Match } from 'meteor/check';
|
|
import os from 'os';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import {
|
|
getProblemsOverview,
|
|
getInProgress,
|
|
getLoginProblems,
|
|
} from '/server/lib/systemStatus';
|
|
import { getCurrentCpu } from '/server/lib/cpuMonitor';
|
|
|
|
// Admin-gated methods behind the Admin Panel / Problems "Status" overview. The
|
|
// same data is available without the Admin Panel via `snap run wekan.problems`.
|
|
|
|
async function requireAdmin() {
|
|
const user = await ReactiveCache.getCurrentUser();
|
|
if (!user || !user.isAdmin) {
|
|
throw new Meteor.Error('not-authorized', 'Admin only');
|
|
}
|
|
return user;
|
|
}
|
|
|
|
// Problem-specific detail, mirroring the `snap run wekan.problems <area>`
|
|
// sub-commands. Kept in one place so the Admin Panel and the snap command agree.
|
|
function cpuDetail() {
|
|
const cpus = os.cpus() || [];
|
|
const mem = process.memoryUsage();
|
|
return {
|
|
area: 'cpu',
|
|
title: 'CPU usage',
|
|
// The live figure shown above the search box on the CPU usage page. Same
|
|
// sample the CPU monitor writes its event rows from, so the header and the
|
|
// rows below it never disagree.
|
|
current: getCurrentCpu(),
|
|
loadAverage: os.loadavg(), // 1 / 5 / 15 min
|
|
cpuCount: cpus.length,
|
|
cpuModel: cpus.length ? cpus[0].model : '',
|
|
uptimeSeconds: Math.round(process.uptime()),
|
|
rssBytes: mem.rss,
|
|
heapUsedBytes: mem.heapUsed,
|
|
note: 'Load average is machine-wide (1/5/15 min). rss/heap are the WeKan server process. Sustained load near or above the CPU count means the machine is saturated. If `top` shows the ferretdb process pegged near 100%/200% for a long time, the FerretDB v1 (SQLite) backend is saturated under WeKan\'s poll load (symptoms: pages take minutes, counts stuck at 0, raw i18n keys). Mitigation: run on MongoDB (snap: `snap set wekan database=mongodb`) or migrate text data across, and check for a migration/repair still running.',
|
|
};
|
|
}
|
|
|
|
Meteor.methods({
|
|
// The full Problems "Status" overview: everything in progress + problems found.
|
|
async systemStatusReport() {
|
|
await requireAdmin();
|
|
const [overview, loginProblems] = await Promise.all([
|
|
getProblemsOverview(),
|
|
getLoginProblems(),
|
|
]);
|
|
return { overview, loginProblems };
|
|
},
|
|
|
|
// Just the in-progress migrations/repairs (cheap; polled by the Status page).
|
|
async migrationsInProgress() {
|
|
await requireAdmin();
|
|
return getInProgress();
|
|
},
|
|
|
|
// Detail for one problem area (currently 'cpu'); mirrors the snap sub-command.
|
|
// `area` MUST be check()ed: Meteor runs with audit-argument-checks, so a method
|
|
// that receives an argument it never checks throws "Did not check() all arguments"
|
|
// on every call. Nothing passed an argument here until the CPU usage page started
|
|
// polling problemDetailReport('cpu'), which then failed every 5 seconds.
|
|
async problemDetailReport(area) {
|
|
check(area, Match.OneOf(String, null, undefined));
|
|
await requireAdmin();
|
|
if (area === 'cpu') return cpuDetail();
|
|
if (area === 'login') return { area: 'login', checks: await getLoginProblems() };
|
|
if (area === 'status' || !area) return getProblemsOverview();
|
|
throw new Meteor.Error('unknown-area', `Unknown problem area: ${area}`);
|
|
},
|
|
});
|