From 2ca49d49d8c7a009f3dbb998948abd5428f0350b Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sat, 27 Mar 2021 01:33:13 -0700 Subject: [PATCH] Request #2410 --- meshcentral-config-schema.json | 2 +- views/default.handlebars | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index a2ce9d26..329689a0 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -303,7 +303,7 @@ "type": "string" }, "filter": { - "description": "Array of node/domain/id or mesh/domain/id strings. When set, the link will only show up for the specified devices or device groups.", + "description": "Array of node// or mesh// or tag: strings. When set, the link will only show up for the specified devices, device groups or device tag.", "type": "array", "items": { "type": "string" } } diff --git a/views/default.handlebars b/views/default.handlebars index 77022584..97fcc7a5 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -4118,7 +4118,7 @@ if ((serverinfo.devicemeshrouterlinks != null) && (Array.isArray(serverinfo.devicemeshrouterlinks.extralinks))) { for (var i in serverinfo.devicemeshrouterlinks.extralinks) { var r = serverinfo.devicemeshrouterlinks.extralinks[i], p = 0; - if ((r.filter == null) || (Array.isArray(r.filter) && ((r.filter.indexOf(node.meshid) >= 0) || (r.filter.indexOf(node._id) >= 0)))) { + if (doesDeviceMatchFilterTags(node, r.filter)) { if (typeof r.protocol == 'number') { p = r.protocol; } else if (r.protocol == 'http') { p = 1; } else if (r.protocol == 'https') { p = 2; } else if (r.protocol == 'rdp') { p = 3; } else if (r.protocol == 'ssh') { p = 4; } else if (r.protocol == 'scp') { p = 5; } x += '' + r.name + ' '; } @@ -4130,6 +4130,16 @@ return x; } + // Check if this device matches any of the given filters + function doesDeviceMatchFilterTags(node, filter) { + if (filter == null) return true; // No filters, every device matches. + if (!Array.isArray(filter)) return false; // Bad filter + if (filter.indexOf(node.meshid) >= 0) return true; // Device group match + if (filter.indexOf(node._id) >= 0) return true; // Nodeid match + if (Array.isArray(node.tags)) { for (var i in node.tags) { if (filter.indexOf('tag:' + node.tags[i]) >= 0) return true; } } // Tag match + return false; + } + // Show device help requests function showDeviceHelpRequests(nodeid, force, e) { if (e) haltEvent(e); @@ -6316,7 +6326,7 @@ if ((serverinfo.devicemeshrouterlinks != null) && (Array.isArray(serverinfo.devicemeshrouterlinks.extralinks))) { for (var i in serverinfo.devicemeshrouterlinks.extralinks) { var r = serverinfo.devicemeshrouterlinks.extralinks[i], p = 0; - if ((r.filter == null) || (Array.isArray(r.filter) && ((r.filter.indexOf(mesh._id) >= 0) || (r.filter.indexOf(node._id) >= 0)))) { + if (doesDeviceMatchFilterTags(node, r.filter)) { if (typeof r.protocol == 'number') { p = r.protocol; } else if (r.protocol == 'http') { p = 1; } else if (r.protocol == 'https') { p = 2; } else if (r.protocol == 'rdp') { p = 3; } else if (r.protocol == 'ssh') { p = 4; } else if (r.protocol == 'scp') { p = 5; } x += '' + r.name + ' '; }