@synetic/et 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/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # ET node collector
2
+
3
+ should be run using:
4
+
5
+ `npx run synetic/et phonehome`
6
+
7
+ with the correct environment variables:
8
+
9
+ SYNETIC_ET_KEY
10
+ SYNETIC_ET_HOME (defaults to 'http://mission-control.test/phonehome')
package/entrypoint.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ const et = require('./index')
4
+ if (require.main === module) {
5
+ et.phoneHome();
6
+ }
package/index.js ADDED
@@ -0,0 +1,38 @@
1
+ const axios = require('axios');
2
+ const yargs = require('yargs')
3
+
4
+ const { encrypt } = require('./lib/encypt');
5
+ const { collect } = require('./lib/collector')
6
+ const KEY = process.env.SYNETIC_ET_KEY || '';
7
+
8
+ const HOME_URL = process.env.SYNETIC_ET_HOME || 'http://mission-control.test/phonehome';
9
+
10
+ const phoneHome = () => {
11
+ console.log(`collecting information to phone home (${HOME_URL})`);
12
+ const data = collect();
13
+ const payload = {
14
+ version: '0.0.1',
15
+ data: encrypt(JSON.stringify(data), KEY)
16
+ }
17
+
18
+ if (yargs.argv.dryRun) {
19
+ console.log('dry running locally');
20
+ console.log(payload);
21
+ if (yargs.argv.reveal) {
22
+ console.log(data);
23
+ }
24
+ process.exit();
25
+ }
26
+
27
+ axios.post(HOME_URL, payload)
28
+ .then(() => {
29
+ console.log('ET phoned home succesfully')
30
+ })
31
+ .catch(error => {
32
+ console.error(error.message);
33
+ });
34
+ }
35
+
36
+ module.exports = {
37
+ phoneHome
38
+ };
@@ -0,0 +1,39 @@
1
+ const fs = require('fs');
2
+ const os = require('os');
3
+
4
+ const framework = () => {
5
+ if (Object.keys(packageJson().dependencies).indexOf('vue') > -1) {
6
+ return `vue ${packageJsonLock().packages["node_modules/vue"].version}`;
7
+ }
8
+ return '';
9
+ }
10
+
11
+ const packageJsonLock = () => {
12
+ const packageJson = fs.readFileSync(`${process.cwd()}/package-lock.json`)
13
+ return JSON.parse(packageJson);
14
+ }
15
+ const packageJson = () => {
16
+ const packageJson = fs.readFileSync(`${process.cwd()}/package-lock.json`)
17
+ return JSON.parse(packageJson);
18
+ }
19
+
20
+ const data = {
21
+ version: {
22
+ engine: `nodejs ${process.version}`,
23
+ framework: framework()
24
+ },
25
+ nodeMeta: {
26
+ // packages: packageJsonLock().packages,
27
+ },
28
+ systemMeta: {
29
+ identifier: os.hostname(),
30
+ ip: '',
31
+ uptime: os.uptime(),
32
+ cpuCount: os.cpus().length,
33
+ load: os.loadavg()
34
+ }
35
+ }
36
+
37
+ module.exports = {
38
+ collect: () => data,
39
+ };
package/lib/encypt.js ADDED
@@ -0,0 +1,31 @@
1
+ const crypto = require('crypto');
2
+ const CYPHER = 'aes-128-cbc';
3
+ const HMAC_CIPHER = 'sha512';
4
+ const KEYPAD_CHAR = '*';
5
+
6
+ const keyLength = crypto.getCipherInfo(CYPHER).ivLength;
7
+ const ensureKeyLength = (string) => string.substring(0, keyLength).padEnd(keyLength, KEYPAD_CHAR)
8
+
9
+ const signHmacSha512 = (text, key) => {
10
+ let hmac = crypto.createHmac(HMAC_CIPHER, key);
11
+ return hmac.update(Buffer.from(text, 'utf-8')).digest('hex')
12
+ }
13
+
14
+ const encrypt = (text, secretString) => {
15
+ const paddedSecretKey = ensureKeyLength(secretString);
16
+ const ivResource = crypto.randomBytes(keyLength);
17
+ const cipher = crypto.createCipheriv(CYPHER, Buffer.from(paddedSecretKey, 'utf-8'), ivResource);
18
+ const value = Buffer.concat([cipher.update(text), cipher.final()]).toString('hex');
19
+ const iv = ivResource.toString('hex')
20
+ return Buffer.from(JSON.stringify({
21
+ iv,
22
+ value,
23
+ mac: signHmacSha512(`${iv}${value}`, paddedSecretKey),
24
+ tag: ''
25
+ }), 'utf-8')
26
+ .toString('base64');
27
+ };
28
+
29
+ module.exports = {
30
+ encrypt
31
+ };
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@synetic/et",
3
+ "version": "1.0.0",
4
+ "description": "The Synetic ET collector for NodeJs",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "./entrypoint.js"
8
+ },
9
+ "bin": "./entrypoint.js",
10
+ "author": "Synetic <info@synetic.nl>",
11
+ "license": "ISC",
12
+ "engines": {
13
+ "node": ">=16",
14
+ "npm": ">=8"
15
+ },
16
+ "dependencies": {
17
+ "axios": "^0.27.2",
18
+ "yargs": "^17.5.1"
19
+ }
20
+ }