Skip to content

Commit

Permalink
Merge branch 'develop-th4' into issue-1264
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 11, 2021
2 parents 17662f6 + 7eb1f41 commit e5cffb5
Show file tree
Hide file tree
Showing 74 changed files with 1,975 additions and 338 deletions.
5 changes: 3 additions & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Tag.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.thp.thehive.dto.v1

import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.{JsObject, Json, OFormat}

import java.util.Date

Expand All @@ -15,7 +15,8 @@ case class OutputTag(
predicate: String,
value: Option[String],
description: Option[String],
colour: String
colour: String,
extraData: JsObject
)

object OutputTag {
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<script src="scripts/components/organisation/OrgCaseTemplateListCmp.js"></script>
<script src="scripts/components/organisation/OrgCaseTemplateModalCtrl.js"></script>
<script src="scripts/components/organisation/OrgConfigListCmp.js"></script>
<script src="scripts/components/organisation/OrgCustomTagsListCmp.js"></script>
<script src="scripts/components/organisation/OrgSwitchCtrl.js"></script>
<script src="scripts/components/organisation/OrgUserListCmp.js"></script>
<script src="scripts/components/search/filters-preview.component.js"></script>
Expand All @@ -170,6 +171,7 @@
<script src="scripts/controllers/admin/organisation/OrgModalCtrl.js"></script>
<script src="scripts/controllers/admin/organisation/OrgUserModalCtrl.js"></script>
<script src="scripts/controllers/admin/organisation/OrgUsersCtrl.js"></script>
<script src="scripts/controllers/admin/platform/PlatformStatusCtrl.js"></script>
<script src="scripts/controllers/admin/profile/ProfileListCtrl.js"></script>
<script src="scripts/controllers/admin/profile/ProfileModalCtrl.js"></script>
<script src="scripts/controllers/admin/taxonomy/TaxonomyListCtrl.js"></script>
Expand Down Expand Up @@ -259,10 +261,12 @@
<script src="scripts/directives/tlp.js"></script>
<script src="scripts/directives/updatable.js"></script>
<script src="scripts/directives/updatableBoolean.js"></script>
<script src="scripts/directives/updatableColour.js"></script>
<script src="scripts/directives/updatableDataDropdown.js"></script>
<script src="scripts/directives/updatableDate.js"></script>
<script src="scripts/directives/updatableSelect.js"></script>
<script src="scripts/directives/updatableSimpleText.js"></script>
<script src="scripts/directives/updatableTag.js"></script>
<script src="scripts/directives/updatableTagList.js"></script>
<script src="scripts/directives/updatableTags.js"></script>
<script src="scripts/directives/updatableText.js"></script>
Expand Down Expand Up @@ -306,6 +310,7 @@
<script src="scripts/services/api/MispSrv.js"></script>
<script src="scripts/services/api/ObservableTypeSrv.js"></script>
<script src="scripts/services/api/OrganisationSrv.js"></script>
<script src="scripts/services/api/PlatformSrv.js"></script>
<script src="scripts/services/api/ProcedureSrv.js"></script>
<script src="scripts/services/api/ProfileSrv.js"></script>
<script src="scripts/services/api/TagSrv.js"></script>
Expand Down
15 changes: 15 additions & 0 deletions frontend/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ angular.module('thehive', [
url: 'administration',
template: '<ui-view/>'
})
.state('app.administration.platform', {
url: '/platform',
templateUrl: 'views/partials/admin/platform/status.html',
controller: 'PlatformStatusCtrl',
controllerAs: '$vm',
title: 'Platform administration',
resolve: {
appConfig: function(VersionSrv) {
return VersionSrv.get();
}
},
guard: {
permissions: ['managePlatform']
}
})
.state('app.administration.profiles', {
url: '/profiles',
templateUrl: 'views/partials/admin/profile/list.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
self.filtering.setPageSize(newValue);
});
});

// TODO: REMOVE ME
if (self.templates && !_.isEmpty(self.templates)) {
self.loadTemplate(self.templates[0]);
}
};

this.load = function() {
Expand Down Expand Up @@ -124,20 +119,6 @@
self.filtering.setSort(sort);
};

this.newTemplate = function() {
self.showTemplate({
name: '',
titlePrefix: '',
severity: 2,
tlp: 2,
pap: 2,
tags: [],
tasks: [],
customFields: {},
description: ''
});
};

this.showTemplate = function(template) {

var promise = template._id ? CaseTemplateSrv.get(template._id) : $q.resolve(template);
Expand Down
167 changes: 167 additions & 0 deletions frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
(function() {
'use strict';

angular.module('theHiveComponents')
.component('orgCustomTagsList', {
controller: function($scope, PaginatedQuerySrv, FilteringSrv, TagSrv, UserSrv, ModalUtilsSrv, NotificationSrv) {
var self = this;

self.tags = [];
self.getUserInfo = UserSrv.getCache;

this.$onInit = function() {
// TODO: FIXME
self.filtering = new FilteringSrv('tag', 'custom-tags.list', {
version: 'v1',
defaults: {
showFilters: true,
showStats: false,
pageSize: 15,
sort: ['+predicate']
},
defaultFilter: []
});

self.filtering.initContext(self.organisation.name)
.then(function() {
self.load();

$scope.$watch('$vm.list.pageSize', function (newValue) {
self.filtering.setPageSize(newValue);
});
});
};

this.load = function() {

self.list = new PaginatedQuerySrv({
name: 'organisation-custom-tags',
version: 'v1',
skipStream: true,
sort: self.filtering.context.sort,
loadAll: false,
pageSize: self.filtering.context.pageSize,
filter: this.filtering.buildQuery(),
operations: [
{
'_name': 'listTag'
},
{
'_name': 'freetags'
}
],
extraData: ['usage'],
onFailure: function(err) {
if(err && err.status === 400) {
self.filtering.resetContext();
self.load();
}
}
});
};

self.deleteTag = function (tag) {
ModalUtilsSrv.confirm('Remove free tag', 'Are you sure you want to delete this tag?', {
okText: 'Yes, remove it',
flavor: 'danger'
})
.then(function () {
return TagSrv.removeTag(tag._id);
})
.then(function () {
NotificationSrv.success('Tag [' + tag.predicate + '] removed successfully');

self.load();

$scope.$emit('freetags:refresh');
});
};

self.updateColour = function(id, colour) {
TagSrv.updateTag(id, {colour: colour})
.then(function(/*response*/) {
NotificationSrv.success('Tag colour updated successfully');
})
.catch(function(err) {
NotificationSrv.error('Tag list', err.data, err.status);
})
}

self.updateTag = function(id, value) {
TagSrv.updateTag(id, {predicate: value})
.then(function(/*response*/) {
NotificationSrv.success('Tag value updated successfully');
})
.catch(function(err) {
NotificationSrv.error('Tag list', err.data, err.status);
})
}

// Filtering
this.toggleFilters = function () {
this.filtering.toggleFilters();
};

this.filter = function () {
self.filtering.filter().then(this.applyFilters);
};

this.clearFilters = function () {
this.filtering.clearFilters()
.then(self.search);
};

this.removeFilter = function (index) {
self.filtering.removeFilter(index)
.then(self.search);
};

this.search = function () {
self.load();
self.filtering.storeContext();
};
this.addFilterValue = function (field, value) {
this.filtering.addFilterValue(field, value);
this.search();
};

this.filterBy = function(field, value) {
self.filtering.clearFilters()
.then(function(){
self.addFilterValue(field, value);
});
};

this.sortBy = function(sort) {
self.list.sort = sort;
self.list.update();
self.filtering.setSort(sort);
};

this.sortByField = function(field) {
var context = this.filtering.context;
var currentSort = Array.isArray(context.sort) ? context.sort[0] : context.sort;
var sort = null;

if(currentSort.substr(1) !== field) {
sort = ['+' + field];
} else {
sort = [(currentSort === '+' + field) ? '-'+field : '+'+field];
}

self.list.sort = sort;
self.list.update();
self.filtering.setSort(sort);
};
},
controllerAs: '$vm',
templateUrl: 'views/components/org/custom-tags/tag-list.html',
bindings: {
organisation: '<',
templates: '=',
fields: '<',
onReload: '&',
onEdit: '&'
}
});
})();
1 change: 1 addition & 0 deletions frontend/app/scripts/controllers/AuthenticationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';
angular.module('theHiveControllers')
.controller('AuthenticationCtrl', function($rootScope, $scope, $state, $location, $uibModalStack, $stateParams, AuthenticationSrv, NotificationSrv, UtilsSrv, UrlParser, appConfig) {
$scope.appConfig = appConfig;
$scope.version = appConfig.versions.TheHive;

$scope.params = {
Expand Down
107 changes: 107 additions & 0 deletions frontend/app/scripts/controllers/admin/platform/PlatformStatusCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
(function() {
'use strict';

angular.module('theHiveControllers').controller('PlatformStatusCtrl', function(ModalSrv, PlatformSrv, NotificationSrv, appConfig) {
var self = this;

self.appConfig = appConfig;
self.indexStatus = {};
self.checkStats = {};

self.loading = {
index: false,
check: false
}

this.loadIndexStatus = function() {
self.indexStatus = {};
self.loading.index = true;

PlatformSrv.getIndexStatus()
.then(function(response) {
self.indexStatus = response.data;
self.loading.index = false;
});
}

this.loadCheckStats = function() {
self.loading.check = true;

PlatformSrv.getCheckStats()
.then(function(response) {
self.checkStats = response.data;
self.loading.check = false;
})
}

this.$onInit = function() {
self.loadIndexStatus();
self.loadCheckStats();
};

this.exportReport = function() {
var date = new moment().format('YYYYMMDD-HH:mmZ');
var fileName = 'Platform-Status-Report-'+date+'.json';

var content = {
indexStatus: self.indexStatus,
checkStatus: self.checkStats,
schemaStatus: self.appConfig.schemaStatus
};

// Create a blob of the data
var fileToSave = new Blob([JSON.stringify(content)], {
type: 'application/json',
name: fileName
});

// Save the file
saveAs(fileToSave, fileName);
}

this.reindex = function(indexName) {
var modalInstance = ModalSrv.confirm(
'Reindex',
'Are you sure you want to trigger ' + indexName + ' data reindex', {
okText: 'Yes, reindex it'
}
);

modalInstance.result
.then(function() {
PlatformSrv.runReindex(indexName);
})
.then(function(/*response*/) {
NotificationSrv.success('Reindexing of ' + indexName + ' data started sucessfully');
})
.catch(function(err) {
if (!_.isString(err)) {
NotificationSrv.error('Platform status', err.data, err.status);
}
});
};

this.checkControl = function(checkName) {
var modalInstance = ModalSrv.confirm(
'Data health check',
'Are you sure you want to trigger ' + checkName + ' health check', {
okText: 'Yes, trigger it'
}
);

modalInstance.result
.then(function() {
PlatformSrv.runCheck(checkName);
})
.then(function(/*response*/) {
NotificationSrv.success('Data health check of ' + checkName + ' started sucessfully');
})
.catch(function(err) {
if (!_.isString(err)) {
NotificationSrv.error('Platform status', err.data, err.status);
}
});
}

});
})();
Loading

0 comments on commit e5cffb5

Please sign in to comment.