Line data Source code
1 : /*
2 : * Copyright (C) 2024 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 : import * as python from "python";
7 :
8 : // @ts-expect-error TS2307 this isn't a TS module, just a magic esbuild "text" import rule
9 : import lastlog2_py from "./lastlog2.py";
10 :
11 : export type LastlogEntry = {
12 : time: number;
13 : tty: string;
14 : host: string;
15 : };
16 :
17 : /* Return lastlog2 database as { username → LastLogin } object.
18 : * Throws an exception if the db does not exist, i.e. the system isn't using lastlog2.
19 : */
20 100 : export async function getLastlog2(user?: string): Promise<Record<string, LastlogEntry>> {
21 18 : const out = await python.spawn(lastlog2_py, user ? [user] : [], { err: "message" });
22 93 : return JSON.parse(out);
23 100 : }
|