Fixed AMT DNS suffix on non-Win32 agents.

This commit is contained in:
Ylian Saint-Hilaire 2021-07-24 10:56:53 -07:00
parent 7766e1ca07
commit e9e24e13dc

View File

@ -1236,6 +1236,7 @@ function handleServerCommand(data) {
if ((apftunnel != null) || (amt == null)) return;
if ((state == null) || (state.ProvisioningState == null)) return;
if ((state.UUID == null) || (state.UUID.length != 36)) return; // Bad UUID
getAmtOsDnsSuffix(state, function () {
var apfarg = {
mpsurl: mesh.ServerUrl.replace('/agent.ashx', '/apf.ashx'),
mpsuser: data.user, // Agent user name
@ -1253,6 +1254,7 @@ function handleServerCommand(data) {
apftunnel.onChannelClosed = function () { addAmtEvent('LMS tunnel closed.'); apftunnel = null; }
try { apftunnel.connect(); } catch (ex) { }
});
});
break;
}
case 'getScript': {
@ -1337,6 +1339,19 @@ function handleServerCommand(data) {
}
}
// On non-Windows platforms, we need to query the DHCP server for the DNS suffix
function getAmtOsDnsSuffix(mestate, func) {
if ((process.platform == 'win32') || (mestate.net0 == null) || (mestate.net0.mac == null)) { func(mestate); return; }
try { require('linux-dhcp') } catch (ex) { func(mestate); return; }
require('linux-dhcp').client.info(mestate.net0.mac).then(function (d) {
if ((typeof d.options == 'object') && (typeof d.options.domainname == 'string')) { mestate.OsDnsSuffix = d.options.domainname; }
func(mestate);
}, function (e) {
console.log('DHCP error', e);
func(mestate);
});
}
// Download a file from the server and check the hash.
// This download is similar to the one used for meshcore self-update.
var trustedDownloads = {};
@ -3956,8 +3971,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
if (amt == null) { response = "Intel AMT not detected."; break; }
if (apftunnel != null) { response = "Intel AMT server tunnel already active"; break; }
amt.getMeiState(15, function (state) {
if ((state == null) || (state.ProvisioningState == null)) { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "Intel AMT not ready for configuration." }); } else {
getAmtOsDnsSuffix(state, function () {
var rx = '';
if ((state == null) || (state.ProvisioningState == null)) { rx = "Intel AMT not ready for configuration."; } else {
var apfarg = {
mpsurl: mesh.ServerUrl.replace('agent.ashx', 'apf.ashx'),
mpsuser: Buffer.from(mesh.ServerInfo.MeshID, 'hex').toString('base64').substring(0, 16),
@ -3983,9 +3999,10 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
rx = JSON.stringify(ex);
}
}
}
if (rx != '') { require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: rx }); }
});
}
});
break;
}
case 'apf': {