diff --git a/www/src/app/pages/admin/organizations/components/analyzer-config-form.controller.js b/www/src/app/pages/admin/organizations/components/analyzers/analyzer-config-form.controller.js similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzer-config-form.controller.js rename to www/src/app/pages/admin/organizations/components/analyzers/analyzer-config-form.controller.js diff --git a/www/src/app/pages/admin/organizations/components/analyzer-config-form.html b/www/src/app/pages/admin/organizations/components/analyzers/analyzer-config-form.html similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzer-config-form.html rename to www/src/app/pages/admin/organizations/components/analyzers/analyzer-config-form.html diff --git a/www/src/app/pages/admin/organizations/components/analyzer.edit.controller.js b/www/src/app/pages/admin/organizations/components/analyzers/analyzer.edit.controller.js similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzer.edit.controller.js rename to www/src/app/pages/admin/organizations/components/analyzers/analyzer.edit.controller.js diff --git a/www/src/app/pages/admin/organizations/components/analyzer.edit.modal.html b/www/src/app/pages/admin/organizations/components/analyzers/analyzer.edit.modal.html similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzer.edit.modal.html rename to www/src/app/pages/admin/organizations/components/analyzers/analyzer.edit.modal.html diff --git a/www/src/app/pages/admin/organizations/components/analyzers-list.controller.js b/www/src/app/pages/admin/organizations/components/analyzers/analyzers-list.controller.js similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzers-list.controller.js rename to www/src/app/pages/admin/organizations/components/analyzers/analyzers-list.controller.js diff --git a/www/src/app/pages/admin/organizations/components/analyzers-list.html b/www/src/app/pages/admin/organizations/components/analyzers/analyzers-list.html similarity index 100% rename from www/src/app/pages/admin/organizations/components/analyzers-list.html rename to www/src/app/pages/admin/organizations/components/analyzers/analyzers-list.html diff --git a/www/src/app/pages/admin/organizations/components/config-list.controller.js b/www/src/app/pages/admin/organizations/components/analyzers/config-list.controller.js similarity index 84% rename from www/src/app/pages/admin/organizations/components/config-list.controller.js rename to www/src/app/pages/admin/organizations/components/analyzers/config-list.controller.js index 76a146cf3..967fbbfa8 100644 --- a/www/src/app/pages/admin/organizations/components/config-list.controller.js +++ b/www/src/app/pages/admin/organizations/components/analyzers/config-list.controller.js @@ -1,8 +1,8 @@ 'use strict'; import _ from 'lodash/core'; -import ConfigurationEditController from './config.edit.controller'; -import configurationEditTpl from './config.edit.modal.html'; +import ConfigurationEditController from '../config.edit.controller'; +import configurationEditTpl from '../config.edit.modal.html'; export default class OrganizationConfigsController { constructor($log, $uibModal, AnalyzerService, NotificationService) { @@ -39,9 +39,9 @@ export default class OrganizationConfigsController { _.forEach(conf.configurationItems, item => { conf.config[item.name] = - conf.config[item.name] !== undefined - ? conf.config[item.name] - : item.defaultValue || (item.multi ? [undefined] : undefined); + conf.config[item.name] !== undefined ? + conf.config[item.name] : + item.defaultValue || (item.multi ? [undefined] : undefined); }); return conf; @@ -70,4 +70,4 @@ export default class OrganizationConfigsController { } }); } -} +} \ No newline at end of file diff --git a/www/src/app/pages/admin/organizations/components/config-list.html b/www/src/app/pages/admin/organizations/components/analyzers/config-list.html similarity index 100% rename from www/src/app/pages/admin/organizations/components/config-list.html rename to www/src/app/pages/admin/organizations/components/analyzers/config-list.html diff --git a/www/src/app/pages/admin/organizations/components/responders/config-list.controller.js b/www/src/app/pages/admin/organizations/components/responders/config-list.controller.js new file mode 100644 index 000000000..c06f193e2 --- /dev/null +++ b/www/src/app/pages/admin/organizations/components/responders/config-list.controller.js @@ -0,0 +1,73 @@ +'use strict'; +import _ from 'lodash/core'; + +import ConfigurationEditController from '../config.edit.controller'; +import configurationEditTpl from '../config.edit.modal.html'; + +export default class OrganizationConfigsController { + constructor($log, $uibModal, ResponderService, NotificationService) { + 'ngInject'; + + this.$log = $log; + this.$uibModal = $uibModal; + this.ResponderService = ResponderService; + this.NotificationService = NotificationService; + + this.state = { + filter: '' + }; + } + + isSet(config) { + return _.indexOf([undefined, null, ''], config) === -1; + } + + edit(config) { + let modal = this.$uibModal.open({ + controller: ConfigurationEditController, + templateUrl: configurationEditTpl, + controllerAs: '$modal', + size: 'lg', + resolve: { + configuration: () => { + // let defaultValues = { + // string: null, + // number: 0, + // boolean: true + // }; + let conf = angular.copy(config); + + _.forEach(conf.configurationItems, item => { + conf.config[item.name] = + conf.config[item.name] !== undefined ? + conf.config[item.name] : + item.defaultValue || (item.multi ? [undefined] : undefined); + }); + + return conf; + } + } + }); + + modal.result + .then(configuration => + this.ResponderService.saveConfiguration(config.name, { + config: configuration + }) + ) + .then(() => this.ResponderService.configurations()) + .then(configs => (this.configurations = configs)) + .then(() => + this.NotificationService.success( + `Configuration ${config.name} updated successfully` + ) + ) + .catch(err => { + if (!_.isString(err)) { + this.NotificationService.error( + `Failed to update configuration ${config.name}` + ); + } + }); + } +} \ No newline at end of file diff --git a/www/src/app/pages/admin/organizations/components/responders/config-list.html b/www/src/app/pages/admin/organizations/components/responders/config-list.html new file mode 100644 index 000000000..b14dc77e6 --- /dev/null +++ b/www/src/app/pages/admin/organizations/components/responders/config-list.html @@ -0,0 +1,68 @@ + + +
+

Available responder configurations ({{$ctrl.configurations.length || 0}})

+ +
+
+
No configurations found.
+
+
+ +
+
+
+ + + + +
+
+
+
+
Options
+
Configuration
+
Responders
+
+
+
+
+
+

{{config.configurationItems.length}}

+ +
+
+
+

+ {{config.name === 'global' ? 'Global Configuration' : config.name}} +

+

+
+ + {{item.name}}: {{item.description}} + (Default: {{item.defaultValue}}) + +
+

+
+
+

+ +

+

+
+ {{item}} +
+

+
+
+ + Edit +
+
+
+
+
\ No newline at end of file diff --git a/www/src/app/pages/admin/organizations/details/organization.page.html b/www/src/app/pages/admin/organizations/details/organization.page.html index 4477b6141..94ab1fe96 100644 --- a/www/src/app/pages/admin/organizations/details/organization.page.html +++ b/www/src/app/pages/admin/organizations/details/organization.page.html @@ -15,7 +15,7 @@

Organization: Analyzers Config - + @@ -26,7 +26,7 @@

Organization: Responders Config - + diff --git a/www/src/app/pages/admin/organizations/organizations.module.js b/www/src/app/pages/admin/organizations/organizations.module.js index 6a2567cbc..b11dc4572 100644 --- a/www/src/app/pages/admin/organizations/organizations.module.js +++ b/www/src/app/pages/admin/organizations/organizations.module.js @@ -13,14 +13,14 @@ import OrganizationUsersController from './components/users-list.controller'; import organizationUsersTpl from './components/users-list.html'; // Analyzers -import AnalyzerConfigFormController from './components/analyzer-config-form.controller'; -import analyzerConfigFormTpl from './components/analyzer-config-form.html'; +import AnalyzerConfigFormController from './components/analyzers/analyzer-config-form.controller'; +import analyzerConfigFormTpl from './components/analyzers/analyzer-config-form.html'; -import OrganizationAnalyzersController from './components/analyzers-list.controller'; -import organizationAnalyzersTpl from './components/analyzers-list.html'; +import OrganizationAnalyzersController from './components/analyzers/analyzers-list.controller'; +import organizationAnalyzersTpl from './components/analyzers/analyzers-list.html'; -import OrganizationConfigsController from './components/config-list.controller'; -import organizationConfigsTpl from './components/config-list.html'; +import OrganizationConfigsController from './components/analyzers/config-list.controller'; +import organizationConfigsTpl from './components/analyzers/config-list.html'; import ConfigurationForm from './components/config-form.controller'; import configurationFormTpl from './components/config-form.html'; @@ -32,8 +32,10 @@ import responderConfigFormTpl from './components/responders/responder-config-for import OrganizationRespondersController from './components/responders/responders-list.controller'; import organizationRespondersTpl from './components/responders/responders-list.html'; +import OrganizationReponderConfigsController from './components/responders/config-list.controller'; +import organizationResponderConfigsTpl from './components/responders/config-list.html'; -import organizationService from './organizations.service.js'; +import organizationService from './organizations.service'; import './organizations.scss'; @@ -71,13 +73,20 @@ const organizationsModule = angular return $q.resolve([]); } }, - configurations: (AuthService, AnalyzerService, $q) => { + analyzersConfigurations: (AuthService, AnalyzerService, $q) => { if (AuthService.hasRole([Roles.ORGADMIN])) { return AnalyzerService.configurations(); } else { return $q.resolve([]); } }, + respondersConfigurations: (AuthService, ResponderService, $q) => { + if (AuthService.hasRole([Roles.ORGADMIN])) { + return ResponderService.configurations(); + } else { + return $q.resolve([]); + } + }, responderDefinitions: (AuthService, ResponderService, $q) => { if (AuthService.hasRole([Roles.ORGADMIN])) { return ResponderService.definitions(); @@ -110,9 +119,10 @@ const organizationsModule = angular users: '<', analyzerDefinitions: '<', analyzers: '<', - configurations: '<', + analyzersConfigurations: '<', responderDefinitions: '<', - responders: '<' + responders: '<', + respondersConfigurations: '<' } }) .component('organizationAnalyzersList', { @@ -148,6 +158,14 @@ const organizationsModule = angular configurations: '<' } }) + .component('organizationResponderConfigList', { + controller: OrganizationReponderConfigsController, + templateUrl: organizationResponderConfigsTpl, + bindings: { + organization: '<', + configurations: '<' + } + }) .component('configurationForm', { controller: ConfigurationForm, templateUrl: configurationFormTpl, diff --git a/www/src/app/pages/responders/responders.service.js b/www/src/app/pages/responders/responders.service.js index 0e8d020da..ee69e28fc 100644 --- a/www/src/app/pages/responders/responders.service.js +++ b/www/src/app/pages/responders/responders.service.js @@ -2,17 +2,13 @@ import _ from 'lodash'; -// import AnalyzerRunController from './analyzer.run.controller'; -// import runAnalyzerModalTpl from './analyzer.run.modal.html'; - export default class ResponderService { - constructor($log, $q, $http, $uibModal) { + constructor($log, $q, $http) { 'ngInject'; this.$log = $log; this.$q = $q; this.$http = $http; - this.$uibModal = $uibModal; this.responderDefinitions = null; this.responders = null; @@ -45,14 +41,10 @@ export default class ResponderService { } scan() { - let defer = this.$q.defer(); - - this.$http + return this.$http .post('./api/responderdefinition/scan', {}) - .then(response => defer.resolve(response.data)) - .catch(err => defer.reject(err)); - - return defer.promise; + .then(response => this.$q.resolve(response.data)) + .catch(err => this.$q.reject(err)); } list() { @@ -83,12 +75,9 @@ export default class ResponderService { } configurations() { - let defer = this.$q.defer(); - this.$http + return this.$http .get('./api/responderconfig') - .then(response => defer.resolve(response.data), err => defer.reject(err)); - - return defer.promise; + .then(response => this.$q.resolve(response.data), err => this.$q.reject(err)); } getBaseConfig(baseConfig) { @@ -107,96 +96,14 @@ export default class ResponderService { } getConfiguration(name) { - let defer = this.$q.defer(); - - this.$http + return this.$http .get(`./api/responderconfig/${name}`) - .then(response => defer.resolve(response.data), err => defer.reject(err)); - - return defer.promise; + .then(response => this.$q.resolve(response.data), err => this.$q.reject(err)); } saveConfiguration(name, values) { - let defer = this.$q.defer(); - - this.$http + return this.$http .patch(`./api/responderconfig/${name}`, values) - .then(response => defer.resolve(response.data), err => defer.reject(err)); - - return defer.promise; + .then(response => this.$q.resolve(response.data), err => this.$q.reject(err)); } - - // openRunModal(analyzers, observable) { - // let modalInstance = this.$uibModal.open({ - // animation: true, - // templateUrl: runAnalyzerModalTpl, - // controller: AnalyzerRunController, - // controllerAs: '$modal', - // size: 'lg', - // resolve: { - // observable: () => angular.copy(observable), - // analyzers: () => angular.copy(analyzers) - // } - // }); - - // return modalInstance.result.then(result => - // this.$q.all( - // result.analyzerIds.map(analyzerId => - // this.run(analyzerId, result.observable) - // ) - // ) - // ); - // } - - // run(id, artifact) { - // let postData; - - // if (artifact.dataType === 'file') { - // postData = { - // attachment: artifact.attachment, - // dataType: artifact.dataType, - // tlp: artifact.tlp - // }; - - // return this.$http({ - // method: 'POST', - // url: './api/analyzer/' + id + '/run', - // headers: { - // 'Content-Type': undefined - // }, - // transformRequest: data => { - // let formData = new FormData(), - // copy = angular.copy(data, {}), - // _json = {}; - - // angular.forEach(data, (value, key) => { - // if ( - // Object.getPrototypeOf(value) instanceof Blob || - // Object.getPrototypeOf(value) instanceof File - // ) { - // formData.append(key, value); - // delete copy[key]; - // } else { - // _json[key] = value; - // } - // }); - - // formData.append('_json', angular.toJson(_json)); - - // return formData; - // }, - // data: postData - // }); - // } else { - // postData = { - // data: artifact.data, - // attributes: { - // dataType: artifact.dataType, - // tlp: artifact.tlp - // } - // }; - - // return this.$http.post('./api/analyzer/' + id + '/run', postData); - // } - // } } \ No newline at end of file