Skip to content

Commit

Permalink
#246 Add links to view already imported observables
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 2, 2018
1 parent 851dcd6 commit c797150
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
2 changes: 2 additions & 0 deletions ui/app/scripts/controllers/case/CaseObservablesItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
endDate: job.endDate
};

$scope.currentJob = jobId;

$timeout(function() {
var reportEl = angular.element(document.getElementById('analysis-report'))[0];

Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/case/ObservableCreationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
};

$scope.cancel = function() {
$uibModalInstance.dismiss();
$uibModalInstance.dismiss('cancel');
};

$scope.isFile = function() {
Expand Down
29 changes: 21 additions & 8 deletions ui/app/scripts/directives/report-observables.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(function() {
'use strict';
angular.module('theHiveDirectives').directive('reportObservables', function($uibModal, UtilsSrv) {
angular.module('theHiveDirectives').directive('reportObservables', function($q, $filter, $uibModal, UtilsSrv) {
return {
restrict: 'E',
scope: {
origin: '=',
observables: '=',
analyzer: '='
analyzer: '=',
caseId: '='
},
templateUrl: 'views/directives/report-observables.html',
link: function(scope) {
Expand Down Expand Up @@ -33,7 +35,7 @@
};

$scope.selectObservable = function(observable) {
if(observable.imported) {
if(observable.id) {
return;
}
if(observable.selected === true) {
Expand All @@ -46,7 +48,7 @@
$scope.selectAll = function() {
var type = $scope.pagination.filter;
_.each(type === '' ? $scope.observables : $scope.groups[type], function(item) {
if(!item.imported) {
if(!item.id && !item.selected) {
item.selected = true;
$scope.selected++;
}
Expand All @@ -63,14 +65,19 @@
$scope.import = function() {
var toImport = _.groupBy(_.filter($scope.observables, function(item) {
return item.selected === true;
}), 'dataType');
}), 'dataType');

var keys = _.keys(toImport);
var promises = [];
var message = [
'### Discovered from:',
'- Observable: **['+ $scope.origin.dataType + '] - ' + $filter('fang')($scope.origin.data) + '**',
'- Analyzer: **'+ $scope.analyzer + '**'
].join('\n')

_.each(toImport, function(list, key) {

var promise = $uibModal.open({
var modal = $uibModal.open({
animation: 'true',
templateUrl: 'views/partials/observables/observable.creation.html',
controller: 'ObservableCreationCtrl',
Expand All @@ -84,7 +91,7 @@
sighted: false,
data: _.pluck(list, 'data').join('\n'),
tlp: 2,
message: '',
message: message,
tags: [],
tagNames: ''
}
Expand All @@ -95,7 +102,13 @@
}
});

promises.push(promise);
modal.result
.then(function(response) {
_.each(list, function(item) {
item.id = true;
item.selected = false;
});
});
});


Expand Down
8 changes: 7 additions & 1 deletion ui/app/views/directives/flow/observable.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
</div>

<div class="flow-item-updates wrap" ng-switch-when="Creation">
description: <span ng-bind="base.object.message| limitTo: 250"></span>
<div ng-if="base.object.message">description: {{base.object.message| limitTo: 250}}</div>
<div ng-if="base.object.tags.length > 0">
Tags:
<span ng-repeat="tag in base.object.tags">
<span class="label label-primary">{{tag}}</span>
</span>
</div>
</div>

<div class="flow-item-updates wrap" ng-switch-default>
Expand Down
21 changes: 13 additions & 8 deletions ui/app/views/directives/report-observables.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
<div class="mv-xxs">
<strong class="text-muted">{{selected}} items selected</strong>
<a class="ml-xs" href ng-click="selectAll()"><i class="fa fa-check"></i> Select all</a>
<a class="ml-xs" href ng-click="clearSelection()"><i class="fa fa-times"></i> Clear Selection</a>
<span class="mh-xs">|</span>
<a href ng-click="import()"><i class="fa fa-plus"></i> Import Selection</a>
<span ng-if="selected > 0">
<a class="ml-xs" href ng-click="clearSelection()"><i class="fa fa-times"></i> Clear Selection</a>
<span class="ml-xs">|</span>
<a class="ml-xs" href ng-click="import()"><i class="fa fa-plus"></i> Import Selection</a>
</span>

</div>
<table class="table table-striped">
<thead>
Expand All @@ -27,26 +30,28 @@
<th style="width:20px;"></th>
<th style="width:150px;">Type</th>
<th>Data</th>
<th style="width:80px;"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="observable in pagination.data | orderBy:'imported':false |
<tr ng-repeat="observable in pagination.data | orderBy:'id':true |
offset: (pagination.currentPage-1)*pagination.pageSize |
limitTo: pagination.pageSize ">
<td><input type="checkbox" ng-model="observable.selected" ng-click="selectObservable(observable)" ng-disabled="observable.imported"></td>
<td><input type="checkbox" ng-model="observable.selected" ng-click="selectObservable(observable)" ng-disabled="observable.id"></td>
<td>
<span uib-tooltip="Observable already imported" tooltip-popup-delay="500" tooltip-placement="bottom" ng-if="observable.imported" class="glyphicon glyphicon-eye-open"></span>
<span uib-tooltip="Observable already id" tooltip-popup-delay="500" tooltip-placement="bottom" ng-if="observable.id" class="glyphicon glyphicon-eye-open"></span>
</td>
<td>{{observable.dataType}}</td>
<td class="wrap">
{{observable.data | fang | ellipsis:250}}
</td>
<td class="wrap">
<a ng-if="observable.id" href ui-sref="app.case.observables-item({caseId: caseId, itemId: observable.id})"><i class="fa fa-search"></i> View</a>
</td>
</tr>
</tbody>
</table>

<!-- <pre>{{selected | json}}</pre> -->

<div class="text-center" ng-show="pagination.data.length > pagination.pageSize">
<ul uib-pagination class="pagination-sm" boundary-links="true" max-size="5" rotate="false"
total-items="pagination.data.length"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ <h3 class="pad10 text-primary">
<div class="panel panel-info">
<div class="panel-heading">
<strong>Observables</strong> <small>Extracted from analysis report</small>

</div>
<div class="panel-body">
<report-observables observables="report.content.artifacts" analyzer="report.template"></report-observables>
<div class="panel-body">
<report-observables origin="artifact" case-id="caseId" observables="report.content.artifacts" analyzer="report.template"></report-observables>
</div>
</div>
</div>
Expand Down

0 comments on commit c797150

Please sign in to comment.