Skip to content

Commit

Permalink
#52 Add a share button on case details page to export to misp
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Sep 6, 2017
1 parent deb0e2c commit a491503
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 102 deletions.
14 changes: 7 additions & 7 deletions thehive-misp/app/connectors/misp/MispCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import play.api.http.Status
import play.api.libs.json.{ JsObject, Json }
import play.api.mvc._
import play.api.routing.SimpleRouter
import play.api.routing.sird.{ GET, UrlContext }
import play.api.routing.sird.{ GET, POST, UrlContext }

import connectors.Connector
import models.{ Alert, Case, Roles, UpdateMispAlertArtifact }
Expand Down Expand Up @@ -40,11 +40,11 @@ class MispCtrl @Inject() (

private[MispCtrl] lazy val logger = Logger(getClass)
val router = SimpleRouter {
case GET(p"/_syncAlerts") syncAlerts
case GET(p"/_syncAllAlerts") syncAllAlerts
case GET(p"/_syncArtifacts") syncArtifacts
case GET(p"/export/$caseId/to/$mispName") exportCase(mispName, caseId)
case r throw NotFoundError(s"${r.uri} not found")
case GET(p"/_syncAlerts") syncAlerts
case GET(p"/_syncAllAlerts") syncAllAlerts
case GET(p"/_syncArtifacts") syncArtifacts
case POST(p"/export/$caseId/$mispName") exportCase(mispName, caseId)
case r throw NotFoundError(s"${r.uri} not found")
}

@Timed
Expand Down Expand Up @@ -83,4 +83,4 @@ class MispCtrl @Inject() (
override def mergeWithCase(alert: Alert, caze: Case)(implicit authContext: AuthContext): Future[Case] = {
mispSrv.mergeWithCase(alert, caze)
}
}
}
3 changes: 1 addition & 2 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
<script src="scripts/controllers/case/CaseCloseModalCtrl.js"></script>
<script src="scripts/controllers/case/CaseCreationCtrl.js"></script>
<script src="scripts/controllers/case/CaseDetailsCtrl.js"></script>
<script src="scripts/controllers/case/CaseExportCtrl.js"></script>
<script src="scripts/controllers/case/CaseLinksCtrl.js"></script>
<script src="scripts/controllers/case/CaseListCtrl.js"></script>
<script src="scripts/controllers/case/CaseMainCtrl.js"></script>
Expand All @@ -161,7 +160,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/misc/ServerInstanceDialogCtrl.js"></script>
<script src="scripts/directives/charts/c3Chart.js"></script>
<script src="scripts/directives/charts/chart.js"></script>
<script src="scripts/directives/charts/donut-chart.js"></script>
Expand Down
11 changes: 0 additions & 11 deletions ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,6 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ngSanitize', 'ui.bootstra
templateUrl: 'views/partials/case/case.links.html',
controller: 'CaseLinksCtrl'
})
.state('app.case.export', {
url: '/export',
templateUrl: 'views/partials/case/case.export.html',
controller: 'CaseExportCtrl',
controllerAs: '$vm',
resolve: {
categories: function(MispSrv) {
return MispSrv.categories();
}
}
})
.state('app.case.tasks-item', {
url: '/tasks/{itemId}',
templateUrl: 'views/partials/case/case.tasks.item.html',
Expand Down
63 changes: 0 additions & 63 deletions ui/app/scripts/controllers/case/CaseExportCtrl.js

This file was deleted.

15 changes: 11 additions & 4 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers').controller('CaseMainCtrl',
function($scope, $rootScope, $state, $stateParams, $q, $uibModal, CaseTabsSrv, CaseSrv, MetricsCacheSrv, UserInfoSrv, StreamStatSrv, NotificationSrv, UtilsSrv, CaseResolutionStatus, CaseImpactStatus, caze) {
function($scope, $rootScope, $state, $stateParams, $q, $uibModal, CaseTabsSrv, CaseSrv, MetricsCacheSrv, UserInfoSrv, MispSrv, StreamStatSrv, NotificationSrv, UtilsSrv, CaseResolutionStatus, CaseImpactStatus, caze) {
$scope.CaseResolutionStatus = CaseResolutionStatus;
$scope.CaseImpactStatus = CaseImpactStatus;

Expand Down Expand Up @@ -199,9 +199,16 @@
};

$scope.shareCase = function() {
$state.go('app.case.export', {
caseId: $scope.caseId
});
var mispConfig = $scope.appConfig.connectors.misp;
MispSrv.getServer(mispConfig)
.then(function(server) {
return MispSrv.export($scope.caseId, server);
})
.then(function(response){
console.log(response);
}, function(err) {
console.log(err);
});
};

/**
Expand Down
20 changes: 20 additions & 0 deletions ui/app/scripts/controllers/misc/ServerInstanceDialogCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('ServerInstanceDialogCtrl', ServerInstanceDialogCtrl);

function ServerInstanceDialogCtrl($uibModalInstance, servers) {
var self = this;

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

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

this.cancel = function() {
$uibModalInstance.dismiss();
};
}
})();
2 changes: 1 addition & 1 deletion ui/app/scripts/services/CortexSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
promptForInstance: function(servers) {
var modalInstance = $uibModal.open({
templateUrl: 'views/partials/cortex/choose-instance-dialog.html',
controller: 'CortexInstanceDialogCtrl',
controller: 'ServerInstanceDialogCtrl',
controllerAs: 'vm',
size: '',
resolve: {
Expand Down
44 changes: 30 additions & 14 deletions ui/app/scripts/services/MispSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('MispSrv', function($q, $http, $rootScope, StatSrv, StreamSrv, PSearchSrv) {
.factory('MispSrv', function($q, $http, $rootScope, $uibModal, StatSrv, StreamSrv, PSearchSrv) {

var baseUrl = './api/connector/misp';

Expand Down Expand Up @@ -118,21 +118,37 @@
return defer.promise;
},

categories: function() {
var defer = $q.defer();

$q.resolve({
'category1': [
'type1.1', 'type1.2', 'type1.3'
],
'category2': [
'type2.1', 'type2.2', 'type2.3'
]
}).then(function(response) {
defer.resolve(response);
promptForInstance: function(servers) {
var modalInstance = $uibModal.open({
templateUrl: 'views/partials/misp/choose-instance-dialog.html',
controller: 'ServerInstanceDialogCtrl',
controllerAs: 'vm',
size: '',
resolve: {
servers: function() {
return servers;
}
}
});

return defer.promise;
return modalInstance.result;
},

getServer: function(mispConfig) {
if(!mispConfig || !mispConfig.enabled || !mispConfig.servers) {
return $q.reject();
}

var servers = mispConfig.servers;
if (servers.length === 1) {
return $q.resolve(servers[0]);
} else {
return factory.promptForInstance(servers);
}
},

export: function(caseId, server) {
return $http.post(baseUrl + '/export/' + caseId + '/' + server, {});
}
};

Expand Down
22 changes: 22 additions & 0 deletions ui/app/views/partials/misp/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 MISP server</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-4 control-label">
MISP 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>
28 changes: 28 additions & 0 deletions ui/app/views/partials/misp/error-modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="modal-header bg-primary">
<h3 class="modal-title">Export case to MISP</h3>
</div>

<div class="modal-body">
<div class="alert alert-danger">
Failed to export the following observables
</div>
<table class="table table-striped">
<thead>
<th>Observable</th>
<th>Reason</th>
</thead>
<tbody>
<tr ng-repeat="o in failures">
<td class="wrap">{{o.data | fang}}</td>
<td class="nowrap">{{o.message}}</td>
</tr>
</tbody>

</table>

</div>

<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="cancel()" type="button">Cancel</button>
<button class="btn btn-primary pull-right" ng-click="copyToClipboard()" type="button"><i class="fa fa-copy"></i> Copy to clipboard</button>
</div>

0 comments on commit a491503

Please sign in to comment.