@axium/sysadmin 0.0.1
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.md +157 -0
- package/README.md +3 -0
- package/db.json +77 -0
- package/dist/_probe.d.ts +1 -0
- package/dist/_probe.js +4 -0
- package/dist/client/.info.js +38 -0
- package/dist/client/cli.d.ts +1 -0
- package/dist/client/cli.js +109 -0
- package/dist/client/hooks.d.ts +1 -0
- package/dist/client/hooks.js +1 -0
- package/dist/client/info.d.ts +2 -0
- package/dist/client/info.js +171 -0
- package/dist/client/socket.d.ts +1 -0
- package/dist/client/socket.js +9 -0
- package/dist/common.d.ts +371 -0
- package/dist/common.js +65 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/info.d.ts +95 -0
- package/dist/info.js +58 -0
- package/dist/server/api.d.ts +1 -0
- package/dist/server/api.js +136 -0
- package/dist/server/db.d.ts +7 -0
- package/dist/server/db.js +1 -0
- package/dist/server/hooks.d.ts +3 -0
- package/dist/server/hooks.js +3 -0
- package/dist/server/socket.d.ts +1 -0
- package/dist/server/socket.js +9 -0
- package/dist/web_hook.d.ts +8 -0
- package/dist/web_hook.js +4 -0
- package/lib/SystemCard.svelte +133 -0
- package/lib/SystemInitDialog.svelte +59 -0
- package/lib/UserCard.svelte +108 -0
- package/lib/UserInitDialog.svelte +49 -0
- package/lib/index.ts +4 -0
- package/lib/tsconfig.json +12 -0
- package/locales/en.json +79 -0
- package/package.json +71 -0
- package/routes/sysadmin/+layout.ts +22 -0
- package/routes/sysadmin/+page.svelte +115 -0
- package/routes/sysadmin/+page.ts +14 -0
- package/routes/sysadmin/systems/+page.svelte +92 -0
- package/routes/sysadmin/systems/+page.ts +11 -0
- package/routes/sysadmin/systems/[id]/+page.svelte +290 -0
- package/routes/sysadmin/systems/[id]/+page.ts +11 -0
- package/routes/sysadmin/users/+page.svelte +85 -0
- package/routes/sysadmin/users/+page.ts +11 -0
- package/routes/sysadmin/users/[id]/+page.svelte +82 -0
- package/routes/sysadmin/users/[id]/+page.ts +11 -0
- package/routes/tsconfig.json +12 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
6
|
+
<https://fsf.org/>
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
9
|
+
license document, but changing it is not allowed.
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
|
13
|
+
supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
## 0. Additional Definitions.
|
|
16
|
+
|
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
|
19
|
+
GNU General Public License.
|
|
20
|
+
|
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
|
22
|
+
than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
|
32
|
+
Version".
|
|
33
|
+
|
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
## 2. Conveying Modified Versions.
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
|
58
|
+
to ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from a
|
|
67
|
+
header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
|
74
|
+
the Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
|
77
|
+
license document.
|
|
78
|
+
|
|
79
|
+
## 4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
|
82
|
+
together, effectively do not restrict modification of the portions of
|
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
|
84
|
+
debugging such modifications, if you also do each of the following:
|
|
85
|
+
|
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
|
87
|
+
the Library is used in it and that the Library and its use are
|
|
88
|
+
covered by this License.
|
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
|
90
|
+
license document.
|
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
|
92
|
+
execution, include the copyright notice for the Library among
|
|
93
|
+
these notices, as well as a reference directing the user to the
|
|
94
|
+
copies of the GNU GPL and this license document.
|
|
95
|
+
- d) Do one of the following:
|
|
96
|
+
- 0) Convey the Minimal Corresponding Source under the terms of
|
|
97
|
+
this License, and the Corresponding Application Code in a form
|
|
98
|
+
suitable for, and under terms that permit, the user to
|
|
99
|
+
recombine or relink the Application with a modified version of
|
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
102
|
+
Corresponding Source.
|
|
103
|
+
- 1) Use a suitable shared library mechanism for linking with
|
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
|
105
|
+
time a copy of the Library already present on the user's
|
|
106
|
+
computer system, and (b) will operate properly with a modified
|
|
107
|
+
version of the Library that is interface-compatible with the
|
|
108
|
+
Linked Version.
|
|
109
|
+
- e) Provide Installation Information, but only if you would
|
|
110
|
+
otherwise be required to provide such information under section 6
|
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
|
112
|
+
necessary to install and execute a modified version of the
|
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
|
119
|
+
Corresponding Source.)
|
|
120
|
+
|
|
121
|
+
## 5. Combined Libraries.
|
|
122
|
+
|
|
123
|
+
You may place library facilities that are a work based on the Library
|
|
124
|
+
side by side in a single library together with other library
|
|
125
|
+
facilities that are not Applications and are not covered by this
|
|
126
|
+
License, and convey such a combined library under terms of your
|
|
127
|
+
choice, if you do both of the following:
|
|
128
|
+
|
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
|
130
|
+
based on the Library, uncombined with any other library
|
|
131
|
+
facilities, conveyed under the terms of this License.
|
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
|
133
|
+
is a work based on the Library, and explaining where to find the
|
|
134
|
+
accompanying uncombined form of the same work.
|
|
135
|
+
|
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
|
137
|
+
|
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
140
|
+
versions will be similar in spirit to the present version, but may
|
|
141
|
+
differ in detail to address new problems or concerns.
|
|
142
|
+
|
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
|
144
|
+
as you received it specifies that a certain numbered version of the
|
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
|
146
|
+
it, you have the option of following the terms and conditions either
|
|
147
|
+
of that published version or of any later version published by the
|
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
|
151
|
+
published by the Free Software Foundation.
|
|
152
|
+
|
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
156
|
+
permanent authorization for you to choose that version for the
|
|
157
|
+
Library.
|
package/README.md
ADDED
package/db.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../server/schemas/db.json",
|
|
3
|
+
"format": 1,
|
|
4
|
+
"versions": [
|
|
5
|
+
{
|
|
6
|
+
"delta": false,
|
|
7
|
+
"tables": {
|
|
8
|
+
"systems": {
|
|
9
|
+
"columns": {
|
|
10
|
+
"id": { "type": "uuid", "required": true, "primary": true, "default": "gen_random_uuid()" },
|
|
11
|
+
"userId": { "type": "uuid", "required": true, "references": "users.id", "onDelete": "cascade" },
|
|
12
|
+
"name": { "type": "text", "required": true },
|
|
13
|
+
"hostname": { "type": "text", "required": true }
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"system_users": {
|
|
17
|
+
"columns": {
|
|
18
|
+
"id": { "type": "uuid", "required": true, "primary": true, "default": "gen_random_uuid()" },
|
|
19
|
+
"userId": { "type": "uuid", "required": true, "references": "users.id", "onDelete": "cascade" },
|
|
20
|
+
"name": { "type": "text", "required": true },
|
|
21
|
+
"username": { "type": "text", "required": true }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"acl.systems": {
|
|
25
|
+
"columns": {
|
|
26
|
+
"userId": { "type": "uuid", "references": "users.id", "onDelete": "cascade" },
|
|
27
|
+
"itemId": { "type": "uuid", "required": true, "references": "systems.id", "onDelete": "cascade" },
|
|
28
|
+
"createdAt": { "type": "timestamptz", "required": true, "default": "now()" },
|
|
29
|
+
"role": { "type": "text" },
|
|
30
|
+
"tag": { "type": "text" },
|
|
31
|
+
"read": { "type": "boolean", "required": true, "default": false },
|
|
32
|
+
"edit": { "type": "boolean", "required": true, "default": false },
|
|
33
|
+
"manage": { "type": "boolean", "required": true, "default": false }
|
|
34
|
+
},
|
|
35
|
+
"constraints": {
|
|
36
|
+
"unique_systems": { "type": "unique", "on": ["itemId", "userId", "role", "tag"], "nulls_not_distinct": true }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"indexes": {
|
|
41
|
+
"systems_userId": { "on": "systems", "columns": ["userId"] },
|
|
42
|
+
"system_users_userId": { "on": "system_users", "columns": ["userId"] },
|
|
43
|
+
"acl_systems_userId": { "on": "acl.systems", "columns": ["userId"] },
|
|
44
|
+
"acl_systems_itemId": { "on": "acl.systems", "columns": ["itemId"] }
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"delta": true,
|
|
49
|
+
"alter_tables": {
|
|
50
|
+
"systems": {
|
|
51
|
+
"add_columns": {
|
|
52
|
+
"type": { "type": "text", "required": true, "default": "'server'" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"delta": true,
|
|
59
|
+
"alter_tables": {
|
|
60
|
+
"systems": {
|
|
61
|
+
"add_constraints": {
|
|
62
|
+
"unique_systems_hostname": { "type": "unique", "on": ["userId", "hostname"] }
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"system_users": {
|
|
66
|
+
"add_constraints": {
|
|
67
|
+
"unique_system_users_username": { "type": "unique", "on": ["userId", "username"] }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"wipe": ["systems", "system_users", "acl.systems"],
|
|
74
|
+
"acl_tables": {
|
|
75
|
+
"systems": "acl.systems"
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/_probe.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/_probe.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { systemInfo } from './info.js';
|
|
2
|
+
import { formatBytes } from '@axium/core';
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
|
+
|
|
5
|
+
const t = ' ',
|
|
6
|
+
t2 = ' ';
|
|
7
|
+
|
|
8
|
+
const { cpus, gpus, memory, storage, networkInterfaces, uptime, ...rest } = systemInfo();
|
|
9
|
+
|
|
10
|
+
function usage(info) {
|
|
11
|
+
return styleText('blueBright', formatBytes(info.used)) + '/' + styleText('blueBright', formatBytes(info.total));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const num = value => styleText('blueBright', value.toString());
|
|
15
|
+
|
|
16
|
+
console.log('CPUs:');
|
|
17
|
+
for (const cpu of cpus) console.log(t, num(cpu.cores) + 'x', styleText('yellow', cpu.model));
|
|
18
|
+
|
|
19
|
+
console.log('GPUs:');
|
|
20
|
+
for (const gpu of gpus) {
|
|
21
|
+
console.log(t, styleText('yellow', gpu.model));
|
|
22
|
+
if (gpu.vram) console.log(t2, 'VRAM:', usage(gpu.vram));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log('Memory:', usage(memory));
|
|
26
|
+
if (memory.swap) console.log(t, 'Swap:', usage(memory.swap));
|
|
27
|
+
|
|
28
|
+
console.log('Storage:');
|
|
29
|
+
for (const drive of storage) console.log(t, styleText('yellow', drive.model), usage(drive));
|
|
30
|
+
|
|
31
|
+
console.log('Network:');
|
|
32
|
+
for (const iface of networkInterfaces) {
|
|
33
|
+
console.log(t, styleText('cyanBright', iface.name), styleText('yellow', iface.model), iface.wireless ? '(wireless)' : '(wired)');
|
|
34
|
+
if (iface.connected)
|
|
35
|
+
console.log(t2, iface.connection ? 'Connected to ' + iface.connection : 'Connected', 'at', num(iface.speed), 'MBit/s');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log(rest);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './socket.js';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { session } from '@axium/client/cli/config';
|
|
2
|
+
import { fetchAPI } from '@axium/client/requests';
|
|
3
|
+
import { connect } from '@axium/client/socket';
|
|
4
|
+
import { formatBytes, formatDuration } from '@axium/core';
|
|
5
|
+
import { program } from 'commander';
|
|
6
|
+
import * as io from 'ioium/node';
|
|
7
|
+
import { styleText } from 'node:util';
|
|
8
|
+
import './socket.js';
|
|
9
|
+
function usage(info) {
|
|
10
|
+
return styleText('blueBright', formatBytes(info.used)) + '/' + styleText('blueBright', formatBytes(info.total));
|
|
11
|
+
}
|
|
12
|
+
const num = (value) => value === undefined ? styleText('red', '<unknown>') : styleText('blueBright', value.toString());
|
|
13
|
+
const tab = ' ', tab2 = ' ';
|
|
14
|
+
function dumpInfo(system, info) {
|
|
15
|
+
console.log(styleText('bold', `${system.hostname} "${system.name}"`), styleText('dim', `(${system.id})`));
|
|
16
|
+
const { cpus, gpus, memory, storage, networkInterfaces, uptime, ...rest } = info;
|
|
17
|
+
console.log('CPUs:');
|
|
18
|
+
for (const cpu of cpus)
|
|
19
|
+
console.log(tab, num(cpu.cores) + 'x', styleText('yellow', cpu.model));
|
|
20
|
+
console.log('GPUs:');
|
|
21
|
+
for (const gpu of gpus) {
|
|
22
|
+
console.log(tab, styleText('yellow', gpu.model));
|
|
23
|
+
if (gpu.vram)
|
|
24
|
+
console.log(tab2, 'VRAM:', usage(gpu.vram));
|
|
25
|
+
}
|
|
26
|
+
console.log('Memory:', usage(memory));
|
|
27
|
+
if (memory.swap)
|
|
28
|
+
console.log(tab, 'Swap:', usage(memory.swap));
|
|
29
|
+
console.log('Storage:');
|
|
30
|
+
for (const drive of storage)
|
|
31
|
+
console.log(tab, styleText('yellow', drive.model), usage(drive));
|
|
32
|
+
console.log('Network:');
|
|
33
|
+
for (const iface of networkInterfaces) {
|
|
34
|
+
console.log(tab, styleText('cyanBright', iface.name), styleText('yellow', iface.model), iface.wireless ? '(wireless)' : '(wired)');
|
|
35
|
+
if (iface.connected)
|
|
36
|
+
console.log(tab2, iface.connection ? 'Connected to ' + iface.connection : 'Connected', 'at', num(iface.speed), 'MBit/s');
|
|
37
|
+
}
|
|
38
|
+
console.log('Uptime:', formatDuration(uptime));
|
|
39
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
40
|
+
console.log(key + ':', value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function getSystems() {
|
|
44
|
+
return await fetchAPI('GET', 'users/:id/sysadmin/systems', {}, session().userId);
|
|
45
|
+
}
|
|
46
|
+
async function getUsers() {
|
|
47
|
+
return await fetchAPI('GET', 'users/:id/sysadmin/users', {}, session().userId);
|
|
48
|
+
}
|
|
49
|
+
/** Resolve a system by its ID or hostname. */
|
|
50
|
+
function resolveSystem(systems, search) {
|
|
51
|
+
const system = systems.find(s => s.id === search || s.hostname === search);
|
|
52
|
+
if (!system)
|
|
53
|
+
io.exit(`No system matching "${search}".`);
|
|
54
|
+
return system;
|
|
55
|
+
}
|
|
56
|
+
/** Resolve a system user by its ID or username. */
|
|
57
|
+
function resolveUser(users, search) {
|
|
58
|
+
const user = users.find(u => u.id === search || u.username === search);
|
|
59
|
+
if (!user)
|
|
60
|
+
io.exit(`No system user matching "${search}".`);
|
|
61
|
+
return user;
|
|
62
|
+
}
|
|
63
|
+
function listSystems(systems) {
|
|
64
|
+
for (const system of systems) {
|
|
65
|
+
console.log(styleText('bold', system.hostname), styleText('yellow', system.type), `"${system.name}"`, styleText('dim', `(${system.id})`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function listUsers(users) {
|
|
69
|
+
for (const user of users) {
|
|
70
|
+
console.log(styleText('bold', user.username), `"${user.name}"`, styleText('dim', `(${user.id})`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const cli = program.command('sysadmin').helpGroup('Plugins:').description('CLI integration for @axium/sysadmin');
|
|
74
|
+
cli.action(async () => {
|
|
75
|
+
const [systems, users] = await Promise.all([getSystems(), getUsers()]);
|
|
76
|
+
console.log(styleText('whiteBright', `${systems.length} system(s):`));
|
|
77
|
+
listSystems(systems);
|
|
78
|
+
console.log(styleText('whiteBright', `\n${users.length} user(s):`));
|
|
79
|
+
listUsers(users);
|
|
80
|
+
});
|
|
81
|
+
cli.command('systems')
|
|
82
|
+
.description('List systems')
|
|
83
|
+
.action(async () => listSystems(await getSystems()));
|
|
84
|
+
cli.command('users')
|
|
85
|
+
.description('List system users')
|
|
86
|
+
.action(async () => listUsers(await getUsers()));
|
|
87
|
+
cli.command('system')
|
|
88
|
+
.description('Show information about a system')
|
|
89
|
+
.argument('<system>', 'the hostname or ID of the system')
|
|
90
|
+
.option('--insecure', 'allow connecting to a server with an untrusted (e.g. self-signed) TLS certificate', false)
|
|
91
|
+
.action(async (search, opt) => {
|
|
92
|
+
const system = resolveSystem(await getSystems(), search);
|
|
93
|
+
const socket = await connect({ rejectUnauthorized: !opt.insecure });
|
|
94
|
+
const all = await socket.emitWithAck('sysadmin:getSystemInfo').catch(() => undefined);
|
|
95
|
+
const info = all?.find(i => i.hostname === system.hostname);
|
|
96
|
+
if (!info) {
|
|
97
|
+
console.log(styleText('bold', `${system.hostname} "${system.name}"`), styleText('dim', `(${system.id})`));
|
|
98
|
+
io.exit('System is offline; live information is unavailable.', 1);
|
|
99
|
+
}
|
|
100
|
+
dumpInfo(system, info);
|
|
101
|
+
process.exit();
|
|
102
|
+
});
|
|
103
|
+
cli.command('user')
|
|
104
|
+
.description('Show information about a system user')
|
|
105
|
+
.argument('<user>', 'the username or ID of the system user')
|
|
106
|
+
.action(async (search) => {
|
|
107
|
+
const user = resolveUser(await getUsers(), search);
|
|
108
|
+
console.log(styleText('bold', `${user.username} "${user.name}"`), styleText('dim', `(${user.id})`));
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './socket.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './socket.js'; // Registers socket listeners
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
/** Read a sysfs/procfs file, returning the trimmed contents or undefined if unreadable. */
|
|
4
|
+
function read(path) {
|
|
5
|
+
try {
|
|
6
|
+
return fs.readFileSync(path, 'utf8').trim();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function list(path) {
|
|
13
|
+
try {
|
|
14
|
+
return fs.readdirSync(path);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let pciDb;
|
|
21
|
+
/** Map `vendor:device` PCI IDs (lowercase hex) to a human-readable name using the system pci.ids database. */
|
|
22
|
+
function pciName(id) {
|
|
23
|
+
const [vendor, device] = id.toLowerCase().split(':');
|
|
24
|
+
if (!pciDb)
|
|
25
|
+
pciDb = read('/usr/share/hwdata/pci.ids') ?? read('/usr/share/misc/pci.ids');
|
|
26
|
+
if (!pciDb || !vendor || !device)
|
|
27
|
+
return id;
|
|
28
|
+
let inVendor = false;
|
|
29
|
+
for (const line of pciDb.split('\n')) {
|
|
30
|
+
if (line.startsWith('#') || !line.trim())
|
|
31
|
+
continue;
|
|
32
|
+
if (!line.startsWith('\t')) {
|
|
33
|
+
// Vendor line: `1002 Advanced Micro Devices, Inc. [AMD/ATI]`
|
|
34
|
+
inVendor = line.slice(0, 4).toLowerCase() === vendor;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (!inVendor || line.startsWith('\t\t'))
|
|
38
|
+
continue;
|
|
39
|
+
// Device line: `\t7550 Device name`
|
|
40
|
+
const entry = line.slice(1);
|
|
41
|
+
if (entry.slice(0, 4).toLowerCase() === device)
|
|
42
|
+
return entry.slice(4).trim();
|
|
43
|
+
}
|
|
44
|
+
return id;
|
|
45
|
+
}
|
|
46
|
+
function gpus() {
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
const result = [];
|
|
49
|
+
for (const card of list('/sys/class/drm')) {
|
|
50
|
+
// Only whole cards (`card0`), not connectors (`card0-DP-1`) or render nodes.
|
|
51
|
+
if (!/^card\d+$/.test(card))
|
|
52
|
+
continue;
|
|
53
|
+
const uevent = read(`/sys/class/drm/${card}/device/uevent`);
|
|
54
|
+
const id = uevent && /^PCI_ID=(.+)$/m.exec(uevent)?.[1];
|
|
55
|
+
if (!id || seen.has(id))
|
|
56
|
+
continue;
|
|
57
|
+
seen.add(id);
|
|
58
|
+
// VRAM totals are exposed by some drivers (e.g. amdgpu) in bytes.
|
|
59
|
+
const vramTotal = read(`/sys/class/drm/${card}/device/mem_info_vram_total`);
|
|
60
|
+
const vramUsed = read(`/sys/class/drm/${card}/device/mem_info_vram_used`);
|
|
61
|
+
const vram = vramTotal && vramUsed ? { total: BigInt(vramTotal), used: BigInt(vramUsed) } : undefined;
|
|
62
|
+
result.push({ model: pciName(id), vram });
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/** Map mounted block devices to the filesystem usage (bytes) of their mount point. */
|
|
67
|
+
function mountUsage() {
|
|
68
|
+
const usage = new Map();
|
|
69
|
+
const mounts = read('/proc/mounts');
|
|
70
|
+
if (!mounts)
|
|
71
|
+
return usage;
|
|
72
|
+
for (const line of mounts.split('\n')) {
|
|
73
|
+
const [source, mountPoint] = line.split(' ');
|
|
74
|
+
if (!source?.startsWith('/dev/'))
|
|
75
|
+
continue;
|
|
76
|
+
let stat;
|
|
77
|
+
try {
|
|
78
|
+
stat = fs.statfsSync(mountPoint, { bigint: true });
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const total = stat.blocks * stat.bsize;
|
|
84
|
+
const used = (stat.blocks - stat.bfree) * stat.bsize;
|
|
85
|
+
usage.set(source.slice('/dev/'.length), { total, used });
|
|
86
|
+
}
|
|
87
|
+
return usage;
|
|
88
|
+
}
|
|
89
|
+
function storage() {
|
|
90
|
+
const usage = mountUsage();
|
|
91
|
+
const result = [];
|
|
92
|
+
for (const dev of list('/sys/block')) {
|
|
93
|
+
// Skip virtual devices (zram, loop, device-mapper) which have no backing `device`.
|
|
94
|
+
if (!fs.existsSync(`/sys/block/${dev}/device`))
|
|
95
|
+
continue;
|
|
96
|
+
const sectors = read(`/sys/block/${dev}/size`);
|
|
97
|
+
if (!sectors)
|
|
98
|
+
continue;
|
|
99
|
+
// `size` is always in 512-byte sectors regardless of logical block size.
|
|
100
|
+
const total = BigInt(sectors) * 512n;
|
|
101
|
+
// Sum filesystem usage across mounted partitions of this disk.
|
|
102
|
+
let used = 0n;
|
|
103
|
+
for (const [mounted, info] of usage) {
|
|
104
|
+
if (mounted === dev || mounted.startsWith(dev + 'p') || (mounted.startsWith(dev) && /\d$/.test(mounted))) {
|
|
105
|
+
used += info.used;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const model = read(`/sys/block/${dev}/device/model`)?.trim() || dev;
|
|
109
|
+
result.push({ model, total, used });
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
function memory() {
|
|
114
|
+
const info = {};
|
|
115
|
+
const content = read('/proc/meminfo');
|
|
116
|
+
if (content)
|
|
117
|
+
for (const line of content.split('\n')) {
|
|
118
|
+
const match = /^(\w+):\s+(\d+)(?:\s+kB)?$/.exec(line.trim());
|
|
119
|
+
if (!match)
|
|
120
|
+
continue;
|
|
121
|
+
const [, key, value] = match;
|
|
122
|
+
info[key] = BigInt(value) * (line.endsWith('kB') ? 1024n : 1n);
|
|
123
|
+
}
|
|
124
|
+
const total = info.MemTotal ?? BigInt(os.totalmem());
|
|
125
|
+
const available = info.MemAvailable ?? BigInt(os.freemem());
|
|
126
|
+
const memory = {
|
|
127
|
+
speed: 0,
|
|
128
|
+
total,
|
|
129
|
+
used: total - available,
|
|
130
|
+
};
|
|
131
|
+
const swapTotal = info.SwapTotal ?? 0n;
|
|
132
|
+
if (swapTotal > 0n)
|
|
133
|
+
memory.swap = { total: swapTotal, used: swapTotal - (info.SwapFree ?? 0n) };
|
|
134
|
+
return memory;
|
|
135
|
+
}
|
|
136
|
+
function networkInterfaces() {
|
|
137
|
+
const result = [];
|
|
138
|
+
for (const name of list('/sys/class/net')) {
|
|
139
|
+
if (name === 'lo')
|
|
140
|
+
continue;
|
|
141
|
+
const operstate = read(`/sys/class/net/${name}/operstate`);
|
|
142
|
+
const connected = operstate === 'up' || read(`/sys/class/net/${name}/carrier`) === '1';
|
|
143
|
+
// `speed` is in Mbit/s; only valid for connected links and may be -1/unreadable.
|
|
144
|
+
const raw = read(`/sys/class/net/${name}/speed`);
|
|
145
|
+
const speed = connected && raw && Number(raw) > 0 ? BigInt(raw) : undefined;
|
|
146
|
+
// Wi-Fi devices expose a `wireless`/`phy80211` subdirectory.
|
|
147
|
+
const wireless = fs.existsSync(`/sys/class/net/${name}/wireless`) || fs.existsSync(`/sys/class/net/${name}/phy80211`);
|
|
148
|
+
const uevent = read(`/sys/class/net/${name}/device/uevent`);
|
|
149
|
+
const id = uevent && /^PCI_ID=(.+)$/m.exec(uevent)?.[1];
|
|
150
|
+
const model = id ? pciName(id) : name;
|
|
151
|
+
result.push({ name, model, connected, wireless, speed });
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
export function systemInfo() {
|
|
156
|
+
return {
|
|
157
|
+
cpus: Object.entries(Object.groupBy(os.cpus(), cpu => cpu.model)).map(([model, info]) => ({ model, cores: info?.length || 1 })),
|
|
158
|
+
gpus: gpus(),
|
|
159
|
+
memory: memory(),
|
|
160
|
+
storage: storage(),
|
|
161
|
+
networkInterfaces: networkInterfaces(),
|
|
162
|
+
arch: os.arch(),
|
|
163
|
+
machine: os.machine(),
|
|
164
|
+
platform: os.platform(),
|
|
165
|
+
release: os.release(),
|
|
166
|
+
type: os.type(),
|
|
167
|
+
uptime: os.uptime(),
|
|
168
|
+
version: os.version(),
|
|
169
|
+
hostname: os.hostname(),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../common.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { addListener } from '@axium/client/socket';
|
|
2
|
+
import '../common.js';
|
|
3
|
+
import { systemInfo } from './info.js';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
addListener('sysadmin:ping', cb => cb({
|
|
6
|
+
hostname: os.hostname(),
|
|
7
|
+
username: os.userInfo().username,
|
|
8
|
+
}));
|
|
9
|
+
addListener('sysadmin:getSystemInfo', cb => cb(systemInfo()));
|