typescript-virtual-container 1.5.3 → 1.5.4
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/README.md +43 -23
- package/dist/.tsbuildinfo +1 -0
- package/dist/SSHMimic/executor.js +23 -5
- package/dist/VirtualPackageManager/index.js +10 -0
- package/dist/commands/basename.d.ts +13 -0
- package/dist/commands/basename.js +45 -0
- package/dist/commands/file.d.ts +8 -0
- package/dist/commands/file.js +57 -0
- package/dist/commands/fun.d.ts +32 -0
- package/dist/commands/fun.js +172 -0
- package/dist/commands/ifconfig.d.ts +7 -0
- package/dist/commands/ifconfig.js +52 -0
- package/dist/commands/last.d.ts +13 -0
- package/dist/commands/last.js +68 -0
- package/dist/commands/manuals-bundle.js +598 -6
- package/dist/commands/registry.js +24 -2
- package/dist/commands/runtime.js +22 -2
- package/dist/commands/sh.js +5 -0
- package/dist/commands/tput.d.ts +13 -0
- package/dist/commands/tput.js +76 -0
- package/dist/commands/w.d.ts +7 -0
- package/dist/commands/w.js +38 -0
- package/dist/utils/expand.d.ts +12 -0
- package/dist/utils/expand.js +84 -0
- package/package.json +9 -3
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -50
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -31
- package/.github/dependabot.yml +0 -27
- package/.github/pull_request_template.md +0 -21
- package/.github/workflows/create-pull-request.yml +0 -85
- package/.github/workflows/publish.yml +0 -25
- package/.github/workflows/test-battery.yml +0 -102
- package/.vscode/settings.json +0 -20
- package/CODE_OF_CONDUCT.md +0 -39
- package/CONTRIBUTING.md +0 -59
- package/HONEYPOT.md +0 -358
- package/SECURITY.md +0 -33
- package/benchmark-results.txt +0 -40
- package/benchmark-virtualshell.ts +0 -88
- package/biome.json +0 -37
- package/build.js +0 -22
- package/builds/fortune-nyx-v1.5.3-directbash-k6.1.0.mjs +0 -1764
- package/builds/fortune-nyx-v1.5.3-ssh-nosftp.js +0 -1764
- package/builds/fortune-nyx-v1.5.3-ssh.cjs +0 -1765
- package/builds/fortune-nyx-v1.5.3-web.min.js +0 -17036
- package/bun.lock +0 -244
- package/docs/.nojekyll +0 -1
- package/docs/app.js +0 -1751
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -162
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1633
- package/docs/classes/HoneyPot.html +0 -31
- package/docs/classes/IdleManager.html +0 -162
- package/docs/classes/SshClient.html +0 -66
- package/docs/classes/VirtualFileSystem.html +0 -279
- package/docs/classes/VirtualPackageManager.html +0 -63
- package/docs/classes/VirtualSftpServer.html +0 -169
- package/docs/classes/VirtualShell.html +0 -285
- package/docs/classes/VirtualSshServer.html +0 -182
- package/docs/classes/VirtualUserManager.html +0 -276
- package/docs/demo.html +0 -82
- package/docs/functions/assertDiff.html +0 -6
- package/docs/functions/diffSnapshots.html +0 -7
- package/docs/functions/formatDiff.html +0 -6
- package/docs/functions/getArg.html +0 -13
- package/docs/functions/getFlag.html +0 -15
- package/docs/functions/ifFlag.html +0 -11
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -1869
- package/docs/interfaces/AuditLogEntry.html +0 -6
- package/docs/interfaces/CommandContext.html +0 -22
- package/docs/interfaces/CommandResult.html +0 -26
- package/docs/interfaces/ExecStream.html +0 -11
- package/docs/interfaces/HoneyPotStats.html +0 -16
- package/docs/interfaces/IdleManagerOptions.html +0 -7
- package/docs/interfaces/InstalledPackage.html +0 -20
- package/docs/interfaces/NanoEditorSession.html +0 -8
- package/docs/interfaces/PackageDefinition.html +0 -30
- package/docs/interfaces/PackageFile.html +0 -8
- package/docs/interfaces/PasswordChallenge.html +0 -16
- package/docs/interfaces/RemoveOptions.html +0 -4
- package/docs/interfaces/ShellEnv.html +0 -6
- package/docs/interfaces/ShellModule.html +0 -14
- package/docs/interfaces/ShellProperties.html +0 -14
- package/docs/interfaces/ShellStream.html +0 -11
- package/docs/interfaces/SudoChallenge.html +0 -24
- package/docs/interfaces/VfsBaseNode.html +0 -12
- package/docs/interfaces/VfsDiff.html +0 -10
- package/docs/interfaces/VfsDiffEntry.html +0 -6
- package/docs/interfaces/VfsDiffModified.html +0 -10
- package/docs/interfaces/VfsDirectoryNode.html +0 -15
- package/docs/interfaces/VfsFileNode.html +0 -17
- package/docs/interfaces/VfsOptions.html +0 -26
- package/docs/interfaces/VfsSnapshot.html +0 -3
- package/docs/interfaces/VfsSnapshotBaseNode.html +0 -8
- package/docs/interfaces/VfsSnapshotDirectoryNode.html +0 -10
- package/docs/interfaces/VfsSnapshotFileNode.html +0 -12
- package/docs/interfaces/VirtualActiveSession.html +0 -12
- package/docs/interfaces/VirtualSftpServerOptions.html +0 -7
- package/docs/interfaces/VirtualShellVfsLike.html +0 -15
- package/docs/interfaces/VirtualShellVfsOptions.html +0 -3
- package/docs/interfaces/WriteFileOptions.html +0 -6
- package/docs/media/LICENSE +0 -21
- package/docs/modules.html +0 -1
- package/docs/types/ArgParseOptions.html +0 -4
- package/docs/types/CommandMode.html +0 -2
- package/docs/types/CommandOutcome.html +0 -2
- package/docs/types/IdleState.html +0 -1
- package/docs/types/VfsNodeStats.html +0 -2
- package/docs/types/VfsNodeType.html +0 -2
- package/docs/types/VfsPersistenceMode.html +0 -5
- package/docs/types/VfsSnapshotNode.html +0 -2
- package/examples/README.md +0 -288
- package/examples/app.js +0 -1751
- package/examples/app.ts +0 -299
- package/examples/build.js +0 -27
- package/examples/demo.html +0 -33
- package/examples/honeypot-audit.ts +0 -180
- package/examples/honeypot-export.ts +0 -253
- package/examples/honeypot-quickstart.ts +0 -110
- package/examples/index.html +0 -82
- package/examples/server.js +0 -55
- package/polyfills/buffer.js +0 -117
- package/polyfills/node_child_process/index.js +0 -2
- package/polyfills/node_crypto/index.js +0 -167
- package/polyfills/node_events/index.js +0 -9
- package/polyfills/node_fs/index.js +0 -202
- package/polyfills/node_fs/promises.js +0 -4
- package/polyfills/node_os/index.js +0 -9
- package/polyfills/node_path/index.js +0 -28
- package/polyfills/node_vm/index.js +0 -7
- package/polyfills/node_zlib/index.js +0 -3
- package/polyfills/process.js +0 -14
- package/polyfills/ssh2/index.js +0 -75
- package/scripts/build-all.mjs +0 -226
- package/scripts/build-names.mjs +0 -43
- package/scripts/generate-manuals-bundle.mjs +0 -49
- package/scripts/postinstall.js +0 -42
- package/scripts/publish-package.sh +0 -70
- package/src/Honeypot/index.ts +0 -457
- package/src/SSHClient/index.ts +0 -270
- package/src/SSHMimic/exec.ts +0 -49
- package/src/SSHMimic/executor.ts +0 -251
- package/src/SSHMimic/hostKey.ts +0 -21
- package/src/SSHMimic/index.ts +0 -337
- package/src/SSHMimic/loginBanner.ts +0 -36
- package/src/SSHMimic/loginFormat.ts +0 -10
- package/src/SSHMimic/prompt.ts +0 -14
- package/src/SSHMimic/sftp.ts +0 -883
- package/src/VirtualFileSystem/binaryPack.ts +0 -258
- package/src/VirtualFileSystem/index.ts +0 -1193
- package/src/VirtualFileSystem/internalTypes.ts +0 -43
- package/src/VirtualFileSystem/journal.ts +0 -171
- package/src/VirtualFileSystem/path.ts +0 -74
- package/src/VirtualPackageManager/index.ts +0 -996
- package/src/VirtualShell/idleManager.ts +0 -137
- package/src/VirtualShell/index.ts +0 -475
- package/src/VirtualShell/shell.ts +0 -700
- package/src/VirtualShell/shellParser.ts +0 -285
- package/src/VirtualUserManager/index.ts +0 -758
- package/src/bun.d.ts +0 -1
- package/src/commands/adduser.ts +0 -103
- package/src/commands/alias.ts +0 -69
- package/src/commands/apt.ts +0 -233
- package/src/commands/awk.ts +0 -168
- package/src/commands/base64.ts +0 -29
- package/src/commands/cat.ts +0 -52
- package/src/commands/cd.ts +0 -25
- package/src/commands/chmod.ts +0 -85
- package/src/commands/clear.ts +0 -15
- package/src/commands/command-helpers.ts +0 -286
- package/src/commands/cp.ts +0 -83
- package/src/commands/curl.ts +0 -147
- package/src/commands/cut.ts +0 -36
- package/src/commands/date.ts +0 -30
- package/src/commands/declare.ts +0 -49
- package/src/commands/deluser.ts +0 -98
- package/src/commands/df.ts +0 -23
- package/src/commands/diff.ts +0 -43
- package/src/commands/dpkg.ts +0 -180
- package/src/commands/du.ts +0 -56
- package/src/commands/echo.ts +0 -58
- package/src/commands/env.ts +0 -23
- package/src/commands/exit.ts +0 -18
- package/src/commands/export.ts +0 -34
- package/src/commands/find.ts +0 -68
- package/src/commands/free.ts +0 -47
- package/src/commands/grep.ts +0 -116
- package/src/commands/groups.ts +0 -19
- package/src/commands/gzip.ts +0 -88
- package/src/commands/head.ts +0 -52
- package/src/commands/help.ts +0 -152
- package/src/commands/helpers.ts +0 -234
- package/src/commands/history.ts +0 -34
- package/src/commands/hostname.ts +0 -14
- package/src/commands/htop.ts +0 -20
- package/src/commands/id.ts +0 -19
- package/src/commands/index.ts +0 -9
- package/src/commands/kill.ts +0 -19
- package/src/commands/ln.ts +0 -71
- package/src/commands/ls.ts +0 -243
- package/src/commands/lsb-release.ts +0 -63
- package/src/commands/man.ts +0 -31
- package/src/commands/manuals/adduser.txt +0 -11
- package/src/commands/manuals/apt-cache.txt +0 -12
- package/src/commands/manuals/apt.txt +0 -20
- package/src/commands/manuals/awk.txt +0 -13
- package/src/commands/manuals/cat.txt +0 -14
- package/src/commands/manuals/cd.txt +0 -16
- package/src/commands/manuals/chmod.txt +0 -16
- package/src/commands/manuals/clear.txt +0 -10
- package/src/commands/manuals/cp.txt +0 -10
- package/src/commands/manuals/curl.txt +0 -20
- package/src/commands/manuals/date.txt +0 -14
- package/src/commands/manuals/declare.txt +0 -12
- package/src/commands/manuals/deluser.txt +0 -10
- package/src/commands/manuals/df.txt +0 -10
- package/src/commands/manuals/dpkg-query.txt +0 -11
- package/src/commands/manuals/dpkg.txt +0 -14
- package/src/commands/manuals/du.txt +0 -11
- package/src/commands/manuals/echo.txt +0 -11
- package/src/commands/manuals/false.txt +0 -10
- package/src/commands/manuals/find.txt +0 -11
- package/src/commands/manuals/free.txt +0 -12
- package/src/commands/manuals/grep.txt +0 -13
- package/src/commands/manuals/groups.txt +0 -10
- package/src/commands/manuals/gzip.txt +0 -11
- package/src/commands/manuals/head.txt +0 -10
- package/src/commands/manuals/help.txt +0 -11
- package/src/commands/manuals/history.txt +0 -11
- package/src/commands/manuals/hostname.txt +0 -10
- package/src/commands/manuals/id.txt +0 -10
- package/src/commands/manuals/kill.txt +0 -13
- package/src/commands/manuals/ls.txt +0 -20
- package/src/commands/manuals/lsb_release.txt +0 -14
- package/src/commands/manuals/mkdir.txt +0 -10
- package/src/commands/manuals/mv.txt +0 -10
- package/src/commands/manuals/nano.txt +0 -11
- package/src/commands/manuals/neofetch.txt +0 -10
- package/src/commands/manuals/node.txt +0 -13
- package/src/commands/manuals/npm.txt +0 -13
- package/src/commands/manuals/npx.txt +0 -13
- package/src/commands/manuals/passwd.txt +0 -11
- package/src/commands/manuals/ping.txt +0 -10
- package/src/commands/manuals/printf.txt +0 -11
- package/src/commands/manuals/ps.txt +0 -10
- package/src/commands/manuals/pwd.txt +0 -10
- package/src/commands/manuals/python3.txt +0 -13
- package/src/commands/manuals/readlink.txt +0 -10
- package/src/commands/manuals/return.txt +0 -10
- package/src/commands/manuals/rm.txt +0 -10
- package/src/commands/manuals/sed.txt +0 -11
- package/src/commands/manuals/set.txt +0 -11
- package/src/commands/manuals/shift.txt +0 -10
- package/src/commands/manuals/sleep.txt +0 -10
- package/src/commands/manuals/sort.txt +0 -12
- package/src/commands/manuals/source.txt +0 -11
- package/src/commands/manuals/ssh.txt +0 -11
- package/src/commands/manuals/stat.txt +0 -10
- package/src/commands/manuals/su.txt +0 -13
- package/src/commands/manuals/sudo.txt +0 -11
- package/src/commands/manuals/tail.txt +0 -10
- package/src/commands/manuals/tar.txt +0 -19
- package/src/commands/manuals/tee.txt +0 -10
- package/src/commands/manuals/test.txt +0 -11
- package/src/commands/manuals/touch.txt +0 -11
- package/src/commands/manuals/tr.txt +0 -10
- package/src/commands/manuals/trap.txt +0 -10
- package/src/commands/manuals/true.txt +0 -10
- package/src/commands/manuals/type.txt +0 -10
- package/src/commands/manuals/uname.txt +0 -12
- package/src/commands/manuals/uniq.txt +0 -12
- package/src/commands/manuals/unset.txt +0 -10
- package/src/commands/manuals/uptime.txt +0 -11
- package/src/commands/manuals/wc.txt +0 -12
- package/src/commands/manuals/wget.txt +0 -12
- package/src/commands/manuals/which.txt +0 -10
- package/src/commands/manuals/whoami.txt +0 -10
- package/src/commands/manuals/xargs.txt +0 -10
- package/src/commands/manuals-bundle.ts +0 -898
- package/src/commands/mkdir.ts +0 -31
- package/src/commands/mv.ts +0 -50
- package/src/commands/nano.ts +0 -38
- package/src/commands/neofetch.ts +0 -53
- package/src/commands/node.ts +0 -341
- package/src/commands/npm.ts +0 -132
- package/src/commands/passwd.ts +0 -50
- package/src/commands/ping.ts +0 -32
- package/src/commands/printf.ts +0 -129
- package/src/commands/ps.ts +0 -58
- package/src/commands/pwd.ts +0 -9
- package/src/commands/python.ts +0 -2229
- package/src/commands/read.ts +0 -46
- package/src/commands/registry.ts +0 -249
- package/src/commands/rm.ts +0 -42
- package/src/commands/runtime.ts +0 -421
- package/src/commands/sed.ts +0 -68
- package/src/commands/seq.ts +0 -43
- package/src/commands/set.ts +0 -29
- package/src/commands/sh.ts +0 -467
- package/src/commands/shift.ts +0 -63
- package/src/commands/sleep.ts +0 -20
- package/src/commands/sort.ts +0 -46
- package/src/commands/source.ts +0 -52
- package/src/commands/stat.ts +0 -61
- package/src/commands/su.ts +0 -72
- package/src/commands/sudo.ts +0 -76
- package/src/commands/tail.ts +0 -53
- package/src/commands/tar.ts +0 -102
- package/src/commands/tee.ts +0 -36
- package/src/commands/test.ts +0 -137
- package/src/commands/touch.ts +0 -28
- package/src/commands/tr.ts +0 -70
- package/src/commands/tree.ts +0 -20
- package/src/commands/true.ts +0 -27
- package/src/commands/type.ts +0 -48
- package/src/commands/uname.ts +0 -29
- package/src/commands/uniq.ts +0 -39
- package/src/commands/unset.ts +0 -17
- package/src/commands/uptime.ts +0 -54
- package/src/commands/wc.ts +0 -55
- package/src/commands/wget.ts +0 -148
- package/src/commands/which.ts +0 -37
- package/src/commands/who.ts +0 -25
- package/src/commands/whoami.ts +0 -14
- package/src/commands/xargs.ts +0 -31
- package/src/index.ts +0 -67
- package/src/modules/linuxRootfs.ts +0 -1961
- package/src/modules/neofetch.ts +0 -358
- package/src/modules/shellInteractive.ts +0 -57
- package/src/modules/shellRuntime.ts +0 -76
- package/src/self-standalone.ts +0 -542
- package/src/standalone-wo-sftp.ts +0 -38
- package/src/standalone.ts +0 -72
- package/src/types/commands.ts +0 -146
- package/src/types/pipeline.ts +0 -52
- package/src/types/streams.ts +0 -32
- package/src/types/tar-stream.d.ts +0 -38
- package/src/types/vfs.ts +0 -98
- package/src/utils/expand.ts +0 -491
- package/src/utils/perfLogger.ts +0 -72
- package/src/utils/tokenize.ts +0 -98
- package/src/utils/vfsDiff.ts +0 -275
- package/tests/command-helpers.test.ts +0 -116
- package/tests/commands-admin-net.test.ts +0 -441
- package/tests/commands-advanced.test.ts +0 -456
- package/tests/commands-core.test.ts +0 -562
- package/tests/commands-missing.test.ts +0 -570
- package/tests/commands-specific-units.test.ts +0 -327
- package/tests/commands-text-sys.test.ts +0 -445
- package/tests/expand.test.ts +0 -170
- package/tests/helpers.test.ts +0 -97
- package/tests/new-features.test.ts +0 -1036
- package/tests/parser-executor.test.ts +0 -37
- package/tests/sftp.test.ts +0 -323
- package/tests/ssh-exec.test.ts +0 -45
- package/tests/test-helper.ts +0 -79
- package/tests/users.test.ts +0 -86
- package/tsconfig.json +0 -49
- package/typedoc.json +0 -47
package/src/commands/mkdir.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ShellModule } from "../types/commands";
|
|
2
|
-
import { getArg } from "./command-helpers";
|
|
3
|
-
import { assertPathAccess, resolvePath } from "./helpers";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create one or more directories.
|
|
7
|
-
* @category files
|
|
8
|
-
* @params ["<dir>"]
|
|
9
|
-
*/
|
|
10
|
-
export const mkdirCommand: ShellModule = {
|
|
11
|
-
name: "mkdir",
|
|
12
|
-
description: "Make directories",
|
|
13
|
-
category: "files",
|
|
14
|
-
params: ["<dir>"],
|
|
15
|
-
run: ({ authUser, shell, cwd, args }) => {
|
|
16
|
-
if (args.length === 0) {
|
|
17
|
-
return { stderr: "mkdir: missing operand", exitCode: 1 };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (let index = 0; index < args.length; index++) {
|
|
21
|
-
const dir = getArg(args, index);
|
|
22
|
-
if (!dir) {
|
|
23
|
-
return { stderr: "mkdir: missing operand", exitCode: 1 };
|
|
24
|
-
}
|
|
25
|
-
const target = resolvePath(cwd, dir);
|
|
26
|
-
assertPathAccess(authUser, target, "mkdir");
|
|
27
|
-
shell.vfs.mkdir(target);
|
|
28
|
-
}
|
|
29
|
-
return { exitCode: 0 };
|
|
30
|
-
},
|
|
31
|
-
};
|
package/src/commands/mv.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ShellModule } from "../types/commands";
|
|
2
|
-
import { assertPathAccess, resolvePath } from "./helpers";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Move or rename files and directories.
|
|
6
|
-
* @category files
|
|
7
|
-
* @params ["<source> <dest>"]
|
|
8
|
-
*/
|
|
9
|
-
export const mvCommand: ShellModule = {
|
|
10
|
-
name: "mv",
|
|
11
|
-
description: "Move or rename files",
|
|
12
|
-
category: "files",
|
|
13
|
-
params: ["<source> <dest>"],
|
|
14
|
-
run: ({ authUser, shell, cwd, args }) => {
|
|
15
|
-
const positionals = args.filter((a) => !a.startsWith("-"));
|
|
16
|
-
const [srcArg, destArg] = positionals;
|
|
17
|
-
|
|
18
|
-
if (!srcArg || !destArg) {
|
|
19
|
-
return { stderr: "mv: missing operand", exitCode: 1 };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const srcPath = resolvePath(cwd, srcArg);
|
|
23
|
-
const destPath = resolvePath(cwd, destArg);
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
assertPathAccess(authUser, srcPath, "mv");
|
|
27
|
-
assertPathAccess(authUser, destPath, "mv");
|
|
28
|
-
|
|
29
|
-
if (!shell.vfs.exists(srcPath)) {
|
|
30
|
-
return {
|
|
31
|
-
stderr: `mv: ${srcArg}: No such file or directory`,
|
|
32
|
-
exitCode: 1,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// If dest is a directory, move into it
|
|
37
|
-
const finalDest =
|
|
38
|
-
shell.vfs.exists(destPath) &&
|
|
39
|
-
shell.vfs.stat(destPath).type === "directory"
|
|
40
|
-
? `${destPath}/${srcArg.split("/").pop()}`
|
|
41
|
-
: destPath;
|
|
42
|
-
|
|
43
|
-
shell.vfs.move(srcPath, finalDest);
|
|
44
|
-
return { exitCode: 0 };
|
|
45
|
-
} catch (err) {
|
|
46
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
47
|
-
return { stderr: `mv: ${msg}`, exitCode: 1 };
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
package/src/commands/nano.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import type { ShellModule } from "../types/commands";
|
|
3
|
-
import { assertPathAccess, resolvePath } from "./helpers";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Simple text editor for editing files.
|
|
7
|
-
* @category files
|
|
8
|
-
* @params ["<file>"]
|
|
9
|
-
*/
|
|
10
|
-
export const nanoCommand: ShellModule = {
|
|
11
|
-
name: "nano",
|
|
12
|
-
description: "Text editor",
|
|
13
|
-
category: "files",
|
|
14
|
-
params: ["<file>"],
|
|
15
|
-
run: ({ authUser, shell, cwd, args }) => {
|
|
16
|
-
const fileArg = args[0];
|
|
17
|
-
if (!fileArg) {
|
|
18
|
-
return { stderr: "nano: missing file operand", exitCode: 1 };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const targetPath = resolvePath(cwd, fileArg);
|
|
22
|
-
assertPathAccess(authUser, targetPath, "nano");
|
|
23
|
-
const initialContent = shell.vfs.exists(targetPath)
|
|
24
|
-
? shell.vfs.readFile(targetPath)
|
|
25
|
-
: "";
|
|
26
|
-
const safeName = path.posix.basename(targetPath) || "buffer";
|
|
27
|
-
const tempPath = `/tmp/sshmimic-nano-${Date.now()}-${safeName}.tmp`;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
openEditor: {
|
|
31
|
-
targetPath,
|
|
32
|
-
tempPath,
|
|
33
|
-
initialContent,
|
|
34
|
-
},
|
|
35
|
-
exitCode: 0,
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
};
|
package/src/commands/neofetch.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { buildNeofetchOutput } from "../modules/neofetch";
|
|
2
|
-
import type { ShellModule } from "../types/commands";
|
|
3
|
-
import { ifFlag } from "./command-helpers";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Display system information in a decorative format.
|
|
7
|
-
* @category system
|
|
8
|
-
* @params ["[--off]"]
|
|
9
|
-
*/
|
|
10
|
-
export const neofetchCommand: ShellModule = {
|
|
11
|
-
name: "neofetch",
|
|
12
|
-
description: "System info display",
|
|
13
|
-
category: "system",
|
|
14
|
-
params: ["[--off]"],
|
|
15
|
-
run: ({ args, authUser, hostname, shell, env }) => {
|
|
16
|
-
if (!shell.packageManager.isInstalled("neofetch")) {
|
|
17
|
-
return {
|
|
18
|
-
stderr:
|
|
19
|
-
"bash: neofetch: command not found\nHint: install it with: apt install neofetch\n",
|
|
20
|
-
exitCode: 127,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
if (ifFlag(args, "--help")) {
|
|
24
|
-
return {
|
|
25
|
-
stdout: "Usage: neofetch [--off]",
|
|
26
|
-
exitCode: 0,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (ifFlag(args, "--off")) {
|
|
31
|
-
return {
|
|
32
|
-
stdout: `${authUser}@${hostname}`,
|
|
33
|
-
exitCode: 0,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
stdout: buildNeofetchOutput({
|
|
39
|
-
user: authUser,
|
|
40
|
-
host: hostname,
|
|
41
|
-
shell: env.vars.SHELL,
|
|
42
|
-
shellProps: shell.properties,
|
|
43
|
-
terminal: env.vars.TERM,
|
|
44
|
-
uptimeSeconds: Math.floor((Date.now() - shell.startTime) / 1000),
|
|
45
|
-
packages: (() => {
|
|
46
|
-
const count = shell.packageManager?.installedCount() ?? 0;
|
|
47
|
-
return `${count} (dpkg)`;
|
|
48
|
-
})(),
|
|
49
|
-
}),
|
|
50
|
-
exitCode: 0,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
};
|
package/src/commands/node.ts
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/style/useNamingConvention: node globals and ENV VAR KEYS */
|
|
2
|
-
/**
|
|
3
|
-
* node.ts — Virtual Node.js runtime.
|
|
4
|
-
*
|
|
5
|
-
* Uses `node:vm` for sandboxed evaluation with a controlled context that
|
|
6
|
-
* intercepts `process`, `require`, `console`, and all standard globals.
|
|
7
|
-
* No host filesystem access, no network, no child processes.
|
|
8
|
-
*/
|
|
9
|
-
import vm from "node:vm";
|
|
10
|
-
import type { ShellModule } from "../types/commands";
|
|
11
|
-
import { ifFlag } from "./command-helpers";
|
|
12
|
-
import { resolvePath } from "./helpers";
|
|
13
|
-
|
|
14
|
-
const VIRTUAL_VERSION = "v18.19.0";
|
|
15
|
-
const VIRTUAL_VERSIONS = {
|
|
16
|
-
node: VIRTUAL_VERSION,
|
|
17
|
-
npm: "9.2.0",
|
|
18
|
-
v8: "10.2.154.26-node.22",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// ─── sandbox context ──────────────────────────────────────────────────────────
|
|
22
|
-
|
|
23
|
-
function makeContext(outputLines: string[], stderrLines: string[]) {
|
|
24
|
-
const fakeProcess = {
|
|
25
|
-
version: VIRTUAL_VERSION,
|
|
26
|
-
versions: VIRTUAL_VERSIONS,
|
|
27
|
-
platform: "linux",
|
|
28
|
-
arch: "x64",
|
|
29
|
-
env: {
|
|
30
|
-
NODE_ENV: "production",
|
|
31
|
-
HOME: "/root",
|
|
32
|
-
PATH: "/usr/local/bin:/usr/bin:/bin",
|
|
33
|
-
},
|
|
34
|
-
argv: ["node"],
|
|
35
|
-
stdout: {
|
|
36
|
-
write: (s: string) => {
|
|
37
|
-
outputLines.push(s);
|
|
38
|
-
return true;
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
stderr: {
|
|
42
|
-
write: (s: string) => {
|
|
43
|
-
stderrLines.push(s);
|
|
44
|
-
return true;
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
exit: (code = 0) => {
|
|
48
|
-
throw new ExitSignal(code);
|
|
49
|
-
},
|
|
50
|
-
cwd: () => "/root",
|
|
51
|
-
hrtime: () => [0, 0],
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const fakeConsole = {
|
|
55
|
-
log: (...a: unknown[]) => outputLines.push(a.map(formatValue).join(" ")),
|
|
56
|
-
error: (...a: unknown[]) => stderrLines.push(a.map(formatValue).join(" ")),
|
|
57
|
-
warn: (...a: unknown[]) => stderrLines.push(a.map(formatValue).join(" ")),
|
|
58
|
-
info: (...a: unknown[]) => outputLines.push(a.map(formatValue).join(" ")),
|
|
59
|
-
dir: (v: unknown) => outputLines.push(formatValue(v)),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const fakeRequire = (mod: string): unknown => {
|
|
63
|
-
// Provide stubs for common modules
|
|
64
|
-
switch (mod) {
|
|
65
|
-
case "path":
|
|
66
|
-
return {
|
|
67
|
-
join: (...parts: string[]) => parts.join("/").replace(/\/+/g, "/"),
|
|
68
|
-
resolve: (...parts: string[]) =>
|
|
69
|
-
`/${parts.join("/").replace(/^\/+/, "")}`,
|
|
70
|
-
dirname: (p: string) => p.split("/").slice(0, -1).join("/") || "/",
|
|
71
|
-
basename: (p: string) => p.split("/").pop() ?? "",
|
|
72
|
-
extname: (p: string) => {
|
|
73
|
-
const b = p.split("/").pop() ?? "";
|
|
74
|
-
const d = b.lastIndexOf(".");
|
|
75
|
-
return d > 0 ? b.slice(d) : "";
|
|
76
|
-
},
|
|
77
|
-
sep: "/",
|
|
78
|
-
delimiter: ":",
|
|
79
|
-
};
|
|
80
|
-
case "os":
|
|
81
|
-
return {
|
|
82
|
-
platform: () => "linux",
|
|
83
|
-
arch: () => "x64",
|
|
84
|
-
type: () => "Linux",
|
|
85
|
-
hostname: () => "fortune-vm",
|
|
86
|
-
homedir: () => "/root",
|
|
87
|
-
tmpdir: () => "/tmp",
|
|
88
|
-
EOL: "\n",
|
|
89
|
-
};
|
|
90
|
-
case "util":
|
|
91
|
-
return {
|
|
92
|
-
format: (...a: unknown[]) => a.map(formatValue).join(" "),
|
|
93
|
-
inspect: (v: unknown) => formatValue(v),
|
|
94
|
-
};
|
|
95
|
-
case "fs":
|
|
96
|
-
case "fs/promises":
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Cannot require '${mod}': filesystem access not available in virtual runtime`,
|
|
99
|
-
);
|
|
100
|
-
case "child_process":
|
|
101
|
-
case "net":
|
|
102
|
-
case "http":
|
|
103
|
-
case "https":
|
|
104
|
-
throw new Error(
|
|
105
|
-
`Cannot require '${mod}': not available in virtual runtime`,
|
|
106
|
-
);
|
|
107
|
-
default:
|
|
108
|
-
throw new Error(`Cannot find module '${mod}'`);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
fakeRequire.resolve = (id: string) => {
|
|
112
|
-
throw new Error(`Cannot resolve '${id}'`);
|
|
113
|
-
};
|
|
114
|
-
fakeRequire.cache = {};
|
|
115
|
-
fakeRequire.extensions = {};
|
|
116
|
-
|
|
117
|
-
return vm.createContext({
|
|
118
|
-
// Core globals
|
|
119
|
-
console: fakeConsole,
|
|
120
|
-
process: fakeProcess,
|
|
121
|
-
require: fakeRequire,
|
|
122
|
-
|
|
123
|
-
// JS built-ins
|
|
124
|
-
Math,
|
|
125
|
-
JSON,
|
|
126
|
-
Object,
|
|
127
|
-
Array,
|
|
128
|
-
String,
|
|
129
|
-
Number,
|
|
130
|
-
Boolean,
|
|
131
|
-
Symbol,
|
|
132
|
-
Date,
|
|
133
|
-
RegExp,
|
|
134
|
-
Error,
|
|
135
|
-
TypeError,
|
|
136
|
-
RangeError,
|
|
137
|
-
SyntaxError,
|
|
138
|
-
Promise,
|
|
139
|
-
Map,
|
|
140
|
-
Set,
|
|
141
|
-
WeakMap,
|
|
142
|
-
WeakSet,
|
|
143
|
-
parseInt,
|
|
144
|
-
parseFloat,
|
|
145
|
-
isNaN,
|
|
146
|
-
isFinite,
|
|
147
|
-
encodeURIComponent,
|
|
148
|
-
decodeURIComponent,
|
|
149
|
-
encodeURI,
|
|
150
|
-
decodeURI,
|
|
151
|
-
setTimeout: () => {},
|
|
152
|
-
clearTimeout: () => {},
|
|
153
|
-
setInterval: () => {},
|
|
154
|
-
clearInterval: () => {},
|
|
155
|
-
queueMicrotask: () => {},
|
|
156
|
-
globalThis: undefined as unknown, // set below
|
|
157
|
-
undefined,
|
|
158
|
-
Infinity,
|
|
159
|
-
NaN,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
class ExitSignal {
|
|
164
|
-
constructor(public readonly code: number) {}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function formatValue(v: unknown): string {
|
|
168
|
-
if (v === null) return "null";
|
|
169
|
-
if (v === undefined) return "undefined";
|
|
170
|
-
if (typeof v === "string") return v;
|
|
171
|
-
if (typeof v === "function") return `[Function: ${v.name || "(anonymous)"}]`;
|
|
172
|
-
if (Array.isArray(v)) return `[ ${v.map(formatValue).join(", ")} ]`;
|
|
173
|
-
if (v instanceof Error) return `${v.name}: ${v.message}`;
|
|
174
|
-
if (typeof v === "object") {
|
|
175
|
-
try {
|
|
176
|
-
const entries = Object.entries(v as Record<string, unknown>)
|
|
177
|
-
.map(([k, val]) => `${k}: ${formatValue(val)}`)
|
|
178
|
-
.join(", ");
|
|
179
|
-
return `{ ${entries} }`;
|
|
180
|
-
} catch {
|
|
181
|
-
return "[Object]";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return String(v);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// ─── execution ────────────────────────────────────────────────────────────────
|
|
188
|
-
|
|
189
|
-
function runJs(code: string): {
|
|
190
|
-
stdout: string;
|
|
191
|
-
stderr: string;
|
|
192
|
-
exitCode: number;
|
|
193
|
-
} {
|
|
194
|
-
const outputLines: string[] = [];
|
|
195
|
-
const stderrLines: string[] = [];
|
|
196
|
-
const ctx = makeContext(outputLines, stderrLines);
|
|
197
|
-
|
|
198
|
-
let exitCode = 0;
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
const result = vm.runInContext(code, ctx, { timeout: 5000 });
|
|
202
|
-
// If the expression returned a value and nothing was console.log'd, print it
|
|
203
|
-
if (result !== undefined && outputLines.length === 0) {
|
|
204
|
-
outputLines.push(formatValue(result));
|
|
205
|
-
}
|
|
206
|
-
} catch (err) {
|
|
207
|
-
if (err instanceof ExitSignal) {
|
|
208
|
-
exitCode = err.code;
|
|
209
|
-
} else if (err instanceof Error) {
|
|
210
|
-
stderrLines.push(`${err.name}: ${err.message}`);
|
|
211
|
-
exitCode = 1;
|
|
212
|
-
} else {
|
|
213
|
-
stderrLines.push(String(err));
|
|
214
|
-
exitCode = 1;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
stdout: outputLines.length ? `${outputLines.join("\n")}\n` : "",
|
|
220
|
-
stderr: stderrLines.length ? `${stderrLines.join("\n")}\n` : "",
|
|
221
|
-
exitCode,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function runJsFile(code: string): {
|
|
226
|
-
stdout: string;
|
|
227
|
-
stderr: string;
|
|
228
|
-
exitCode: number;
|
|
229
|
-
} {
|
|
230
|
-
// If the code is a single expression (no semicolons, no newlines, no statements),
|
|
231
|
-
// wrap it to capture the return value like a REPL would
|
|
232
|
-
const trimmed = code.trim();
|
|
233
|
-
const isExpression =
|
|
234
|
-
!trimmed.includes("\n") &&
|
|
235
|
-
!trimmed.startsWith("const ") &&
|
|
236
|
-
!trimmed.startsWith("let ") &&
|
|
237
|
-
!trimmed.startsWith("var ") &&
|
|
238
|
-
!trimmed.startsWith("function ") &&
|
|
239
|
-
!trimmed.startsWith("class ") &&
|
|
240
|
-
!trimmed.startsWith("if ") &&
|
|
241
|
-
!trimmed.startsWith("for ") &&
|
|
242
|
-
!trimmed.startsWith("while ") &&
|
|
243
|
-
!trimmed.startsWith("import ") &&
|
|
244
|
-
!trimmed.startsWith("//");
|
|
245
|
-
|
|
246
|
-
if (isExpression) return runJs(trimmed);
|
|
247
|
-
|
|
248
|
-
// Multi-line: wrap in IIFE
|
|
249
|
-
return runJs(`(async () => { ${code} })()`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// ─── command ──────────────────────────────────────────────────────────────────
|
|
253
|
-
/**
|
|
254
|
-
* `node` virtual runtime command. Executes JS in a safe sandbox with
|
|
255
|
-
* limited globals and no host FS/child process access.
|
|
256
|
-
* @category system
|
|
257
|
-
* @params []
|
|
258
|
-
*/
|
|
259
|
-
export const nodeCommand: ShellModule = {
|
|
260
|
-
name: "node",
|
|
261
|
-
description: "JavaScript runtime (virtual)",
|
|
262
|
-
category: "system",
|
|
263
|
-
params: ["[--version] [-e <expr>] [-p <expr>] [file]"],
|
|
264
|
-
run: ({ args, shell, cwd }) => {
|
|
265
|
-
// Require explicit installation via `apt install nodejs`
|
|
266
|
-
if (!shell.packageManager.isInstalled("nodejs")) {
|
|
267
|
-
return {
|
|
268
|
-
stderr:
|
|
269
|
-
"bash: node: command not found\nHint: install it with: apt install nodejs\n",
|
|
270
|
-
exitCode: 127,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
if (ifFlag(args, ["--version", "-v"])) {
|
|
274
|
-
return { stdout: `${VIRTUAL_VERSION}\n`, exitCode: 0 };
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (ifFlag(args, ["--versions"])) {
|
|
278
|
-
return {
|
|
279
|
-
stdout: `${JSON.stringify(VIRTUAL_VERSIONS, null, 2)}\n`,
|
|
280
|
-
exitCode: 0,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// -e 'expr'
|
|
285
|
-
const eIdx = args.findIndex((a) => a === "-e" || a === "--eval");
|
|
286
|
-
if (eIdx !== -1) {
|
|
287
|
-
const expr = args[eIdx + 1];
|
|
288
|
-
if (!expr)
|
|
289
|
-
return { stderr: "node: -e requires an argument\n", exitCode: 1 };
|
|
290
|
-
const { stdout, stderr, exitCode } = runJs(expr);
|
|
291
|
-
return {
|
|
292
|
-
stdout: stdout || undefined,
|
|
293
|
-
stderr: stderr || undefined,
|
|
294
|
-
exitCode,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// -p 'expr' — print mode
|
|
299
|
-
const pIdx = args.findIndex((a) => a === "-p" || a === "--print");
|
|
300
|
-
if (pIdx !== -1) {
|
|
301
|
-
const expr = args[pIdx + 1];
|
|
302
|
-
if (!expr)
|
|
303
|
-
return { stderr: "node: -p requires an argument\n", exitCode: 1 };
|
|
304
|
-
const { stdout, stderr, exitCode } = runJs(expr);
|
|
305
|
-
return {
|
|
306
|
-
stdout: stdout || (exitCode === 0 ? "\n" : undefined),
|
|
307
|
-
stderr: stderr || undefined,
|
|
308
|
-
exitCode,
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// node <file>
|
|
313
|
-
const file = args.find((a) => !a.startsWith("-"));
|
|
314
|
-
if (file) {
|
|
315
|
-
const filePath = resolvePath(cwd, file);
|
|
316
|
-
if (!shell.vfs.exists(filePath)) {
|
|
317
|
-
return {
|
|
318
|
-
stderr: `node: cannot open file '${file}': No such file or directory\n`,
|
|
319
|
-
exitCode: 1,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
const code = shell.vfs.readFile(filePath);
|
|
323
|
-
const { stdout, stderr, exitCode } = runJsFile(code);
|
|
324
|
-
return {
|
|
325
|
-
stdout: stdout || undefined,
|
|
326
|
-
stderr: stderr || undefined,
|
|
327
|
-
exitCode,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// No args — REPL hint
|
|
332
|
-
return {
|
|
333
|
-
stdout: [
|
|
334
|
-
`Welcome to Node.js ${VIRTUAL_VERSION}.`,
|
|
335
|
-
`Type ".exit" to exit the REPL.`,
|
|
336
|
-
`> `,
|
|
337
|
-
].join("\n"),
|
|
338
|
-
exitCode: 0,
|
|
339
|
-
};
|
|
340
|
-
},
|
|
341
|
-
};
|
package/src/commands/npm.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* npm.ts — Virtual npm command.
|
|
3
|
-
* Gated behind `apt install npm`. Provides version info and informative
|
|
4
|
-
* stubs for common subcommands.
|
|
5
|
-
*/
|
|
6
|
-
import type { ShellModule } from "../types/commands";
|
|
7
|
-
import { ifFlag } from "./command-helpers";
|
|
8
|
-
|
|
9
|
-
const NPM_VERSION = "9.2.0";
|
|
10
|
-
const NODE_VERSION = "18.19.0";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* `npm` virtual CLI. Requires `apt install npm` in the virtual package manager.
|
|
14
|
-
* @category system
|
|
15
|
-
* @params ["<command> [args]"]
|
|
16
|
-
*/
|
|
17
|
-
export const npmCommand: ShellModule = {
|
|
18
|
-
name: "npm",
|
|
19
|
-
description: "Node.js package manager (virtual)",
|
|
20
|
-
category: "system",
|
|
21
|
-
params: ["<command> [args]"],
|
|
22
|
-
run: ({ args, shell }) => {
|
|
23
|
-
// Require explicit installation
|
|
24
|
-
if (!shell.packageManager.isInstalled("npm")) {
|
|
25
|
-
return {
|
|
26
|
-
stderr:
|
|
27
|
-
"bash: npm: command not found\nHint: install it with: apt install npm\n",
|
|
28
|
-
exitCode: 127,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (ifFlag(args, ["--version", "-v"])) {
|
|
33
|
-
return { stdout: `${NPM_VERSION}\n`, exitCode: 0 };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const sub = args[0]?.toLowerCase();
|
|
37
|
-
|
|
38
|
-
switch (sub) {
|
|
39
|
-
case "version":
|
|
40
|
-
case "-version":
|
|
41
|
-
return {
|
|
42
|
-
stdout: `{ npm: '${NPM_VERSION}', node: '${NODE_VERSION}', v8: '10.2.154.26' }\n`,
|
|
43
|
-
exitCode: 0,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
case "install":
|
|
47
|
-
case "i":
|
|
48
|
-
case "add":
|
|
49
|
-
return {
|
|
50
|
-
stderr:
|
|
51
|
-
"npm warn: package installation is not available in the virtual runtime.\nnpm warn: This environment simulates npm CLI behaviour only.\n",
|
|
52
|
-
exitCode: 1,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
case "run":
|
|
56
|
-
case "exec":
|
|
57
|
-
case "x":
|
|
58
|
-
return {
|
|
59
|
-
stderr: `npm error: script execution is not available in the virtual runtime.\n`,
|
|
60
|
-
exitCode: 1,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
case "init":
|
|
64
|
-
return {
|
|
65
|
-
stdout: "Wrote to /home/user/package.json\n",
|
|
66
|
-
exitCode: 0,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
case "list":
|
|
70
|
-
case "ls":
|
|
71
|
-
return {
|
|
72
|
-
stdout: `${sub === "ls" || sub === "list" ? "virtual-env@1.0.0" : ""}\n└── (empty)\n`,
|
|
73
|
-
exitCode: 0,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
case "help":
|
|
77
|
-
case undefined:
|
|
78
|
-
return {
|
|
79
|
-
stdout: `${[
|
|
80
|
-
`npm ${NPM_VERSION}`,
|
|
81
|
-
"",
|
|
82
|
-
"Usage: npm <command>",
|
|
83
|
-
"",
|
|
84
|
-
"Commands:",
|
|
85
|
-
" install (not available in virtual runtime)",
|
|
86
|
-
" run (not available in virtual runtime)",
|
|
87
|
-
" exec (not available in virtual runtime)",
|
|
88
|
-
" list List installed packages",
|
|
89
|
-
" version Print versions",
|
|
90
|
-
" --version Print npm version",
|
|
91
|
-
].join("\n")}\n`,
|
|
92
|
-
exitCode: 0,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
default:
|
|
96
|
-
return {
|
|
97
|
-
stderr: `npm error: unknown command: ${sub}\n`,
|
|
98
|
-
exitCode: 1,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* `npx` virtual runner. Requires `apt install npm` in the virtual package manager.
|
|
106
|
-
* @category system
|
|
107
|
-
* @params ["<package> [args]"]
|
|
108
|
-
*/
|
|
109
|
-
export const npxCommand: ShellModule = {
|
|
110
|
-
name: "npx",
|
|
111
|
-
description: "Node.js package runner (virtual)",
|
|
112
|
-
category: "system",
|
|
113
|
-
params: ["<package> [args]"],
|
|
114
|
-
run: ({ args, shell }) => {
|
|
115
|
-
if (!shell.packageManager.isInstalled("npm")) {
|
|
116
|
-
return {
|
|
117
|
-
stderr:
|
|
118
|
-
"bash: npx: command not found\nHint: install it with: apt install npm\n",
|
|
119
|
-
exitCode: 127,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (ifFlag(args, ["--version"])) {
|
|
124
|
-
return { stdout: `${NPM_VERSION}\n`, exitCode: 0 };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
stderr: `npx: package execution is not available in the virtual runtime.\n`,
|
|
129
|
-
exitCode: 1,
|
|
130
|
-
};
|
|
131
|
-
},
|
|
132
|
-
};
|
package/src/commands/passwd.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ShellModule } from "../types/commands";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `passwd [username]` — change a virtual user's password.
|
|
5
|
-
*
|
|
6
|
-
* - Root can change any user's password.
|
|
7
|
-
* - Non-root can only change their own password.
|
|
8
|
-
* - Interactive: emits `passwordChallenge` for hidden-input prompting.
|
|
9
|
-
* - Non-interactive: reads new password from stdin first line.
|
|
10
|
-
*/
|
|
11
|
-
export const passwdCommand: ShellModule = {
|
|
12
|
-
name: "passwd",
|
|
13
|
-
description: "Change user password",
|
|
14
|
-
category: "users",
|
|
15
|
-
params: ["[username]"],
|
|
16
|
-
run: async ({ authUser, args, shell, stdin }) => {
|
|
17
|
-
const targetUser = args[0] ?? authUser;
|
|
18
|
-
|
|
19
|
-
// Permission check
|
|
20
|
-
if (authUser !== "root" && authUser !== targetUser) {
|
|
21
|
-
return { stderr: "passwd: permission denied", exitCode: 1 };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Target must exist
|
|
25
|
-
if (!shell.users.listUsers().includes(targetUser)) {
|
|
26
|
-
return { stderr: `passwd: user '${targetUser}' does not exist`, exitCode: 1 };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Non-interactive: read new password from stdin
|
|
30
|
-
if (stdin !== undefined && stdin.trim().length > 0) {
|
|
31
|
-
const password = stdin.trim().split("\n")[0]!;
|
|
32
|
-
await shell.users.setPassword(targetUser, password);
|
|
33
|
-
return {
|
|
34
|
-
stdout: `passwd: password updated successfully\n`,
|
|
35
|
-
exitCode: 0,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Interactive: emit password challenge
|
|
40
|
-
return {
|
|
41
|
-
passwordChallenge: {
|
|
42
|
-
prompt: "New password: ",
|
|
43
|
-
confirmPrompt: "Retype new password: ",
|
|
44
|
-
action: "passwd" as const,
|
|
45
|
-
targetUsername: targetUser,
|
|
46
|
-
},
|
|
47
|
-
exitCode: 0,
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|