Skip to content

Commit

Permalink
Merge pull request #1100 from swaterkamp/AlembaVFire
Browse files Browse the repository at this point in the history
Add Alemba vFire alert to GUI
  • Loading branch information
timopollmeier authored Dec 20, 2018
2 parents 47becd3 + 4533309 commit 165d724
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 9 deletions.
1 change: 1 addition & 0 deletions gsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ set (GSA_JS_SRC_FILES
${GSA_SRC_DIR}/src/web/pages/agents/dialog.js
${GSA_SRC_DIR}/src/web/pages/agents/row.js
${GSA_SRC_DIR}/src/web/pages/agents/table.js
${GSA_SRC_DIR}/src/web/pages/alerts/alembavfiremethodpart.js
${GSA_SRC_DIR}/src/web/pages/alerts/component.js
${GSA_SRC_DIR}/src/web/pages/alerts/condition.js
${GSA_SRC_DIR}/src/web/pages/alerts/details.js
Expand Down
24 changes: 18 additions & 6 deletions gsa/src/gmp/commands/alerts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* Greenbone Security Assistant
/* Copyright (C) 2016 - 2018 Greenbone Networks GmbH
*
* Authors:
* Björn Ricks <bjoern.ricks@greenbone.net>
*
* Copyright:
* Copyright (C) 2016 - 2018 Greenbone Networks GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -78,6 +74,17 @@ const method_data_fields = [
'tp_sms_tls_workaround',
'delta_type',
'delta_report_id',
'report_formats',
'vfire_base_url',
'vfire_credential',
'vfire_session_type',
'vfire_client_id',
'vfire_call_partition_name',
'vfire_call_description',
'vfire_call_template_name',
'vfire_call_type_name',
'vfire_call_impact_name',
'vfire_call_urgency_name',
];
const condition_data_fields = [
'severity', 'direction', 'at_least_filter_id',
Expand Down Expand Up @@ -111,6 +118,7 @@ class AlertCommand extends EntityCommand {
condition,
filter_id,
method,
report_format_ids,
...other
} = args;
const data = {
Expand All @@ -125,6 +133,7 @@ class AlertCommand extends EntityCommand {
condition,
method,
filter_id,
'report_format_ids:': report_format_ids,
};
log.debug('Creating new alert', args, data);
return this.action(data);
Expand All @@ -140,6 +149,7 @@ class AlertCommand extends EntityCommand {
condition,
filter_id,
method,
report_format_ids = [],
...other
} = args;
const data = {
Expand All @@ -155,6 +165,8 @@ class AlertCommand extends EntityCommand {
condition,
method,
filter_id,
'report_format_ids:': report_format_ids.length > 0 ?
report_format_ids : undefined,
};
log.debug('Saving alert', args, data);
return this.action(data);
Expand Down
22 changes: 22 additions & 0 deletions gsa/src/gmp/models/__tests__/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('Alert Model tests', () => {
expect(alert.method).toEqual({
data: {
bar: {value: '42'},
report_formats: [],
},
type: 'foo',
});
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('Alert Model tests', () => {
},
value: '42',
},
report_formats: [],
},
type: 'foo',
});
Expand Down Expand Up @@ -123,6 +125,26 @@ describe('Alert Model tests', () => {
expect(alert.tasks).toEqual([]);
});

test('should parse report format ids', () => {
const elem = {
method: {
data: {
__text: '123, 456, 789',
name: 'report_formats',
},
},
};
const alert = new Alert(elem);

expect(alert.method.data.report_formats).toEqual(['123', '456', '789']);
});

test('should return empty array if no report format ids are given', () => {
const alert = new Alert({});

expect(alert.method.data.report_formats).toEqual([]);
});

test('isActive() should return correct true/false', () => {
const alert1 = new Alert({active: '0'});
const alert2 = new Alert({active: '1'});
Expand Down
11 changes: 11 additions & 0 deletions gsa/src/gmp/models/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const CONDITION_DIRECTION_DECREASED = 'decreased';
export const CONDITION_DIRECTION_INCREASED = 'increased';
export const CONDITION_DIRECTION_CHANGED = 'changed';

export const METHOD_TYPE_ALEMBA_VFIRE = 'Alemba vFire';
export const METHOD_TYPE_SCP = 'SCP';
export const METHOD_TYPE_SEND = 'Send';
export const METHOD_TYPE_SMB = 'SMB';
Expand Down Expand Up @@ -122,6 +123,16 @@ class Alert extends Model {
ret.tasks = [];
}

const methDatRepForm = ret.method.data.report_formats;

if (isDefined(methDatRepForm) && isDefined(methDatRepForm.value)) {
const methDatRepFormSplit = methDatRepForm.value.split(',');
ret.method.data.report_formats = methDatRepFormSplit.map(rf => rf.trim());
}
else {
ret.method.data.report_formats = [];
}

ret.active = parseYesNo(elem.active);

return ret;
Expand Down
7 changes: 7 additions & 0 deletions gsa/src/gmp/models/credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const EMAIL_CREDENTIAL_TYPES = [
PGP_CREDENTIAL_TYPE,
];

export const VFIRE_CREDENTIAL_TYPES = [
USERNAME_PASSWORD_CREDENTIAL_TYPE,
];

export const ALL_CREDENTIAL_TYPES = [
USERNAME_PASSWORD_CREDENTIAL_TYPE,
USERNAME_SSH_KEY_CREDENTIAL_TYPE,
Expand All @@ -84,6 +88,9 @@ export const email_credential_filter = credential =>
credential.credential_type === SMIME_CREDENTIAL_TYPE ||
credential.credential_type === PGP_CREDENTIAL_TYPE;

export const vFire_credential_filter = credential =>
credential.credential_type === USERNAME_PASSWORD_CREDENTIAL_TYPE;

export const SNMP_AUTH_ALGORITHM_MD5 = 'md5';
export const SNMP_AUTH_ALGORITHM_SHA1 = 'sha1';

Expand Down
224 changes: 224 additions & 0 deletions gsa/src/web/pages/alerts/alembavfiremethodpart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/* Copyright (C) 2018 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import React from 'react';

import _ from 'gmp/locale';

import {USERNAME_PASSWORD_CREDENTIAL_TYPE} from 'gmp/models/credential';

import Divider from 'web/components/layout/divider';
import Layout from 'web/components/layout/layout';

import PropTypes from 'web/utils/proptypes';
import {renderSelectItems} from 'web/utils/render';
import withPrefix from 'web/utils/withPrefix';

import MultiSelect from 'web/components/form/multiselect';
import Select from 'web/components/form/select';
import FormGroup from 'web/components/form/formgroup';
import Radio from 'web/components/form/radio';
import TextArea from 'web/components/form/textarea';
import TextField from 'web/components/form/textfield';

import NewIcon from 'web/components/icon/newicon';

import {VFIRE_CALL_DESCRIPTION} from 'web/pages/alerts/dialog';

const VFIRE_CREDENTIAL_TYPES = [USERNAME_PASSWORD_CREDENTIAL_TYPE];

const AlembaVfireMethodPart = ({
credentials,
prefix,
reportFormats = [],
reportFormatIds = [],
vFireBaseUrl,
vFireCallDescription = VFIRE_CALL_DESCRIPTION,
vFireCallImpactName,
vFireCallPartitionName,
vFireCallTemplateName,
vFireCallTypeName,
vFireCallUrgencyName,
vFireClientId,
vFireCredential,
vFireSessionType = 'Analyst',
onChange,
onCredentialChange,
onNewVfireCredentialClick,
onReportFormatsChange,
}) => {
credentials = credentials.filter(
cred => cred.credential_type === USERNAME_PASSWORD_CREDENTIAL_TYPE);
return (
<Layout
flex="column"
grow="1"
>
<FormGroup title={_('Report Formats')}>
<MultiSelect
name={'report_format_ids'}
items={renderSelectItems(reportFormats)}
value={reportFormatIds}
onChange={onReportFormatsChange}
/>
</FormGroup>

<FormGroup title={_('Base URL')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_base_url'}
value={vFireBaseUrl}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Credential')}>
<Divider>
<Select
name={prefix + 'vfire_credential'}
items={renderSelectItems(credentials)}
value={vFireCredential}
onChange={onCredentialChange}
/>
<Layout>
<NewIcon
size="small"
title={_('Create a credential')}
value={VFIRE_CREDENTIAL_TYPES}
onClick={onNewVfireCredentialClick}
/>
</Layout>
</Divider>
</FormGroup>

<FormGroup title={_('Session Type')}>
<Radio
title={_('Analyst')}
name={prefix + 'vfire_session_type'}
checked={vFireSessionType === 'Analyst'}
value="Analyst"
onChange={onChange}
/>
<Radio
title={_('User')}
name={prefix + 'vfire_session_type'}
checked={vFireSessionType === 'User'}
value="User"
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Alemba Client ID')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_client_id'}
value={vFireClientId}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Partition')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_call_partition_name'}
value={vFireCallPartitionName}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Call Description')}>
<TextArea
grow="1"
rows="9"
name={prefix + 'vfire_call_description'}
value={vFireCallDescription}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Call Template')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_call_template_name'}
value={vFireCallTemplateName}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Call Type')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_call_type_name'}
value={vFireCallTypeName}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Impact')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_call_impact_name'}
value={vFireCallImpactName}
onChange={onChange}
/>
</FormGroup>

<FormGroup title={_('Urgency')}>
<TextField
grow="1"
maxLength="256"
name={prefix + 'vfire_call_urgency_name'}
value={vFireCallUrgencyName}
onChange={onChange}
/>
</FormGroup>

</Layout>
);
};

AlembaVfireMethodPart.propTypes = {
credentials: PropTypes.array,
prefix: PropTypes.string,
reportFormatIds: PropTypes.array,
reportFormats: PropTypes.array,
vFireBaseUrl: PropTypes.string,
vFireCallDescription: PropTypes.string,
vFireCallImpactName: PropTypes.string,
vFireCallPartitionName: PropTypes.string,
vFireCallTemplateName: PropTypes.string,
vFireCallTypeName: PropTypes.string,
vFireCallUrgencyName: PropTypes.string,
vFireClientId: PropTypes.string,
vFireCredential: PropTypes.string,
vFireSessionType: PropTypes.string,
onChange: PropTypes.func.isRequired,
onCredentialChange: PropTypes.func.isRequired,
onNewVfireCredentialClick: PropTypes.func.isRequired,
onReportFormatsChange: PropTypes.func.isRequired,
};

export default withPrefix(AlembaVfireMethodPart);

// vim: set ts=2 sw=2 tw=80:
Loading

0 comments on commit 165d724

Please sign in to comment.