Skip to content

Commit

Permalink
move identifiers to server side to allow future updates (#5641)
Browse files Browse the repository at this point in the history
* move identifiers to server side to allow future updates

Signed-off-by: si458 <[email protected]>

* add rpi support

Signed-off-by: si458 <[email protected]>

---------

Signed-off-by: si458 <[email protected]>
  • Loading branch information
si458 authored Dec 22, 2023
1 parent a17fd2f commit bfae0d6
Show file tree
Hide file tree
Showing 2 changed files with 792 additions and 16 deletions.
33 changes: 17 additions & 16 deletions agents/meshcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ if ((require('fs').existsSync(process.cwd() + 'batterystate.txt')) && (require('
else {
try {
// Setup normal battery monitoring
if (require('identifiers').isBatteryPowered && require('identifiers').isBatteryPowered()) {
if (require('computer-identifiers').isBatteryPowered && require('computer-identifiers').isBatteryPowered()) {
require('MeshAgent')._battLevelChanged = function _battLevelChanged(val) {
_battLevelChanged.self._currentBatteryLevel = val;
_battLevelChanged.self.SendCommand({ action: 'battery', state: _battLevelChanged.self._currentPowerState, level: val });
Expand Down Expand Up @@ -657,14 +657,14 @@ try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; meshCoreO
// Get Volumes and BitLocker if Windows
try {
if (process.platform == 'win32'){
if (require('identifiers').volumes_promise != null){
var p = require('identifiers').volumes_promise();
if (require('computer-identifiers').volumes_promise != null){
var p = require('computer-identifiers').volumes_promise();
p.then(function (res){
meshCoreObj.volumes = res;
meshCoreObjChanged();
});
}else if (require('identifiers').volumes != null){
meshCoreObj.volumes = require('identifiers').volumes();
}else if (require('computer-identifiers').volumes != null){
meshCoreObj.volumes = require('computer-identifiers').volumes();
meshCoreObjChanged();
}
}
Expand Down Expand Up @@ -1813,16 +1813,15 @@ function onFileWatcher(a, b) {
*/

// Replace all key name spaces with _ in an object recursively.
// This is a workaround since require('identifiers').get() returns key names with spaces in them on Linux.
// This is a workaround since require('computer-identifiers').get() returns key names with spaces in them on Linux.
function replaceSpacesWithUnderscoresRec(o) {
if (typeof o != 'object') return;
for (var i in o) { if (i.indexOf(' ') >= 0) { o[i.split(' ').join('_')] = o[i]; delete o[i]; } replaceSpacesWithUnderscoresRec(o[i]); }
}

function getSystemInformation(func) {
try {
var results = { hardware: require('identifiers').get() }; // Hardware info

var results = { hardware: require('computer-identifiers').get() }; // Hardware info
if (results.hardware && results.hardware.windows) {
// Remove extra entries and things that change quickly
var x = results.hardware.windows.osinfo;
Expand Down Expand Up @@ -1873,9 +1872,11 @@ function getSystemInformation(func) {
}
if(results.hardware && results.hardware.linux) {
if (!results.hardware.identifiers['bios_serial']) {
if (require('fs').statSync('/sys/class/dmi/id/product_serial').isFile()){
results.hardware.identifiers['bios_serial'] = require('fs').readFileSync('/sys/class/dmi/id/product_serial').toString().trim();
}
try {
if (require('fs').statSync('/sys/class/dmi/id/product_serial').isFile()){
results.hardware.identifiers['bios_serial'] = require('fs').readFileSync('/sys/class/dmi/id/product_serial').toString().trim();
}
} catch (ex) { }
}
if (!results.hardware.identifiers['bios_mode']) {
try {
Expand Down Expand Up @@ -1928,19 +1929,19 @@ function getSystemInformation(func) {
{
results.pendingReboot = require('win-info').pendingReboot(); // Pending reboot

if (require('identifiers').volumes_promise != null)
if (require('computer-identifiers').volumes_promise != null)
{
var p = require('identifiers').volumes_promise();
var p = require('computer-identifiers').volumes_promise();
p.then(function (res)
{
results.hardware.windows.volumes = res;
results.hash = hasher.syncHash(JSON.stringify(results)).toString('hex');
func(results);
});
}
else if (require('identifiers').volumes != null)
else if (require('computer-identifiers').volumes != null)
{
results.hardware.windows.volumes = require('identifiers').volumes();
results.hardware.windows.volumes = require('computer-identifiers').volumes();
results.hash = hasher.syncHash(JSON.stringify(results)).toString('hex');
func(results);
}
Expand Down Expand Up @@ -4250,7 +4251,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
}
break;
case 'vm':
response = 'Virtual Machine = ' + require('identifiers').isVM();
response = 'Virtual Machine = ' + require('computer-identifiers').isVM();
break;
case 'startupoptions':
response = JSON.stringify(require('MeshAgent').getStartupOptions());
Expand Down
Loading

0 comments on commit bfae0d6

Please sign in to comment.