diff --git a/modules/amt-lme.js b/modules/amt-lme.js index 63ff1bd..c5263ae 100644 --- a/modules/amt-lme.js +++ b/modules/amt-lme.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -169,23 +169,23 @@ function lme_heci(options) { } } if (this[name][port] == null) - { // Bind a new server socket if not already present - this[name][port] = require('net').createServer(); - this[name][port].HECI = this; - + { try { + // Bind a new server socket if not already present + this[name][port] = require('net').createServer(); + this[name][port].HECI = this; if (lme_port_offset == 0) { this[name][port].listen({ port: port, host: '127.0.0.1' }); // Normal mode } else { this[name][port].listen({ port: (port + lme_port_offset) }); // Debug mode } - } catch (ex) { console.log('Binding error, LMS port ' + (port + lme_port_offset) + ': ' + ex) } // TODO: We can't bind - this[name][port].on('connection', function (socket) { - //console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort); - this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset); - }); - this._binded[port] = true; - this.LMS.emit('bind', this._binded); + this[name][port].on('connection', function (socket) { + //console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort); + this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset); + }); + this._binded[port] = true; + this.LMS.emit('bind', this._binded); + } catch (ex) { console.log(ex, 'Port ' + port); } } var outBuffer = Buffer.alloc(5); outBuffer.writeUInt8(81, 0); diff --git a/modules/amt-mei.js b/modules/amt-mei.js index e2cec41..3a724e1 100644 --- a/modules/amt-mei.js +++ b/modules/amt-mei.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ function amt_heci() { emitterUtils.createEvent('error'); var heci = require('heci'); + var sendConsole = function (msg) { try { require('MeshAgent').SendCommand({ "action": "msg", "type": "console", "value": msg }); } catch (ex) { } } this._ObjectID = "pthi"; this._rq = new Q(); diff --git a/modules/amt-scanner.js b/modules/amt-scanner.js index c455b75..0eb762d 100644 --- a/modules/amt-scanner.js +++ b/modules/amt-scanner.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ function AMTScanner() { if (masknum <= 16 || masknum > 32) return null; masknum = 32 - masknum; for (var i = 0; i < masknum; i++) { mask = (mask << 1); mask++; } - return { min: ip & (0xFFFFFFFF - mask), max: (ip & (0xFFFFFFFF - mask)) + mask }; + return { min: (ip & (0xFFFFFFFF - mask))+1, max: (ip & (0xFFFFFFFF - mask)) + mask -1 };//remove network and broadcast address to avoid irrecoverable socket error } x = this.parseIpv4Addr(range); if (x == null) return null; @@ -83,7 +83,7 @@ function AMTScanner() { return ((num >> 24) & 0xFF) + '.' + ((num >> 16) & 0xFF) + '.' + ((num >> 8) & 0xFF) + '.' + (num & 0xFF); } - this.scan = function (rangestr, timeout) { + this.scan = function (rangestr, timeout, callback) { var iprange = this.parseIPv4Range(rangestr); var rmcp = this.buildRmcpPing(0); var server = this.dgram.createSocket({ type: 'udp4' }); @@ -91,11 +91,15 @@ function AMTScanner() { server.scanResults = []; server.on('error', function (err) { console.log('Error:' + err); }); server.on('message', function (msg, rinfo) { if (rinfo.size > 4) { this.parent.parseRmcpPacket(this, msg, rinfo, function (s, res) { s.scanResults.push(res); }) }; }); - server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) { server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } }); + server.on('listening', function () { for (var i = iprange.min; i <= iprange.max; i++) { + server.send(rmcp, 623, server.parent.IPv4NumToStr(i)); } }); server.bind({ address: '0.0.0.0', port: 0, exclusive: true }); var tmout = setTimeout(function cb() { //console.log("Server closed"); server.close(); + if (callback) { + callback(server.scanResults); + } server.parent.emit('found', server.scanResults); delete server; }, timeout); diff --git a/modules/amt-wsman-duk.js b/modules/amt-wsman-duk.js index 4e9bc33..fcf94d8 100644 --- a/modules/amt-wsman-duk.js +++ b/modules/amt-wsman-duk.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -88,8 +88,10 @@ function CreateWsmanComm(/*host, port, user, pass, tls, extra*/) obj.digest.http = require('http'); } var request = { protocol: (obj.tls == 1 ? 'https:' : 'http:'), method: 'POST', host: obj.host, path: '/wsman', port: obj.port, rejectUnauthorized: false, checkServerIdentity: function (cert) { console.log('checkServerIdentity', JSON.stringify(cert)); } }; + var req = obj.digest.request(request); //console.log('Request ' + (obj.RequestCount++)); + req.on('error', function (e) { obj.gotNextMessagesError({ status: 600 }, 'error', null, [postdata, callback, tag]); }); req.on('response', function (response) { //console.log('Response: ' + response.statusCode); @@ -105,6 +107,7 @@ function CreateWsmanComm(/*host, port, user, pass, tls, extra*/) // Send POST body, this work with binary. req.end(postdata); + obj.ActiveAjaxCount++; return req; } diff --git a/modules/amt-wsman.js b/modules/amt-wsman.js index 6561bd4..f9445ea 100644 --- a/modules/amt-wsman.js +++ b/modules/amt-wsman.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -177,7 +177,7 @@ function WsmanStackCreateService(/*CreateWsmanComm, host, port, user, pass, tls, } function _PutObjToSelectorsXml(selectorSet) { - if (!selectorSet) return ''; + if ((selectorSet == null) || (selectorSet == 'null')) return ''; if (typeof selectorSet == 'string') return selectorSet; if (selectorSet['InstanceID']) return "" + selectorSet['InstanceID'] + ""; var result = ''; diff --git a/modules/amt-xml.js b/modules/amt-xml.js index 5890d74..26f91ea 100644 --- a/modules/amt-xml.js +++ b/modules/amt-xml.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -121,65 +121,68 @@ function _getChildElementsByTagName(name) { var ret = []; if (this.childNodes != function _getChildElementsByTagNameNS(ns, name) { var ret = []; if (this.childNodes != null) { for (var node in this.childNodes) { if (this.childNodes[node].localName == name && (ns == '*' || this.childNodes[node].namespace == ns)) { ret.push(this.childNodes[node]); } } } return (ret); } function _xmlTraverseAllRec(nodes, func) { for (var i in nodes) { func(nodes[i]); if (nodes[i].childNodes) { _xmlTraverseAllRec(nodes[i].childNodes, func); } } } function _turnToXmlRec(text) { - var elementStack = new _treeBuilder(), lastElement = null, x1 = text.split('<'), ret = [], element = null, currentElementName = null; - for (var i in x1) { - var x2 = x1[i].split('>'), x3 = x2[0].split(' '), elementName = x3[0]; - if ((elementName.length > 0) && (elementName[0] != '?')) { - if (elementName[0] != '/') { - var attributes = [], localName, localname2 = elementName.split(' ')[0].split(':'), localName = (localname2.length > 1) ? localname2[1] : localname2[0]; - Object.defineProperty(attributes, "get", - { - value: function () { - if (arguments.length == 1) { - for (var a in this) { if (this[a].name == arguments[0]) { return (this[a]); } } - } - else if (arguments.length == 2) { - for (var a in this) { if (this[a].name == arguments[1] && (arguments[0] == '*' || this[a].namespace == arguments[0])) { return (this[a]); } } - } - else { - throw ('attributes.get(): Invalid number of parameters'); - } - } - }); - elementStack.push({ name: elementName, localName: localName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS, getChildElementsByTagNameNS: _getChildElementsByTagNameNS, attributes: attributes, childNodes: [], nsTable: {} }); - // Parse Attributes - if (x3.length > 0) { - var skip = false; - for (var j in x3) { - if (x3[j] == '/') { - // This is an empty Element - elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':'))); - elementStack.peek().textContent = ''; - lastElement = elementStack.pop(); - skip = true; - break; - } - var k = x3[j].indexOf('='); - if (k > 0) { - var attrName = x3[j].substring(0, k); - var attrValue = x3[j].substring(k + 2, x3[j].length - 1); - var attrNS = elementStack.getNamespace('*'); - - if (attrName == 'xmlns') { - elementStack.addNamespace('*', attrValue); - attrNS = attrValue; - } else if (attrName.startsWith('xmlns:')) { - elementStack.addNamespace(attrName.substring(6), attrValue); - } else { - var ax = attrName.split(':'); - if (ax.length == 2) { attrName = ax[1]; attrNS = elementStack.getNamespace(ax[0]); } + try { + if (text == null) return null; + var elementStack = new _treeBuilder(), lastElement = null, x1 = text.split('<'), ret = [], element = null, currentElementName = null; + for (var i in x1) { + var x2 = x1[i].split('>'), x3 = x2[0].split(' '), elementName = x3[0]; + if ((elementName.length > 0) && (elementName[0] != '?')) { + if (elementName[0] != '/') { + var attributes = [], localName, localname2 = elementName.split(' ')[0].split(':'), localName = (localname2.length > 1) ? localname2[1] : localname2[0]; + Object.defineProperty(attributes, "get", + { + value: function () { + if (arguments.length == 1) { + for (var a in this) { if (this[a].name == arguments[0]) { return (this[a]); } } + } + else if (arguments.length == 2) { + for (var a in this) { if (this[a].name == arguments[1] && (arguments[0] == '*' || this[a].namespace == arguments[0])) { return (this[a]); } } + } + else { + throw ('attributes.get(): Invalid number of parameters'); } - var x = { name: attrName, value: attrValue } - if (attrNS != null) x.namespace = attrNS; - elementStack.peek().attributes.push(x); } + }); + elementStack.push({ name: elementName, localName: localName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS, getChildElementsByTagNameNS: _getChildElementsByTagNameNS, attributes: attributes, childNodes: [], nsTable: {} }); + // Parse Attributes + if (x3.length > 0) { + var skip = false; + for (var j in x3) { + if (x3[j] == '/') { + // This is an empty Element + elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':'))); + elementStack.peek().textContent = ''; + lastElement = elementStack.pop(); + skip = true; + break; + } + var k = x3[j].indexOf('='); + if (k > 0) { + var attrName = x3[j].substring(0, k); + var attrValue = x3[j].substring(k + 2, x3[j].length - 1); + var attrNS = elementStack.getNamespace('*'); + + if (attrName == 'xmlns') { + elementStack.addNamespace('*', attrValue); + attrNS = attrValue; + } else if (attrName.startsWith('xmlns:')) { + elementStack.addNamespace(attrName.substring(6), attrValue); + } else { + var ax = attrName.split(':'); + if (ax.length == 2) { attrName = ax[1]; attrNS = elementStack.getNamespace(ax[0]); } + } + var x = { name: attrName, value: attrValue } + if (attrNS != null) x.namespace = attrNS; + elementStack.peek().attributes.push(x); + } + } + if (skip) { continue; } } - if (skip) { continue; } - } - elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':'))); - if (x2[1]) { elementStack.peek().textContent = x2[1]; } - } else { lastElement = elementStack.pop(); } + elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':'))); + if (x2[1]) { elementStack.peek().textContent = x2[1]; } + } else { lastElement = elementStack.pop(); } + } } - } + } catch (ex) { return null; } return lastElement; } diff --git a/modules/amt.js b/modules/amt.js index 6a3b914..c764f66 100644 --- a/modules/amt.js +++ b/modules/amt.js @@ -1,5 +1,5 @@ /* -Copyright 2018-2019 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/identifiers.js b/modules/identifiers.js index b0fdb6c..781f5fa 100644 --- a/modules/identifiers.js +++ b/modules/identifiers.js @@ -1,5 +1,5 @@ /* -Copyright 2019 Intel Corporation +Copyright 2019-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/monitor-border.js b/modules/monitor-border.js index 01b9a0d..fcc0985 100644 --- a/modules/monitor-border.js +++ b/modules/monitor-border.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/power-monitor.js b/modules/power-monitor.js index 96eaabe..ab70bbb 100644 --- a/modules/power-monitor.js +++ b/modules/power-monitor.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/smbios.js b/modules/smbios.js index 822cd9a..ad8fa8c 100644 --- a/modules/smbios.js +++ b/modules/smbios.js @@ -191,7 +191,12 @@ function SMBiosTables() catch(e) { } - if (JSON.stringify(r).length > 65535) { r = {}; } + try + { + if (JSON.stringify(r).length > 65535) { r = {}; } + } + catch(ee) + {} return r; } this.processorInfo = function processorInfo(data) { diff --git a/modules/sysinfo.js b/modules/sysinfo.js index 5b73b4f..a2dabcb 100644 --- a/modules/sysinfo.js +++ b/modules/sysinfo.js @@ -1,5 +1,5 @@ /* -Copyright 2019 Intel Corporation +Copyright 2019-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -const PDH_FMT_LONG = 0x00000100; -const PDH_FMT_DOUBLE = 0x00000200; +var PDH_FMT_LONG = 0x00000100; +var PDH_FMT_DOUBLE = 0x00000200; var promise = require('promise'); if (process.platform == 'win32') @@ -72,11 +72,11 @@ function windows_cpuUtilization() szName = item.Deref(0, GM.PointerSize).Deref(); if (szName.String == '_Total') { - u.total = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2); + u.total = item.Deref(16, 8).toBuffer().readDoubleLE(); } else { - u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE().toFixed(2); + u.cpus[parseInt(szName.String)] = item.Deref(16, 8).toBuffer().readDoubleLE(); } } @@ -99,8 +99,8 @@ function windows_memUtilization() MemFree: require('bignum').fromBuffer(info.Deref(16, 8).toBuffer(), { endian: 'little' }) }; - ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2); - ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100).toFixed(2); + ret.percentFree = ((ret.MemFree.div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2); + ret.percentConsumed = ((ret.MemTotal.sub(ret.MemFree).div(require('bignum')('1048576')).toNumber() / ret.MemTotal.div(require('bignum')('1048576')).toNumber()) * 100);//.toFixed(2); ret.MemTotal = ret.MemTotal.toString(); ret.MemFree = ret.MemFree.toString(); return (ret); @@ -123,7 +123,7 @@ function linux_cpuUtilization() while (columns[++x] == ''); for (y = x; y < columns.length; ++y) { sum += parseInt(columns[y]); } idle = parseInt(columns[3 + x]); - utilization = (100 - ((idle / sum) * 100)).toFixed(2); + utilization = (100 - ((idle / sum) * 100)); //.toFixed(2); if (!ret.total) { ret.total = utilization; @@ -157,8 +157,8 @@ function linux_memUtilization() break; } } - ret.percentFree = ((ret.free / ret.total) * 100).toFixed(2); - ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100).toFixed(2); + ret.percentFree = ((ret.free / ret.total) * 100);//.toFixed(2); + ret.percentConsumed = (((ret.total - ret.free) / ret.total) * 100);//.toFixed(2); return (ret); } @@ -205,8 +205,8 @@ function macos_memUtilization() mem.MemTotal = parseInt(bdown[0].trim().split(' ')[0]); mem.MemFree = parseInt(bdown[1].trim().split(' ')[0]); - mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100).toFixed(2); - mem.percentConsumed = (((mem.MemTotal - mem.MemFree)/ mem.MemTotal) * 100).toFixed(2); + mem.percentFree = ((mem.MemFree / mem.MemTotal) * 100);//.toFixed(2); + mem.percentConsumed = (((mem.MemTotal - mem.MemFree) / mem.MemTotal) * 100);//.toFixed(2); return (mem); } else diff --git a/modules/wifi-scanner-windows.js b/modules/wifi-scanner-windows.js index afd922c..a457456 100644 --- a/modules/wifi-scanner-windows.js +++ b/modules/wifi-scanner-windows.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/wifi-scanner.js b/modules/wifi-scanner.js index ee81048..32da867 100644 --- a/modules/wifi-scanner.js +++ b/modules/wifi-scanner.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/win-console.js b/modules/win-console.js index 3b982d8..32ae289 100644 --- a/modules/win-console.js +++ b/modules/win-console.js @@ -1,5 +1,5 @@ /* -Copyright 2018 Intel Corporation +Copyright 2018-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/modules/win-info.js b/modules/win-info.js index f14e6be..0f650d4 100644 --- a/modules/win-info.js +++ b/modules/win-info.js @@ -1,5 +1,5 @@ /* -Copyright 2019 Intel Corporation +Copyright 2019-2020 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.