code-poltergeist-system-monitor 1.0.6
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 code-poltergeist-system-monitor might be problematic. Click here for more details.
- package/index.js +74 -0
- package/package.json +21 -0
- package/te/node_modules/.package-lock.json +44 -0
- package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
- package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
- package/te/node_modules/systeminformation/LICENSE +20 -0
- package/te/node_modules/systeminformation/README.md +1116 -0
- package/te/node_modules/systeminformation/lib/audio.js +222 -0
- package/te/node_modules/systeminformation/lib/battery.js +311 -0
- package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
- package/te/node_modules/systeminformation/lib/cli.js +91 -0
- package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
- package/te/node_modules/systeminformation/lib/docker.js +758 -0
- package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
- package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
- package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
- package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
- package/te/node_modules/systeminformation/lib/index.js +504 -0
- package/te/node_modules/systeminformation/lib/internet.js +237 -0
- package/te/node_modules/systeminformation/lib/memory.js +575 -0
- package/te/node_modules/systeminformation/lib/network.js +1783 -0
- package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
- package/te/node_modules/systeminformation/lib/printer.js +210 -0
- package/te/node_modules/systeminformation/lib/processes.js +1296 -0
- package/te/node_modules/systeminformation/lib/system.js +742 -0
- package/te/node_modules/systeminformation/lib/usb.js +279 -0
- package/te/node_modules/systeminformation/lib/users.js +363 -0
- package/te/node_modules/systeminformation/lib/util.js +1373 -0
- package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
- package/te/node_modules/systeminformation/lib/wifi.js +834 -0
- package/te/node_modules/systeminformation/package.json +99 -0
- package/te/package-lock.json +52 -0
- package/te/package.json +15 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
'use strict';
|
2
|
+
// @ts-check
|
3
|
+
// ==================================================================================
|
4
|
+
// internet.js
|
5
|
+
// ----------------------------------------------------------------------------------
|
6
|
+
// Description: System Information - library
|
7
|
+
// for Node.js
|
8
|
+
// Copyright: (c) 2014 - 2024
|
9
|
+
// Author: Sebastian Hildebrandt
|
10
|
+
// ----------------------------------------------------------------------------------
|
11
|
+
// License: MIT
|
12
|
+
// ==================================================================================
|
13
|
+
// 12. Internet
|
14
|
+
// ----------------------------------------------------------------------------------
|
15
|
+
|
16
|
+
const util = require('./util');
|
17
|
+
|
18
|
+
let _platform = process.platform;
|
19
|
+
|
20
|
+
const _linux = (_platform === 'linux' || _platform === 'android');
|
21
|
+
const _darwin = (_platform === 'darwin');
|
22
|
+
const _windows = (_platform === 'win32');
|
23
|
+
const _freebsd = (_platform === 'freebsd');
|
24
|
+
const _openbsd = (_platform === 'openbsd');
|
25
|
+
const _netbsd = (_platform === 'netbsd');
|
26
|
+
const _sunos = (_platform === 'sunos');
|
27
|
+
|
28
|
+
// --------------------------
|
29
|
+
// check if external site is available
|
30
|
+
|
31
|
+
function inetChecksite(url, callback) {
|
32
|
+
|
33
|
+
return new Promise((resolve) => {
|
34
|
+
process.nextTick(() => {
|
35
|
+
let result = {
|
36
|
+
url: url,
|
37
|
+
ok: false,
|
38
|
+
status: 404,
|
39
|
+
ms: null
|
40
|
+
};
|
41
|
+
if (typeof url !== 'string') {
|
42
|
+
if (callback) { callback(result); }
|
43
|
+
return resolve(result);
|
44
|
+
}
|
45
|
+
let urlSanitized = '';
|
46
|
+
const s = util.sanitizeShellString(url, true);
|
47
|
+
const l = util.mathMin(s.length, 2000);
|
48
|
+
for (let i = 0; i <= l; i++) {
|
49
|
+
if (s[i] !== undefined) {
|
50
|
+
s[i].__proto__.toLowerCase = util.stringToLower;
|
51
|
+
const sl = s[i].toLowerCase();
|
52
|
+
if (sl && sl[0] && !sl[1] && sl[0].length === 1) {
|
53
|
+
urlSanitized = urlSanitized + sl[0];
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
result.url = urlSanitized;
|
58
|
+
try {
|
59
|
+
if (urlSanitized && !util.isPrototypePolluted()) {
|
60
|
+
urlSanitized.__proto__.startsWith = util.stringStartWith;
|
61
|
+
if (urlSanitized.startsWith('file:') || urlSanitized.startsWith('gopher:') || urlSanitized.startsWith('telnet:') || urlSanitized.startsWith('mailto:') || urlSanitized.startsWith('news:') || urlSanitized.startsWith('nntp:')) {
|
62
|
+
if (callback) { callback(result); }
|
63
|
+
return resolve(result);
|
64
|
+
}
|
65
|
+
let t = Date.now();
|
66
|
+
if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
|
67
|
+
let args = ['-I', '--connect-timeout', '5', '-m', '5'];
|
68
|
+
args.push(urlSanitized);
|
69
|
+
let cmd = 'curl';
|
70
|
+
util.execSafe(cmd, args).then((stdout) => {
|
71
|
+
const lines = stdout.split('\n');
|
72
|
+
let statusCode = lines[0] && lines[0].indexOf(' ') >= 0 ? parseInt(lines[0].split(' ')[1], 10) : 404;
|
73
|
+
result.status = statusCode || 404;
|
74
|
+
result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
|
75
|
+
result.ms = (result.ok ? Date.now() - t : null);
|
76
|
+
if (callback) { callback(result); }
|
77
|
+
resolve(result);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
if (_windows) { // if this is stable, this can be used for all OS types
|
81
|
+
const http = (urlSanitized.startsWith('https:') ? require('https') : require('http'));
|
82
|
+
try {
|
83
|
+
http.get(urlSanitized, (res) => {
|
84
|
+
const statusCode = res.statusCode;
|
85
|
+
|
86
|
+
result.status = statusCode || 404;
|
87
|
+
result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
|
88
|
+
|
89
|
+
if (statusCode !== 200) {
|
90
|
+
res.resume();
|
91
|
+
result.ms = (result.ok ? Date.now() - t : null);
|
92
|
+
if (callback) { callback(result); }
|
93
|
+
resolve(result);
|
94
|
+
} else {
|
95
|
+
res.on('data', () => { });
|
96
|
+
res.on('end', () => {
|
97
|
+
result.ms = (result.ok ? Date.now() - t : null);
|
98
|
+
if (callback) { callback(result); }
|
99
|
+
resolve(result);
|
100
|
+
});
|
101
|
+
}
|
102
|
+
}).on('error', () => {
|
103
|
+
if (callback) { callback(result); }
|
104
|
+
resolve(result);
|
105
|
+
});
|
106
|
+
} catch (err) {
|
107
|
+
if (callback) { callback(result); }
|
108
|
+
resolve(result);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
} else {
|
112
|
+
if (callback) { callback(result); }
|
113
|
+
resolve(result);
|
114
|
+
}
|
115
|
+
} catch (err) {
|
116
|
+
if (callback) { callback(result); }
|
117
|
+
resolve(result);
|
118
|
+
}
|
119
|
+
});
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
123
|
+
exports.inetChecksite = inetChecksite;
|
124
|
+
|
125
|
+
// --------------------------
|
126
|
+
// check inet latency
|
127
|
+
|
128
|
+
function inetLatency(host, callback) {
|
129
|
+
|
130
|
+
// fallback - if only callback is given
|
131
|
+
if (util.isFunction(host) && !callback) {
|
132
|
+
callback = host;
|
133
|
+
host = '';
|
134
|
+
}
|
135
|
+
|
136
|
+
host = host || '8.8.8.8';
|
137
|
+
|
138
|
+
return new Promise((resolve) => {
|
139
|
+
process.nextTick(() => {
|
140
|
+
if (typeof host !== 'string') {
|
141
|
+
if (callback) { callback(null); }
|
142
|
+
return resolve(null);
|
143
|
+
}
|
144
|
+
let hostSanitized = '';
|
145
|
+
const s = (util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host, true)).trim();
|
146
|
+
const l = util.mathMin(s.length, 2000);
|
147
|
+
for (let i = 0; i <= l; i++) {
|
148
|
+
if (!(s[i] === undefined)) {
|
149
|
+
s[i].__proto__.toLowerCase = util.stringToLower;
|
150
|
+
const sl = s[i].toLowerCase();
|
151
|
+
if (sl && sl[0] && !sl[1]) {
|
152
|
+
hostSanitized = hostSanitized + sl[0];
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
hostSanitized.__proto__.startsWith = util.stringStartWith;
|
157
|
+
if (hostSanitized.startsWith('file:') || hostSanitized.startsWith('gopher:') || hostSanitized.startsWith('telnet:') || hostSanitized.startsWith('mailto:') || hostSanitized.startsWith('news:') || hostSanitized.startsWith('nntp:')) {
|
158
|
+
if (callback) { callback(null); }
|
159
|
+
return resolve(null);
|
160
|
+
}
|
161
|
+
let params;
|
162
|
+
if (_linux || _freebsd || _openbsd || _netbsd || _darwin) {
|
163
|
+
if (_linux) {
|
164
|
+
params = ['-c', '2', '-w', '3', hostSanitized];
|
165
|
+
}
|
166
|
+
if (_freebsd || _openbsd || _netbsd) {
|
167
|
+
params = ['-c', '2', '-t', '3', hostSanitized];
|
168
|
+
}
|
169
|
+
if (_darwin) {
|
170
|
+
params = ['-c2', '-t3', hostSanitized];
|
171
|
+
}
|
172
|
+
util.execSafe('ping', params).then((stdout) => {
|
173
|
+
let result = null;
|
174
|
+
if (stdout) {
|
175
|
+
const lines = stdout.split('\n').filter((line) => (line.indexOf('rtt') >= 0 || line.indexOf('round-trip') >= 0 || line.indexOf('avg') >= 0)).join('\n');
|
176
|
+
|
177
|
+
const line = lines.split('=');
|
178
|
+
if (line.length > 1) {
|
179
|
+
const parts = line[1].split('/');
|
180
|
+
if (parts.length > 1) {
|
181
|
+
result = parseFloat(parts[1]);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
if (callback) { callback(result); }
|
186
|
+
resolve(result);
|
187
|
+
});
|
188
|
+
}
|
189
|
+
if (_sunos) {
|
190
|
+
const params = ['-s', '-a', hostSanitized, '56', '2'];
|
191
|
+
const filt = 'avg';
|
192
|
+
util.execSafe('ping', params, { timeout: 3000 }).then((stdout) => {
|
193
|
+
let result = null;
|
194
|
+
if (stdout) {
|
195
|
+
const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
|
196
|
+
const line = lines.split('=');
|
197
|
+
if (line.length > 1) {
|
198
|
+
const parts = line[1].split('/');
|
199
|
+
if (parts.length > 1) {
|
200
|
+
result = parseFloat(parts[1].replace(',', '.'));
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
if (callback) { callback(result); }
|
205
|
+
resolve(result);
|
206
|
+
});
|
207
|
+
}
|
208
|
+
if (_windows) {
|
209
|
+
let result = null;
|
210
|
+
try {
|
211
|
+
const params = [hostSanitized, '-n', '1'];
|
212
|
+
util.execSafe('ping', params, util.execOptsWin).then((stdout) => {
|
213
|
+
if (stdout) {
|
214
|
+
let lines = stdout.split('\r\n');
|
215
|
+
lines.shift();
|
216
|
+
lines.forEach(function (line) {
|
217
|
+
if ((line.toLowerCase().match(/ms/g) || []).length === 3) {
|
218
|
+
let l = line.replace(/ +/g, ' ').split(' ');
|
219
|
+
if (l.length > 6) {
|
220
|
+
result = parseFloat(l[l.length - 1]);
|
221
|
+
}
|
222
|
+
}
|
223
|
+
});
|
224
|
+
}
|
225
|
+
if (callback) { callback(result); }
|
226
|
+
resolve(result);
|
227
|
+
});
|
228
|
+
} catch (e) {
|
229
|
+
if (callback) { callback(result); }
|
230
|
+
resolve(result);
|
231
|
+
}
|
232
|
+
}
|
233
|
+
});
|
234
|
+
});
|
235
|
+
}
|
236
|
+
|
237
|
+
exports.inetLatency = inetLatency;
|