Skip to content

Commit

Permalink
#53 Prompt for cortex server to be used for an analysis if TheHive de…
Browse files Browse the repository at this point in the history
…fines more than one Cortex server
  • Loading branch information
nadouani committed Dec 13, 2016
1 parent d4f9f10 commit 9df9cd1
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 100 deletions.
1 change: 1 addition & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<script src="scripts/controllers/case/CaseTasksItemCtrl.js"></script>
<script src="scripts/controllers/case/ObservableCreationCtrl.js"></script>
<script src="scripts/controllers/case/ObservablesStatsCtrl.js"></script>
<script src="scripts/controllers/cortex/CortexInstanceDialogCtrl.js"></script>
<script src="scripts/controllers/misp/MispBulkImportCtrl.js"></script>
<script src="scripts/controllers/misp/MispEventCtrl.js"></script>
<script src="scripts/controllers/misp/MispListCtrl.js"></script>
Expand Down
156 changes: 79 additions & 77 deletions ui/app/scripts/controllers/case/CaseObservablesCtrl.js

Large diffs are not rendered by default.

52 changes: 33 additions & 19 deletions ui/app/scripts/controllers/case/CaseObservablesItemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseObservablesItemCtrl',
function ($scope, $state, $stateParams, CaseTabsSrv, CaseArtifactSrv, CortexSrv, PSearchSrv, AnalyzerSrv, JobSrv, AlertSrv) {
function ($scope, $state, $stateParams, $q, CaseTabsSrv, CaseArtifactSrv, CortexSrv, PSearchSrv, AnalyzerSrv, JobSrv, AlertSrv) {
var observableId = $stateParams.itemId,
observableName = 'observable-' + observableId;

Expand Down Expand Up @@ -84,11 +84,11 @@

AnalyzerSrv.get(job.analyzerId)
.finally(function (data) {
$scope.analyzers[data.analyzerId] = {
active: false,
showRows: false
};
});
$scope.analyzers[data.analyzerId] = {
active: false,
showRows: false
};
});
}
});
};
Expand All @@ -98,7 +98,7 @@
template: job.analyzerId,
content: job.report,
status: job.status
}
}
}

$scope.similarArtifacts = CaseArtifactSrv.api().similar({
Expand Down Expand Up @@ -136,20 +136,34 @@

$scope.runAnalyzer = function (analyzerId) {
var artifactName = $scope.artifact.data || $scope.artifact.attachment.name;
return CortexSrv.createJob({
cortexId: 'local',
artifactId: $scope.artifact.id,
analyzerId: analyzerId
}).then(function () {
AlertSrv.log('Analyzer ' + analyzerId + ' has been successfully started for observable: ' + artifactName, 'success');
}, function (response) {
AlertSrv.log('Unable to run analyzer ' + analyzerId + ' for observable: ' + artifactName, 'error');
});

AnalyzerSrv.serversFor([analyzerId])
.then(function(servers) {
if(servers.length === 1) {
return $q.resolve(servers[0]);
} else {
return CortexSrv.promptForInstance(servers);
}
})
.then(function (serverId) {
return CortexSrv.createJob({
cortexId: serverId,
artifactId: $scope.artifact.id,
analyzerId: analyzerId
});
})
.then(function () {
AlertSrv.log('Analyzer ' + analyzerId + ' has been successfully started for observable: ' + artifactName, 'success');
}, function (response) {
if(response.status) {
AlertSrv.log('Unable to run analyzer ' + analyzerId + ' for observable: ' + artifactName, 'error');
}
});
};

$scope.runAll = function() {
_.each($scope.analyzers, function(analyzer, id) {
if(analyzer.active === true) {
$scope.runAll = function () {
_.each($scope.analyzers, function (analyzer, id) {
if (analyzer.active === true) {
$scope.runAnalyzer(id);
}
});
Expand Down
20 changes: 20 additions & 0 deletions ui/app/scripts/controllers/cortex/CortexInstanceDialogCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('CortexInstanceDialogCtrl', CortexInstanceDialogCtrl);

function CortexInstanceDialogCtrl($modalInstance, servers) {
var self = this;

this.servers = servers;
this.selected = null;

this.ok = function() {
$modalInstance.close(this.selected);
};

this.cancel = function() {
$modalInstance.dismiss();
};
}
})();
19 changes: 19 additions & 0 deletions ui/app/scripts/services/AnalyzerSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@
deferred.resolve(filtered);
});

return deferred.promise;
},

serversFor: function(analyzerIds) {
var deferred = $q.defer();

factory.query()
.then(function(all) {
var cortexIds = [];

_.each(all, function(value, key) {
if(analyzerIds.indexOf(key) > -1){
cortexIds = cortexIds.concat(value.cortexIds);
}
});

deferred.resolve(_.uniq(cortexIds));
});

return deferred.promise;
}
};
Expand Down
2 changes: 2 additions & 0 deletions ui/app/scripts/services/AuditSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
ret.pop();
}
messageAdded += 1;
} else {
console.log('message already in the flow: ', message);
}

}
Expand Down
18 changes: 17 additions & 1 deletion ui/app/scripts/services/CortexSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveServices')
.factory('CortexSrv', function ($q, $http, $rootScope, StatSrv, StreamSrv, PSearchSrv) {
.factory('CortexSrv', function ($q, $http, $rootScope, $modal, StatSrv, StreamSrv, PSearchSrv) {

var baseUrl = '/api/connector/cortex';

Expand Down Expand Up @@ -30,6 +30,22 @@

createJob: function (job) {
return $http.post(baseUrl + '/job', job);
},

promptForInstance: function (servers) {
var modalInstance = $modal.open({
templateUrl: 'views/partials/cortex/choose-instance-dialog.html',
controller: 'CortexInstanceDialogCtrl',
controllerAs: 'vm',
size: '',
resolve: {
servers: function() {
return servers;
}
}
});

return modalInstance.result;
}
};

Expand Down
1 change: 1 addition & 0 deletions ui/app/scripts/services/StreamSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},

handleStreamResponse: function(data) {
console.log(data);
var byRootIds = {};
var byObjectTypes = {};
var byRootIdsWithObjectTypes = {};
Expand Down
6 changes: 3 additions & 3 deletions ui/app/views/directives/flow/observable-job.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="flow-observable-job">
<div class="flow-item-title wrap">
<div class="flow-item-title wrap">
<i class="glyphicon glyphicon-cog"></i>
<span ng-if="base.details.startDate">
<span ng-if="!base.object.endDate">
Job: <em>{{base.object.analyzerId}}</em> started
</span>
<span ng-if="base.details.endDate">
<span ng-if="base.object.endDate">
Job <em>{{base.object.analyzerId}}</em> terminated
</span>
</div>
Expand Down
22 changes: 22 additions & 0 deletions ui/app/views/partials/cortex/choose-instance-dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<form class="form-horizontal" name="form" ng-submit="vm.ok()" novalidate>
<div class="modal-header bg-primary">
<h3 class="modal-title">Select Cortex server</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-4 control-label">
Cortex Server
<i class="fa fa-asterisk text-danger"></i>
</label>
<div class="col-sm-8">
<select class="form-control" ng-model="vm.selected" ng-options="s for s in vm.servers" required>
<option value="">-- choose server --</option>
</select>
</div>
</div>
</div>
<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="vm.cancel()">Cancel</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="form.$invalid">Yes, select this server</button>
</div>
</form>

0 comments on commit 9df9cd1

Please sign in to comment.