Skip to content

Commit

Permalink
Add UI elements to configure NVD mirroring via API
Browse files Browse the repository at this point in the history
Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Nov 5, 2023
1 parent 0c3df88 commit d444c7a
Showing 1 changed file with 83 additions and 2 deletions.
85 changes: 83 additions & 2 deletions src/views/administration/vuln-sources/VulnSourceNvd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
v-bind="labelIcon"
/>
{{$t('admin.vulnsource_nvd_enable')}}
<hr/>
<b-validated-input-group-form-input
id="nvd-feeds-url"
:label="$t('admin.vulnsource_nvd_feeds_url')"
Expand All @@ -20,6 +21,55 @@
lazy="true"
/>
<hr/>
<c-switch
id="nvdApiEnabled"
color="primary"
v-model="nvdApiEnabled"
label
v-bind="labelIcon"
/>
Enable API
<p class="font-sm text-muted">
<span class="fa fa-question-circle">&nbsp;</span>
<!-- TODO: Explain why users may want to enable API over feeds; Point out caveats (feed files no longer being downloaded etc.) -->
Foobarbaz
</p>
<b-validated-input-group-form-input
id="nvdApiEndpoint"
label="API endpoint"
input-group-size="mb-3"
v-model="nvdApiEndpoint"
lazy="true"
/>
<b-validated-input-group-form-input
id="nvdApiKey"
label="API key"
input-group-size="mb-3"
type="password"
v-model="nvdApiKey"
lazy="true"
/>
<b-form-group label="Last Modification">
<b-input-group>
<b-form-datepicker
id="nvdApiLastModifiedDate"
v-model="nvdApiLastModifiedDate"
:date-format-options="{ year: 'numeric', month: 'numeric', day: 'numeric' }"
locale="en-GB"
/>
<b-form-timepicker
id="nvdApiLastModifiedTime"
v-model="nvdApiLastModifiedTime"
locale="en-GB"
/>
</b-input-group>
</b-form-group>
<p class="font-sm text-muted">
<span class="fa fa-question-circle">&nbsp;</span>
<!-- TODO: Explain what the last modified datetime is used for and when users may want to modify it. -->
Foobarbaz
</p>
<hr/>
{{ $t('admin.vulnsource_nvd_desc') }}
</b-card-body>
<b-card-footer>
Expand All @@ -37,6 +87,7 @@
<script>
import { Switch as cSwitch } from '@coreui/vue';
import BValidatedInputGroupFormInput from '../../../forms/BValidatedInputGroupFormInput';
import BInputGroupFormDatepicker from "../../../forms/BInputGroupFormDatepicker";
import common from "../../../shared/common";
import configPropertyMixin from "../mixins/configPropertyMixin";
Expand All @@ -47,12 +98,18 @@ export default {
},
components: {
cSwitch,
BValidatedInputGroupFormInput
BValidatedInputGroupFormInput,
BInputGroupFormDatepicker
},
data() {
return {
vulnsourceEnabled: false,
nvdFeedsUrl: '',
nvdApiEnabled: false,
nvdApiEndpoint: '',
nvdApiKey: '',
nvdApiLastModifiedDate: new Date().toISOString(),
nvdApiLastModifiedTime: '',
labelIcon: {
dataOn: '\u2713',
dataOff: '\u2715'
Expand All @@ -63,8 +120,16 @@ export default {
saveChanges: function() {
this.updateConfigProperties([
{groupName: 'vuln-source', propertyName: 'nvd.enabled', propertyValue: this.vulnsourceEnabled},
{groupName: 'vuln-source', propertyName: 'nvd.feeds.url', propertyValue: this.nvdFeedsUrl}
{groupName: 'vuln-source', propertyName: 'nvd.feeds.url', propertyValue: this.nvdFeedsUrl},
{groupName: 'vuln-source', propertyName: 'nvd.api.enabled', propertyValue: this.nvdApiEnabled},
{groupName: 'vuln-source', propertyName: 'nvd.api.url', propertyValue: this.nvdApiEndpoint},
{groupName: 'vuln-source', propertyName: 'nvd.api.key', propertyValue: this.nvdApiKey},
{groupName: 'vuln-source', propertyName: 'nvd.api.last.modified.epoch.seconds', propertyValue: this.getApiLastModifiedEpochSeconds()}
]);
},
getApiLastModifiedEpochSeconds() {
let lastModifiedDateTime = Date.parse(`${this.nvdApiLastModifiedDate}T${this.nvdApiLastModifiedTime}Z`);
return lastModifiedDateTime ? lastModifiedDateTime / 1000 : null;
}
},
created () {
Expand All @@ -77,6 +142,22 @@ export default {
this.vulnsourceEnabled = common.toBoolean(item.propertyValue); break;
case "nvd.feeds.url":
this.nvdFeedsUrl = item.propertyValue; break;
case "nvd.api.enabled":
this.nvdApiEnabled = common.toBoolean(item.propertyValue); break;
case "nvd.api.url":
this.nvdApiEndpoint = item.propertyValue; break;
case "nvd.api.key":
this.nvdApiKey = item.propertyValue; break;
case "nvd.api.last.modified.epoch.seconds":
let epochSeconds = parseInt(item.propertyValue);
if (!epochSeconds) {
continue;
}
let date = new Date(0);
date.setUTCSeconds(epochSeconds);
this.nvdApiLastModifiedDate = date.toISOString().split("T")[0]; // YYYY-MM-DD
this.nvdApiLastModifiedTime = date.toLocaleTimeString("en-GB"); // HH:mm:SS
break;
}
}
});
Expand Down

0 comments on commit d444c7a

Please sign in to comment.