Added Last-Modified HTTP header for agent downloads, #3281

This commit is contained in:
Ylian Saint-Hilaire 2021-11-18 18:43:27 -08:00
parent 081b7316bf
commit a95341b171
5 changed files with 43 additions and 56 deletions

View File

@ -1,2 +1 @@
MeshService-signed.exe hashagents.js > hashagents.json MeshService-signed.exe hashagents.js > hashagents.json
pause

View File

@ -27,10 +27,10 @@ var agents = {
'meshagent_osx-universal-64': 10005 'meshagent_osx-universal-64': 10005
} }
var agentinfo = []; var agentinfo = {};
for (var i in agents) { for (var i in agents) {
var info = getAgentInfo(i, agents[i]); var info = getAgentInfo(i, agents[i]);
if (info != null) { agentinfo.push(info); } if (info != null) { agentinfo[agents[i]] = info; }
} }
console.log(JSON.stringify(agentinfo, null, 2)); console.log(JSON.stringify(agentinfo, null, 2));
process.exit(); process.exit();
@ -38,5 +38,5 @@ process.exit();
function getAgentInfo(filename, id) { function getAgentInfo(filename, id) {
if (fs.existsSync(filename) != true) return null; if (fs.existsSync(filename) != true) return null;
var stats = fs.statSync(filename); var stats = fs.statSync(filename);
return { id: id, filename: filename, hash: getSHA384FileHash(filename).toString('hex'), size: stats.size, mtime: stats.mtime }; return { filename: filename, hash: getSHA384FileHash(filename).toString('hex'), size: stats.size, mtime: stats.mtime };
} }

View File

@ -1,156 +1,134 @@
[ {
{ "3": {
"id": 3,
"filename": "MeshService-signed.exe", "filename": "MeshService-signed.exe",
"hash": "2CDC48B46AB3580DF2B184CEA7A77F6DA61DC8B7F0A8D46076A3CB1AFB394D6302E7ACE9918B67754F48578C26967929", "hash": "2CDC48B46AB3580DF2B184CEA7A77F6DA61DC8B7F0A8D46076A3CB1AFB394D6302E7ACE9918B67754F48578C26967929",
"size": 3423040, "size": 3423040,
"mtime": "2021-08-30T21:06:32Z" "mtime": "2021-08-30T21:06:32Z"
}, },
{ "4": {
"id": 4,
"filename": "MeshService64-signed.exe", "filename": "MeshService64-signed.exe",
"hash": "80645B8D669A2A74B9E53CE2A19CEAA73E0F7F45808B1EBDA4007A85740A64871F0CB8D6FEF12ED25F6352A3C9ED6468", "hash": "80645B8D669A2A74B9E53CE2A19CEAA73E0F7F45808B1EBDA4007A85740A64871F0CB8D6FEF12ED25F6352A3C9ED6468",
"size": 3037504, "size": 3037504,
"mtime": "2021-08-30T21:06:35Z" "mtime": "2021-08-30T21:06:35Z"
}, },
{ "5": {
"id": 5,
"filename": "meshagent_x86", "filename": "meshagent_x86",
"hash": "AF99F40A4BBF394CB15E6196D2AC58B605DCE855297240687131CB91947DC2B35556C2F7E11D2BCB9B10D3D023006D29", "hash": "AF99F40A4BBF394CB15E6196D2AC58B605DCE855297240687131CB91947DC2B35556C2F7E11D2BCB9B10D3D023006D29",
"size": 3592672, "size": 3592672,
"mtime": "2021-09-10T07:19:52Z" "mtime": "2021-09-10T07:19:52Z"
}, },
{ "6": {
"id": 6,
"filename": "meshagent_x86-64", "filename": "meshagent_x86-64",
"hash": "9EF3E973A6363C13C5311699494F6C52574408805DFD848589B59000BDE3E8A414884BB8FCAA912689E051A57503E977", "hash": "9EF3E973A6363C13C5311699494F6C52574408805DFD848589B59000BDE3E8A414884BB8FCAA912689E051A57503E977",
"size": 3667280, "size": 3667280,
"mtime": "2021-09-10T07:20:01Z" "mtime": "2021-09-10T07:20:01Z"
}, },
{ "7": {
"id": 9,
"filename": "meshagent_arm",
"hash": "67191C284B94F8A491224128A7FCA46934D71AB40E85C3A711E93693D544BB42C9A29A936DAC70FD0FA3C6EA5444EB60",
"size": 3082440,
"mtime": "2021-09-10T07:20:18Z"
},
{
"id": 7,
"filename": "meshagent_mips", "filename": "meshagent_mips",
"hash": "CBF5734FA56F446B2638409520B05BA4F3FB0B21ECC7F4A449FD4E05F782C4D15E1B1B183C3D61E7B4F9957F42D4CDE5", "hash": "CBF5734FA56F446B2638409520B05BA4F3FB0B21ECC7F4A449FD4E05F782C4D15E1B1B183C3D61E7B4F9957F42D4CDE5",
"size": 4459048, "size": 4459048,
"mtime": "2021-09-10T07:20:09Z" "mtime": "2021-09-10T07:20:09Z"
}, },
{ "9": {
"id": 13, "filename": "meshagent_arm",
"hash": "67191C284B94F8A491224128A7FCA46934D71AB40E85C3A711E93693D544BB42C9A29A936DAC70FD0FA3C6EA5444EB60",
"size": 3082440,
"mtime": "2021-09-10T07:20:18Z"
},
"13": {
"filename": "meshagent_pogo", "filename": "meshagent_pogo",
"hash": "8149F61A680EB7F423D2238C464F3D4B129CC7D8BE535EA90AC85AA4953090980AC76A950EE0FBD733D7F56C04A85C0F", "hash": "8149F61A680EB7F423D2238C464F3D4B129CC7D8BE535EA90AC85AA4953090980AC76A950EE0FBD733D7F56C04A85C0F",
"size": 3090672, "size": 3090672,
"mtime": "2021-09-10T07:20:28Z" "mtime": "2021-09-10T07:20:28Z"
}, },
{ "15": {
"id": 15,
"filename": "meshagent_poky", "filename": "meshagent_poky",
"hash": "E105402B8E8FD16D0FF167F05B5A5D31AA00A59138BD59DA71FAC598CB1FD7DEF0DB678C890C4BCEED3D154D17D0D48C", "hash": "E105402B8E8FD16D0FF167F05B5A5D31AA00A59138BD59DA71FAC598CB1FD7DEF0DB678C890C4BCEED3D154D17D0D48C",
"size": 3722776, "size": 3722776,
"mtime": "2021-09-10T07:20:38Z" "mtime": "2021-09-10T07:20:38Z"
}, },
{ "16": {
"id": 16,
"filename": "meshagent_osx-x86-64", "filename": "meshagent_osx-x86-64",
"hash": "87A62A4A2973CED1ECAA0B9041C146C021ADF629654DAA88D3F91291423610155E02B6520F64F00D460EF2994B9AEE20", "hash": "87A62A4A2973CED1ECAA0B9041C146C021ADF629654DAA88D3F91291423610155E02B6520F64F00D460EF2994B9AEE20",
"size": 4602880, "size": 4602880,
"mtime": "2021-08-30T22:13:56Z" "mtime": "2021-08-30T22:13:56Z"
}, },
{ "18": {
"id": 18,
"filename": "meshagent_poky64", "filename": "meshagent_poky64",
"hash": "DA5A4D60ECF4F9E8209B75A6DECFD0E441069992817AFAB35C2B7C15E23F1AC282112834C98C40F6E191C1AB1707CCC9", "hash": "DA5A4D60ECF4F9E8209B75A6DECFD0E441069992817AFAB35C2B7C15E23F1AC282112834C98C40F6E191C1AB1707CCC9",
"size": 3421528, "size": 3421528,
"mtime": "2021-09-10T07:20:49Z" "mtime": "2021-09-10T07:20:49Z"
}, },
{ "19": {
"id": 19,
"filename": "meshagent_x86_nokvm", "filename": "meshagent_x86_nokvm",
"hash": "C442B07E3B8AE297637F4CD8FAC0265E933B1CFBAB32CF853FA820D7A5C458D8F1EABA6357930063CCA1535431858F75", "hash": "C442B07E3B8AE297637F4CD8FAC0265E933B1CFBAB32CF853FA820D7A5C458D8F1EABA6357930063CCA1535431858F75",
"size": 3311940, "size": 3311940,
"mtime": "2021-09-10T07:20:58Z" "mtime": "2021-09-10T07:20:58Z"
}, },
{ "20": {
"id": 20,
"filename": "meshagent_x86-64_nokvm", "filename": "meshagent_x86-64_nokvm",
"hash": "D636882449476750999C1A74A302D97ECBD90E018F8D2708CA0AF64C6708A62D64A84AD6A543D50776DA888FC11AA5A0", "hash": "D636882449476750999C1A74A302D97ECBD90E018F8D2708CA0AF64C6708A62D64A84AD6A543D50776DA888FC11AA5A0",
"size": 3372336, "size": 3372336,
"mtime": "2021-09-10T07:21:06Z" "mtime": "2021-09-10T07:21:06Z"
}, },
{ "24": {
"id": 24,
"filename": "meshagent_arm-linaro", "filename": "meshagent_arm-linaro",
"hash": "68FEC6927EEDC000FC768A47685B9240D72A625F11A69DE2198AD125096DAA93699C2BDAC130A4C8E060946FBF64F910", "hash": "68FEC6927EEDC000FC768A47685B9240D72A625F11A69DE2198AD125096DAA93699C2BDAC130A4C8E060946FBF64F910",
"size": 2149632, "size": 2149632,
"mtime": "2021-09-10T07:21:19Z" "mtime": "2021-09-10T07:21:19Z"
}, },
{ "25": {
"id": 25,
"filename": "meshagent_armhf", "filename": "meshagent_armhf",
"hash": "327956E768DCCF7B02DD1AE1E024169E2FCA1D7B605703CC8AE948E7FF94C8572BC561794C5667C0E51C3844DACFD4E1", "hash": "327956E768DCCF7B02DD1AE1E024169E2FCA1D7B605703CC8AE948E7FF94C8572BC561794C5667C0E51C3844DACFD4E1",
"size": 3109428, "size": 3109428,
"mtime": "2021-09-10T00:59:44Z" "mtime": "2021-09-10T00:59:44Z"
}, },
{ "27": {
"id": 27,
"filename": "meshagent_armhf2", "filename": "meshagent_armhf2",
"hash": "0AE840520D3B677B9767EA097F3AA5A1E24212529E688200F43935DB1541AB9FB441EC2C7BA8002D45299B04695FD037", "hash": "0AE840520D3B677B9767EA097F3AA5A1E24212529E688200F43935DB1541AB9FB441EC2C7BA8002D45299B04695FD037",
"size": 2837724, "size": 2837724,
"mtime": "2021-08-30T21:10:03Z" "mtime": "2021-08-30T21:10:03Z"
}, },
{ "28": {
"id": 28,
"filename": "meshagent_mips24kc", "filename": "meshagent_mips24kc",
"hash": "E78A135132AD6E8C7CBAD0576FCC61FAE97D3AB0C29FCEFB704AA664B179AE296E2B562B84A7A0D717CB6C12A680289A", "hash": "E78A135132AD6E8C7CBAD0576FCC61FAE97D3AB0C29FCEFB704AA664B179AE296E2B562B84A7A0D717CB6C12A680289A",
"size": 4105420, "size": 4105420,
"mtime": "2021-08-30T22:02:32Z" "mtime": "2021-08-30T22:02:32Z"
}, },
{ "29": {
"id": 29,
"filename": "meshagent_osx-arm-64", "filename": "meshagent_osx-arm-64",
"hash": "6B65D0949B5505A61552AD14DA6F59A8B98E922186F0027925BC64979D2D84EF76169ABCFF08A67515AE7368F63D0C87", "hash": "6B65D0949B5505A61552AD14DA6F59A8B98E922186F0027925BC64979D2D84EF76169ABCFF08A67515AE7368F63D0C87",
"size": 3843944, "size": 3843944,
"mtime": "2021-08-30T22:13:56Z" "mtime": "2021-08-30T22:13:56Z"
}, },
{ "30": {
"id": 30,
"filename": "meshagent_freebsd_x86-64", "filename": "meshagent_freebsd_x86-64",
"hash": "D65C1F4180C03387F438F9051A7830C7F56DBFD618A951FB2142F7871AD998D5B61182FB693DDDDB2F31B3000D59E52D", "hash": "D65C1F4180C03387F438F9051A7830C7F56DBFD618A951FB2142F7871AD998D5B61182FB693DDDDB2F31B3000D59E52D",
"size": 4599672, "size": 4599672,
"mtime": "2021-09-10T01:07:08Z" "mtime": "2021-09-10T01:07:08Z"
}, },
{ "32": {
"id": 32,
"filename": "meshagent_aarch64", "filename": "meshagent_aarch64",
"hash": "49216370F497A7C0DA531FA2DFC478582865E7C547FD54E44E84BA12A271CD7AC529F7B7A8F2C8F531726E625631A941", "hash": "49216370F497A7C0DA531FA2DFC478582865E7C547FD54E44E84BA12A271CD7AC529F7B7A8F2C8F531726E625631A941",
"size": 3170528, "size": 3170528,
"mtime": "2021-09-10T00:59:00Z" "mtime": "2021-09-10T00:59:00Z"
}, },
{ "40": {
"id": 40,
"filename": "meshagent_mipsel24kc", "filename": "meshagent_mipsel24kc",
"hash": "A94FE82E0265B1265B1C373722C448631035486E819132B037733BA205730DD71D8C8C16B1057B36B5569AEB4411ADB1", "hash": "A94FE82E0265B1265B1C373722C448631035486E819132B037733BA205730DD71D8C8C16B1057B36B5569AEB4411ADB1",
"size": 4101068, "size": 4101068,
"mtime": "2021-08-30T22:03:12Z" "mtime": "2021-08-30T22:03:12Z"
}, },
{ "41": {
"id": 41,
"filename": "meshagent_aarch64-cortex-a53", "filename": "meshagent_aarch64-cortex-a53",
"hash": "B481A87A8EB803E09118B6F55B9344403926EA9324B3C669D2BA37014DDB79655678BC7D8D7843AD19FFADBB130D0203", "hash": "B481A87A8EB803E09118B6F55B9344403926EA9324B3C669D2BA37014DDB79655678BC7D8D7843AD19FFADBB130D0203",
"size": 3002552, "size": 3002552,
"mtime": "2021-08-30T22:03:50Z" "mtime": "2021-08-30T22:03:50Z"
}, },
{ "10005": {
"id": 10005,
"filename": "meshagent_osx-universal-64", "filename": "meshagent_osx-universal-64",
"hash": "52EB0C2321108E57A113AB3115E0DE74EA4B07F4B7D80E4FB146DE275D63B1354869071AE7F56097B0D6271205B1FDAD", "hash": "52EB0C2321108E57A113AB3115E0DE74EA4B07F4B7D80E4FB146DE275D63B1354869071AE7F56097B0D6271205B1FDAD",
"size": 8464232, "size": 8464232,
"mtime": "2021-08-30T22:13:56Z" "mtime": "2021-08-30T22:13:56Z"
} }
] }

View File

@ -2716,6 +2716,10 @@ function CreateMeshCentralServer(config, args) {
// Update the list of available mesh agents // Update the list of available mesh agents
obj.updateMeshAgentsTable = function (func) { obj.updateMeshAgentsTable = function (func) {
// Load agent information file. This includes the data & time of the agent.
var agentInfo = [];
try { agentInfo = JSON.parse(obj.fs.readFileSync(obj.path.join(__dirname, 'agents', 'hashagents.json'), 'utf8')); } catch (ex) { }
var archcount = 0; var archcount = 0;
for (var archid in obj.meshAgentsArchitectureNumbers) { for (var archid in obj.meshAgentsArchitectureNumbers) {
var agentpath = obj.path.join(__dirname, 'agents', obj.meshAgentsArchitectureNumbers[archid].localname); var agentpath = obj.path.join(__dirname, 'agents', obj.meshAgentsArchitectureNumbers[archid].localname);
@ -2730,6 +2734,7 @@ function CreateMeshCentralServer(config, args) {
obj.meshAgentBinaries[archid].path = agentpath; obj.meshAgentBinaries[archid].path = agentpath;
obj.meshAgentBinaries[archid].url = 'http://' + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?id=' + archid; obj.meshAgentBinaries[archid].url = 'http://' + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?id=' + archid;
obj.meshAgentBinaries[archid].size = stats.size; obj.meshAgentBinaries[archid].size = stats.size;
if ((agentInfo[archid] != null) && (agentInfo[archid].mtime != null)) { obj.meshAgentBinaries[archid].mtime = new Date(agentInfo[archid].mtime); } // Set agent time if available
// If this is a windows binary, pull binary information // If this is a windows binary, pull binary information
if (obj.meshAgentsArchitectureNumbers[archid].platform == 'win32') { if (obj.meshAgentsArchitectureNumbers[archid].platform == 'win32') {

View File

@ -4770,6 +4770,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
if ((domain.agentcustomization != null) && (typeof domain.agentcustomization.filename == 'string')) { meshagentFilename = domain.agentcustomization.filename; } if ((domain.agentcustomization != null) && (typeof domain.agentcustomization.filename == 'string')) { meshagentFilename = domain.agentcustomization.filename; }
setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent'); setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent');
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
res.statusCode = 200; res.statusCode = 200;
obj.parent.exeHandler.streamExeWithJavaScript({ platform: argentInfo.platform, sourceFileName: argentInfo.path, destinationStream: res, js: Buffer.from(js, 'utf8'), peinfo: argentInfo.pe }); obj.parent.exeHandler.streamExeWithJavaScript({ platform: argentInfo.platform, sourceFileName: argentInfo.path, destinationStream: res, js: Buffer.from(js, 'utf8'), peinfo: argentInfo.pe });
} else if (req.query.id != null) { } else if (req.query.id != null) {
@ -4785,11 +4786,13 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
if ((user != null) && ((user.siteadmin == 0xFFFFFFFF) || ((Array.isArray(obj.parent.config.settings.agentcoredumpusers)) && (obj.parent.config.settings.agentcoredumpusers.indexOf(user._id) >= 0)))) { if ((user != null) && ((user.siteadmin == 0xFFFFFFFF) || ((Array.isArray(obj.parent.config.settings.agentcoredumpusers)) && (obj.parent.config.settings.agentcoredumpusers.indexOf(user._id) >= 0)))) {
if (argentInfo.id == 3) { if (argentInfo.id == 3) {
setContentDispositionHeader(res, 'application/octet-stream', 'MeshService.pdb', null, 'MeshService.pdb'); setContentDispositionHeader(res, 'application/octet-stream', 'MeshService.pdb', null, 'MeshService.pdb');
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
try { res.sendFile(argentInfo.path.split('MeshService-signed.exe').join('MeshService.pdb')); } catch (ex) { } try { res.sendFile(argentInfo.path.split('MeshService-signed.exe').join('MeshService.pdb')); } catch (ex) { }
return; return;
} }
if (argentInfo.id == 4) { if (argentInfo.id == 4) {
setContentDispositionHeader(res, 'application/octet-stream', 'MeshService64.pdb', null, 'MeshService64.pdb'); setContentDispositionHeader(res, 'application/octet-stream', 'MeshService64.pdb', null, 'MeshService64.pdb');
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
try { res.sendFile(argentInfo.path.split('MeshService64-signed.exe').join('MeshService64.pdb')); } catch (ex) { } try { res.sendFile(argentInfo.path.split('MeshService64-signed.exe').join('MeshService64.pdb')); } catch (ex) { }
return; return;
} }
@ -4802,6 +4805,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Get the agent filename // Get the agent filename
var meshagentFilename = argentInfo.rname; var meshagentFilename = argentInfo.rname;
if ((domain.agentcustomization != null) && (typeof domain.agentcustomization.filename == 'string')) { meshagentFilename = domain.agentcustomization.filename; } if ((domain.agentcustomization != null) && (typeof domain.agentcustomization.filename == 'string')) { meshagentFilename = domain.agentcustomization.filename; }
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
if (req.query.zip == 1) { if (argentInfo.zdata != null) { setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename + '.zip', null, 'meshagent.zip'); res.send(argentInfo.zdata); } else { try { res.sendStatus(404); } catch (ex) { } } return; } // Send compressed agent if (req.query.zip == 1) { if (argentInfo.zdata != null) { setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename + '.zip', null, 'meshagent.zip'); res.send(argentInfo.zdata); } else { try { res.sendStatus(404); } catch (ex) { } } return; } // Send compressed agent
setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent'); setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent');
if (argentInfo.data == null) { res.sendFile(argentInfo.path); } else { res.send(argentInfo.data); } if (argentInfo.data == null) { res.sendFile(argentInfo.path); } else { res.send(argentInfo.data); }
@ -4883,6 +4887,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
if (parent.agentTranslations != null) { meshsettings += 'translation=' + parent.agentTranslations + '\r\n'; } // Translation strings, not for MeshCentral Assistant if (parent.agentTranslations != null) { meshsettings += 'translation=' + parent.agentTranslations + '\r\n'; } // Translation strings, not for MeshCentral Assistant
} }
setContentDispositionHeader(res, 'application/octet-stream', meshfilename, null, argentInfo.rname); setContentDispositionHeader(res, 'application/octet-stream', meshfilename, null, argentInfo.rname);
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
obj.parent.exeHandler.streamExeWithMeshPolicy({ platform: 'win32', sourceFileName: obj.parent.meshAgentBinaries[req.query.id].path, destinationStream: res, msh: meshsettings, peinfo: obj.parent.meshAgentBinaries[req.query.id].pe }); obj.parent.exeHandler.streamExeWithMeshPolicy({ platform: 'win32', sourceFileName: obj.parent.meshAgentBinaries[req.query.id].path, destinationStream: res, msh: meshsettings, peinfo: obj.parent.meshAgentBinaries[req.query.id].pe });
return; return;
} }