Skip to content

Commit

Permalink
#170 Add jobTimout config to responders
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 3, 2019
1 parent deecf42 commit 937d870
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

import _ from 'lodash/core';
import omit from 'lodash/omit';

export default class AnalyzerConfigFormController {
constructor($log, Tlps, AnalyzerService) {
constructor($Tlps, AnalyzerService) {
'ngInject';

this.AnalyzerService = AnalyzerService;
Expand All @@ -24,10 +25,15 @@ export default class AnalyzerConfigFormController {
}

applyGlobalConfig() {
this.applyConfig(this.globalConfig.config);
const props = ['jobCache', 'jobTimeout'];

this.applyConfig(omit(this.globalConfig.config, props));
_.each(props, prop => {
this.analyzer[prop] = this.globalConfig.config[prop];
});
}

applyBaseConfig() {
this.applyConfig(this.baseConfig.config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ export default class OrganizationAnalyzersController {
disable(analyzerId) {
let modalInstance = this.ModalService.confirm(
'Disable analyzer',
'Are you sure you want to disable this analyzer? The corresponding configuration will be lost.',
{
'Are you sure you want to disable this analyzer? The corresponding configuration will be lost.', {
flavor: 'danger',
okText: 'Yes, disable it'
}
Expand Down Expand Up @@ -181,4 +180,4 @@ export default class OrganizationAnalyzersController {
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

import _ from 'lodash/core';
import omit from 'lodash/omit';

export default class ResponderConfigFormController {
constructor($log, Tlps, ResponderService) {
constructor(Tlps, ResponderService) {
'ngInject';

this.ResponderService = ResponderService;
Expand All @@ -19,7 +20,12 @@ export default class ResponderConfigFormController {
}

applyGlobalConfig() {
this.applyConfig(this.globalConfig.config);
const props = ['jobTimeout'];

this.applyConfig(omit(this.globalConfig.config, props));
_.each(props, prop => {
this.responder[prop] = this.globalConfig.config[prop];
});
}

applyBaseConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section>
<h4>Base details</h4>

<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-9">
Expand All @@ -18,8 +18,9 @@ <h4>
<i class="fa fa-copy"></i> Apply defaults</a>
</small>
</div>
</h4>
<configuration-form items="$ctrl.definition.configurationItems" configuration="$ctrl.responder.configuration"></configuration-form>
</h4>
<configuration-form items="$ctrl.definition.configurationItems" configuration="$ctrl.responder.configuration">
</configuration-form>
</section>

<section>
Expand All @@ -30,66 +31,78 @@ <h4>
<a href ng-click="$ctrl.applyGlobalConfig()">
<i class="fa fa-copy"></i> Apply defaults</a>
</small>
</div>
</div>
</h4>
<div class="form-group">
<label class="col-sm-3 control-label">Enable TLP check</label>
<div class="col-sm-9 form-inline">
<div class="btn-group">
<label uib-btn-radio="true" class="btn btn-default" ng-model="$ctrl.responder.configuration.check_tlp">True</label>
<label uib-btn-radio="false" class="btn btn-default" ng-model="$ctrl.responder.configuration.check_tlp">False</label>
<label uib-btn-radio="true" class="btn btn-default"
ng-model="$ctrl.responder.configuration.check_tlp">True</label>
<label uib-btn-radio="false" class="btn btn-default"
ng-model="$ctrl.responder.configuration.check_tlp">False</label>
</div>
<div class="form-group" style="margin-left: 30px;" ng-show="$ctrl.responder.configuration.check_tlp">
<label>Max TLP</label>
<select class="form-control" style="width: 200px;" ng-model="$ctrl.responder.configuration.max_tlp"
ng-options="tlp.value as tlp.key for tlp in $ctrl.Tlps" ng-required="$ctrl.responder.configuration.check_tlp"></select>
</div>
ng-options="tlp.value as tlp.key for tlp in $ctrl.Tlps"
ng-required="$ctrl.responder.configuration.check_tlp"></select>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Enable PAP check</label>
<div class="col-sm-9 form-inline">
<div class="btn-group">
<label uib-btn-radio="true" class="btn btn-default" ng-model="$ctrl.responder.configuration.check_pap">True</label>
<label uib-btn-radio="false" class="btn btn-default" ng-model="$ctrl.responder.configuration.check_pap">False</label>
<label uib-btn-radio="true" class="btn btn-default"
ng-model="$ctrl.responder.configuration.check_pap">True</label>
<label uib-btn-radio="false" class="btn btn-default"
ng-model="$ctrl.responder.configuration.check_pap">False</label>
</div>
<div class="form-group" style="margin-left: 30px;" ng-show="$ctrl.responder.configuration.check_pap">
<label>Max PAP</label>
<select class="form-control" style="width: 200px;" ng-model="$ctrl.responder.configuration.max_pap"
ng-options="tlp.value as tlp.key for tlp in $ctrl.Tlps" ng-required="$ctrl.responder.configuration.check_pap"></select>
ng-options="tlp.value as tlp.key for tlp in $ctrl.Tlps"
ng-required="$ctrl.responder.configuration.check_pap"></select>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">HTTP Proxy</label>
<div class="col-sm-9">
<input class="form-control" type="text" ng-model="$ctrl.responder.configuration.proxy_http">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">HTTPS Proxy</label>
<div class="col-sm-9">
<input class="form-control" type="text" ng-model="$ctrl.responder.configuration.proxy_https">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CA Certs</label>
<div class="col-sm-9">
<textarea class="form-control vertical" rows="5" ng-model="$ctrl.responder.configuration.cacerts"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Job timeout</label>
<div class="col-sm-9">
<input class="form-control" type="text" ng-model="$ctrl.responder.jobTimeout" ui-number-mask="0">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Rate Limiting</label>
<div class="col-sm-4">
<input class="form-control" type="text" ng-model="$ctrl.responder.rate" ui-number-mask="0" ui-hide-group-sep>
</div>
<div class="col-sm-5">
<div class="col-sm-5">
<select class="form-control" ng-model="$ctrl.responder.rateUnit" ng-options="unit for unit in $ctrl.rateUnits">
<option value="">-- choose unit --</option>
</select>
</div>
</div>
<div class="col-sm-offset-3 col-sm-9">
<p class="help-block">Define the maximum number of requests and the associated unit if applicable.</p>
</div>
</div>
</div>
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default class ResponderEditController {
name: this.definition.id,
configuration: {},
rate: undefined,
rateUnit: undefined
rateUnit: undefined,
jobTimeout: undefined
};

_.forEach(this.definition.configurationItems, item => {
Expand All @@ -49,7 +50,6 @@ export default class ResponderEditController {
'proxy_http',
'proxy_https',
'cacerts',
'jobCache',
'jobTimeout'
];
_.forEach(globalConfig, cnf => {
Expand All @@ -74,6 +74,10 @@ export default class ResponderEditController {
responder.configuration.max_pap = 2;
}

if (responder.jobTimeout === undefined) {
responder.jobTimeout = this.globalConfig.config.jobTimeout;
}

this.responder = responder;
}
}
Expand All @@ -84,4 +88,4 @@ export default class ResponderEditController {
cancel() {
this.$uibModalInstance.dismiss('cancel');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export default class OrganizationRespondersController {
'configuration',
'rate',
'rateUnit',
'name'
'name',
'jobTimeout'
)
);
}
Expand Down
18 changes: 17 additions & 1 deletion www/src/app/pages/analyzers/analyzers.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,23 @@ export default class AnalyzerService {

this.$http
.get(`./api/analyzerconfig/${name}`)
.then(response => defer.resolve(response.data), err => defer.reject(err));
.then(response => {
let cfg = response.data;

if (name === 'global') {
// Prepare the default values of the global config
let globalWithDefaults = {};
_.each(cfg.configurationItems, item => {
globalWithDefaults[item.name] = item.defaultValue;
});

// Set the default value of the global config that are not set
_.defaults(cfg.config, globalWithDefaults);
}

defer.resolve(cfg);
})
.catch(err => defer.reject(err));

return defer.promise;
}
Expand Down
18 changes: 17 additions & 1 deletion www/src/app/pages/responders/responders.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,23 @@ export default class ResponderService {
getConfiguration(name) {
return this.$http
.get(`./api/responderconfig/${name}`)
.then(response => this.$q.resolve(response.data), err => this.$q.reject(err));
.then(response => {
let cfg = response.data;

if (name === 'global') {
// Prepare the default values of the global config
let globalWithDefaults = {};
_.each(cfg.configurationItems, item => {
globalWithDefaults[item.name] = item.defaultValue;
});

// Set the default value of the global config that are not set
_.defaults(cfg.config, globalWithDefaults);
}

return this.$q.resolve(cfg);
})
.catch(err => this.$q.reject(err));
}

saveConfiguration(name, values) {
Expand Down

0 comments on commit 937d870

Please sign in to comment.