diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed0531..cb8795a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.23.19 | 2024-12-24 | `cpu()` refactored using internal node functions | | 5.23.18 | 2024-12-24 | `cpu()` Handle RISC-V CPU Manufacturer and Brand | | 5.23.17 | 2024-12-23 | `wifiConnections()` refactored - Sequoia compatibel (macOS) | | 5.23.16 | 2024-12-22 | `networkConnections()` refactored PID parsing (macOS) | diff --git a/docs/history.html b/docs/history.html index 5fc51e1..7d7498c 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,7 +57,11 @@ - + + 5.23.19 + 2024-12-24 + inetChecksite() refactored using internal node functions + 5.23.18 2024-12-24 diff --git a/docs/index.html b/docs/index.html index 61b6a15..28e26db 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.23.18
+
New Version: 5.23.19
diff --git a/lib/internet.js b/lib/internet.js index 8e8685b..ffa6e67 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -62,52 +62,14 @@ function inetChecksite(url, callback) { if (callback) { callback(result); } return resolve(result); } - let t = Date.now(); - if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) { - let args = ['-I', '--connect-timeout', '5', '-m', '5']; - args.push(urlSanitized); - let cmd = 'curl'; - util.execSafe(cmd, args).then((stdout) => { - const lines = stdout.split('\n'); - let statusCode = lines[0] && lines[0].indexOf(' ') >= 0 ? parseInt(lines[0].split(' ')[1], 10) : 404; - result.status = statusCode || 404; - result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304); - result.ms = (result.ok ? Date.now() - t : null); - if (callback) { callback(result); } - resolve(result); - }); - } - if (_windows) { // if this is stable, this can be used for all OS types - const http = (urlSanitized.startsWith('https:') ? require('https') : require('http')); - try { - http.get(urlSanitized, (res) => { - const statusCode = res.statusCode; - result.status = statusCode || 404; - result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304); - - if (statusCode !== 200) { - res.resume(); - result.ms = (result.ok ? Date.now() - t : null); - if (callback) { callback(result); } - resolve(result); - } else { - res.on('data', () => { }); - res.on('end', () => { - result.ms = (result.ok ? Date.now() - t : null); - if (callback) { callback(result); } - resolve(result); - }); - } - }).on('error', () => { - if (callback) { callback(result); } - resolve(result); - }); - } catch (err) { - if (callback) { callback(result); } - resolve(result); - } - } + util.checkWebsite(urlSanitized).then((res) => { + result.status = res.statusCode; + result.ok = res.statusCode >= 200 && res.statusCode <= 399;; + result.ms = (result.ok ? res.time : null); + if (callback) { callback(result); } + resolve(result); + }); } else { if (callback) { callback(result); } resolve(result); diff --git a/lib/util.js b/lib/util.js index 8a3ce5e..bd819f0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2483,6 +2483,42 @@ function getAppleModel(key) { }; } +function checkWebsite(url, timeout = 5000) { + const http = ((url.startsWith('https:') || url.indexOf(':443/') > 0 || url.indexOf(':8443/') > 0) ? require('https') : require('http')); + const t = Date.now(); + return new Promise((resolve) => { + http + .get(url, { rejectUnauthorized: false }, function (res) { + res.on('data', () => { }); + res.on('end', () => { + resolve({ + url, + statusCode: res.statusCode, + message: res.statusMessage, + time: Date.now() - t + }); + }); + }) + .on("error", function (e) { + resolve({ + url, + statusCode: 404, + message: e.message, + time: Date.now() - t + }); + }) + .setTimeout(timeout, () => { + request.close(); + resolve({ + url, + statusCode: 408, + message: 'Request Timeout', + time: Date.now() - t + }); + }); + }); +}; + function noop() { } exports.toInt = toInt; @@ -2536,3 +2572,4 @@ exports.WINDIR = WINDIR; exports.getFilesInPath = getFilesInPath; exports.semverCompare = semverCompare; exports.getAppleModel = getAppleModel; +exports.checkWebsite = checkWebsite;