mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-30 03:16:12 +03:00
1 line
5.2 KiB
JavaScript
1 line
5.2 KiB
JavaScript
function trimIdentifiers(b){for(var a in b){if(!b[a]||b[a]=="None"||b[a]==""){delete b[a]}}}function linux_identifiers(){var c={};var d={};var e={};if(!require("fs").existsSync("/sys/class/dmi/id")){throw ("this platform does not have DMI statistics")}var a=require("fs").readdirSync("/sys/class/dmi/id");for(var b in a){if(require("fs").statSync("/sys/class/dmi/id/"+a[b]).isFile()){d[a[b]]=require("fs").readFileSync("/sys/class/dmi/id/"+a[b]).toString().trim();if(d[a[b]]=="None"){delete d[a[b]]}}}c.bios_date=d.bios_date;c.bios_vendor=d.bios_vendor;c.bios_version=d.bios_version;c.board_name=d.board_name;c.board_serial=d.board_serial;c.board_vendor=d.board_vendor;c.board_version=d.board_version;c.product_uuid=d.product_uuid;e.identifiers=c;e.linux=d;trimIdentifiers(e.identifiers);return(e)}function windows_wmic_results(h){var e=h.trim().split("\r\n");var c=e[0].split(",");var a,b,d;var j;var g=[];for(a=1;a<e.length;++a){var f={};j=e[a].split(",");for(b=0;b<c.length;++b){if(j[b].trim()){f[c[b].trim()]=j[b].trim()}}g.push(f)}return(g)}function windows_identifiers(){var e={windows:{}};values={};var d;var b;var c;var a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","bios","get","/VALUE"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();var d=a.stdout.str.split("\r\r\n");for(b in d){c=d[b].split("=");values[c[0]]=c[1]}e.identifiers={};e.identifiers["bios_date"]=values.ReleaseDate;e.identifiers["bios_vendor"]=values.Manufacturer;e.identifiers["bios_version"]=values.SMBIOSBIOSVersion;a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","BASEBOARD","get","/VALUE"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();var d=a.stdout.str.split("\r\r\n");for(b in d){c=d[b].split("=");values[c[0]]=c[1]}e.identifiers["board_name"]=values.Product;e.identifiers["board_serial"]=values.SerialNumber;e.identifiers["board_vendor"]=values.Manufacturer;e.identifiers["board_version"]=values.Version;a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","CSProduct","get","/VALUE"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();var d=a.stdout.str.split("\r\r\n");for(b in d){c=d[b].split("=");values[c[0]]=c[1]}e.identifiers["product_uuid"]=values.UUID;trimIdentifiers(e.identifiers);a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","MEMORYCHIP","LIST","/FORMAT:CSV"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();e.windows.memory=windows_wmic_results(a.stdout.str);a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","OS","GET","/FORMAT:CSV"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();e.windows.osinfo=windows_wmic_results(a.stdout.str)[0];a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","PARTITION","LIST","/FORMAT:CSV"]);a.stdout.str="";a.stdout.on("data",function(f){this.str+=f.toString()});a.waitExit();e.windows.partitions=windows_wmic_results(a.stdout.str);return(e)}function macos_identifiers(){var b={identifiers:{}};var a;a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(d){this.str+=d.toString()});a.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep board-id | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');a.waitExit();b.identifiers.board_name=a.stdout.str.trim();a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(d){this.str+=d.toString()});a.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep IOPlatformSerialNumber | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');a.waitExit();b.identifiers.board_serial=a.stdout.str.trim();a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(d){this.str+=d.toString()});a.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep manufacturer | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');a.waitExit();b.identifiers.board_vendor=a.stdout.str.trim();a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(d){this.str+=d.toString()});a.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep version | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');a.waitExit();b.identifiers.board_version=a.stdout.str.trim();a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(d){this.str+=d.toString()});a.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');a.waitExit();b.identifiers.product_uuid=a.stdout.str.trim();trimIdentifiers(b.identifiers);return(b)}switch(process.platform){case"linux":module.exports={_ObjectID:"identifiers",get:linux_identifiers};break;case"win32":module.exports={_ObjectID:"identifiers",get:windows_identifiers};break;case"darwin":module.exports={_ObjectID:"identifiers",get:macos_identifiers};break;default:module.exports={get:function(){throw ("Unsupported Platform")}};break}; |