-
Notifications
You must be signed in to change notification settings - Fork 640
/
Copy pathreport-observables.js
121 lines (108 loc) · 4.53 KB
/
report-observables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(function() {
'use strict';
angular.module('theHiveDirectives').directive('reportObservables', function($q, $filter, $uibModal) {
return {
restrict: 'E',
scope: {
origin: '=',
observables: '=',
analyzer: '=',
caseId: '='
},
templateUrl: 'views/directives/report-observables.html',
link: function(scope) {
scope.$watch('observables', function() {
scope.selected = 0;
scope.groups = _.groupBy(scope.observables, 'dataType');
scope.pagination = {
pageSize: 10,
currentPage: 1,
filter: '',
data: scope.observables
};
});
},
controller: function($scope) {
$scope.filterArtifacts = function(type) {
$scope.pagination.filter = type;
$scope.pagination.currentPage = 1;
if(type !== '') {
$scope.pagination.data = $scope.groups[type];
} else {
$scope.pagination.data = $scope.observables;
}
};
$scope.selectObservable = function(observable) {
if(observable.id) {
return;
}
if(observable.selected === true) {
$scope.selected++;
} else {
$scope.selected--;
}
};
$scope.selectAll = function() {
var type = $scope.pagination.filter;
_.each(type === '' ? $scope.observables : $scope.groups[type], function(item) {
if(!item.id && !item.selected) {
item.selected = true;
$scope.selected++;
}
});
};
$scope.clearSelection = function() {
_.each($scope.observables, function(item) {
delete item.selected;
});
$scope.selected = 0;
};
$scope.import = function() {
var toImport = _.groupBy(_.filter($scope.observables, function(item) {
return item.selected === true;
}), 'dataType');
var message = [
'### Discovered from:',
'- Observable: **['+ $scope.origin.dataType + '] - ' + $filter('fang')($scope.origin.data) + '**',
'- Analyzer: **'+ $scope.analyzer + '**'
].join('\n');
_.each(toImport, function(list, key) {
var params = {
dataType: key,
single: list.length === 1,
ioc: false,
sighted: false,
tlp: 2,
message: message,
tags: [{text: 'src:' + $scope.analyzer}]
};
if(key === 'file') {
params.attachment = _.pluck(list, 'attachment');
params.isUpload = false;
} else {
params.data = _.pluck(list, 'data').join('\n');
}
var modal = $uibModal.open({
animation: 'true',
templateUrl: 'views/partials/observables/observable.creation.html',
controller: 'ObservableCreationCtrl',
size: 'lg',
resolve: {
params: function() {
return params;
}
}
});
modal.result
.then(function(/*response*/) {
_.each(list, function(item) {
item.id = true;
item.selected = false;
});
});
});
};
}
};
});
})();