computer-vitals 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +165 -2
- package/package.json +48 -4
- package/src/data/os-support.json +33 -0
- package/src/index.js +160 -0
- package/src/lib/apps.js +211 -0
- package/src/lib/diagnose.js +285 -0
- package/src/lib/disk.js +346 -0
- package/src/lib/gather.js +346 -0
- package/src/lib/parse.js +328 -0
- package/src/lib/report.js +70 -0
- package/src/lib/run.js +79 -0
- package/src/lib/safety.js +443 -0
- package/src/lib/startup.js +255 -0
- package/src/lib/text.js +16 -0
- package/src/lib/units.js +16 -0
- package/src/lib/win.js +40 -0
- package/src/win/computer.ps1 +88 -0
- package/src/win/folders.ps1 +29 -0
- package/src/win/safety.ps1 +57 -0
- package/src/win/startup.ps1 +54 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The text report for check_computer. The first part is written for the person; the measurements
|
|
2
|
+
// at the end are for whoever helps them. The computer's name, user names and serial numbers are
|
|
3
|
+
// never included.
|
|
4
|
+
import { diagnose, pct } from "./diagnose.js";
|
|
5
|
+
import { memSize, diskSize } from "./units.js";
|
|
6
|
+
import { topBy } from "./apps.js";
|
|
7
|
+
|
|
8
|
+
const MARK = { problem: "[problem]", warning: "[warning]", note: "[note] ", ok: "[ok] " };
|
|
9
|
+
|
|
10
|
+
export function measurements(f) {
|
|
11
|
+
const out = [];
|
|
12
|
+
const when = new Date().toISOString().replace("T", " ").slice(0, 16) + " UTC";
|
|
13
|
+
out.push(`Measurements (${when})`);
|
|
14
|
+
out.push(` Processor: ${pct(f.cpu?.usePct)} busy over about 2 seconds, ${f.cores} core${f.cores === 1 ? "" : "s"}`);
|
|
15
|
+
const apps = (f.apps || []).filter((a) => a.kind !== "self");
|
|
16
|
+
const cpu = topBy(apps, "cpuPct", 5).filter((a) => a.cpuPct >= 1);
|
|
17
|
+
if (cpu.length) out.push(` Busiest programs: ${cpu.map((a) => `${a.name} ${pct(a.cpuPct)}`).join("; ")}`);
|
|
18
|
+
const m = f.memory;
|
|
19
|
+
if (m?.total) {
|
|
20
|
+
const bits = [`${memSize(m.total)} installed`];
|
|
21
|
+
if (m.available !== null && m.available !== undefined) bits.push(`${memSize(m.available)} available`);
|
|
22
|
+
if (m.pressure) bits.push(`pressure ${m.pressure === "warn" ? "warning" : m.pressure}`);
|
|
23
|
+
if (m.swapUsed !== null && m.swapUsed !== undefined && m.swapTotal) bits.push(`${memSize(m.swapUsed)} of ${memSize(m.swapTotal)} swap used`);
|
|
24
|
+
if (m.commitPct !== null && m.commitPct !== undefined) bits.push(`${Math.round(m.commitPct)}% of the commit limit used`);
|
|
25
|
+
if (m.waitPct !== null && m.waitPct !== undefined) bits.push(`programs waited for memory ${m.waitPct}% of the last 10 s`);
|
|
26
|
+
out.push(` Memory: ${bits.join(", ")}`);
|
|
27
|
+
}
|
|
28
|
+
const mem = topBy(apps, "memBytes", 5).filter((a) => a.memBytes >= 100 * 1024 ** 2);
|
|
29
|
+
if (mem.length) out.push(` Most memory: ${mem.map((a) => `${a.name} ${memSize(a.memBytes)}${a.count > 1 ? ` in ${a.count} processes` : ""}`).join("; ")}`);
|
|
30
|
+
const d = f.drive || {};
|
|
31
|
+
if (Number.isFinite(d.total)) {
|
|
32
|
+
const bits = [`${diskSize(d.free, f.platform)} free of ${diskSize(d.total, f.platform)}`];
|
|
33
|
+
if (d.virtual) bits.push("virtual disk");
|
|
34
|
+
else if (d.kind) bits.push(d.kind === "ssd" ? "SSD" : "spinning hard drive");
|
|
35
|
+
if (d.health) bits.push(`health ${d.health === "ok" ? "good" : d.health === "warn" ? "warning" : "FAILING"}`);
|
|
36
|
+
if (d.busyPct !== null && d.busyPct !== undefined) bits.push(`${Math.round(d.busyPct)}% busy`);
|
|
37
|
+
out.push(` System drive: ${bits.join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
if (Number.isFinite(f.uptimeSec)) out.push(` Running since last restart: ${Math.floor(f.uptimeSec / 86400)} days ${Math.floor((f.uptimeSec % 86400) / 3600)} hours${f.restart?.pending ? ", restart pending for updates" : ""}`);
|
|
40
|
+
const b = f.battery || {};
|
|
41
|
+
if (b.present) {
|
|
42
|
+
const bits = [];
|
|
43
|
+
if (b.percent !== null && b.percent !== undefined) bits.push(`${b.percent}% charged`);
|
|
44
|
+
if (b.onBattery !== null && b.onBattery !== undefined) bits.push(b.onBattery ? "on battery" : "plugged in");
|
|
45
|
+
bits.push(b.healthPct !== null && b.healthPct !== undefined ? `holds ${b.healthPct}% of original capacity` : "wear not readable here");
|
|
46
|
+
if (b.cycles) bits.push(`${b.cycles} charge cycles`);
|
|
47
|
+
if (b.condition) bits.push(`condition: ${b.condition}`);
|
|
48
|
+
out.push(` Battery: ${bits.join(", ")}`);
|
|
49
|
+
}
|
|
50
|
+
if (f.power?.saver !== null && f.power?.saver !== undefined) out.push(` Battery-saving mode: ${f.power.saver ? "on" : "off"}`);
|
|
51
|
+
if (f.thermal?.speedLimit !== null && f.thermal?.speedLimit !== undefined) out.push(` Processor speed limit for heat: ${f.thermal.speedLimit}%`);
|
|
52
|
+
if (f.startup?.count !== null && f.startup?.count !== undefined) out.push(` Optional startup programs turned on: ${f.startup.count}`);
|
|
53
|
+
out.push(` Programs running: ${f.processCount ?? "?"} processes`);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function renderComputer(f) {
|
|
58
|
+
const d = diagnose(f);
|
|
59
|
+
const about = [f.osName || f.platform];
|
|
60
|
+
if (f.memory?.total) about.push(`${memSize(f.memory.total)} memory`);
|
|
61
|
+
const lines = [`Computer Vitals: computer check (${about.join(", ")}; took ${f.seconds} s)`, "", `Verdict: ${d.verdict.title}`, "", "What I found"];
|
|
62
|
+
const order = { problem: 0, warning: 1, note: 2, ok: 3 };
|
|
63
|
+
for (const x of [...d.findings].sort((a, b) => order[a.level] - order[b.level])) lines.push(`${MARK[x.level]} ${x.text}`);
|
|
64
|
+
if (d.steps.length) {
|
|
65
|
+
lines.push("", "What to do");
|
|
66
|
+
d.steps.forEach((s, i) => lines.push(`${i + 1}. ${s}`));
|
|
67
|
+
}
|
|
68
|
+
lines.push("", ...measurements(f), "", "This was one look, a few seconds long. Nothing was changed.");
|
|
69
|
+
return lines.join("\n");
|
|
70
|
+
}
|
package/src/lib/run.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Starts the few system programs this tool reads from. Each one is looked up at a fixed
|
|
2
|
+
// location (never through PATH or a shell) and always gets a fixed argument list, so nothing a
|
|
3
|
+
// caller types can turn into a command. Every run has a time limit.
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
|
|
7
|
+
const SYS32 = `${process.env.SystemRoot || "C:\\Windows"}\\System32\\`;
|
|
8
|
+
|
|
9
|
+
const PROGRAMS = {
|
|
10
|
+
// macOS
|
|
11
|
+
ps: { darwin: ["/bin/ps"] },
|
|
12
|
+
sysctl: { darwin: ["/usr/sbin/sysctl"] },
|
|
13
|
+
pmset: { darwin: ["/usr/bin/pmset"] },
|
|
14
|
+
diskutil: { darwin: ["/usr/sbin/diskutil"] },
|
|
15
|
+
system_profiler: { darwin: ["/usr/sbin/system_profiler"] },
|
|
16
|
+
sw_vers: { darwin: ["/usr/bin/sw_vers"] },
|
|
17
|
+
fdesetup: { darwin: ["/usr/bin/fdesetup"] },
|
|
18
|
+
socketfilterfw: { darwin: ["/usr/libexec/ApplicationFirewall/socketfilterfw"] },
|
|
19
|
+
spctl: { darwin: ["/usr/sbin/spctl"] },
|
|
20
|
+
csrutil: { darwin: ["/usr/bin/csrutil"] },
|
|
21
|
+
sysadminctl: { darwin: ["/usr/sbin/sysadminctl"] },
|
|
22
|
+
defaults: { darwin: ["/usr/bin/defaults"] },
|
|
23
|
+
tmutil: { darwin: ["/usr/bin/tmutil"] },
|
|
24
|
+
// Linux
|
|
25
|
+
systemctl: { linux: ["/usr/bin/systemctl", "/bin/systemctl"] },
|
|
26
|
+
// Windows
|
|
27
|
+
powershell: { win32: [`${SYS32}WindowsPowerShell\\v1.0\\powershell.exe`] },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const found = new Map();
|
|
31
|
+
|
|
32
|
+
export function programPath(name, platform = process.platform) {
|
|
33
|
+
const key = `${platform}:${name}`;
|
|
34
|
+
if (!found.has(key)) {
|
|
35
|
+
const list = PROGRAMS[name]?.[platform] || [];
|
|
36
|
+
found.set(key, list.find((p) => fs.existsSync(p)) || null);
|
|
37
|
+
}
|
|
38
|
+
return found.get(key);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run a known program. Resolves (never rejects) with
|
|
43
|
+
* { ok, missing, code, stdout, stderr, timedOut }.
|
|
44
|
+
*/
|
|
45
|
+
export function run(name, args, { timeoutMs = 10000 } = {}) {
|
|
46
|
+
const file = programPath(name);
|
|
47
|
+
if (!file) return Promise.resolve({ ok: false, missing: true, code: null, stdout: "", stderr: "", timedOut: false });
|
|
48
|
+
// English output where the system allows it, so the readers see the words they expect.
|
|
49
|
+
const env = process.platform === "win32" ? process.env : { ...process.env, LC_ALL: "C", LANG: "C" };
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const child = execFile(
|
|
52
|
+
file,
|
|
53
|
+
args,
|
|
54
|
+
{ timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, windowsHide: true, env, encoding: "utf8" },
|
|
55
|
+
(err, stdout, stderr) => {
|
|
56
|
+
resolve({
|
|
57
|
+
ok: !err,
|
|
58
|
+
missing: false,
|
|
59
|
+
code: err ? (typeof err.code === "number" ? err.code : null) : 0,
|
|
60
|
+
stdout: String(stdout || ""),
|
|
61
|
+
stderr: String(stderr || ""),
|
|
62
|
+
timedOut: Boolean(err && err.killed),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
// Nothing is ever typed into these programs; closing their input stops any of them waiting for it.
|
|
67
|
+
child.stdin?.on("error", () => {});
|
|
68
|
+
child.stdin?.end();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Read a small text file, or null if it is missing or not readable. */
|
|
73
|
+
export function readText(file) {
|
|
74
|
+
try {
|
|
75
|
+
return fs.readFileSync(file, "utf8");
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// check_safety: "is my computer safe?" A check of settings: firewall, disk encryption, whether the
|
|
2
|
+
// system still gets updates, malware protection, login, backups, and remote-access doors.
|
|
3
|
+
// Read-only. It is not a virus scan: it never looks inside files.
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import net from "node:net";
|
|
7
|
+
|
|
8
|
+
import { run, readText } from "./run.js";
|
|
9
|
+
import { runWinScript, arr } from "./win.js";
|
|
10
|
+
import {
|
|
11
|
+
parseMountinfo,
|
|
12
|
+
mountFor,
|
|
13
|
+
parseOsRelease,
|
|
14
|
+
parseDistroCsv,
|
|
15
|
+
parseUpdatesAvailable,
|
|
16
|
+
parseListening,
|
|
17
|
+
parseSoftwareUpdate,
|
|
18
|
+
parseInstallHistory,
|
|
19
|
+
parseFileVault,
|
|
20
|
+
parseMacFirewall,
|
|
21
|
+
parseGatekeeper,
|
|
22
|
+
parseSip,
|
|
23
|
+
parseScreenLock,
|
|
24
|
+
parseTimeMachine,
|
|
25
|
+
} from "./parse.js";
|
|
26
|
+
import { linuxDevice } from "./gather.js";
|
|
27
|
+
import { cleanText } from "./text.js";
|
|
28
|
+
|
|
29
|
+
const PLATFORM = process.platform;
|
|
30
|
+
export const SUPPORT = JSON.parse(fs.readFileSync(new URL("../data/os-support.json", import.meta.url), "utf8"));
|
|
31
|
+
|
|
32
|
+
const DAY = 86400000;
|
|
33
|
+
const iso = (d) => new Date(d).toISOString().slice(0, 10);
|
|
34
|
+
const daysSince = (date, today) => (date ? Math.floor((Date.parse(today) - Date.parse(date)) / DAY) : null);
|
|
35
|
+
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
36
|
+
/** "2027-10-12" -> "October 2027" */
|
|
37
|
+
export const monthYear = (date) => {
|
|
38
|
+
const m = /^(\d{4})-(\d{2})/.exec(String(date || ""));
|
|
39
|
+
return m ? `${MONTHS[Number(m[2]) - 1]} ${m[1]}` : "an unknown date";
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function compareVersions(a, b) {
|
|
43
|
+
const x = String(a).split(".").map(Number);
|
|
44
|
+
const y = String(b).split(".").map(Number);
|
|
45
|
+
for (let i = 0; i < Math.max(x.length, y.length); i += 1) {
|
|
46
|
+
const d = (x[i] || 0) - (y[i] || 0);
|
|
47
|
+
if (d) return d;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Is anything accepting connections on this port of this computer? */
|
|
53
|
+
function localPort(port, timeoutMs = 700) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const s = net.connect({ host: "127.0.0.1", port });
|
|
56
|
+
const done = (v) => {
|
|
57
|
+
s.destroy();
|
|
58
|
+
resolve(v);
|
|
59
|
+
};
|
|
60
|
+
s.setTimeout(timeoutMs, () => done(false));
|
|
61
|
+
s.once("connect", () => done(true));
|
|
62
|
+
s.once("error", () => done(false));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ---------- Windows ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
/** Windows Security Center state number -> { on, upToDate }. */
|
|
69
|
+
export function productState(n) {
|
|
70
|
+
const v = Number(n);
|
|
71
|
+
if (!Number.isFinite(v)) return { on: null, upToDate: null };
|
|
72
|
+
return { on: ((v >> 12) & 0xf) === 1, upToDate: ((v >> 4) & 0xf) === 0 };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const HOME_EDITION = /^(Core|CoreN|CoreSingleLanguage|CoreCountrySpecific|Professional|ProfessionalN|ProfessionalWorkstation|ProfessionalEducation|ProfessionalSingleLanguage)$/i;
|
|
76
|
+
|
|
77
|
+
/** The JSON from src/win/safety.ps1 -> facts in the shape assess() takes. */
|
|
78
|
+
export function normalizeWinSafety(j, { support = SUPPORT, today = iso(Date.now()) } = {}) {
|
|
79
|
+
if (!j) return null;
|
|
80
|
+
const f = { platform: "win32", today, laptop: j.laptop === null || j.laptop === undefined ? null : Boolean(j.laptop) };
|
|
81
|
+
const build = Number(j.version?.build);
|
|
82
|
+
const isServer = /server/i.test(j.version?.type || "");
|
|
83
|
+
const major = Number.isFinite(build) ? (build >= 22000 ? 11 : 10) : null;
|
|
84
|
+
f.osName = major ? `Windows ${isServer ? "Server" : major}${j.version?.display ? ` ${j.version.display}` : ""}` : "Windows";
|
|
85
|
+
|
|
86
|
+
const fw = j.firewall;
|
|
87
|
+
const others = arr(j.firewallProducts).filter((p) => productState(p.state).on).map((p) => p.name);
|
|
88
|
+
f.firewall = fw ? { on: Boolean(fw.private && fw.public), partly: Boolean(fw.private || fw.public || fw.domain), other: others[0] || null } : { on: others.length ? true : null, other: others[0] || null };
|
|
89
|
+
|
|
90
|
+
const b = j.bitlocker;
|
|
91
|
+
f.encryption = { state: b === 1 || b === 3 || b === 6 ? "on" : b === 2 ? "off" : b === 5 ? "suspended" : b === 7 ? "waiting" : null, name: "BitLocker (device encryption)" };
|
|
92
|
+
|
|
93
|
+
// Which version, and does it still get security updates?
|
|
94
|
+
f.support = { state: null };
|
|
95
|
+
if (isServer || (j.version?.edition && !HOME_EDITION.test(j.version.edition))) f.support = { state: "unjudged", why: isServer ? "This is Windows Server." : "This is a work or school edition of Windows; its update dates are set by the organization." };
|
|
96
|
+
else if (major === 10) f.support = { state: "ended", ended: support.windows.windows10End, extendedEnd: support.windows.windows10ExtendedEnd };
|
|
97
|
+
else if (major === 11 && j.version?.display) {
|
|
98
|
+
const end = support.windows.windows11[j.version.display];
|
|
99
|
+
const known = Object.keys(support.windows.windows11);
|
|
100
|
+
if (end) f.support = today > end ? { state: "version-ended", ended: end, version: j.version.display } : { state: "ok", until: end, version: j.version.display };
|
|
101
|
+
else if (j.version.display > known[known.length - 1]) f.support = { state: "ok", version: j.version.display, newerThanTable: true };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const paused = j.pausedUntil && Date.parse(j.pausedUntil) > Date.parse(today) ? String(j.pausedUntil).slice(0, 10) : null;
|
|
105
|
+
f.updates = { lastInstall: j.lastUpdate || null, daysSince: daysSince(j.lastUpdate, today), pausedUntil: paused, autoOff: j.noAutoUpdate === 1, pending: [] };
|
|
106
|
+
|
|
107
|
+
const av = arr(j.antivirus).map((p) => ({ name: cleanText(p.name, 48) || "an antivirus program", ...productState(p.state) }));
|
|
108
|
+
f.malware = { known: j.antivirus !== null && j.antivirus !== undefined, products: av, defender: j.defender || null };
|
|
109
|
+
|
|
110
|
+
f.login = { autoLogin: j.autoLogon === null || j.autoLogon === undefined ? null : String(j.autoLogon) === "1", screenLock: null };
|
|
111
|
+
f.uacOff = j.uac === 0;
|
|
112
|
+
f.remote = [];
|
|
113
|
+
if (j.remoteDesktop === 0) f.remote.push({ what: "Remote Desktop", off: "Settings > System > Remote Desktop" });
|
|
114
|
+
if (j.sshServer === true) f.remote.push({ what: "An SSH server (remote command line)", off: "Settings > System > Optional features, or the Services app (OpenSSH SSH Server)" });
|
|
115
|
+
if (Number.isFinite(j.sharedFolders) && j.sharedFolders > 0) f.remote.push({ what: `File sharing (${j.sharedFolders} shared folder${j.sharedFolders === 1 ? "" : "s"})`, off: "right-click the folder > Properties > Sharing" });
|
|
116
|
+
f.remoteKnown = j.remoteDesktop !== null && j.remoteDesktop !== undefined;
|
|
117
|
+
|
|
118
|
+
const bk = j.backup;
|
|
119
|
+
f.backup = bk ? { seen: bk.documentsInOneDrive ? "Your Documents folder is kept in OneDrive" : null, cloudOnly: Boolean(bk.documentsInOneDrive), hint: bk.oneDrive || bk.dropbox || bk.iCloudDrive ? "A cloud folder is set up on this computer, but your Documents folder is not inside it." : null } : { seen: null };
|
|
120
|
+
return f;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ---------- macOS ---------------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
export function macSupport(version, { support = SUPPORT } = {}) {
|
|
126
|
+
const major = String(version || "").split(".")[0];
|
|
127
|
+
if (!/^\d+$/.test(major)) return { state: null };
|
|
128
|
+
const majors = Object.keys(support.macos.supported).map(Number);
|
|
129
|
+
const row = support.macos.supported[major];
|
|
130
|
+
if (row) return { state: "ok", version, latest: row.latest, behind: compareVersions(version, row.latest) < 0 };
|
|
131
|
+
if (Number(major) > Math.max(...majors)) return { state: "ok", version, newerThanTable: true };
|
|
132
|
+
return { state: "ended", version, apple: true };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function macSafety(today) {
|
|
136
|
+
const [fv, fw, gk, sip, lock, auto, tm, su, ver, icloud, batt, ssh, screen, files] = await Promise.all([
|
|
137
|
+
run("fdesetup", ["status"]),
|
|
138
|
+
run("socketfilterfw", ["--getglobalstate"]),
|
|
139
|
+
run("spctl", ["--status"]),
|
|
140
|
+
run("csrutil", ["status"]),
|
|
141
|
+
run("sysadminctl", ["-screenLock", "status"]),
|
|
142
|
+
run("defaults", ["read", "/Library/Preferences/com.apple.loginwindow", "autoLoginUser"]),
|
|
143
|
+
run("tmutil", ["destinationinfo"]),
|
|
144
|
+
run("defaults", ["read", "/Library/Preferences/com.apple.SoftwareUpdate"]),
|
|
145
|
+
run("sw_vers", ["-productVersion"]),
|
|
146
|
+
run("defaults", ["read", "com.apple.finder", "FXICloudDriveDocuments"]),
|
|
147
|
+
run("pmset", ["-g", "batt"]),
|
|
148
|
+
localPort(22),
|
|
149
|
+
localPort(5900),
|
|
150
|
+
localPort(445),
|
|
151
|
+
]);
|
|
152
|
+
const version = ver.stdout.trim();
|
|
153
|
+
const sw = parseSoftwareUpdate(su.stdout);
|
|
154
|
+
const lastInstall = sw?.lastInstall || parseInstallHistory(readText("/Library/Receipts/InstallHistory.plist"));
|
|
155
|
+
const sl = parseScreenLock(`${lock.stdout}\n${lock.stderr}`);
|
|
156
|
+
const t = parseTimeMachine(`${tm.stdout}\n${tm.stderr}`);
|
|
157
|
+
const docsInICloud = icloud.ok && icloud.stdout.trim() === "1";
|
|
158
|
+
const remote = [];
|
|
159
|
+
if (ssh) remote.push({ what: "Remote Login (SSH)", off: "System Settings > General > Sharing" });
|
|
160
|
+
if (screen) remote.push({ what: "Screen Sharing or Remote Management", off: "System Settings > General > Sharing" });
|
|
161
|
+
if (files) remote.push({ what: "File Sharing", off: "System Settings > General > Sharing" });
|
|
162
|
+
const fvOn = parseFileVault(`${fv.stdout}\n${fv.stderr}`);
|
|
163
|
+
return {
|
|
164
|
+
platform: "darwin",
|
|
165
|
+
today,
|
|
166
|
+
laptop: batt.ok ? /InternalBattery/.test(batt.stdout) : null,
|
|
167
|
+
osName: `macOS ${version}`.trim(),
|
|
168
|
+
firewall: { on: parseMacFirewall(fw.stdout), other: null },
|
|
169
|
+
encryption: { state: fvOn === null ? null : fvOn ? "on" : "off", name: "FileVault" },
|
|
170
|
+
support: macSupport(version),
|
|
171
|
+
updates: { lastInstall, daysSince: daysSince(lastInstall, today), pausedUntil: null, autoOff: sw ? sw.autoInstallOS === false && sw.criticalInstall === false : false, autoPartly: sw ? sw.autoInstallOS === false : false, pending: sw?.pending || [] },
|
|
172
|
+
malware: { builtIn: true, gatekeeper: parseGatekeeper(`${gk.stdout}\n${gk.stderr}`), sip: parseSip(sip.stdout) },
|
|
173
|
+
login: { autoLogin: auto.missing ? null : auto.ok && auto.stdout.trim().length > 0, screenLock: sl },
|
|
174
|
+
remote,
|
|
175
|
+
remoteKnown: true,
|
|
176
|
+
backup: t.configured ? { seen: "A Time Machine backup drive is set up" } : { seen: docsInICloud ? "Your Desktop and Documents folders appear to sync to iCloud" : null, cloudOnly: docsInICloud, timeMachine: t.configured },
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---------- Linux -------------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
export function linuxSupport(release, csvText, today) {
|
|
183
|
+
if (release.SUPPORT_END && /^\d{4}-\d{2}-\d{2}$/.test(release.SUPPORT_END)) {
|
|
184
|
+
return today > release.SUPPORT_END ? { state: "ended", ended: release.SUPPORT_END } : { state: "ok", until: release.SUPPORT_END };
|
|
185
|
+
}
|
|
186
|
+
const row = parseDistroCsv(csvText, release.VERSION_ID);
|
|
187
|
+
if (!row || !row.eol) return { state: null };
|
|
188
|
+
if (today <= row.eol) return { state: "ok", until: row.eol };
|
|
189
|
+
return { state: "ended", ended: row.eol, extendedEnd: row.eolEsm && today <= row.eolEsm ? row.eolEsm : null, extendedName: release.ID === "ubuntu" ? "Ubuntu Pro" : "long-term support" };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function linuxSafety(today) {
|
|
193
|
+
const rel = parseOsRelease(readText("/etc/os-release") || readText("/usr/lib/os-release"));
|
|
194
|
+
const csv = rel.ID === "ubuntu" || rel.ID === "debian" ? readText(`/usr/share/distro-info/${rel.ID}.csv`) : null;
|
|
195
|
+
const root = linuxDevice(mountFor(parseMountinfo(readText("/proc/self/mountinfo")), "/"));
|
|
196
|
+
const ufw = /^\s*ENABLED\s*=\s*yes/im.test(readText("/etc/ufw/ufw.conf") || "");
|
|
197
|
+
const firewalld = ufw ? false : (await run("systemctl", ["is-active", "firewalld"], { timeoutMs: 4000 })).stdout.trim() === "active";
|
|
198
|
+
let laptop = null;
|
|
199
|
+
try {
|
|
200
|
+
laptop = fs.readdirSync("/sys/class/power_supply").some((n) => /^BAT/i.test(n));
|
|
201
|
+
} catch {
|
|
202
|
+
/* no such folder */
|
|
203
|
+
}
|
|
204
|
+
const ports = new Set([...parseListening(readText("/proc/net/tcp")), ...parseListening(readText("/proc/net/tcp6"))]);
|
|
205
|
+
const remote = [];
|
|
206
|
+
if (ports.has(22)) remote.push({ what: "An SSH server (remote command line)", off: "sudo systemctl disable --now ssh" });
|
|
207
|
+
if (ports.has(3389)) remote.push({ what: "Remote Desktop", off: "Settings > Sharing (or System > Remote Desktop)" });
|
|
208
|
+
if (ports.has(5900)) remote.push({ what: "Screen sharing (VNC)", off: "Settings > Sharing" });
|
|
209
|
+
if (ports.has(445)) remote.push({ what: "File sharing (Samba)", off: "sudo systemctl disable --now smbd" });
|
|
210
|
+
const waiting = parseUpdatesAvailable(readText("/var/lib/update-notifier/updates-available"));
|
|
211
|
+
let lastInstall = null;
|
|
212
|
+
for (const f of ["/var/lib/apt/periodic/upgrade-stamp", "/var/log/dpkg.log", "/var/lib/dnf/history.sqlite"]) {
|
|
213
|
+
try {
|
|
214
|
+
const d = iso(fs.statSync(f).mtimeMs);
|
|
215
|
+
if (!lastInstall || d > lastInstall) lastInstall = d;
|
|
216
|
+
} catch {
|
|
217
|
+
/* not this kind of system */
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const auto20 = readText("/etc/apt/apt.conf.d/20auto-upgrades");
|
|
221
|
+
const gdm = `${readText("/etc/gdm3/custom.conf") || ""}\n${readText("/etc/gdm/custom.conf") || ""}`;
|
|
222
|
+
const lightdm = readText("/etc/lightdm/lightdm.conf") || "";
|
|
223
|
+
const autoLogin = /^\s*AutomaticLoginEnable\s*=\s*true/im.test(gdm) || /^\s*autologin-user\s*=\s*\S+/im.test(lightdm);
|
|
224
|
+
return {
|
|
225
|
+
platform: "linux",
|
|
226
|
+
today,
|
|
227
|
+
laptop,
|
|
228
|
+
osName: cleanText(rel.PRETTY_NAME, 48) || "Linux",
|
|
229
|
+
firewall: { on: ufw || firewalld ? true : null, other: null, linux: true },
|
|
230
|
+
encryption: { state: root.disk ? (root.encrypted ? "on" : "off") : null, name: "Disk encryption (LUKS)" },
|
|
231
|
+
support: linuxSupport(rel, csv, today),
|
|
232
|
+
updates: {
|
|
233
|
+
lastInstall,
|
|
234
|
+
daysSince: daysSince(lastInstall, today),
|
|
235
|
+
anyPackage: true, // the date of the last package change of any kind, not only of a system update
|
|
236
|
+
pausedUntil: null,
|
|
237
|
+
autoOff: auto20 !== null && !/Unattended-Upgrade\s+"1"/.test(auto20),
|
|
238
|
+
pending: waiting && waiting.security > 0 ? [`${waiting.security} security update${waiting.security === 1 ? "" : "s"}`] : [],
|
|
239
|
+
restartNeeded: fs.existsSync("/var/run/reboot-required"),
|
|
240
|
+
},
|
|
241
|
+
malware: null,
|
|
242
|
+
login: { autoLogin: gdm.trim() || lightdm ? autoLogin : null, screenLock: null },
|
|
243
|
+
remote,
|
|
244
|
+
remoteKnown: readText("/proc/net/tcp") !== null,
|
|
245
|
+
backup: { seen: null },
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export async function gatherSafety() {
|
|
250
|
+
const today = iso(Date.now());
|
|
251
|
+
if (PLATFORM === "win32") {
|
|
252
|
+
const j = await runWinScript("safety");
|
|
253
|
+
const f = normalizeWinSafety(j, { today });
|
|
254
|
+
return f || { platform: PLATFORM, today, failed: true, osName: "Windows" };
|
|
255
|
+
}
|
|
256
|
+
if (PLATFORM === "darwin") return macSafety(today);
|
|
257
|
+
if (PLATFORM === "linux") return linuxSafety(today);
|
|
258
|
+
return { platform: PLATFORM, today, failed: true, osName: os.type() };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ---------- judging ---------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
/** Facts -> { findings: [{ level, area, text }], steps: [] }. Pure. */
|
|
264
|
+
export function assess(f, { support = SUPPORT } = {}) {
|
|
265
|
+
const findings = [];
|
|
266
|
+
const steps = [];
|
|
267
|
+
const add = (level, area, text) => findings.push({ level, area, text });
|
|
268
|
+
const step = (s) => !steps.includes(s) && steps.push(s);
|
|
269
|
+
const win = f.platform === "win32";
|
|
270
|
+
const mac = f.platform === "darwin";
|
|
271
|
+
|
|
272
|
+
// Firewall
|
|
273
|
+
const fw = f.firewall || {};
|
|
274
|
+
if (fw.other) add("ok", "firewall", `A firewall is on (${fw.other}).`);
|
|
275
|
+
else if (fw.on === true) add("ok", "firewall", "The firewall is on.");
|
|
276
|
+
else if (fw.on === false) {
|
|
277
|
+
add(mac ? "warning" : "problem", "firewall", mac ? "The macOS firewall is off. At home behind a router that is a small risk; on public Wi-Fi it matters more." : "The firewall is off, or off for some kinds of network.");
|
|
278
|
+
step(mac ? "Turn the firewall on: System Settings > Network > Firewall." : "Turn the firewall on: Settings > Privacy & security > Windows Security > Firewall & network protection, and switch it on for every network type.");
|
|
279
|
+
} else if (fw.linux) {
|
|
280
|
+
add("note", "firewall", "I could not see a firewall turned on. Behind a home router that is common on Linux; on a laptop that joins public Wi-Fi, turn one on.");
|
|
281
|
+
step("If this computer joins public Wi-Fi, turn on the firewall: sudo ufw enable");
|
|
282
|
+
} else add("note", "firewall", "I could not tell whether the firewall is on.");
|
|
283
|
+
|
|
284
|
+
// Disk encryption
|
|
285
|
+
const enc = f.encryption || {};
|
|
286
|
+
const laptopWords = f.laptop === false ? "" : " This matters most on a laptop.";
|
|
287
|
+
if (enc.state === "on") add("ok", "encryption", `Disk encryption is on (${enc.name}). If this computer is lost or stolen, nobody can read its files without your password.`);
|
|
288
|
+
else if (enc.state === "off") {
|
|
289
|
+
add(f.laptop === false ? "note" : "warning", "encryption", `Disk encryption is off. If this computer is lost or stolen, someone can read its files by removing the drive.${laptopWords}`);
|
|
290
|
+
step(
|
|
291
|
+
mac
|
|
292
|
+
? "Turn on FileVault: System Settings > Privacy & Security > FileVault. Keep the recovery key somewhere safe."
|
|
293
|
+
: win
|
|
294
|
+
? "Turn on encryption: Settings > Privacy & security > Device encryption (or search for \"BitLocker\"). Save the recovery key to your Microsoft account or on paper."
|
|
295
|
+
: "Full-disk encryption on Linux is chosen when the system is installed. Without it, keep sensitive files in an encrypted folder or drive.",
|
|
296
|
+
);
|
|
297
|
+
} else if (enc.state === "suspended") {
|
|
298
|
+
add("warning", "encryption", "Disk encryption is set up but paused (suspended), so the drive is not protected right now. This can happen during an update and should clear after a restart.");
|
|
299
|
+
step("Restart the computer. If encryption is still paused, open \"Manage BitLocker\" and choose Resume protection.");
|
|
300
|
+
} else if (enc.state === "waiting") {
|
|
301
|
+
add("warning", "encryption", "Disk encryption is waiting to be finished. The drive is not protected until you sign in with a Microsoft account or turn BitLocker on.");
|
|
302
|
+
step("Finish turning on encryption: Settings > Privacy & security > Device encryption.");
|
|
303
|
+
} else add("note", "encryption", `I could not tell whether disk encryption is on.${win ? " Look in Settings > Privacy & security > Device encryption." : ""}`);
|
|
304
|
+
|
|
305
|
+
// Still getting security updates?
|
|
306
|
+
const s = f.support || {};
|
|
307
|
+
const asOf = support.asOf;
|
|
308
|
+
if (s.state === "ended" && win) {
|
|
309
|
+
const recent = f.updates?.daysSince !== null && f.updates?.daysSince !== undefined && f.updates.daysSince <= 60;
|
|
310
|
+
if (recent) add("warning", "support", `This is Windows 10. Normal security updates ended in ${monthYear(s.ended)}. This PC still received an update recently, so it looks enrolled in Microsoft's Extended Security Updates, which run until ${monthYear(s.extendedEnd)}.`);
|
|
311
|
+
else add("problem", "support", `This is Windows 10, which stopped getting normal security updates in ${monthYear(s.ended)}. Unless this PC is enrolled in Microsoft's Extended Security Updates (available until ${monthYear(s.extendedEnd)}), new security holes are no longer being fixed.`);
|
|
312
|
+
step("Move to Windows 11 if this PC can run it (Settings > Windows Update shows whether it can). If it cannot, enroll in Extended Security Updates there, and plan to replace the PC.");
|
|
313
|
+
} else if (s.state === "version-ended") {
|
|
314
|
+
add("problem", "support", `This version of Windows 11 (${s.version}) stopped getting security updates in ${monthYear(s.ended)}. A newer version is free.`);
|
|
315
|
+
step("Open Settings > Windows Update and install the newest version of Windows 11.");
|
|
316
|
+
} else if (s.state === "ended" && s.apple) {
|
|
317
|
+
add("problem", "support", `This Mac runs macOS ${s.version}. Apple's newest security updates (${monthYear(support.macos.latestDate)}) were only for macOS ${Object.keys(support.macos.supported).sort((a, b) => b - a).join(", ")}, so this version is very likely no longer being fixed. Apple does not announce end dates.`);
|
|
318
|
+
step("Open System Settings > General > Software Update and upgrade to a newer macOS if this Mac can run one. If it cannot, be careful with it online and plan to replace it.");
|
|
319
|
+
} else if (s.state === "ended") {
|
|
320
|
+
add("problem", "support", `This version of the system stopped getting security updates in ${monthYear(s.ended)}.${s.extendedEnd ? ` Paid or sign-up extended updates (${s.extendedName}) run until ${monthYear(s.extendedEnd)}.` : ""}`);
|
|
321
|
+
step("Upgrade to a release that still gets security updates.");
|
|
322
|
+
} else if (s.state === "ok") {
|
|
323
|
+
const until = s.until ? ` until ${monthYear(s.until)}` : "";
|
|
324
|
+
add("ok", "support", `${f.osName} still gets security updates${until}${f.platform === "linux" && s.until ? ", according to this system's own release list" : ""}.${s.newerThanTable ? " (It is newer than the list bundled with this version of Computer Vitals.)" : ""}`);
|
|
325
|
+
if (s.behind) {
|
|
326
|
+
add("warning", "updates", `A newer update exists for this Mac: at least macOS ${s.latest} (${monthYear(support.macos.latestDate)}). This Mac has ${s.version}.`);
|
|
327
|
+
step("Install the waiting update: System Settings > General > Software Update.");
|
|
328
|
+
}
|
|
329
|
+
} else if (s.state === "unjudged") add("note", "support", `${s.why} I did not judge its update dates.`);
|
|
330
|
+
else add("note", "support", "I could not tell whether this version of the system still gets security updates.");
|
|
331
|
+
|
|
332
|
+
// Updates
|
|
333
|
+
const u = f.updates || {};
|
|
334
|
+
const where = mac ? "System Settings > General > Software Update" : win ? "Settings > Windows Update" : "open your system's updater (on Ubuntu: Software Updater, or run sudo apt upgrade)";
|
|
335
|
+
if (u.pending?.length) {
|
|
336
|
+
add("warning", "updates", `Updates are waiting to be installed: ${u.pending.slice(0, 4).map((x) => cleanText(x, 60)).join(", ")}${u.pending.length > 4 ? ` and ${u.pending.length - 4} more` : ""}.`);
|
|
337
|
+
step(`Install the waiting updates: ${where}.`);
|
|
338
|
+
}
|
|
339
|
+
if (u.pausedUntil) {
|
|
340
|
+
add("warning", "updates", `Updates are paused until ${u.pausedUntil}.`);
|
|
341
|
+
step(`Resume updates: ${where}.`);
|
|
342
|
+
}
|
|
343
|
+
if (u.daysSince !== null && u.daysSince !== undefined && !s.behind) {
|
|
344
|
+
const ago = u.daysSince <= 1 ? "in the last day" : `${u.daysSince} days ago`;
|
|
345
|
+
if (u.daysSince > 90 && !mac) {
|
|
346
|
+
add("warning", "updates", `${u.anyPackage ? "Software on this system was last installed or updated" : "The last system update was installed"} ${ago}. Security fixes come out every month.`);
|
|
347
|
+
step(`Check for updates: ${where}.`);
|
|
348
|
+
} else if (u.daysSince > 90) add("note", "updates", `The last macOS update was installed ${ago}.`);
|
|
349
|
+
else if (!u.pending?.length) add("ok", "updates", u.anyPackage ? `Software on this system was last installed or updated ${ago}.` : `The last system update was installed ${ago}.`);
|
|
350
|
+
} else if ((u.daysSince === null || u.daysSince === undefined) && !u.pending?.length && !s.behind) add("note", "updates", "I could not see when the last update was installed.");
|
|
351
|
+
if (u.autoOff) {
|
|
352
|
+
add("warning", "updates", "Automatic updates are turned off.");
|
|
353
|
+
step(`Turn on automatic updates: ${where}.`);
|
|
354
|
+
} else if (u.autoPartly) add("note", "updates", "macOS updates are not set to install by themselves, so someone has to click Install. Security responses still install automatically.");
|
|
355
|
+
if (u.restartNeeded) add("note", "updates", "A restart is needed to finish installing updates.");
|
|
356
|
+
|
|
357
|
+
// Malware protection
|
|
358
|
+
const m = f.malware;
|
|
359
|
+
if (win && m) {
|
|
360
|
+
const on = m.products.filter((p) => p.on);
|
|
361
|
+
const stale = on.filter((p) => p.upToDate === false);
|
|
362
|
+
const off = m.products.filter((p) => p.on === false && !/defender/i.test(p.name));
|
|
363
|
+
if (on.length) {
|
|
364
|
+
add(stale.length === on.length ? "warning" : "ok", "malware", stale.length === on.length ? `${on.map((p) => p.name).join(" and ")} is on, but its virus definitions are out of date.` : `Antivirus is on and up to date (${on.map((p) => p.name).join(", ")}).`);
|
|
365
|
+
if (stale.length === on.length) step("Open your antivirus and update it, or open Windows Security > Virus & threat protection > Protection updates.");
|
|
366
|
+
} else if (m.defender?.enabled && m.defender?.realtime) add("ok", "malware", "Antivirus is on (Windows Defender).");
|
|
367
|
+
else if (m.known) {
|
|
368
|
+
add("problem", "malware", "No antivirus is switched on.");
|
|
369
|
+
step("Turn on Windows Security: Settings > Privacy & security > Windows Security > Virus & threat protection. It is built in and free.");
|
|
370
|
+
} else add("note", "malware", "I could not tell whether antivirus is on. Look in Windows Security > Virus & threat protection.");
|
|
371
|
+
if (off.length && (on.length || m.defender?.enabled)) add("note", "malware", `${off.map((p) => p.name).join(" and ")} is installed but not running, often an expired trial. Windows Defender is covering for it; you can uninstall the other one.`);
|
|
372
|
+
} else if (mac && m) {
|
|
373
|
+
if (m.gatekeeper === false) {
|
|
374
|
+
add("warning", "malware", "Gatekeeper is off. It is the part of macOS that stops apps from unknown makers opening without a warning.");
|
|
375
|
+
step("Turn Gatekeeper back on: System Settings > Privacy & Security > allow apps from \"App Store & Known Developers\".");
|
|
376
|
+
}
|
|
377
|
+
if (m.sip === false) {
|
|
378
|
+
add("warning", "malware", "System Integrity Protection is off. It stops software, including malware, from changing macOS itself.");
|
|
379
|
+
step("Turn System Integrity Protection back on (this needs a restart into Recovery; Apple's support site has the steps).");
|
|
380
|
+
}
|
|
381
|
+
if (m.gatekeeper !== false && m.sip !== false) add("ok", "malware", `The built-in macOS protections are on${m.gatekeeper === null || m.sip === null ? " as far as I could see" : ""} (Gatekeeper, System Integrity Protection, and the XProtect malware scanner).`);
|
|
382
|
+
}
|
|
383
|
+
if (f.uacOff) {
|
|
384
|
+
add("warning", "malware", "User Account Control is off, so programs can make system-wide changes without asking you.");
|
|
385
|
+
step("Turn User Account Control back on: search for \"Change User Account Control settings\" and move the slider up.");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Login
|
|
389
|
+
const l = f.login || {};
|
|
390
|
+
if (l.autoLogin === true) {
|
|
391
|
+
add("warning", "login", "This computer signs in by itself without asking for a password. Anyone who opens it has everything.");
|
|
392
|
+
step(mac ? "Turn off automatic login: System Settings > Users & Groups > \"Automatically log in as\" > Off." : win ? "Turn off automatic sign-in: run \"netplwiz\" and tick \"Users must enter a user name and password\"." : "Turn off automatic login in Settings > Users.");
|
|
393
|
+
} else if (l.autoLogin === false) add("ok", "login", "A password (or fingerprint, face or PIN) is needed to sign in after start-up.");
|
|
394
|
+
if (l.screenLock?.on === false) {
|
|
395
|
+
add("warning", "login", "The screen does not lock when the Mac sleeps or the screen saver starts.");
|
|
396
|
+
step("Require a password after sleep: System Settings > Lock Screen > \"Require password after screen saver begins or display is turned off\".");
|
|
397
|
+
} else if (l.screenLock?.on && l.screenLock.delaySec > 900) add("note", "login", `After the screen turns off, the Mac waits ${Math.round(l.screenLock.delaySec / 60)} minutes before asking for the password again.`);
|
|
398
|
+
else if (l.screenLock?.on) add("ok", "login", "The screen locks when it turns off.");
|
|
399
|
+
|
|
400
|
+
// Backup
|
|
401
|
+
const b = f.backup || {};
|
|
402
|
+
if (b.seen && !b.cloudOnly) add("ok", "backup", `${b.seen}. I can't see when it last ran, so check that now and then.`);
|
|
403
|
+
else if (b.seen) {
|
|
404
|
+
add("note", "backup", `${b.seen}. That protects those files if the computer dies, but it is not a full backup: a file deleted or damaged here is deleted or damaged there too.`);
|
|
405
|
+
step(mac ? "For a real backup, plug in an external drive and turn on Time Machine (System Settings > General > Time Machine), or use a backup service." : "For a real backup, plug in an external drive and turn on File History, or use a backup service.");
|
|
406
|
+
} else {
|
|
407
|
+
add("warning", "backup", `I could not see a backup. ${b.hint ? `${b.hint} ` : ""}That does not prove there is none: backup apps I do not know about would not show up here.`);
|
|
408
|
+
step(mac ? "If you have no backup: plug in an external drive and turn on Time Machine (System Settings > General > Time Machine)." : win ? "If you have no backup: turn on OneDrive folder backup (Settings > Accounts > Windows Backup), or plug in an external drive and use File History." : "If you have no backup: set one up with the Backups app (Deja Dup) and an external drive.");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Remote access
|
|
412
|
+
if (f.remote?.length) {
|
|
413
|
+
for (const r of f.remote) add("note", "remote", `${r.what} is turned on. That lets other devices on your network try to connect to this computer. Fine if you use it; if not, turn it off (${r.off}).`);
|
|
414
|
+
} else if (f.remoteKnown) add("ok", "remote", "No remote-access features are turned on.");
|
|
415
|
+
|
|
416
|
+
return { findings, steps, asOf };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const MARK = { problem: "[problem]", warning: "[warning]", note: "[note] ", ok: "[ok] " };
|
|
420
|
+
|
|
421
|
+
export function renderSafety(f) {
|
|
422
|
+
const head = `Computer Vitals: safety check${f.osName ? ` (${f.osName})` : ""}`;
|
|
423
|
+
if (f.failed) return `${head}\n\nI could not read this computer's security settings.`;
|
|
424
|
+
const a = assess(f);
|
|
425
|
+
const count = (lv) => a.findings.filter((x) => x.level === lv).length;
|
|
426
|
+
const bits = [];
|
|
427
|
+
if (count("problem")) bits.push(`${count("problem")} to fix`);
|
|
428
|
+
if (count("warning")) bits.push(`${count("warning")} worth fixing`);
|
|
429
|
+
if (count("note")) bits.push(`${count("note")} to know about`);
|
|
430
|
+
bits.push(`${count("ok")} fine`);
|
|
431
|
+
const lines = [head, "", `Summary: ${bits.join(", ")}.`, "", "What I found"];
|
|
432
|
+
const order = { problem: 0, warning: 1, note: 2, ok: 3 };
|
|
433
|
+
for (const x of [...a.findings].sort((p, q) => order[p.level] - order[q.level])) lines.push(`${MARK[x.level]} ${x.text}`);
|
|
434
|
+
if (a.steps.length) {
|
|
435
|
+
lines.push("", "What to do");
|
|
436
|
+
a.steps.forEach((s, i) => lines.push(`${i + 1}. ${s}`));
|
|
437
|
+
}
|
|
438
|
+
lines.push(
|
|
439
|
+
"",
|
|
440
|
+
`About this check: it reads settings only. It is not a virus scan: it does not look inside files, and it cannot tell whether this computer is already infected. Nothing was changed and nothing was sent anywhere. ${f.platform === "linux" ? "" : `Which versions still get updates comes from a list bundled with this version of Computer Vitals, as of ${a.asOf}.`}`.trim(),
|
|
441
|
+
);
|
|
442
|
+
return lines.join("\n");
|
|
443
|
+
}
|