mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-03-09 15:40:18 +00:00 
			
		
		
		
	add mac memory/storage (#5869)
* add mac memory * add macos storage --------- Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
		
							parent
							
								
									269ec02dc0
								
							
						
					
					
						commit
						1b60e4dbfb
					
				
					 3 changed files with 130 additions and 1 deletions
				
			
		| 
						 | 
					@ -563,7 +563,7 @@ function windows_identifiers()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
function macos_identifiers()
 | 
					function macos_identifiers()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    var ret = { identifiers: {} };
 | 
					    var ret = { identifiers: {}, darwin: {} };
 | 
				
			||||||
    var child;
 | 
					    var child;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    child = require('child_process').execFile('/bin/sh', ['sh']);
 | 
					    child = require('child_process').execFile('/bin/sh', ['sh']);
 | 
				
			||||||
| 
						 | 
					@ -602,6 +602,84 @@ function macos_identifiers()
 | 
				
			||||||
    child.waitExit();
 | 
					    child.waitExit();
 | 
				
			||||||
    ret.identifiers.cpu_name = child.stdout.str.trim();
 | 
					    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);
 | 
					    trimIdentifiers(ret.identifiers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -610,6 +688,17 @@ function macos_identifiers()
 | 
				
			||||||
    return (ret);
 | 
					    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()
 | 
					function win_chassisType()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'SystemEnclosure', 'get', 'ChassisTypes']);
 | 
					    var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'SystemEnclosure', 'get', 'ChassisTypes']);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6109,6 +6109,26 @@
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (hardware.darwin) {
 | 
				
			||||||
 | 
					                if (hardware.darwin.memory && (hardware.darwin.memory.length > 0)) {
 | 
				
			||||||
 | 
					                    var x = '';
 | 
				
			||||||
 | 
					                    x += '<table style=width:100%>';
 | 
				
			||||||
 | 
					                    for (var i in hardware.darwin.memory) {
 | 
				
			||||||
 | 
					                        var m = hardware.darwin.memory[i];
 | 
				
			||||||
 | 
					                        if(m.Size && (m.Size == 'No Module Installed')) continue;
 | 
				
			||||||
 | 
					                        x += '<tr><td><div class=style10 style=border-radius:5px;padding:8px>';
 | 
				
			||||||
 | 
					                        x += '<div style=margin-bottom:3px><b>' + EscapeHtml((m.DeviceLocator ? m.DeviceLocator : 'Unknown')) + '</b></div>';
 | 
				
			||||||
 | 
					                        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 += '</div>';
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    x += '</table>';
 | 
				
			||||||
 | 
					                    if (x != '') { sections.push({ name: "Memory", html: x, img: 'ram'}); }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Storage
 | 
					            // Storage
 | 
				
			||||||
            if (hardware.identifiers && ident.storage_devices) {
 | 
					            if (hardware.identifiers && ident.storage_devices) {
 | 
				
			||||||
                var x = '';
 | 
					                var x = '';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12091,6 +12091,26 @@
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (hardware.darwin) {
 | 
				
			||||||
 | 
					                if (hardware.darwin.memory && (hardware.darwin.memory.length > 0)) {
 | 
				
			||||||
 | 
					                    var x = '';
 | 
				
			||||||
 | 
					                    x += '<table style=width:100%>';
 | 
				
			||||||
 | 
					                    for (var i in hardware.darwin.memory) {
 | 
				
			||||||
 | 
					                        var m = hardware.darwin.memory[i];
 | 
				
			||||||
 | 
					                        if(m.Size && (m.Size == 'No Module Installed')) continue;
 | 
				
			||||||
 | 
					                        x += '<tr><td><div class=style10 style=border-radius:5px;padding:8px>';
 | 
				
			||||||
 | 
					                        x += '<div style=margin-bottom:3px><b>' + EscapeHtml((m.DeviceLocator ? m.DeviceLocator : 'Unknown')) + '</b></div>';
 | 
				
			||||||
 | 
					                        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 += '</div>';
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    x += '</table>';
 | 
				
			||||||
 | 
					                    if (x != '') { sections.push({ name: "Memory", html: x, img: 'ram64.png'}); }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Storage
 | 
					            // Storage
 | 
				
			||||||
            if (hardware.identifiers && hardware.identifiers.storage_devices) {
 | 
					            if (hardware.identifiers && hardware.identifiers.storage_devices) {
 | 
				
			||||||
                var x = '';
 | 
					                var x = '';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue