@kalipto/local 1.0.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/index.js +94 -0
- package/kalipto-local-1.0.0.tgz +0 -0
- package/package.json +9 -0
package/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import WebSocket from "ws";
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
|
|
6
|
+
const tokenIndex = process.argv.indexOf("--token");
|
|
7
|
+
const token =
|
|
8
|
+
tokenIndex !== -1
|
|
9
|
+
? process.argv[tokenIndex + 1]
|
|
10
|
+
: null;
|
|
11
|
+
|
|
12
|
+
if (!token) {
|
|
13
|
+
console.error(
|
|
14
|
+
"Usage: npx @kalipto/local --token YOUR_TOKEN"
|
|
15
|
+
);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const WS_URL =
|
|
20
|
+
`ws://api.kaliptosal.dev:3001?token=${token}`;
|
|
21
|
+
|
|
22
|
+
console.log(
|
|
23
|
+
`[Kalipto] Connecting to ${WS_URL}`
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const ws = new WebSocket(WS_URL);
|
|
27
|
+
|
|
28
|
+
ws.on("open", () => {
|
|
29
|
+
console.log(
|
|
30
|
+
`[Kalipto] Connected as ${token}`
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
ws.send(
|
|
34
|
+
JSON.stringify({
|
|
35
|
+
type: "register",
|
|
36
|
+
token,
|
|
37
|
+
hostname: process.env.HOSTNAME || "unknown",
|
|
38
|
+
platform: process.platform,
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
ws.on("message", (msg) => {
|
|
44
|
+
try {
|
|
45
|
+
const data = JSON.parse(msg.toString());
|
|
46
|
+
|
|
47
|
+
console.log(
|
|
48
|
+
"[Kalipto] Message:",
|
|
49
|
+
data
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (data.type === "command") {
|
|
53
|
+
console.log(
|
|
54
|
+
`[Kalipto] Running: ${data.command}`
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
exec(
|
|
58
|
+
data.command,
|
|
59
|
+
{ timeout: 30000 },
|
|
60
|
+
(err, stdout, stderr) => {
|
|
61
|
+
ws.send(
|
|
62
|
+
JSON.stringify({
|
|
63
|
+
type: "result",
|
|
64
|
+
token,
|
|
65
|
+
command: data.command,
|
|
66
|
+
success: !err,
|
|
67
|
+
stdout,
|
|
68
|
+
stderr,
|
|
69
|
+
exitCode: err?.code ?? 0,
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error(
|
|
77
|
+
"[Kalipto] Parse error:",
|
|
78
|
+
e.message
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
ws.on("close", () => {
|
|
84
|
+
console.log(
|
|
85
|
+
"[Kalipto] Connection closed"
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
ws.on("error", (err) => {
|
|
90
|
+
console.error(
|
|
91
|
+
"[Kalipto] Error:",
|
|
92
|
+
err.message
|
|
93
|
+
);
|
|
94
|
+
});
|
|
Binary file
|