terminal-expose 1.0.0 → 1.2.0
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 +12 -18
- package/index.js +40 -447
- package/package.json +5 -9
- package/src/config/env.js +24 -0
- package/src/core/socket.js +56 -0
- package/src/core/terminal.js +93 -0
- package/src/core/tunnel.js +40 -0
- package/src/server/app.js +45 -0
- package/src/templates/viewer.html +482 -0
- package/src/utils/args.js +52 -0
- package/src/utils/system.js +34 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function parseArgs(args) {
|
|
2
|
+
const options = {
|
|
3
|
+
publicTunnel: false,
|
|
4
|
+
tunnelSubdomain: process.env.TUNNEL_SUBDOMAIN || null,
|
|
5
|
+
tunnelHost: process.env.TUNNEL_HOST || undefined,
|
|
6
|
+
};
|
|
7
|
+
const commandArgs = [];
|
|
8
|
+
|
|
9
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
10
|
+
const arg = args[index];
|
|
11
|
+
|
|
12
|
+
if (arg === "--public" || arg === "--tunnel") {
|
|
13
|
+
options.publicTunnel = true;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (arg === "--subdomain") {
|
|
18
|
+
options.tunnelSubdomain = args[index + 1] || null;
|
|
19
|
+
index += 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (arg.startsWith("--subdomain=")) {
|
|
24
|
+
options.tunnelSubdomain = arg.slice("--subdomain=".length) || null;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (arg === "--tunnel-host") {
|
|
29
|
+
options.tunnelHost = args[index + 1] || undefined;
|
|
30
|
+
index += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (arg.startsWith("--tunnel-host=")) {
|
|
35
|
+
options.tunnelHost = arg.slice("--tunnel-host=".length) || undefined;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
commandArgs.push(arg);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
process.env.PUBLIC_TUNNEL === "1" ||
|
|
44
|
+
process.env.PUBLIC_TUNNEL === "true"
|
|
45
|
+
) {
|
|
46
|
+
options.publicTunnel = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { options, commandArgs };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { parseArgs };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const os = require("os");
|
|
2
|
+
|
|
3
|
+
const getDefaultShell = () => {
|
|
4
|
+
switch (process.platform) {
|
|
5
|
+
case "win32":
|
|
6
|
+
return process.env.ComSpec || "powershell.exe";
|
|
7
|
+
|
|
8
|
+
case "darwin":
|
|
9
|
+
return process.env.SHELL || "/bin/zsh";
|
|
10
|
+
|
|
11
|
+
case "linux":
|
|
12
|
+
return process.env.SHELL || "/bin/bash";
|
|
13
|
+
|
|
14
|
+
default:
|
|
15
|
+
return process.env.SHELL || "/bin/sh";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function getLanUrls({ port, session_token }) {
|
|
20
|
+
const urls = [];
|
|
21
|
+
const interfaces = os.networkInterfaces();
|
|
22
|
+
|
|
23
|
+
Object.values(interfaces).forEach((addresses = []) => {
|
|
24
|
+
addresses
|
|
25
|
+
.filter((address) => address.family === "IPv4" && !address.internal)
|
|
26
|
+
.forEach((address) => {
|
|
27
|
+
urls.push(`http://${address.address}:${port}/s/${session_token}`);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return urls;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { getDefaultShell, getLanUrls };
|