Skip to content

Commit

Permalink
Merge pull request #1227 from wazuh/issue-1164
Browse files Browse the repository at this point in the history
Configuration assessment
  • Loading branch information
Jesús Ángel authored Feb 21, 2019
2 parents 5bd8a81 + 1ef60f7 commit c8a173a
Show file tree
Hide file tree
Showing 27 changed files with 623 additions and 72 deletions.
78 changes: 75 additions & 3 deletions public/controllers/agent/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ export class AgentsController {
this.ignoredTabs = ['syscollector', 'welcome', 'configuration'];

this.$scope.showSyscheckFiles = false;
this.$scope.editGroup = false;
this.$scope.showConfigurationAssessmentScan = false;

this.$scope.editGroup = false;
this.$scope.addingGroupToAgent = false;

this.$scope.lookingAssessment = false;
this.$scope.expandArray = [
false,
false,
Expand Down Expand Up @@ -157,7 +159,7 @@ export class AgentsController {
this.tabVisualizations.assign('agents');

this.$scope.hostMonitoringTabs = ['general', 'fim', 'syscollector'];
this.$scope.systemAuditTabs = ['pm', 'audit', 'oscap', 'ciscat'];
this.$scope.systemAuditTabs = ['pm', 'configuration-assessment', 'audit', 'oscap', 'ciscat'];
this.$scope.securityTabs = ['vuls', 'virustotal', 'osquery'];
this.$scope.complianceTabs = ['pci', 'gdpr'];

Expand Down Expand Up @@ -202,6 +204,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', () => {
Expand Down Expand Up @@ -356,6 +364,17 @@ export class AgentsController {
if (!this.$scope.$$phase) this.$scope.$digest();
};

this.$scope.switchConfigurationAssessmentScan = () => {
this.$scope.lookingAssessment = false;
this.$scope.showConfigurationAssessmentScan = !this.$scope.showConfigurationAssessmentScan;
if (!this.$scope.showConfigurationAssessmentScan) {
this.$rootScope.$emit('changeTabView', {
tabView: this.$scope.tabView
});
}
if (!this.$scope.$$phase) this.$scope.$digest();
};

this.$scope.goDiscover = () => this.goDiscover();

this.$scope.$on('$routeChangeStart', () =>
Expand All @@ -375,6 +394,9 @@ export class AgentsController {

this.$scope.cancelAddGroup = () => (this.$scope.addingGroupToAgent = false);

this.$scope.loadAssessmentChecks = policy => this.$scope.lookingAssessment = { name: policy.name, id: policy.policy_id };
this.$scope.closeAssessmentChecks = () => this.$scope.lookingAssessment = false;

this.$scope.confirmAddGroup = group => {
this.groupHandler
.addAgentToGroup(group, this.$scope.agent.id)
Expand Down Expand Up @@ -467,7 +489,6 @@ export class AgentsController {
) {
const condition =
!this.changeAgent && (localChange || preserveDiscover);

await this.visFactoryService.buildAgentsVisualizations(
this.filterHandler,
this.$scope.tab,
Expand Down Expand Up @@ -522,6 +543,7 @@ export class AgentsController {

try {
this.$scope.showSyscheckFiles = false;
this.$scope.showConfigurationAssessmentScan = false;
if (tab === 'pci') {
const pciTabs = await this.commonData.getPCI();
this.$scope.pciTabs = pciTabs;
Expand All @@ -532,6 +554,16 @@ export class AgentsController {
this.$scope.gdprTabs = gdprTabs;
this.$scope.selectedGdprIndex = 0;
}

if (tab === 'configuration-assessment') {
try {
this.$scope.load = true;
const policies = await this.apiReq.request('GET', `/configuration-assessment/${this.$scope.agent.id}`, {});
this.$scope.policies = policies.data.data.items;
} catch (error) { this.$scope.policies = []; }
this.$scope.load = false;
}

if (tab === 'syscollector')
try {
await this.loadSyscollector(this.$scope.agent.id);
Expand Down Expand Up @@ -909,6 +941,46 @@ export class AgentsController {
);
}

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;
}

falseAllExpand() {
this.$scope.expandArray = [
false,
Expand Down
3 changes: 0 additions & 3 deletions public/directives/wz-config-viewer/wz-config-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class WzConfigViewer {
);
};

const init = () => {};

const refreshJsonBox = json => {
$scope.jsoncontent = json;
if (!$scope.jsonCodeBox) {
Expand Down Expand Up @@ -102,7 +100,6 @@ class WzConfigViewer {
refreshXmlBox(params.data);
});

init();
}
}

Expand Down
9 changes: 4 additions & 5 deletions public/directives/wz-data-table/wz-data-table-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/**
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
};
Expand Down
23 changes: 22 additions & 1 deletion public/directives/wz-table/lib/parse-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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,
`<a href="${matched}">${matched}</a>`
);
item.event = $sce.trustAsHtml(item.event);
}
}
}
if (key === 'state' && instancePath.includes('processes')) {
return ProcessEquivalence[item.state] || 'Unknown';
}
Expand Down
18 changes: 16 additions & 2 deletions public/directives/wz-table/wz-table-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ app.directive('wzTable', function () {
appState,
globalState,
groupHandler,
wazuhConfig
wazuhConfig,
$sce
) {
$scope.showColumns = false;
$scope.originalkeys = $scope.keys.map((key, idx) => ({ key, idx }));
Expand Down Expand Up @@ -233,7 +234,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
Expand Down Expand Up @@ -382,6 +384,18 @@ app.directive('wzTable', function () {
}
};

$scope.isPolicyMonitoring = () => {
return instance.path.includes('configuration-assessment') && instance.path.includes('/checks')
}

$scope.expandPolicyMonitoringCheck = item => {
if (item.expanded) item.expanded = false;
else {
$scope.pagedItems[$scope.currentPage].map(item => item.expanded = false);
item.expanded = true;
}

}
$scope.showTooltip = (id1, id2, item) => {
var $element = $('#td-' + id1 + '-' + id2 + ' div');
var $c = $element
Expand Down
76 changes: 75 additions & 1 deletion public/directives/wz-table/wz-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class="fa fa-fw fa-gear"></i></span>
</div>

<div layout="row" ng-show="!error && !wazuh_table_loading && items.length">
<div layout="row" ng-show="!error && !wazuh_table_loading && items.length" ng-if="!isPolicyMonitoring()">
<table class="table table-striped table-condensed table-hover" style="table-layout: fixed !important" id="wz_table">
<thead class="wz-text-bold">
<th ng-repeat="key in keys" class="wz-text-left" ng-class="{ 'cursor-pointer' : !key.nosortable, 'col-lg-1' : !key.size, 'col-lg-{{key.size}}' : key.size }"
Expand Down Expand Up @@ -112,6 +112,80 @@
</table>
</div>

<div layout="row" ng-show="!error && !wazuh_table_loading && items.length" ng-if="isPolicyMonitoring()">
<table class="table table-striped table-condensed table-hover" style="table-layout: fixed !important" id="wz_table">
<thead class="wz-text-bold">
<th ng-repeat="key in keys" class="wz-text-left" ng-class="{ 'cursor-pointer' : !key.nosortable, 'col-lg-1' : !key.size, 'col-lg-{{key.size}}' : key.size }"
ng-click="!key.nosortable && sort(key)">
{{ keyEquivalence[key.value || key] || key.value || key }}
<i ng-if="!key.nosortable" class="fa wz-theader-sort-icon" ng-class="sortValue === (key.value || key) ? (sortDir ? 'fa-sort-asc' : 'fa-sort-desc') : 'fa-sort'"
aria-hidden="true"></i>
</th>
</thead>
<tbody>
<tr class="wz-word-wrap cursor-pointer" ng-repeat-start="item in pagedItems[currentPage] | filter:{item:'!'}"
ng-click="expandPolicyMonitoringCheck(item)">
<td ng-repeat="key in keys">
<div class="wz-text-truncatable">
<span>
{{
parseValue(key,item)
}}
</span>
</div>
</td>
</tr>
<tr class="wz-word-wrap" style="background-color: #ecf6fb !important" ng-if="item.expanded" ng-repeat-end="">
<td colspan="3">
<div layout="column" ng-if="item.rationale" class="wz-margin-top-10">
<span class="wz-headline-title"><strong>Rationale</strong></span>
<md-divider class="wz-margin-top-10"></md-divider>
<p class="wz-margin-top-10">{{item.rationale}}</p>
</div>
<div layout="column" ng-if="item.remediation" class="wz-margin-top-10">
<span class="wz-headline-title"><strong>Remediation</strong></span>
<md-divider class="wz-margin-top-10"></md-divider>
<p class="wz-margin-top-10">{{item.remediation}}</p>
</div>
<div layout="column" ng-if="item.directory" class="wz-margin-top-10">
<span class="wz-headline-title"><strong>Path(s)</strong></span>
<md-divider class="wz-margin-top-10"></md-divider>
<p class="wz-margin-top-10">{{ item.directory }}</p>
</div>
<div layout="column" ng-if="item.compliance" class="wz-margin-top-10">
<span class="wz-headline-title"><strong>Compliance</strong></span>
<md-divider class="wz-margin-top-10"></md-divider>
<p class="wz-margin-top-10"><span class="wz-padding-right-8" ng-repeat="c in item.compliance">{{c.key}}/{{c.value}}</span></p>
</div>
<div layout="column" class="wz-margin-top-10"></div>
</td>
</tr>
</tbody>
<tfoot>
<td colspan="{{keys.length}}">
<span ng-show="!wazuh_table_loading" class="color-grey">{{ totalItems }} items ({{time | number: 2}}
seconds)</span>
<div ng-show="items.length >= itemsPerPage" class="pagination pull-right" style="margin:0 !important">
<ul layout="row">
<li ng-show="currentPage" class="md-padding">
<a href ng-click="prevPage()">« Prev</a>
</li>

<li ng-repeat="n in range(pagedItems.length, currentPage, currentPage + gap) " ng-class="{'wz-text-active': n == currentPage}"
ng-click="setPage()" class="md-padding">
<a href ng-bind="n + 1">1</a>
</li>

<li ng-show="currentPage < pagedItems.length - 1" class="md-padding">
<a href ng-click="nextPage()">Next »</a>
</li>
</ul>
</div>
</td>
</tfoot>
</table>
</div>

<div layout="row" ng-if="!error && !wazuh_table_loading && !totalItems">
<div flex class="euiCallOut euiCallOut--warning">
<div class="euiCallOutHeader">
Expand Down
1 change: 1 addition & 0 deletions public/factories/tab-visualizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TabVisualizations {
pci: 6,
virustotal: 6,
configuration: 0,
'configuration-assessment': 4,
osquery: 5
};

Expand Down
3 changes: 3 additions & 0 deletions public/less/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ div.uil-ring-css {
}

/* Custom colors styles */
.color-white {
color: white;
}

.green {
background-color: rgb(42, 204, 67);
Expand Down
8 changes: 8 additions & 0 deletions public/less/layout.less
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
margin-top: 10px;
}

.wz-margin-top-16 {
margin-top: 16px;
}

.wz-margin-top-17 {
margin-top: 17px;
}
Expand Down Expand Up @@ -163,6 +167,10 @@
padding-right: 8px;
}

.wz-padding-right-16 {
padding-right: 16px
}

.wz-padding-right-17 {
padding-right: 17px;
}
Expand Down
Loading

0 comments on commit c8a173a

Please sign in to comment.