typescript-virtual-container 1.3.4 → 1.4.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/.vscode/settings.json +0 -1
- package/README.md +674 -1504
- package/benchmark-results.txt +21 -21
- package/builds/self-standalone.js +282 -332
- package/builds/self-standalone.js.map +4 -4
- package/builds/standalone-wo-sftp.js +218 -282
- package/builds/standalone-wo-sftp.js.map +4 -4
- package/builds/standalone.js +271 -335
- package/builds/standalone.js.map +4 -4
- package/builds/web-full-api.min.js +3 -3
- package/builds/web-full-api.min.js.map +4 -4
- package/builds/web.min.js +2 -2
- package/builds/web.min.js.map +4 -4
- package/bun.lock +14 -12
- package/dist/SSHClient/index.d.ts.map +1 -1
- package/dist/SSHClient/index.js +5 -3
- package/dist/SSHMimic/executor.d.ts +1 -3
- package/dist/SSHMimic/executor.d.ts.map +1 -1
- package/dist/SSHMimic/executor.js +20 -22
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +5 -3
- package/dist/SSHMimic/sftp.d.ts.map +1 -1
- package/dist/SSHMimic/sftp.js +26 -21
- package/dist/VirtualPackageManager/index.d.ts.map +1 -1
- package/dist/VirtualPackageManager/index.js +29 -1
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +25 -3
- package/dist/VirtualShell/shellParser.d.ts +1 -8
- package/dist/VirtualShell/shellParser.d.ts.map +1 -1
- package/dist/VirtualShell/shellParser.js +2 -81
- package/dist/VirtualUserManager/index.d.ts +7 -1
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.js +47 -16
- package/dist/commands/adduser.d.ts +10 -4
- package/dist/commands/adduser.d.ts.map +1 -1
- package/dist/commands/adduser.js +75 -12
- package/dist/commands/alias.d.ts +5 -0
- package/dist/commands/alias.d.ts.map +1 -1
- package/dist/commands/alias.js +5 -0
- package/dist/commands/apt.d.ts +5 -0
- package/dist/commands/apt.d.ts.map +1 -1
- package/dist/commands/apt.js +5 -0
- package/dist/commands/awk.d.ts +10 -8
- package/dist/commands/awk.d.ts.map +1 -1
- package/dist/commands/awk.js +156 -28
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +0 -3
- package/dist/commands/clear.d.ts +5 -0
- package/dist/commands/clear.d.ts.map +1 -1
- package/dist/commands/clear.js +5 -0
- package/dist/commands/command-helpers.d.ts.map +1 -1
- package/dist/commands/command-helpers.js +8 -0
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +2 -1
- package/dist/commands/declare.d.ts +5 -0
- package/dist/commands/declare.d.ts.map +1 -1
- package/dist/commands/declare.js +5 -0
- package/dist/commands/deluser.d.ts +12 -0
- package/dist/commands/deluser.d.ts.map +1 -1
- package/dist/commands/deluser.js +72 -6
- package/dist/commands/df.d.ts +5 -0
- package/dist/commands/df.d.ts.map +1 -1
- package/dist/commands/df.js +5 -0
- package/dist/commands/du.d.ts +5 -0
- package/dist/commands/du.d.ts.map +1 -1
- package/dist/commands/du.js +5 -0
- package/dist/commands/export.d.ts +5 -0
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +5 -0
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +22 -4
- package/dist/commands/groups.d.ts +5 -0
- package/dist/commands/groups.d.ts.map +1 -1
- package/dist/commands/groups.js +5 -0
- package/dist/commands/gzip.d.ts +5 -2
- package/dist/commands/gzip.d.ts.map +1 -1
- package/dist/commands/gzip.js +54 -28
- package/dist/commands/head.d.ts.map +1 -1
- package/dist/commands/head.js +12 -3
- package/dist/commands/htop.d.ts +5 -0
- package/dist/commands/htop.d.ts.map +1 -1
- package/dist/commands/htop.js +5 -0
- package/dist/commands/kill.d.ts +5 -0
- package/dist/commands/kill.d.ts.map +1 -1
- package/dist/commands/kill.js +5 -0
- package/dist/commands/ln.d.ts +2 -0
- package/dist/commands/ln.d.ts.map +1 -1
- package/dist/commands/ln.js +22 -0
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +15 -0
- package/dist/commands/lsb-release.d.ts +5 -0
- package/dist/commands/lsb-release.d.ts.map +1 -1
- package/dist/commands/lsb-release.js +5 -0
- package/dist/commands/man.d.ts.map +1 -1
- package/dist/commands/man.js +30 -136
- package/dist/commands/mkdir.d.ts +5 -0
- package/dist/commands/mkdir.d.ts.map +1 -1
- package/dist/commands/mkdir.js +5 -0
- package/dist/commands/mv.d.ts +5 -0
- package/dist/commands/mv.d.ts.map +1 -1
- package/dist/commands/mv.js +5 -0
- package/dist/commands/nano.d.ts +5 -0
- package/dist/commands/nano.d.ts.map +1 -1
- package/dist/commands/nano.js +5 -0
- package/dist/commands/neofetch.d.ts +5 -0
- package/dist/commands/neofetch.d.ts.map +1 -1
- package/dist/commands/neofetch.js +14 -5
- package/dist/commands/passwd.d.ts +8 -0
- package/dist/commands/passwd.d.ts.map +1 -1
- package/dist/commands/passwd.js +32 -11
- package/dist/commands/ping.d.ts +5 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +5 -0
- package/dist/commands/printf.d.ts +5 -0
- package/dist/commands/printf.d.ts.map +1 -1
- package/dist/commands/printf.js +43 -12
- package/dist/commands/ps.d.ts +5 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +5 -0
- package/dist/commands/read.d.ts +5 -0
- package/dist/commands/read.d.ts.map +1 -1
- package/dist/commands/read.js +5 -0
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +4 -1
- package/dist/commands/rm.d.ts +5 -0
- package/dist/commands/rm.d.ts.map +1 -1
- package/dist/commands/rm.js +5 -0
- package/dist/commands/runtime.d.ts.map +1 -1
- package/dist/commands/runtime.js +1 -57
- package/dist/commands/sed.d.ts +5 -0
- package/dist/commands/sed.d.ts.map +1 -1
- package/dist/commands/sed.js +5 -0
- package/dist/commands/set.d.ts +5 -6
- package/dist/commands/set.d.ts.map +1 -1
- package/dist/commands/set.js +5 -22
- package/dist/commands/sh.d.ts +6 -0
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +6 -0
- package/dist/commands/shift.d.ts +10 -0
- package/dist/commands/shift.d.ts.map +1 -1
- package/dist/commands/shift.js +10 -0
- package/dist/commands/sleep.d.ts +5 -0
- package/dist/commands/sleep.d.ts.map +1 -1
- package/dist/commands/sleep.js +5 -0
- package/dist/commands/sort.d.ts +5 -0
- package/dist/commands/sort.d.ts.map +1 -1
- package/dist/commands/sort.js +5 -0
- package/dist/commands/source.d.ts +5 -0
- package/dist/commands/source.d.ts.map +1 -1
- package/dist/commands/source.js +5 -0
- package/dist/commands/stat.d.ts +7 -0
- package/dist/commands/stat.d.ts.map +1 -0
- package/dist/commands/stat.js +56 -0
- package/dist/commands/su.d.ts +13 -0
- package/dist/commands/su.d.ts.map +1 -1
- package/dist/commands/su.js +45 -14
- package/dist/commands/sudo.d.ts.map +1 -1
- package/dist/commands/sudo.js +5 -0
- package/dist/commands/tail.d.ts +5 -0
- package/dist/commands/tail.d.ts.map +1 -1
- package/dist/commands/tail.js +15 -3
- package/dist/commands/tar.d.ts +5 -0
- package/dist/commands/tar.d.ts.map +1 -1
- package/dist/commands/tar.js +40 -10
- package/dist/commands/tee.d.ts +5 -0
- package/dist/commands/tee.d.ts.map +1 -1
- package/dist/commands/tee.js +5 -0
- package/dist/commands/touch.d.ts +5 -0
- package/dist/commands/touch.d.ts.map +1 -1
- package/dist/commands/touch.js +5 -0
- package/dist/commands/tr.d.ts.map +1 -1
- package/dist/commands/tr.js +45 -10
- package/dist/commands/tree.d.ts +5 -0
- package/dist/commands/tree.d.ts.map +1 -1
- package/dist/commands/tree.js +5 -0
- package/dist/commands/true.d.ts +10 -0
- package/dist/commands/true.d.ts.map +1 -1
- package/dist/commands/true.js +10 -0
- package/dist/commands/type.d.ts +5 -0
- package/dist/commands/type.d.ts.map +1 -1
- package/dist/commands/type.js +5 -0
- package/dist/commands/uname.d.ts +5 -0
- package/dist/commands/uname.d.ts.map +1 -1
- package/dist/commands/uname.js +5 -0
- package/dist/commands/uniq.d.ts +5 -0
- package/dist/commands/uniq.d.ts.map +1 -1
- package/dist/commands/uniq.js +5 -0
- package/dist/commands/unset.d.ts +5 -0
- package/dist/commands/unset.d.ts.map +1 -1
- package/dist/commands/unset.js +5 -0
- package/dist/commands/uptime.d.ts +5 -0
- package/dist/commands/uptime.d.ts.map +1 -1
- package/dist/commands/uptime.js +5 -0
- package/dist/commands/wc.d.ts +5 -0
- package/dist/commands/wc.d.ts.map +1 -1
- package/dist/commands/wc.js +5 -0
- package/dist/commands/wget.d.ts +5 -0
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +16 -1
- package/dist/commands/who.d.ts +5 -0
- package/dist/commands/who.d.ts.map +1 -1
- package/dist/commands/who.js +5 -0
- package/dist/commands/whoami.d.ts +5 -0
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +5 -0
- package/dist/commands/xargs.d.ts +5 -0
- package/dist/commands/xargs.d.ts.map +1 -1
- package/dist/commands/xargs.js +5 -0
- package/dist/self-standalone.js +254 -30
- package/dist/types/commands.d.ts +36 -0
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/utils/tokenize.d.ts +20 -0
- package/dist/utils/tokenize.d.ts.map +1 -0
- package/dist/utils/tokenize.js +74 -0
- package/examples/web.min.js +2 -2
- package/package.json +2 -2
- package/src/SSHClient/index.ts +6 -3
- package/src/SSHMimic/executor.ts +21 -44
- package/src/SSHMimic/index.ts +7 -5
- package/src/SSHMimic/sftp.ts +28 -21
- package/src/VirtualPackageManager/index.ts +29 -1
- package/src/VirtualShell/shell.ts +34 -4
- package/src/VirtualShell/shellParser.ts +2 -103
- package/src/VirtualUserManager/index.ts +43 -19
- package/src/commands/adduser.ts +86 -13
- package/src/commands/alias.ts +5 -0
- package/src/commands/apt.ts +5 -0
- package/src/commands/awk.ts +154 -29
- package/src/commands/cd.ts +0 -4
- package/src/commands/clear.ts +5 -0
- package/src/commands/command-helpers.ts +9 -0
- package/src/commands/curl.ts +2 -1
- package/src/commands/declare.ts +5 -0
- package/src/commands/deluser.ts +84 -7
- package/src/commands/df.ts +5 -0
- package/src/commands/du.ts +5 -0
- package/src/commands/export.ts +5 -0
- package/src/commands/grep.ts +21 -8
- package/src/commands/groups.ts +5 -0
- package/src/commands/gzip.ts +61 -28
- package/src/commands/head.ts +14 -4
- package/src/commands/htop.ts +5 -0
- package/src/commands/kill.ts +5 -0
- package/src/commands/ln.ts +22 -0
- package/src/commands/ls.ts +17 -0
- package/src/commands/lsb-release.ts +5 -0
- package/src/commands/man.ts +38 -143
- package/src/commands/manuals/adduser.txt +11 -0
- package/src/commands/manuals/apt-cache.txt +12 -0
- package/src/commands/manuals/apt.txt +20 -0
- package/src/commands/manuals/awk.txt +13 -0
- package/src/commands/manuals/cat.txt +14 -0
- package/src/commands/manuals/cd.txt +16 -0
- package/src/commands/manuals/chmod.txt +16 -0
- package/src/commands/manuals/clear.txt +10 -0
- package/src/commands/manuals/cp.txt +10 -0
- package/src/commands/manuals/curl.txt +20 -0
- package/src/commands/manuals/date.txt +14 -0
- package/src/commands/manuals/declare.txt +12 -0
- package/src/commands/manuals/deluser.txt +10 -0
- package/src/commands/manuals/df.txt +10 -0
- package/src/commands/manuals/dpkg-query.txt +11 -0
- package/src/commands/manuals/dpkg.txt +14 -0
- package/src/commands/manuals/du.txt +11 -0
- package/src/commands/manuals/echo.txt +11 -0
- package/src/commands/manuals/false.txt +10 -0
- package/src/commands/manuals/find.txt +11 -0
- package/src/commands/manuals/free.txt +12 -0
- package/src/commands/manuals/grep.txt +13 -0
- package/src/commands/manuals/groups.txt +10 -0
- package/src/commands/manuals/gzip.txt +11 -0
- package/src/commands/manuals/head.txt +10 -0
- package/src/commands/manuals/help.txt +11 -0
- package/src/commands/manuals/history.txt +11 -0
- package/src/commands/manuals/hostname.txt +10 -0
- package/src/commands/manuals/id.txt +10 -0
- package/src/commands/manuals/kill.txt +13 -0
- package/src/commands/manuals/ls.txt +20 -0
- package/src/commands/manuals/lsb_release.txt +14 -0
- package/src/commands/manuals/mkdir.txt +10 -0
- package/src/commands/manuals/mv.txt +10 -0
- package/src/commands/manuals/nano.txt +11 -0
- package/src/commands/manuals/neofetch.txt +10 -0
- package/src/commands/manuals/node.txt +13 -0
- package/src/commands/manuals/npm.txt +13 -0
- package/src/commands/manuals/npx.txt +13 -0
- package/src/commands/manuals/passwd.txt +11 -0
- package/src/commands/manuals/ping.txt +10 -0
- package/src/commands/manuals/printf.txt +11 -0
- package/src/commands/manuals/ps.txt +10 -0
- package/src/commands/manuals/pwd.txt +10 -0
- package/src/commands/manuals/python3.txt +13 -0
- package/src/commands/manuals/readlink.txt +10 -0
- package/src/commands/manuals/return.txt +10 -0
- package/src/commands/manuals/rm.txt +10 -0
- package/src/commands/manuals/sed.txt +11 -0
- package/src/commands/manuals/set.txt +11 -0
- package/src/commands/manuals/shift.txt +10 -0
- package/src/commands/manuals/sleep.txt +10 -0
- package/src/commands/manuals/sort.txt +12 -0
- package/src/commands/manuals/source.txt +11 -0
- package/src/commands/manuals/ssh.txt +11 -0
- package/src/commands/manuals/stat.txt +10 -0
- package/src/commands/manuals/su.txt +13 -0
- package/src/commands/manuals/sudo.txt +11 -0
- package/src/commands/manuals/tail.txt +10 -0
- package/src/commands/manuals/tar.txt +19 -0
- package/src/commands/manuals/tee.txt +10 -0
- package/src/commands/manuals/test.txt +11 -0
- package/src/commands/manuals/touch.txt +11 -0
- package/src/commands/manuals/tr.txt +10 -0
- package/src/commands/manuals/trap.txt +10 -0
- package/src/commands/manuals/true.txt +10 -0
- package/src/commands/manuals/type.txt +10 -0
- package/src/commands/manuals/uname.txt +12 -0
- package/src/commands/manuals/uniq.txt +12 -0
- package/src/commands/manuals/unset.txt +10 -0
- package/src/commands/manuals/uptime.txt +11 -0
- package/src/commands/manuals/wc.txt +12 -0
- package/src/commands/manuals/wget.txt +12 -0
- package/src/commands/manuals/which.txt +10 -0
- package/src/commands/manuals/whoami.txt +10 -0
- package/src/commands/manuals/xargs.txt +10 -0
- package/src/commands/mkdir.ts +5 -0
- package/src/commands/mv.ts +5 -0
- package/src/commands/nano.ts +5 -0
- package/src/commands/neofetch.ts +15 -6
- package/src/commands/passwd.ts +35 -12
- package/src/commands/ping.ts +5 -0
- package/src/commands/printf.ts +30 -13
- package/src/commands/ps.ts +5 -0
- package/src/commands/read.ts +5 -0
- package/src/commands/registry.ts +4 -1
- package/src/commands/rm.ts +5 -0
- package/src/commands/runtime.ts +1 -61
- package/src/commands/sed.ts +5 -0
- package/src/commands/set.ts +5 -24
- package/src/commands/sh.ts +9 -3
- package/src/commands/shift.ts +10 -0
- package/src/commands/sleep.ts +5 -0
- package/src/commands/sort.ts +5 -0
- package/src/commands/source.ts +5 -0
- package/src/commands/stat.ts +61 -0
- package/src/commands/su.ts +54 -16
- package/src/commands/sudo.ts +5 -0
- package/src/commands/tail.ts +17 -3
- package/src/commands/tar.ts +38 -15
- package/src/commands/tee.ts +5 -0
- package/src/commands/touch.ts +5 -0
- package/src/commands/tr.ts +54 -10
- package/src/commands/tree.ts +5 -0
- package/src/commands/true.ts +10 -0
- package/src/commands/type.ts +5 -0
- package/src/commands/uname.ts +5 -0
- package/src/commands/uniq.ts +5 -0
- package/src/commands/unset.ts +5 -0
- package/src/commands/uptime.ts +5 -0
- package/src/commands/wc.ts +5 -0
- package/src/commands/wget.ts +17 -1
- package/src/commands/who.ts +5 -0
- package/src/commands/whoami.ts +5 -0
- package/src/commands/xargs.ts +5 -0
- package/src/self-standalone.ts +316 -33
- package/src/types/commands.ts +37 -0
- package/src/utils/tokenize.ts +78 -0
- package/tests/new-features.test.ts +2 -2
- package/builds/web-iife.min.js +0 -13
- package/builds/web-iife.min.js.map +0 -7
package/dist/commands/uname.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
|
+
/**
|
|
3
|
+
* Print system information (kernel name, version, machine type).
|
|
4
|
+
* @category system
|
|
5
|
+
* @params ["[-a] [-s] [-r] [-m]"]
|
|
6
|
+
*/
|
|
2
7
|
export declare const unameCommand: ShellModule;
|
|
3
8
|
//# sourceMappingURL=uname.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uname.d.ts","sourceRoot":"","sources":["../../src/commands/uname.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,YAAY,EAAE,WAoB1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"uname.d.ts","sourceRoot":"","sources":["../../src/commands/uname.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAoB1B,CAAC"}
|
package/dist/commands/uname.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { ifFlag } from "./command-helpers";
|
|
2
|
+
/**
|
|
3
|
+
* Print system information (kernel name, version, machine type).
|
|
4
|
+
* @category system
|
|
5
|
+
* @params ["[-a] [-s] [-r] [-m]"]
|
|
6
|
+
*/
|
|
2
7
|
export const unameCommand = {
|
|
3
8
|
name: "uname",
|
|
4
9
|
description: "Print system information",
|
package/dist/commands/uniq.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/commands/uniq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,WAAW,EAAE,WA8BzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"uniq.d.ts","sourceRoot":"","sources":["../../src/commands/uniq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WA8BzB,CAAC"}
|
package/dist/commands/uniq.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { ifFlag } from "./command-helpers";
|
|
2
|
+
/**
|
|
3
|
+
* Report or filter out repeated consecutive lines.
|
|
4
|
+
* @category text
|
|
5
|
+
* @params ["[-c] [-d] [-u] [file]"]
|
|
6
|
+
*/
|
|
2
7
|
export const uniqCommand = {
|
|
3
8
|
name: "uniq",
|
|
4
9
|
description: "Report or filter out repeated lines",
|
package/dist/commands/unset.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unset.d.ts","sourceRoot":"","sources":["../../src/commands/unset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,YAAY,EAAE,WAS1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"unset.d.ts","sourceRoot":"","sources":["../../src/commands/unset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAS1B,CAAC"}
|
package/dist/commands/unset.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uptime.d.ts","sourceRoot":"","sources":["../../src/commands/uptime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,aAAa,EAAE,WA6C3B,CAAC"}
|
|
1
|
+
{"version":3,"file":"uptime.d.ts","sourceRoot":"","sources":["../../src/commands/uptime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WA6C3B,CAAC"}
|
package/dist/commands/uptime.js
CHANGED
package/dist/commands/wc.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wc.d.ts","sourceRoot":"","sources":["../../src/commands/wc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,SAAS,EAAE,WA6CvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"wc.d.ts","sourceRoot":"","sources":["../../src/commands/wc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,WA6CvB,CAAC"}
|
package/dist/commands/wc.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ifFlag } from "./command-helpers";
|
|
2
2
|
import { assertPathAccess, resolvePath } from "./helpers";
|
|
3
|
+
/**
|
|
4
|
+
* Count words, lines, and/or bytes in files or stdin.
|
|
5
|
+
* @category text
|
|
6
|
+
* @params ["[-l] [-w] [-c] [file...]"]
|
|
7
|
+
*/
|
|
3
8
|
export const wcCommand = {
|
|
4
9
|
name: "wc",
|
|
5
10
|
description: "Count words/lines/bytes",
|
package/dist/commands/wget.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
|
+
/**
|
|
3
|
+
* Download files from the web (fetch-based implementation).
|
|
4
|
+
* @category network
|
|
5
|
+
* @params ["[options] <url>"]
|
|
6
|
+
*/
|
|
2
7
|
export declare const wgetCommand: ShellModule;
|
|
3
8
|
//# sourceMappingURL=wget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wget.d.ts","sourceRoot":"","sources":["../../src/commands/wget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"wget.d.ts","sourceRoot":"","sources":["../../src/commands/wget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WA0IzB,CAAC"}
|
package/dist/commands/wget.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ifFlag, parseArgs } from "./command-helpers";
|
|
2
2
|
import { assertPathAccess, resolvePath, stripUrlFilename } from "./helpers";
|
|
3
|
+
/**
|
|
4
|
+
* Download files from the web (fetch-based implementation).
|
|
5
|
+
* @category network
|
|
6
|
+
* @params ["[options] <url>"]
|
|
7
|
+
*/
|
|
3
8
|
export const wgetCommand = {
|
|
4
9
|
name: "wget",
|
|
5
10
|
description: "File downloader (pure fetch)",
|
|
@@ -39,7 +44,17 @@ export const wgetCommand = {
|
|
|
39
44
|
exitCode: 0,
|
|
40
45
|
};
|
|
41
46
|
}
|
|
42
|
-
const
|
|
47
|
+
const urlWithoutProtocol = positionals[0];
|
|
48
|
+
if (!urlWithoutProtocol) {
|
|
49
|
+
return {
|
|
50
|
+
stderr: "wget: missing URL\nUsage: wget [OPTION]... [URL]...",
|
|
51
|
+
exitCode: 1,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const url = urlWithoutProtocol.startsWith("http://") ||
|
|
55
|
+
urlWithoutProtocol.startsWith("https://")
|
|
56
|
+
? urlWithoutProtocol
|
|
57
|
+
: `http://${urlWithoutProtocol}`;
|
|
43
58
|
if (!url)
|
|
44
59
|
return {
|
|
45
60
|
stderr: "wget: missing URL\nUsage: wget [OPTION]... [URL]...",
|
package/dist/commands/who.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"who.d.ts","sourceRoot":"","sources":["../../src/commands/who.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,UAAU,EAAE,WAgBxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"who.d.ts","sourceRoot":"","sources":["../../src/commands/who.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,WAgBxB,CAAC"}
|
package/dist/commands/who.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,aAAa,EAAE,WAM3B,CAAC"}
|
|
1
|
+
{"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WAM3B,CAAC"}
|
package/dist/commands/whoami.js
CHANGED
package/dist/commands/xargs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xargs.d.ts","sourceRoot":"","sources":["../../src/commands/xargs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,YAAY,EAAE,WAsB1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"xargs.d.ts","sourceRoot":"","sources":["../../src/commands/xargs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAsB1B,CAAC"}
|
package/dist/commands/xargs.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { runCommand } from "./runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Build and execute commands from stdin arguments.
|
|
4
|
+
* @category text
|
|
5
|
+
* @params ["[command] [args...]"]
|
|
6
|
+
*/
|
|
2
7
|
export const xargsCommand = {
|
|
3
8
|
name: "xargs",
|
|
4
9
|
description: "Build and execute command lines from stdin",
|
package/dist/self-standalone.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
1
2
|
import { basename } from "node:path";
|
|
2
3
|
import { stdin, stdout } from "node:process";
|
|
3
4
|
import { createInterface } from "node:readline";
|
|
4
5
|
import { makeDefaultEnv, runCommand } from "./commands/runtime";
|
|
6
|
+
import { spawnNanoEditorProcess } from "./modules/shellInteractive";
|
|
5
7
|
import { buildLoginBanner } from "./SSHMimic/loginBanner";
|
|
6
8
|
import { buildPrompt } from "./SSHMimic/prompt";
|
|
7
9
|
import { VirtualShell } from "./VirtualShell";
|
|
@@ -40,9 +42,50 @@ function readLastLogin(username) {
|
|
|
40
42
|
return null;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
function
|
|
45
|
+
function askHiddenQuestion(rl, promptText) {
|
|
44
46
|
return new Promise((resolve) => {
|
|
45
|
-
|
|
47
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
48
|
+
rl.question(promptText, resolve);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const wasRawMode = Boolean(stdin.isRaw);
|
|
52
|
+
let buffer = "";
|
|
53
|
+
const cleanup = () => {
|
|
54
|
+
stdin.off("data", onData);
|
|
55
|
+
if (!wasRawMode) {
|
|
56
|
+
stdin.setRawMode(false);
|
|
57
|
+
}
|
|
58
|
+
rl.resume();
|
|
59
|
+
};
|
|
60
|
+
const finish = (value) => {
|
|
61
|
+
cleanup();
|
|
62
|
+
stdout.write("\n");
|
|
63
|
+
resolve(value);
|
|
64
|
+
};
|
|
65
|
+
const onData = (chunk) => {
|
|
66
|
+
const input = chunk.toString("utf8");
|
|
67
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
68
|
+
const ch = input[index];
|
|
69
|
+
if (ch === "\r" || ch === "\n") {
|
|
70
|
+
finish(buffer);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (ch === "\u007f" || ch === "\b") {
|
|
74
|
+
buffer = buffer.slice(0, -1);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch >= " ") {
|
|
78
|
+
buffer += ch;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
rl.pause();
|
|
83
|
+
stdout.write(promptText);
|
|
84
|
+
if (!wasRawMode) {
|
|
85
|
+
stdin.setRawMode(true);
|
|
86
|
+
}
|
|
87
|
+
stdin.resume();
|
|
88
|
+
stdin.on("data", onData);
|
|
46
89
|
});
|
|
47
90
|
}
|
|
48
91
|
function writeLastLogin(username, from) {
|
|
@@ -52,6 +95,42 @@ function writeLastLogin(username, from) {
|
|
|
52
95
|
}
|
|
53
96
|
virtualShell.vfs.writeFile(`/virtual-env-js/.lastlog/${username}.json`, JSON.stringify({ at: new Date().toISOString(), from }));
|
|
54
97
|
}
|
|
98
|
+
async function flushVfs() {
|
|
99
|
+
await virtualShell.vfs.flushMirror();
|
|
100
|
+
}
|
|
101
|
+
function loadHistory() {
|
|
102
|
+
const historyPath = "/virtual-env-js/.bash_history";
|
|
103
|
+
if (!virtualShell.vfs.exists(historyPath)) {
|
|
104
|
+
virtualShell.vfs.writeFile(historyPath, "");
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return virtualShell.vfs
|
|
108
|
+
.readFile(historyPath)
|
|
109
|
+
.split("\n")
|
|
110
|
+
.map((line) => line.trim())
|
|
111
|
+
.filter((line) => line.length > 0);
|
|
112
|
+
}
|
|
113
|
+
function saveHistory(history) {
|
|
114
|
+
const data = history.length > 0 ? `${history.join("\n")}\n` : "";
|
|
115
|
+
virtualShell.vfs.writeFile("/virtual-env-js/.bash_history", data);
|
|
116
|
+
}
|
|
117
|
+
function applySessionState(authUserState, cwdState, result, shellEnvState) {
|
|
118
|
+
let authUser = authUserState;
|
|
119
|
+
let cwd = cwdState;
|
|
120
|
+
if (result.switchUser) {
|
|
121
|
+
authUser = result.switchUser;
|
|
122
|
+
cwd = result.nextCwd ?? `/home/${authUser}`;
|
|
123
|
+
shellEnvState.vars.USER = authUser;
|
|
124
|
+
shellEnvState.vars.LOGNAME = authUser;
|
|
125
|
+
shellEnvState.vars.HOME = `/home/${authUser}`;
|
|
126
|
+
shellEnvState.vars.PWD = cwd;
|
|
127
|
+
}
|
|
128
|
+
else if (result.nextCwd) {
|
|
129
|
+
cwd = result.nextCwd;
|
|
130
|
+
shellEnvState.vars.PWD = cwd;
|
|
131
|
+
}
|
|
132
|
+
return { authUser, cwd };
|
|
133
|
+
}
|
|
55
134
|
virtualShell.addCommand("demo", [], () => {
|
|
56
135
|
return {
|
|
57
136
|
stdout: "This is a demo command. It does nothing useful.",
|
|
@@ -61,6 +140,9 @@ virtualShell.addCommand("demo", [], () => {
|
|
|
61
140
|
async function runReadlineShell() {
|
|
62
141
|
const rl = createInterface({ input: stdin, output: stdout, terminal: true });
|
|
63
142
|
await virtualShell.ensureInitialized();
|
|
143
|
+
let history = loadHistory();
|
|
144
|
+
const rlWithHistory = rl;
|
|
145
|
+
rlWithHistory.history = [...history].reverse();
|
|
64
146
|
const selectedUser = initialUser.trim() || "root";
|
|
65
147
|
const userExists = virtualShell.users.getPasswordHash(selectedUser) !== null;
|
|
66
148
|
if (!userExists) {
|
|
@@ -72,8 +154,161 @@ async function runReadlineShell() {
|
|
|
72
154
|
let cwd = `/home/${authUser}`;
|
|
73
155
|
shellEnv.vars.PWD = cwd;
|
|
74
156
|
const remoteAddress = "localhost";
|
|
157
|
+
const terminalSize = {
|
|
158
|
+
cols: stdout.columns ?? 80,
|
|
159
|
+
rows: stdout.rows ?? 24,
|
|
160
|
+
};
|
|
161
|
+
async function startNanoEditor(targetPath, initialContent, tempPath) {
|
|
162
|
+
if (virtualShell.vfs.exists(targetPath)) {
|
|
163
|
+
await writeFile(tempPath, initialContent, "utf8");
|
|
164
|
+
}
|
|
165
|
+
rl.pause();
|
|
166
|
+
const editor = spawnNanoEditorProcess(tempPath, terminalSize, {
|
|
167
|
+
write: stdout.write.bind(stdout),
|
|
168
|
+
exit: () => undefined,
|
|
169
|
+
end: () => undefined,
|
|
170
|
+
});
|
|
171
|
+
const wasRawMode = Boolean(stdin.isRaw);
|
|
172
|
+
const forwardInput = (chunk) => {
|
|
173
|
+
editor.stdin.write(chunk);
|
|
174
|
+
};
|
|
175
|
+
stdin.resume();
|
|
176
|
+
if (!wasRawMode) {
|
|
177
|
+
stdin.setRawMode(true);
|
|
178
|
+
}
|
|
179
|
+
stdin.on("data", forwardInput);
|
|
180
|
+
await new Promise((resolve) => {
|
|
181
|
+
const cleanup = () => {
|
|
182
|
+
stdin.off("data", forwardInput);
|
|
183
|
+
if (!wasRawMode) {
|
|
184
|
+
stdin.setRawMode(false);
|
|
185
|
+
}
|
|
186
|
+
rl.resume();
|
|
187
|
+
};
|
|
188
|
+
editor.on("error", (error) => {
|
|
189
|
+
cleanup();
|
|
190
|
+
stdout.write(`nano: ${error.message}\r\n`);
|
|
191
|
+
resolve();
|
|
192
|
+
});
|
|
193
|
+
editor.on("close", async () => {
|
|
194
|
+
cleanup();
|
|
195
|
+
rl.write("", { ctrl: true, name: "u" });
|
|
196
|
+
try {
|
|
197
|
+
const updatedContent = await readFile(tempPath, "utf8");
|
|
198
|
+
virtualShell.writeFileAsUser(authUser, targetPath, updatedContent);
|
|
199
|
+
await flushVfs();
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// Save skipped or temp file missing.
|
|
203
|
+
}
|
|
204
|
+
await unlink(tempPath).catch(() => undefined);
|
|
205
|
+
stdout.write("\r\n");
|
|
206
|
+
resolve();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
async function handleSudoChallenge(challenge) {
|
|
211
|
+
if (challenge.onPassword) {
|
|
212
|
+
let promptText = challenge.prompt;
|
|
213
|
+
while (true) {
|
|
214
|
+
const typed = await askHiddenQuestion(rl, promptText);
|
|
215
|
+
const step = await challenge.onPassword(typed, virtualShell);
|
|
216
|
+
if (step.result === null) {
|
|
217
|
+
promptText = step.nextPrompt ?? promptText;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
await handleCommandResult(step.result);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const password = await askHiddenQuestion(rl, challenge.prompt);
|
|
225
|
+
if (!virtualShell.users.verifyPassword(challenge.username, password)) {
|
|
226
|
+
process.stderr.write("Sorry, try again.\n");
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (!challenge.commandLine) {
|
|
230
|
+
authUser = challenge.targetUser;
|
|
231
|
+
cwd = `/home/${authUser}`;
|
|
232
|
+
shellEnv.vars.USER = authUser;
|
|
233
|
+
shellEnv.vars.LOGNAME = authUser;
|
|
234
|
+
shellEnv.vars.HOME = `/home/${authUser}`;
|
|
235
|
+
shellEnv.vars.PWD = cwd;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const runCwd = challenge.loginShell ? `/home/${challenge.targetUser}` : cwd;
|
|
239
|
+
const nestedResult = await runCommand(challenge.commandLine, challenge.targetUser, hostname, "shell", runCwd, virtualShell, undefined, shellEnv);
|
|
240
|
+
await handleCommandResult(nestedResult);
|
|
241
|
+
}
|
|
242
|
+
async function handlePasswordChallenge(challenge) {
|
|
243
|
+
const first = await askHiddenQuestion(rl, challenge.prompt);
|
|
244
|
+
if (challenge.confirmPrompt) {
|
|
245
|
+
const second = await askHiddenQuestion(rl, challenge.confirmPrompt);
|
|
246
|
+
if (second !== first) {
|
|
247
|
+
process.stderr.write("passwords do not match\n");
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
switch (challenge.action) {
|
|
252
|
+
case "passwd":
|
|
253
|
+
await virtualShell.users.setPassword(challenge.targetUsername, first);
|
|
254
|
+
stdout.write("passwd: password updated successfully\n");
|
|
255
|
+
break;
|
|
256
|
+
case "adduser":
|
|
257
|
+
if (!challenge.newUsername) {
|
|
258
|
+
process.stderr.write("adduser: missing username\n");
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
await virtualShell.users.addUser(challenge.newUsername, first);
|
|
262
|
+
stdout.write(`adduser: user '${challenge.newUsername}' created\n`);
|
|
263
|
+
break;
|
|
264
|
+
case "deluser":
|
|
265
|
+
await virtualShell.users.deleteUser(challenge.targetUsername);
|
|
266
|
+
stdout.write(`Removing user '${challenge.targetUsername}' ...\ndeluser: done.\n`);
|
|
267
|
+
break;
|
|
268
|
+
case "su":
|
|
269
|
+
authUser = challenge.targetUsername;
|
|
270
|
+
cwd = `/home/${authUser}`;
|
|
271
|
+
shellEnv.vars.USER = authUser;
|
|
272
|
+
shellEnv.vars.LOGNAME = authUser;
|
|
273
|
+
shellEnv.vars.HOME = `/home/${authUser}`;
|
|
274
|
+
shellEnv.vars.PWD = cwd;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function handleCommandResult(result) {
|
|
279
|
+
if (result.openEditor) {
|
|
280
|
+
await startNanoEditor(result.openEditor.targetPath, result.openEditor.initialContent, result.openEditor.tempPath);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (result.sudoChallenge) {
|
|
284
|
+
await handleSudoChallenge(result.sudoChallenge);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (result.passwordChallenge) {
|
|
288
|
+
await handlePasswordChallenge(result.passwordChallenge);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (result.stdout) {
|
|
292
|
+
stdout.write(result.stdout.endsWith("\n") ? result.stdout : `${result.stdout}\n`);
|
|
293
|
+
}
|
|
294
|
+
if (result.stderr) {
|
|
295
|
+
process.stderr.write(result.stderr.endsWith("\n") ? result.stderr : `${result.stderr}\n`);
|
|
296
|
+
}
|
|
297
|
+
if (result.clearScreen) {
|
|
298
|
+
stdout.write("\u001b[2J\u001b[H");
|
|
299
|
+
console.clear();
|
|
300
|
+
}
|
|
301
|
+
const updatedState = applySessionState(authUser, cwd, result, shellEnv);
|
|
302
|
+
authUser = updatedState.authUser;
|
|
303
|
+
cwd = updatedState.cwd;
|
|
304
|
+
if (result.closeSession) {
|
|
305
|
+
await flushVfs();
|
|
306
|
+
rl.close();
|
|
307
|
+
process.exit(result.exitCode ?? 0);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
75
310
|
if (process.env.USER !== "root" && virtualShell.users.hasPassword(authUser)) {
|
|
76
|
-
const password = await
|
|
311
|
+
const password = await askHiddenQuestion(rl, `Password for ${authUser}: `);
|
|
77
312
|
if (!virtualShell.users.verifyPassword(authUser, password)) {
|
|
78
313
|
process.stderr.write("self-standalone: authentication failed\n");
|
|
79
314
|
process.exit(1);
|
|
@@ -93,43 +328,32 @@ async function runReadlineShell() {
|
|
|
93
328
|
prompt();
|
|
94
329
|
});
|
|
95
330
|
rl.on("close", () => {
|
|
96
|
-
|
|
97
|
-
|
|
331
|
+
void (async () => {
|
|
332
|
+
await flushVfs();
|
|
333
|
+
console.log("");
|
|
334
|
+
process.exit(0);
|
|
335
|
+
})();
|
|
98
336
|
});
|
|
99
337
|
stdout.write(buildLoginBanner(hostname, virtualShell.properties, readLastLogin(authUser)));
|
|
100
338
|
writeLastLogin(authUser, remoteAddress);
|
|
339
|
+
await flushVfs();
|
|
101
340
|
prompt();
|
|
102
341
|
while (true) {
|
|
103
342
|
const inputLine = await new Promise((resolve) => {
|
|
104
343
|
rl.once("line", (line) => resolve(line));
|
|
105
344
|
});
|
|
106
345
|
rl.pause();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (result.clearScreen) {
|
|
115
|
-
stdout.write("\u001b[2J\u001b[H");
|
|
116
|
-
}
|
|
117
|
-
if (result.switchUser) {
|
|
118
|
-
authUser = result.switchUser;
|
|
119
|
-
cwd = result.nextCwd ?? `/home/${authUser}`;
|
|
120
|
-
shellEnv.vars.USER = authUser;
|
|
121
|
-
shellEnv.vars.LOGNAME = authUser;
|
|
122
|
-
shellEnv.vars.HOME = `/home/${authUser}`;
|
|
123
|
-
shellEnv.vars.PWD = cwd;
|
|
124
|
-
}
|
|
125
|
-
else if (result.nextCwd) {
|
|
126
|
-
cwd = result.nextCwd;
|
|
127
|
-
shellEnv.vars.PWD = cwd;
|
|
128
|
-
}
|
|
129
|
-
if (result.closeSession) {
|
|
130
|
-
rl.close();
|
|
131
|
-
process.exit(result.exitCode ?? 0);
|
|
346
|
+
if (inputLine.trim().length > 0) {
|
|
347
|
+
history.push(inputLine);
|
|
348
|
+
if (history.length > 500) {
|
|
349
|
+
history = history.slice(history.length - 500);
|
|
350
|
+
}
|
|
351
|
+
saveHistory(history);
|
|
352
|
+
rlWithHistory.history = [...history].reverse();
|
|
132
353
|
}
|
|
354
|
+
const result = await runCommand(inputLine, authUser, hostname, "shell", cwd, virtualShell, undefined, shellEnv);
|
|
355
|
+
await handleCommandResult(result);
|
|
356
|
+
await flushVfs();
|
|
133
357
|
prompt();
|
|
134
358
|
rl.resume();
|
|
135
359
|
}
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface CommandResult {
|
|
|
29
29
|
openHtop?: boolean;
|
|
30
30
|
/** Request sudo password challenge flow. */
|
|
31
31
|
sudoChallenge?: SudoChallenge;
|
|
32
|
+
/** Request a generic password challenge (adduser, passwd). */
|
|
33
|
+
passwordChallenge?: PasswordChallenge;
|
|
32
34
|
}
|
|
33
35
|
/** Deferred sudo challenge metadata returned by sudo command. */
|
|
34
36
|
export interface SudoChallenge {
|
|
@@ -42,6 +44,40 @@ export interface SudoChallenge {
|
|
|
42
44
|
loginShell: boolean;
|
|
43
45
|
/** Prompt text shown before password input. */
|
|
44
46
|
prompt: string;
|
|
47
|
+
/**
|
|
48
|
+
* Challenge mode.
|
|
49
|
+
* - `"sudo"` (default): verify `username`'s password, then run `commandLine`.
|
|
50
|
+
* - `"passwd"`: multi-step new-password flow; `onPassword` handles each step.
|
|
51
|
+
* - `"confirm"`: text confirmation flow (e.g. deluser); `onPassword` receives typed text.
|
|
52
|
+
*/
|
|
53
|
+
mode?: "sudo" | "passwd" | "confirm";
|
|
54
|
+
/**
|
|
55
|
+
* Optional async handler called when the user submits input.
|
|
56
|
+
* Receives the typed text and the shell instance.
|
|
57
|
+
* Returns a `CommandResult` written to the terminal, or `null` to show
|
|
58
|
+
* another prompt (pass `nextPrompt` to change the prompt text).
|
|
59
|
+
*/
|
|
60
|
+
onPassword?: (input: string, shell: import("../VirtualShell").VirtualShell) => Promise<{
|
|
61
|
+
result: CommandResult | null;
|
|
62
|
+
nextPrompt?: string;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
/** Generic password challenge — used by adduser, passwd, deluser. */
|
|
66
|
+
export interface PasswordChallenge {
|
|
67
|
+
/** Lines to print before the first prompt. */
|
|
68
|
+
preamble?: string;
|
|
69
|
+
/** Primary prompt text (e.g. "New password: "). */
|
|
70
|
+
prompt: string;
|
|
71
|
+
/** If set, a second prompt is shown for confirmation. */
|
|
72
|
+
confirmPrompt?: string;
|
|
73
|
+
/** Prompt shown for a destructive confirmation (y/N). */
|
|
74
|
+
confirmText?: string;
|
|
75
|
+
/** Tag identifying what to do with the entered value. */
|
|
76
|
+
action: "adduser" | "passwd" | "deluser" | "su";
|
|
77
|
+
/** Username targeted by the action. */
|
|
78
|
+
targetUsername: string;
|
|
79
|
+
/** For adduser: the new user's username (already validated). */
|
|
80
|
+
newUsername?: string;
|
|
45
81
|
}
|
|
46
82
|
/** State payload used by nano command interactive editor flow. */
|
|
47
83
|
export interface NanoEditorSession {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/types/commands.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,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