diff --git a/agents/modules_meshcore/computer-identifiers.js b/agents/modules_meshcore/computer-identifiers.js index fce89a35..197bfa18 100644 --- a/agents/modules_meshcore/computer-identifiers.js +++ b/agents/modules_meshcore/computer-identifiers.js @@ -563,7 +563,7 @@ function windows_identifiers() } function macos_identifiers() { - var ret = { identifiers: {} }; + var ret = { identifiers: {}, darwin: {} }; var child; child = require('child_process').execFile('/bin/sh', ['sh']); @@ -602,6 +602,84 @@ function macos_identifiers() child.waitExit(); ret.identifiers.cpu_name = child.stdout.str.trim(); + child = require('child_process').execFile('/bin/sh', ['sh']); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stdin.write('system_profiler SPMemoryDataType\nexit\n'); + child.waitExit(); + var lines = child.stdout.str.trim().split('\n'); + if(lines.length > 0) { + const memorySlots = []; + if(lines[2].trim().includes('Memory Slots:')) { // OLD MACS WITH SLOTS + const Memory = []; + const bankMatches = child.stdout.str.trim().match(/BANK \d+\/DIMM\d+:[\s\S]*?(?=(BANK|$))/g); + bankMatches.forEach(function(match, index) { + const bankInfo = match.match(/BANK (\d+)\/DIMM(\d+):[\s\S]*?Size: (\d+ \w+)[\s\S]*?Type: (\w+)[\s\S]*?Speed: (\d+ \w+)[\s\S]*?Status: (\w+)[\s\S]*?Manufacturer: (0x[0-9A-Fa-f]+)[\s\S]*?Part Number: (0x[0-9A-Fa-f]+)[\s\S]*?Serial Number: (.+)/); + if (bankInfo) { + const bankIndex = bankInfo[1].trim(); + const dimmIndex = bankInfo[2].trim(); + const size = bankInfo[3].trim(); + const type = bankInfo[4].trim(); + const speed = bankInfo[5].trim(); + const status = bankInfo[6].trim(); + const manufacturer = bankInfo[7].trim(); + const partNumber = bankInfo[8].trim(); + const serialNumber = bankInfo[9].trim(); + Memory.push({ + DeviceLocator: "BANK " + bankIndex + "/DIMM" + dimmIndex, + Size: size, + Type: type, + Speed: speed, + Status: status, + Manufacturer: hexToAscii(manufacturer), + PartNumber: hexToAscii(partNumber), + SerialNumber: serialNumber, + }); + } + }); + memorySlots = Memory; + } else { // NEW MACS WITHOUT SLOTS + memorySlots.push({ DeviceLocator: "Onboard Memory", Size: lines[2].split(":")[1].trim(), PartNumber: lines[3].split(":")[1].trim(), Manufacturer: lines[4].split(":")[1].trim() }) + } + ret.darwin.memory = memorySlots; + } + + child = require('child_process').execFile('/bin/sh', ['sh']); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stdin.write('diskutil info -all\nexit\n'); + child.waitExit(); + var sections = child.stdout.str.split('**********\n'); + if(sections.length > 0){ + var devices = []; + for (var i = 0; i < sections.length; i++) { + var lines = sections[i].split('\n'); + var deviceInfo = {}; + var wholeYes = false; + var physicalYes = false; + var oldmac = false; + for (var j = 0; j < lines.length; j++) { + var keyValue = lines[j].split(':'); + var key = keyValue[0].trim(); + var value = keyValue[1] ? keyValue[1].trim() : ''; + if (key === 'Virtual') oldmac = true; + if (key === 'Whole' && value === 'Yes') wholeYes = true; + if (key === 'Virtual' && value === 'No') physicalYes = true; + if(value && key === 'Device / Media Name'){ + deviceInfo['Caption'] = value; + } + if(value && key === 'Disk Size'){ + deviceInfo['Size'] = value.split(' ')[0] + ' ' + value.split(' ')[1]; + } + } + if (wholeYes) { + if (oldmac) { + if (physicalYes) devices.push(deviceInfo); + } else { + devices.push(deviceInfo); + } + } + } + ret.identifiers.storage_devices = devices; + } trimIdentifiers(ret.identifiers); @@ -610,6 +688,17 @@ function macos_identifiers() return (ret); } +function hexToAscii(hexString) { + hexString = hexString.startsWith('0x') ? hexString.slice(2) : hexString; + var str = ''; + for (var i = 0; i < hexString.length; i += 2) { + var hexPair = hexString.substr(i, 2); + str += String.fromCharCode(parseInt(hexPair, 16)); + } + str = str.replace(/[\u007F-\uFFFF]/g, ''); // Remove characters from 0x0080 to 0xFFFF + return str.trim(); +} + function win_chassisType() { var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'SystemEnclosure', 'get', 'ChassisTypes']); diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index c39cd82b..916366bd 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -6109,6 +6109,26 @@ } } + if (hardware.darwin) { + if (hardware.darwin.memory && (hardware.darwin.memory.length > 0)) { + var x = ''; + x += ''; + for (var i in hardware.darwin.memory) { + var m = hardware.darwin.memory[i]; + if(m.Size && (m.Size == 'No Module Installed')) continue; + x += '
'; + x += '
' + EscapeHtml((m.DeviceLocator ? m.DeviceLocator : 'Unknown')) + '
'; + if (m.Size && m.Speed) { x += addDetailItem("Capacity / Speed", format("{0}, {1}", m.Size, m.Speed), s); } + else if (m.Size) { x += addDetailItem("Capacity", format("{0}", (m.Size)), s); } + console.log(m.Manufacturer); + if (m.PartNumber) { x += addDetailItem("Part Number", EscapeHtml((m.Manufacturer && m.Manufacturer != '')?(m.Manufacturer + ', '):'') + EscapeHtml(m.PartNumber), s); } + x += '
'; + } + x += '
'; + if (x != '') { sections.push({ name: "Memory", html: x, img: 'ram'}); } + } + } + // Storage if (hardware.identifiers && ident.storage_devices) { var x = ''; diff --git a/views/default.handlebars b/views/default.handlebars index 5014b4b5..a256737c 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -12091,6 +12091,26 @@ } } + if (hardware.darwin) { + if (hardware.darwin.memory && (hardware.darwin.memory.length > 0)) { + var x = ''; + x += ''; + for (var i in hardware.darwin.memory) { + var m = hardware.darwin.memory[i]; + if(m.Size && (m.Size == 'No Module Installed')) continue; + x += '
'; + x += '
' + EscapeHtml((m.DeviceLocator ? m.DeviceLocator : 'Unknown')) + '
'; + if (m.Size && m.Speed) { x += addDetailItem("Capacity / Speed", format("{0}, {1}", m.Size, m.Speed), s); } + else if (m.Size) { x += addDetailItem("Capacity", format("{0}", (m.Size)), s); } + console.log(m.Manufacturer); + if (m.PartNumber) { x += addDetailItem("Part Number", EscapeHtml((m.Manufacturer && m.Manufacturer != '')?(m.Manufacturer + ', '):'') + EscapeHtml(m.PartNumber), s); } + x += '
'; + } + x += '
'; + if (x != '') { sections.push({ name: "Memory", html: x, img: 'ram64.png'}); } + } + } + // Storage if (hardware.identifiers && hardware.identifiers.storage_devices) { var x = '';