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
pause

View File

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

View File

@ -2716,6 +2716,10 @@ function CreateMeshCentralServer(config, args) {
// Update the list of available mesh agents
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;
for (var archid in obj.meshAgentsArchitectureNumbers) {
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].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;
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 (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; }
setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent');
if (argentInfo.mtime != null) { res.setHeader('Last-Modified', argentInfo.mtime.toUTCString()); }
res.statusCode = 200;
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) {
@ -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 (argentInfo.id == 3) {
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) { }
return;
}
if (argentInfo.id == 4) {
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) { }
return;
}
@ -4802,6 +4805,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Get the agent filename
var meshagentFilename = argentInfo.rname;
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
setContentDispositionHeader(res, 'application/octet-stream', meshagentFilename, null, 'meshagent');
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
}
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 });
return;
}