diff --git a/public/controllers/agent/agents.js b/public/controllers/agent/agents.js index 2cd0b6e6d..dadb9d368 100644 --- a/public/controllers/agent/agents.js +++ b/public/controllers/agent/agents.js @@ -90,8 +90,9 @@ export class AgentsController { this.ignoredTabs = ['syscollector', 'welcome', 'configuration']; this.$scope.showSyscheckFiles = false; - this.$scope.editGroup = false; + this.$scope.showRootcheckScan = false; + this.$scope.editGroup = false; this.$scope.addingGroupToAgent = false; } @@ -183,6 +184,12 @@ export class AgentsController { this.$scope.searchSyscheckFile = (term, specificFilter) => this.$scope.$broadcast('wazuhSearch', { term, specificFilter }); + this.$scope.searchRootcheck = (term, specificFilter) => + this.$scope.$broadcast('wazuhSearch', { term, specificFilter }); + + this.$scope.launchRootcheckScan = () => this.launchRootcheckScan(); + this.$scope.launchSyscheckScan = () => this.launchSyscheckScan(); + this.$scope.startVis2Png = () => this.startVis2Png(); this.$scope.$on('$destroy', () => { @@ -309,6 +316,16 @@ export class AgentsController { if (!this.$scope.$$phase) this.$scope.$digest(); }; + this.$scope.switchRootcheckScan = () => { + this.$scope.showRootcheckScan = !this.$scope.showRootcheckScan; + if (!this.$scope.showRootcheckScan) { + this.$rootScope.$emit('changeTabView', { + tabView: this.$scope.tabView + }); + } + if (!this.$scope.$$phase) this.$scope.$digest(); + }; + this.$scope.goDiscover = () => this.goDiscover(); this.$scope.$on('$routeChangeStart', () => @@ -468,10 +485,11 @@ export class AgentsController { (((agentInfo || {}).data || {}).data || {}).status || this.$scope.agent.status; } - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line try { this.$scope.showSyscheckFiles = false; + this.$scope.showRootcheckScan = false; if (tab === 'pci') { const pciTabs = await this.commonData.getPCI(); this.$scope.pciTabs = pciTabs; @@ -485,7 +503,7 @@ export class AgentsController { if (tab === 'syscollector') try { await this.loadSyscollector(this.$scope.agent.id); - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line if (tab === 'configuration') { const isSync = await this.apiReq.request( 'GET', @@ -603,7 +621,7 @@ export class AgentsController { {} ); netifaceResponse = ((resultNetiface || {}).data || {}).data || false; - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line // This API call may fail so we put it out of Promise.all let netaddrResponse = false; @@ -615,7 +633,7 @@ export class AgentsController { ); netaddrResponse = ((resultNetaddrResponse || {}).data || {}).data || false; - } catch (error) {} // eslint-disable-line + } catch (error) { } // eslint-disable-line // Before proceeding, syscollector data is an empty object this.$scope.syscollector = {}; @@ -631,7 +649,7 @@ export class AgentsController { this.$scope.syscollector = { hardware: typeof hardwareResponse === 'object' && - Object.keys(hardwareResponse).length + Object.keys(hardwareResponse).length ? { ...hardwareResponse } : false, os: @@ -815,4 +833,44 @@ export class AgentsController { syscollectorFilters.length ? syscollectorFilters : null ); } + + async launchRootcheckScan() { + try { + const isActive = ((this.$scope.agent || {}).status || '') === 'Active'; + if (!isActive) { + throw new Error('Agent is not active') + } + await this.apiReq.request( + 'PUT', + `/rootcheck/${this.$scope.agent.id}`, + {} + ); + this.errorHandler.info( + `Policy monitoring scan launched successfully on agent ${ + this.$scope.agent.id + }`, + '' + ); + } catch (error) { + this.errorHandler.handle(error, ''); + } + return; + } + + async launchSyscheckScan() { + try { + const isActive = ((this.$scope.agent || {}).status || '') === 'Active'; + if (!isActive) { + throw new Error('Agent is not active') + } + await this.apiReq.request('PUT', `/syscheck/${this.$scope.agent.id}`, {}); + this.errorHandler.info( + `FIM scan launched successfully on agent ${this.$scope.agent.id}`, + '' + ); + } catch (error) { + this.errorHandler.handle(error, ''); + } + return; + } } diff --git a/public/directives/wz-config-viewer/wz-config-viewer.js b/public/directives/wz-config-viewer/wz-config-viewer.js index 1114306d9..7fd3e92b7 100644 --- a/public/directives/wz-config-viewer/wz-config-viewer.js +++ b/public/directives/wz-config-viewer/wz-config-viewer.js @@ -62,8 +62,6 @@ class WzConfigViewer { ); }; - const init = () => {}; - const refreshJsonBox = json => { $scope.jsoncontent = json; if (!$scope.jsonCodeBox) { @@ -102,7 +100,6 @@ class WzConfigViewer { refreshXmlBox(params.data); }); - init(); } } diff --git a/public/directives/wz-data-table/wz-data-table-directive.js b/public/directives/wz-data-table/wz-data-table-directive.js index 6aa23e179..2c15c218b 100644 --- a/public/directives/wz-data-table/wz-data-table-directive.js +++ b/public/directives/wz-data-table/wz-data-table-directive.js @@ -19,12 +19,13 @@ import { checkGap } from '../wz-table/lib/check-gap'; const app = uiModules.get('app/wazuh', []); -app.directive('wzDataTable', function() { +app.directive('wzDataTable', function () { return { restrict: 'E', scope: { rowSizes: '=rowSizes', - data: '=' + data: '=', + keys: '=' }, controller($scope, $filter, errorHandler, $window) { /** @@ -61,8 +62,6 @@ app.directive('wzDataTable', function() { const fetch = () => { try { $scope.filterTable(); - $scope.keys = Object.keys(items[0]); - return; } catch (error) { errorHandler.handle(error, 'Error loading table'); } @@ -121,7 +120,7 @@ app.directive('wzDataTable', function() { $scope.prevPage = () => pagination.prevPage($scope); $scope.nextPage = async currentPage => pagination.nextPage(currentPage, $scope, errorHandler, fetch); - $scope.setPage = function() { + $scope.setPage = function () { $scope.currentPage = this.n; $scope.nextPage(this.n); }; diff --git a/public/directives/wz-table/lib/parse-value.js b/public/directives/wz-table/lib/parse-value.js index 2f449fe05..806ec082f 100644 --- a/public/directives/wz-table/lib/parse-value.js +++ b/public/directives/wz-table/lib/parse-value.js @@ -26,7 +26,28 @@ const checkIfArray = item => { return typeof item === 'object' ? splitArray(item) : item === 0 ? '0' : item; }; -export function parseValue(key, item, instancePath) { +export function parseValue(key, item, instancePath, $sce = null) { + if ( + (key === 'event' || (key.value && key.value === 'event')) && + instancePath.includes('rootcheck') && + $sce + ) { + if (typeof (item || {}).event === 'string') { + const urlRegex = new RegExp( + /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, + 'g' + ); + + const matched = item.event.match(urlRegex); + if (matched) { + item.event = item.event.replace( + matched, + `${matched}` + ); + item.event = $sce.trustAsHtml(item.event); + } + } + } if (key === 'state' && instancePath.includes('processes')) { return ProcessEquivalence[item.state] || 'Unknown'; } diff --git a/public/directives/wz-table/wz-table-directive.js b/public/directives/wz-table/wz-table-directive.js index c42a6afb8..f7b0dc8e6 100644 --- a/public/directives/wz-table/wz-table-directive.js +++ b/public/directives/wz-table/wz-table-directive.js @@ -50,7 +50,8 @@ app.directive('wzTable', function() { appState, globalState, groupHandler, - wazuhConfig + wazuhConfig, + $sce ) { /** * Init variables @@ -205,7 +206,8 @@ app.directive('wzTable', function() { return; }; - $scope.parseValue = (key, item) => parseValue(key, item, instance.path); + $scope.parseValue = (key, item) => + parseValue(key, item, instance.path, $sce); /** * On controller loads diff --git a/public/directives/wz-table/wz-table.html b/public/directives/wz-table/wz-table.html index 87b389bb1..6f88b0629 100644 --- a/public/directives/wz-table/wz-table.html +++ b/public/directives/wz-table/wz-table.html @@ -20,11 +20,9 @@