From 469775de66b0455404d24e816664dbd0d0978318 Mon Sep 17 00:00:00 2001 From: Chester Enright Date: Sat, 16 Sep 2023 23:46:53 -0500 Subject: [PATCH] feat: wip - starting on smartbar --- .../src/components/CustomDashboardsView.vue | 1 + frontend/labyrinth/src/components/Host.vue | 1 + frontend/labyrinth/src/views/Dashboard.vue | 184 +++++++++++++----- 3 files changed, 141 insertions(+), 45 deletions(-) diff --git a/frontend/labyrinth/src/components/CustomDashboardsView.vue b/frontend/labyrinth/src/components/CustomDashboardsView.vue index dd086e3..14104bd 100644 --- a/frontend/labyrinth/src/components/CustomDashboardsView.vue +++ b/frontend/labyrinth/src/components/CustomDashboardsView.vue @@ -19,6 +19,7 @@ :style="generateHostStyle(host)" >
-
{{parsed_data}}
+
- @@ -180,7 +178,9 @@
@@ -227,6 +228,7 @@ export default { data() { return { loading: false, + smartbar: "", offsetTop: [], full_data: [], @@ -265,39 +267,114 @@ export default { DoughnutChart, }, computed: { - parsed_data: function(){ - let data = this.full_data + parsed_data: function () { + let data = this.full_data; + if (this.smartbar == "") { + return this.sortSubnets(data); + } + + let search = { + service: null, + host: null, + tag: [], + field: [], + port: null, + group: null, + ip: null, + + invert: false, + }; + + let searches = []; + + let search_parts = this.smartbar.split(" ").map((x) => x.toLowerCase()); + + search_parts.forEach((part) => { + let temp = JSON.parse(JSON.stringify(search)); + + let splits = part.split("="); + if (splits.length == 2) { + let left = splits[0]; + let right = splits[1]; + + if (left.indexOf("tag:") != -1) { + let tag_name = left.replace("tag:", ""); + temp.tag.push({ tag: tag_name, value: right }); + } else if (left.indexOf("field:") != -1) { + let field_name = left.replace("field:", ""); + temp.field.push({ field: field_name, value: right }); + } else { + switch (left) { + case "service": + temp.service = right; + break; + case "host": + temp.host = right; + break; + case "port": + temp.port = right; + break; + case "group": + temp.group = right; + break; + case "ip": + temp.ip = right; + break; + default: + break; + } + } + + searches.push(temp); + } + }); + + data.forEach((subnet) => { + if (subnet.groups) { + subnet.groups.forEach((group) => { + if (group.hosts) { + group.hosts.forEach((host) => { + if (this.checkHostFilter(host, searches)) { + host.display = true; + } else { + host.display = false; + } + }); + } + }); + } + }); - return this.sortSubnets(data) + return data; }, - all_ips_computed: function(){ - let retval = new Set() - this.full_data.forEach(subnet=>{ - if(subnet.groups){ - subnet.groups.forEach(group=>{ - if(group.hosts){ - group.hosts.forEach(host=>{ - if(host.ip){ - retval.add(host.ip) + all_ips_computed: function () { + let retval = new Set(); + this.full_data.forEach((subnet) => { + if (subnet.groups) { + subnet.groups.forEach((group) => { + if (group.hosts) { + group.hosts.forEach((host) => { + if (host.ip) { + retval.add(host.ip); } - }) + }); } - }) + }); } - }) - return retval - } + }); + return retval; + }, }, methods: { capitalize: Helper.capitalize, convertSubnet(subnet) { try { - let splits = subnet.split("."); + let splits = subnet.split("."); if (splits.length != 3) { return -1; } - let output = splits[0] * 100000 + splits[1] * 1000 + splits[2] * 10; + let output = splits[0] * 100000 + splits[1] * 1000 + splits[2] * 10; return output; } catch (e) { return -1; @@ -305,7 +382,7 @@ export default { }, sortSubnets(all_items) { // Returns 1 (a after b), 0 (a==b), -1 (b after a) - let temp = JSON.parse(JSON.stringify(all_items)); + let temp = JSON.parse(JSON.stringify(all_items)); return temp.sort((a, b) => { if (a.subnet == undefined || b.subnet == undefined) { return 0; @@ -314,17 +391,35 @@ export default { if (this.convertSubnet(a.subnet) == this.convertSubnet(b.subnet)) { return 0; } - let outcome = + let outcome = this.convertSubnet(a.subnet) < this.convertSubnet(b.subnet) ? -1 : 1; return outcome; }); }, + checkHostFilter(host, searches) { + console.log("Host:", host); + console.log("Searches:", searches); + let retval = false; + searches.forEach((search) => { + if ( + host.services + .map((x) => x.name.toLowerCase()) + .indexOf(search.service.toLowerCase()) != -1 + ) { + retval = true; + } + if (host.open_ports.indexOf(parseInt(search.port)) != -1) { + retval = true; + } + }); + return retval; + }, filterMonitored: function (group, subnet) { if (!subnet) { return group; } - let temp = JSON.parse(JSON.stringify(group)); + let temp = JSON.parse(JSON.stringify(group)); return temp.filter((x) => { if (x.hosts == undefined) { @@ -336,13 +431,12 @@ export default { }); }, - parseCommandLine: function(){ + parseCommandLine: function () { // Parses the command line - }, loadThemes: /* istanbul ignore next */ function () { - let auth = this.$auth; + let auth = this.$auth; Helper.apiCall("themes", "", auth) .then((res) => { this.themes = res; @@ -352,8 +446,8 @@ export default { }); }, onDrop: /* istanbul ignore next */ function (name) { - let auth = this.$auth; - let url = this.dragged_ip; + let auth = this.$auth; + let url = this.dragged_ip; if (name != "") { url += "/" + name + "/"; } @@ -367,12 +461,12 @@ export default { }, processGroupChart: function (group) { // Generates the datastructure for the doughnut chart for the group - let output = {}; + let output = {}; output.labels = ["OK", "Warning", "Critical"]; - let total_green = 0; - let total_orange = 0; - let total_red = 0; + let total_green = 0; + let total_orange = 0; + let total_red = 0; // Process the group group.hosts.forEach((host) => { if (host.services != undefined) { @@ -402,8 +496,8 @@ export default { return output; }, loadData: /* istanbul ignore next */ async function (showLoading) { - let auth = this.$auth; - let url = ""; + let auth = this.$auth; + let url = ""; if (showLoading) { this.loading = true; url = "1"; @@ -422,8 +516,8 @@ export default { this.originLinks = this.prepareOriginsLinks(this.full_data); - for (let i = 0; i < this.full_data.length; i++) { - let temp = this.full_data[i]; + for (let i = 0; i < this.full_data.length; i++) { + let temp = this.full_data[i]; if (temp.groups != undefined) { // Sort the groups temp.groups.sort((prev, next) => { @@ -457,7 +551,7 @@ export default { }); }, findClass: function (subnet, isTitle) { - let retval = ""; + let retval = ""; // Color if (subnet.color != undefined && this.themes != []) { @@ -481,7 +575,7 @@ export default { }, prepareOriginsLinks: function (subnets) { - let retval = []; + let retval = []; const width = 7; subnets = subnets.filter( (x) => @@ -494,7 +588,7 @@ export default { ); subnets.forEach((x, idx) => { - let found = this.themes.find( + let found = this.themes.find( (y) => x.links.color != undefined && y.name == x.links.color ); if (!found) {