vortix 1.0.1 → 1.0.2
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/agent/agent.js +67 -7
- package/package.json +1 -1
package/agent/agent.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const WebSocket = require("ws");
|
|
2
2
|
const { exec } = require("child_process");
|
|
3
3
|
const os = require("os");
|
|
4
|
+
const readline = require("readline");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
4
7
|
|
|
5
8
|
process.on("uncaughtException", (err) => {
|
|
6
9
|
console.error("Uncaught Exception:", err);
|
|
@@ -10,11 +13,60 @@ process.on("unhandledRejection", (err) => {
|
|
|
10
13
|
console.error("Unhandled Rejection:", err);
|
|
11
14
|
});
|
|
12
15
|
|
|
16
|
+
const CONFIG_FILE = path.join(os.homedir(), '.vortix-config.json');
|
|
17
|
+
|
|
18
|
+
// Load or create config
|
|
19
|
+
function loadConfig() {
|
|
20
|
+
try {
|
|
21
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
22
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error("Error loading config:", err.message);
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function saveConfig(config) {
|
|
31
|
+
try {
|
|
32
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error("Error saving config:", err.message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function promptPassword() {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const rl = readline.createInterface({
|
|
41
|
+
input: process.stdin,
|
|
42
|
+
output: process.stdout
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
rl.question('Set a password for this device: ', (password) => {
|
|
46
|
+
rl.close();
|
|
47
|
+
resolve(password.trim());
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
13
52
|
const command = process.argv[2];
|
|
14
53
|
|
|
15
54
|
if (command === "login") {
|
|
16
|
-
|
|
17
|
-
|
|
55
|
+
(async () => {
|
|
56
|
+
const password = await promptPassword();
|
|
57
|
+
if (!password) {
|
|
58
|
+
console.log("Password is required");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const config = loadConfig();
|
|
63
|
+
config.password = password;
|
|
64
|
+
saveConfig(config);
|
|
65
|
+
|
|
66
|
+
console.log("Password saved successfully!");
|
|
67
|
+
console.log("You can now run: vortix start");
|
|
68
|
+
console.log("\nIMPORTANT: Use this same password in the dashboard to access this device.");
|
|
69
|
+
})();
|
|
18
70
|
return;
|
|
19
71
|
}
|
|
20
72
|
|
|
@@ -24,20 +76,28 @@ if (command === "start") {
|
|
|
24
76
|
}
|
|
25
77
|
|
|
26
78
|
console.log("Available commands:");
|
|
79
|
+
console.log(" vortix login - Set device password");
|
|
27
80
|
console.log(" vortix start - Start the agent");
|
|
28
|
-
console.log(" vortix help - Show help");
|
|
29
81
|
|
|
30
82
|
function startAgent() {
|
|
83
|
+
const config = loadConfig();
|
|
84
|
+
|
|
85
|
+
if (!config.password) {
|
|
86
|
+
console.log("Please set a password first: vortix login");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
31
90
|
const deviceName = os.hostname();
|
|
32
|
-
const
|
|
91
|
+
const deviceToken = `device-${deviceName.toLowerCase()}`;
|
|
92
|
+
const token = `${deviceToken}:${config.password}`;
|
|
33
93
|
|
|
34
|
-
console.log(`
|
|
35
|
-
console.log(
|
|
94
|
+
console.log(`Device: ${deviceName}`);
|
|
95
|
+
console.log("Connecting to backend...");
|
|
36
96
|
|
|
37
97
|
// Production backend URL - Render deployment
|
|
38
98
|
const BACKEND_URL = process.env.BACKEND_URL || 'wss://vortix.onrender.com';
|
|
39
99
|
|
|
40
|
-
const ws = new WebSocket(`${BACKEND_URL}?token=${token}`);
|
|
100
|
+
const ws = new WebSocket(`${BACKEND_URL}?token=${encodeURIComponent(token)}`);
|
|
41
101
|
|
|
42
102
|
ws.on("open", () => {
|
|
43
103
|
console.log("Authenticated and connected to backend");
|