@saccolabs/tars 1.10.0 → 1.11.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/package.json
CHANGED
|
@@ -6,6 +6,7 @@ const si = require('systeminformation');
|
|
|
6
6
|
const chokidar = require('chokidar');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
9
10
|
const dotenv = require('dotenv');
|
|
10
11
|
const { exec } = require('child_process');
|
|
11
12
|
|
|
@@ -17,11 +18,12 @@ const handle = app.getRequestHandler();
|
|
|
17
18
|
|
|
18
19
|
const port = process.env.PORT || 3000;
|
|
19
20
|
const DASH_PASSWORD = process.env.DASH_PASSWORD || 'changeme';
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
// Path Agnostic Configuration
|
|
23
|
+
const REAL_HOME = process.env.REAL_HOME || os.homedir();
|
|
24
|
+
const BASE_DIR = process.env.BASE_DIR || path.join(REAL_HOME, '.tars');
|
|
21
25
|
const DATA_DIR = path.join(BASE_DIR, 'data');
|
|
22
26
|
|
|
23
|
-
// Hardcoding the real home for PM2 logs as process.env.HOME is being overriden in the tars shell environment
|
|
24
|
-
const REAL_HOME = '/home/stark';
|
|
25
27
|
const OUT_LOG = path.join(REAL_HOME, '.pm2/logs/tars-supervisor-out.log');
|
|
26
28
|
const ERR_LOG = path.join(REAL_HOME, '.pm2/logs/tars-supervisor-error.log');
|
|
27
29
|
|
|
@@ -91,22 +93,23 @@ app.prepare().then(() => {
|
|
|
91
93
|
// Tars CLI Commands
|
|
92
94
|
server.post('/api/tars/command', (req, res) => {
|
|
93
95
|
const { action, key, value } = req.body;
|
|
96
|
+
const TARS_BIN = path.join(BASE_DIR, 'apps/tars/dist/cli/index.js');
|
|
94
97
|
let command = '';
|
|
95
98
|
|
|
96
99
|
if (action === 'restart') {
|
|
97
|
-
command =
|
|
100
|
+
command = `${TARS_BIN} restart`;
|
|
98
101
|
} else if (action === 'secret' && key && value) {
|
|
99
102
|
// Basic sanitization to prevent command injection
|
|
100
103
|
const sanitizedKey = key.replace(/[^a-zA-Z0-9_]/g, '');
|
|
101
104
|
const sanitizedValue = value.replace(/'/g, "'\\''");
|
|
102
|
-
command =
|
|
105
|
+
command = `${TARS_BIN} secret set ${sanitizedKey} '${sanitizedValue}'`;
|
|
103
106
|
} else {
|
|
104
107
|
return res.status(400).json({ error: 'Invalid action or missing parameters' });
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
console.log(`Executing Tars Command: ${command}`);
|
|
108
|
-
//
|
|
109
|
-
exec(
|
|
111
|
+
// Inherit environment including PATH
|
|
112
|
+
exec(command, { env: process.env }, (error, stdout, stderr) => {
|
|
110
113
|
if (error) {
|
|
111
114
|
console.error(`Tars Command Error: ${error.message}`);
|
|
112
115
|
return res.status(500).json({ error: error.message, stderr });
|