secrez 1.1.1 → 1.1.3
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 +503 -444
- package/bin/secrez.js +50 -47
- package/coverage.report +91 -85
- package/package.json +10 -12
- package/src/Command.js +78 -57
- package/src/PreCommand.js +75 -70
- package/src/Welcome.js +144 -134
- package/src/cliConfig.js +14 -14
- package/src/commands/Alias.js +123 -100
- package/src/commands/Bash.js +10 -12
- package/src/commands/Cat.js +117 -107
- package/src/commands/Cd.js +39 -42
- package/src/commands/Chat.js +75 -63
- package/src/commands/Conf.js +123 -99
- package/src/commands/Contacts.js +189 -171
- package/src/commands/Copy.js +132 -113
- package/src/commands/Courier.js +123 -105
- package/src/commands/Ds.js +88 -76
- package/src/commands/Edit.js +122 -103
- package/src/commands/Export.js +201 -116
- package/src/commands/Find.js +115 -110
- package/src/commands/Help.js +20 -23
- package/src/commands/Import.js +296 -225
- package/src/commands/Lcat.js +36 -39
- package/src/commands/Lcd.js +38 -39
- package/src/commands/Lls.js +58 -55
- package/src/commands/Lpwd.js +20 -24
- package/src/commands/Ls.js +107 -97
- package/src/commands/Mkdir.js +35 -38
- package/src/commands/Mv.js +147 -114
- package/src/commands/Paste.js +68 -65
- package/src/commands/Pwd.js +18 -23
- package/src/commands/Quit.js +22 -24
- package/src/commands/Rm.js +78 -70
- package/src/commands/Shell.js +31 -32
- package/src/commands/Ssh.js +77 -63
- package/src/commands/Tag.js +133 -112
- package/src/commands/Totp.js +166 -136
- package/src/commands/Touch.js +169 -56
- package/src/commands/Use.js +44 -41
- package/src/commands/Ver.js +16 -18
- package/src/commands/Whoami.js +34 -37
- package/src/commands/chat/Contacts.js +41 -44
- package/src/commands/chat/Help.js +20 -23
- package/src/commands/chat/Join.js +59 -55
- package/src/commands/chat/Leave.js +16 -22
- package/src/commands/chat/Quit.js +19 -24
- package/src/commands/chat/Send.js +58 -57
- package/src/commands/chat/Show.js +60 -51
- package/src/commands/chat/Whoami.js +18 -22
- package/src/commands/index.js +20 -22
- package/src/index.js +3 -3
- package/src/prompts/ChatPrompt.js +87 -82
- package/src/prompts/ChatPromptMock.js +11 -17
- package/src/prompts/CommandPrompt.js +146 -138
- package/src/prompts/Completion.js +64 -69
- package/src/prompts/MainPrompt.js +84 -77
- package/src/prompts/MainPromptMock.js +19 -30
- package/src/prompts/MultiEditorPrompt.js +21 -22
- package/src/prompts/SigintManager.js +21 -24
- package/src/utils/AliasManager.js +16 -18
- package/src/utils/ContactManager.js +15 -17
- package/src/utils/Fido2Client.js +59 -49
- package/src/utils/HelpProto.js +130 -117
- package/src/utils/Logger.js +48 -50
- package/.eslintignore +0 -0
- package/.eslintrc +0 -33
- package/.jshintrc +0 -3
package/src/commands/Lcat.js
CHANGED
@@ -1,72 +1,69 @@
|
|
1
|
-
const utils = require(
|
2
|
-
const fs = require(
|
3
|
-
|
4
|
-
class Lcat extends require('../Command') {
|
1
|
+
const utils = require("@secrez/utils");
|
2
|
+
const fs = require("fs-extra");
|
5
3
|
|
4
|
+
class Lcat extends require("../Command") {
|
6
5
|
setHelpAndCompletion() {
|
7
6
|
this.cliConfig.completion.lcat = {
|
8
7
|
_func: this.selfCompletion(this, {
|
9
|
-
external: true
|
8
|
+
external: true,
|
10
9
|
}),
|
11
|
-
_self: this
|
12
|
-
}
|
13
|
-
this.cliConfig.completion.help.lcat = true
|
10
|
+
_self: this,
|
11
|
+
};
|
12
|
+
this.cliConfig.completion.help.lcat = true;
|
14
13
|
this.optionDefinitions = [
|
15
14
|
{
|
16
|
-
name:
|
17
|
-
alias:
|
18
|
-
type: Boolean
|
15
|
+
name: "help",
|
16
|
+
alias: "h",
|
17
|
+
type: Boolean,
|
19
18
|
},
|
20
19
|
{
|
21
|
-
name:
|
22
|
-
completionType:
|
23
|
-
alias:
|
20
|
+
name: "path",
|
21
|
+
completionType: "file",
|
22
|
+
alias: "p",
|
24
23
|
defaultOption: true,
|
25
|
-
type: String
|
24
|
+
type: String,
|
26
25
|
},
|
27
26
|
{
|
28
|
-
name:
|
29
|
-
alias:
|
30
|
-
type: Boolean
|
31
|
-
}
|
32
|
-
]
|
27
|
+
name: "force",
|
28
|
+
alias: "f",
|
29
|
+
type: Boolean,
|
30
|
+
},
|
31
|
+
];
|
33
32
|
}
|
34
33
|
|
35
34
|
help() {
|
36
35
|
return {
|
37
|
-
description: [
|
36
|
+
description: ["Similar to a standard cat in the external fs."],
|
38
37
|
examples: [
|
39
|
-
|
40
|
-
[
|
41
|
-
]
|
42
|
-
}
|
38
|
+
"lcat ../passwords/Facebook",
|
39
|
+
["lcat -f somefile.ext", "Force view even if file looks binary"],
|
40
|
+
],
|
41
|
+
};
|
43
42
|
}
|
44
43
|
|
45
44
|
async lcat(options) {
|
46
|
-
let efs = this.externalFs
|
47
|
-
let p = efs.getNormalizedPath(options.path)
|
48
|
-
if (!options.force && await utils.isBinary(p)) {
|
49
|
-
throw new Error(
|
45
|
+
let efs = this.externalFs;
|
46
|
+
let p = efs.getNormalizedPath(options.path);
|
47
|
+
if (!options.force && (await utils.isBinary(p))) {
|
48
|
+
throw new Error("The file looks as a binary file");
|
50
49
|
} else {
|
51
|
-
return await fs.readFile(p,
|
50
|
+
return await fs.readFile(p, "utf8");
|
52
51
|
}
|
53
52
|
}
|
54
53
|
|
55
54
|
async exec(options = {}) {
|
56
55
|
if (options.help) {
|
57
|
-
return this.showHelp()
|
56
|
+
return this.showHelp();
|
58
57
|
}
|
59
58
|
try {
|
60
|
-
this.validate(options)
|
61
|
-
let data = await this.lcat(options)
|
62
|
-
this.Logger.reset(data)
|
59
|
+
this.validate(options);
|
60
|
+
let data = await this.lcat(options);
|
61
|
+
this.Logger.reset(data);
|
63
62
|
} catch (e) {
|
64
|
-
this.Logger.red(e.message)
|
63
|
+
this.Logger.red(e.message);
|
65
64
|
}
|
66
|
-
await this.prompt.run()
|
65
|
+
await this.prompt.run();
|
67
66
|
}
|
68
67
|
}
|
69
68
|
|
70
|
-
module.exports = Lcat
|
71
|
-
|
72
|
-
|
69
|
+
module.exports = Lcat;
|
package/src/commands/Lcd.js
CHANGED
@@ -1,77 +1,76 @@
|
|
1
|
-
class Lcd extends require(
|
2
|
-
|
1
|
+
class Lcd extends require("../Command") {
|
3
2
|
setHelpAndCompletion() {
|
4
3
|
this.cliConfig.completion.lcd = {
|
5
4
|
_func: this.selfCompletion(this, {
|
6
5
|
external: true,
|
7
6
|
all: true,
|
8
|
-
dironly: true
|
7
|
+
dironly: true,
|
9
8
|
}),
|
10
|
-
_self: this
|
11
|
-
}
|
12
|
-
this.cliConfig.completion.help.lcd = true
|
9
|
+
_self: this,
|
10
|
+
};
|
11
|
+
this.cliConfig.completion.help.lcd = true;
|
13
12
|
this.optionDefinitions = [
|
14
13
|
{
|
15
|
-
name:
|
16
|
-
alias:
|
17
|
-
type: Boolean
|
14
|
+
name: "help",
|
15
|
+
alias: "h",
|
16
|
+
type: Boolean,
|
18
17
|
},
|
19
18
|
{
|
20
|
-
name:
|
21
|
-
completionType:
|
22
|
-
alias:
|
19
|
+
name: "path",
|
20
|
+
completionType: "file",
|
21
|
+
alias: "p",
|
23
22
|
defaultOption: true,
|
24
23
|
type: String,
|
25
|
-
defaultValue:
|
26
|
-
}
|
27
|
-
]
|
24
|
+
defaultValue: "/",
|
25
|
+
},
|
26
|
+
];
|
28
27
|
}
|
29
28
|
|
30
29
|
help() {
|
31
30
|
return {
|
32
|
-
description: [
|
33
|
-
|
31
|
+
description: [
|
32
|
+
"Changes the external working directory.",
|
33
|
+
"Secrez refers to external when refers to unencrypted standard files in the OS.",
|
34
34
|
],
|
35
35
|
examples: [
|
36
|
-
|
37
|
-
[
|
38
|
-
|
39
|
-
]
|
40
|
-
}
|
36
|
+
"lcd ~/Downloads",
|
37
|
+
["lcd", 'change to home dir, like "lcd ~"'],
|
38
|
+
"lcd /var/nginx/log",
|
39
|
+
],
|
40
|
+
};
|
41
41
|
}
|
42
42
|
|
43
43
|
async lcd(options) {
|
44
|
-
let dir = options.path
|
44
|
+
let dir = options.path;
|
45
45
|
if (!this.externalFs.initialLocalWorkingDir) {
|
46
|
-
this.externalFs.initialLocalWorkingDir =
|
46
|
+
this.externalFs.initialLocalWorkingDir =
|
47
|
+
this.secrez.config.localWorkingDir;
|
47
48
|
}
|
48
|
-
if (/^~\//.test(dir) || dir ===
|
49
|
-
dir = dir.replace(/^~/, this.externalFs.initialLocalWorkingDir)
|
49
|
+
if (/^~\//.test(dir) || dir === "~") {
|
50
|
+
dir = dir.replace(/^~/, this.externalFs.initialLocalWorkingDir);
|
50
51
|
}
|
51
|
-
dir = this.externalFs.getNormalizedPath(dir)
|
52
|
+
dir = this.externalFs.getNormalizedPath(dir);
|
52
53
|
if (await this.externalFs.isDir(dir)) {
|
53
|
-
this.secrez.config.localWorkingDir = dir
|
54
|
+
this.secrez.config.localWorkingDir = dir;
|
54
55
|
} else {
|
55
|
-
throw new Error(
|
56
|
+
throw new Error("No such directory");
|
56
57
|
}
|
57
58
|
}
|
58
59
|
|
59
60
|
async exec(options = {}) {
|
60
61
|
if (options.help) {
|
61
|
-
return this.showHelp()
|
62
|
+
return this.showHelp();
|
62
63
|
}
|
63
64
|
try {
|
64
|
-
this.validate(options)
|
65
|
-
options.all = true
|
66
|
-
options.dironly = true
|
67
|
-
await this.lcd(options)
|
65
|
+
this.validate(options);
|
66
|
+
options.all = true;
|
67
|
+
options.dironly = true;
|
68
|
+
await this.lcd(options);
|
68
69
|
} catch (e) {
|
69
|
-
this.Logger.red(e.message)
|
70
|
+
this.Logger.red(e.message);
|
70
71
|
}
|
71
|
-
await this.prompt.run()
|
72
|
+
await this.prompt.run();
|
72
73
|
}
|
73
74
|
}
|
74
75
|
|
75
|
-
module.exports = Lcd
|
76
|
-
|
77
|
-
|
76
|
+
module.exports = Lcd;
|
package/src/commands/Lls.js
CHANGED
@@ -1,100 +1,103 @@
|
|
1
|
-
const {FsUtils} = require(
|
2
|
-
|
3
|
-
class Lls extends require('../Command') {
|
1
|
+
const { FsUtils } = require("@secrez/fs");
|
4
2
|
|
3
|
+
class Lls extends require("../Command") {
|
5
4
|
setHelpAndCompletion() {
|
6
5
|
this.cliConfig.completion.lls = {
|
7
6
|
_func: this.selfCompletion(this, {
|
8
|
-
external: true
|
7
|
+
external: true,
|
9
8
|
}),
|
10
|
-
_self: this
|
11
|
-
}
|
12
|
-
this.cliConfig.completion.help.lls = true
|
9
|
+
_self: this,
|
10
|
+
};
|
11
|
+
this.cliConfig.completion.help.lls = true;
|
13
12
|
this.optionDefinitions = [
|
14
13
|
{
|
15
|
-
name:
|
16
|
-
alias:
|
17
|
-
type: Boolean
|
14
|
+
name: "help",
|
15
|
+
alias: "h",
|
16
|
+
type: Boolean,
|
18
17
|
},
|
19
18
|
{
|
20
|
-
name:
|
21
|
-
completionType:
|
22
|
-
alias:
|
19
|
+
name: "path",
|
20
|
+
completionType: "file",
|
21
|
+
alias: "p",
|
23
22
|
defaultOption: true,
|
24
|
-
type: String
|
23
|
+
type: String,
|
25
24
|
},
|
26
25
|
{
|
27
|
-
name:
|
28
|
-
alias:
|
29
|
-
type: Boolean
|
26
|
+
name: "list",
|
27
|
+
alias: "l",
|
28
|
+
type: Boolean,
|
30
29
|
},
|
31
30
|
{
|
32
|
-
name:
|
33
|
-
alias:
|
34
|
-
type: Boolean
|
31
|
+
name: "all", // includes hidden files
|
32
|
+
alias: "a",
|
33
|
+
type: Boolean,
|
35
34
|
},
|
36
35
|
{
|
37
|
-
name:
|
38
|
-
alias:
|
39
|
-
type: Boolean
|
36
|
+
name: "dironly", // has priority on fileonly
|
37
|
+
alias: "d",
|
38
|
+
type: Boolean,
|
40
39
|
},
|
41
40
|
{
|
42
|
-
name:
|
43
|
-
alias:
|
44
|
-
type: Boolean
|
45
|
-
}
|
46
|
-
]
|
41
|
+
name: "fileonly",
|
42
|
+
alias: "f",
|
43
|
+
type: Boolean,
|
44
|
+
},
|
45
|
+
];
|
47
46
|
}
|
48
47
|
|
49
48
|
help() {
|
50
49
|
return {
|
51
|
-
description: [
|
52
|
-
|
53
|
-
|
50
|
+
description: [
|
51
|
+
"Browses the external directories.",
|
52
|
+
"This is a quick command. Alternatively, you can run commands like",
|
53
|
+
' shell "ls -la"',
|
54
54
|
],
|
55
55
|
examples: [
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
[
|
60
|
-
]
|
61
|
-
}
|
56
|
+
"lls coin",
|
57
|
+
"lls -l ../passwords",
|
58
|
+
"lls ~",
|
59
|
+
["lls -a", "Shows all the file, included hidden ones"],
|
60
|
+
],
|
61
|
+
};
|
62
62
|
}
|
63
63
|
|
64
64
|
async lls(options) {
|
65
|
-
options.returnIsDir = true
|
66
|
-
let [isDir, list] = await this.externalFs.fileList(options)
|
65
|
+
options.returnIsDir = true;
|
66
|
+
let [isDir, list] = await this.externalFs.fileList(options);
|
67
67
|
if (!isDir) {
|
68
|
-
list = await FsUtils.filterLs(options, list)
|
68
|
+
list = await FsUtils.filterLs(options, list);
|
69
69
|
}
|
70
|
-
return list
|
70
|
+
return list;
|
71
71
|
}
|
72
72
|
|
73
73
|
async exec(options = {}) {
|
74
74
|
if (options.help) {
|
75
|
-
return this.showHelp()
|
75
|
+
return this.showHelp();
|
76
76
|
}
|
77
77
|
try {
|
78
|
-
this.validate(options)
|
79
|
-
let list = await this.lls(options)
|
78
|
+
this.validate(options);
|
79
|
+
let list = await this.lls(options);
|
80
80
|
if (list) {
|
81
81
|
if (list.length) {
|
82
|
-
this.Logger.reset(
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
this.Logger.reset(
|
83
|
+
options.list
|
84
|
+
? list.join("\n")
|
85
|
+
: this.prompt.commandPrompt.formatList(
|
86
|
+
list,
|
87
|
+
26,
|
88
|
+
true,
|
89
|
+
this.threeRedDots()
|
90
|
+
)
|
91
|
+
);
|
86
92
|
} else {
|
87
|
-
this.Logger.yellow(
|
93
|
+
this.Logger.yellow("-- no files found --");
|
88
94
|
}
|
89
95
|
}
|
90
96
|
} catch (e) {
|
91
|
-
this.Logger.red(e.message)
|
97
|
+
this.Logger.red(e.message);
|
92
98
|
}
|
93
|
-
await this.prompt.run()
|
99
|
+
await this.prompt.run();
|
94
100
|
}
|
95
101
|
}
|
96
102
|
|
97
|
-
module.exports = Lls
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
module.exports = Lls;
|
package/src/commands/Lpwd.js
CHANGED
@@ -1,46 +1,42 @@
|
|
1
|
-
class Lpwd extends require(
|
2
|
-
|
1
|
+
class Lpwd extends require("../Command") {
|
3
2
|
setHelpAndCompletion() {
|
4
|
-
this.cliConfig.completion.lpwd = {}
|
5
|
-
this.cliConfig.completion.help.lpwd = true
|
3
|
+
this.cliConfig.completion.lpwd = {};
|
4
|
+
this.cliConfig.completion.help.lpwd = true;
|
6
5
|
this.optionDefinitions = [
|
7
6
|
{
|
8
|
-
name:
|
9
|
-
alias:
|
10
|
-
type: Boolean
|
11
|
-
}
|
12
|
-
]
|
7
|
+
name: "help",
|
8
|
+
alias: "h",
|
9
|
+
type: Boolean,
|
10
|
+
},
|
11
|
+
];
|
13
12
|
}
|
14
13
|
|
15
14
|
help() {
|
16
15
|
return {
|
17
|
-
description: [
|
18
|
-
|
16
|
+
description: [
|
17
|
+
"Shows the path of the external working directory.",
|
18
|
+
"Secrez refers to external when refers to unencrypted standard files in the OS.",
|
19
19
|
],
|
20
|
-
examples: [
|
21
|
-
|
22
|
-
]
|
23
|
-
}
|
20
|
+
examples: ["lpwd"],
|
21
|
+
};
|
24
22
|
}
|
25
23
|
|
26
24
|
async lpwd() {
|
27
|
-
return this.secrez.config.localWorkingDir
|
25
|
+
return this.secrez.config.localWorkingDir;
|
28
26
|
}
|
29
27
|
|
30
28
|
async exec(options = {}) {
|
31
29
|
if (options.help) {
|
32
|
-
return this.showHelp()
|
30
|
+
return this.showHelp();
|
33
31
|
}
|
34
32
|
try {
|
35
|
-
this.validate(options)
|
36
|
-
this.Logger.reset(await this.lpwd())
|
33
|
+
this.validate(options);
|
34
|
+
this.Logger.reset(await this.lpwd());
|
37
35
|
} catch (e) {
|
38
|
-
this.Logger.red(e.message)
|
36
|
+
this.Logger.red(e.message);
|
39
37
|
}
|
40
|
-
await this.prompt.run()
|
38
|
+
await this.prompt.run();
|
41
39
|
}
|
42
40
|
}
|
43
41
|
|
44
|
-
module.exports = Lpwd
|
45
|
-
|
46
|
-
|
42
|
+
module.exports = Lpwd;
|