Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVSS might be inserted as a number #163

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 85 additions & 85 deletions src/gui/src/components/common/attribute/AttributeCVSS.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<template>

<!--<div>
<v-row v-for="(value, index) in values" :key="value.index"
class="valueHolder"
Expand Down Expand Up @@ -46,45 +45,29 @@
</v-btn>
</div>-->

<AttributeItemLayout
:add_button="addButtonVisible"
@add-value="add()"
:values="values"
>
<AttributeItemLayout :add_button="addButtonVisible" @add-value="add()" :values="values">
<template v-slot:content>
<v-row v-for="(value, index) in values" :key="value.index"
class="valueHolder"
>
<span v-if="read_only || values[index].remote">{{values[index].value}}</span>
<AttributeValueLayout
v-if="!read_only && canModify && !values[index].remote"
:del_button="delButtonVisible"
@del-value="del(index)"
:occurrence="attribute_group.min_occurrence"
:values="values"
:val_index="index"
>
<v-row v-for="(value, index) in values" :key="value.index" class="valueHolder">
<span v-if="read_only || values[index].remote">{{ values[index].value }}</span>
<AttributeValueLayout v-if="!read_only && canModify && !values[index].remote" :del_button="delButtonVisible"
@del-value="del(index)" :occurrence="attribute_group.min_occurrence" :values="values"
:val_index="index">
<template v-slot:col_left>
<CalculatorCVSS
:value="calcValue"
@update-value="updateValue"
@success="report"
/>
<CalculatorCVSS :value="calcValue" @update-value="updateValue" @success="report" />
</template>
<template v-slot:col_middle>
<v-text-field v-model="calcValue"
:label="$t('attribute.value')"
@focus="onFocus(index)" @blur="onBlur(index)" @keyup="directValueChange"
:class="getLockedStyle(index)"
:disabled="values[index].locked || !canModify"
:rules="[rules.vector]"
></v-text-field>
<v-text-field v-model="calcValue" :label="$t('attribute.value')" @focus="onFocus(index)"
@blur="onBlur(index)" @keyup="directValueChange" :class="getLockedStyle(index)"
:disabled="values[index].locked || !canModify" :rules="[rules.vector]"></v-text-field>

<v-card class="text-center pb-3" color="white" outlined>
<v-row justify="center">
<v-col v-for="metric in score.all" :key="metric.name" class="pa-0 mr-1 severity" :class="metric.severity" style="width: calc(100% / 3); border-radius: 4px;">
<span class="body-2 white--text">{{ $t('cvss_calculator.'+metric.name+'_score') + " " }}</span>
<span class="body-2 white--text font-weight-bold text-uppercase">{{ $t('cvss_calculator.' + metric.severity) }}</span>
<v-col v-for="metric in score.all" :key="metric.name" class="pa-0 mr-1 severity"
:class="metric.severity" style="width: calc(100% / 3); border-radius: 4px;">
<span class="body-2 white--text">{{ $t('cvss_calculator.' + metric.name + '_score') + " "}}
</span>
<span class="body-2 white--text font-weight-bold text-uppercase">{{
$t('cvss_calculator.' + metric.severity) }}</span>
<br>
<span class="px-4 cs_metric_score headline font-weight-medium">{{ metric.score }}</span>
</v-col>
Expand All @@ -95,75 +78,92 @@
</v-row>
</template>
</AttributeItemLayout>

</template>

<script>
import AttributesMixin from "@/components/common/attribute/attributes_mixin";
import CalculatorCVSS from "@/components/common/CalculatorCVSS";
import Cvss31Mixin from "@/assets/cvss31_mixin";
import AttributesMixin from "@/components/common/attribute/attributes_mixin";
import CalculatorCVSS from "@/components/common/CalculatorCVSS";
import Cvss31Mixin from "@/assets/cvss31_mixin";

import AttributeItemLayout from "../../layouts/AttributeItemLayout";
import AttributeValueLayout from "../../layouts/AttributeValueLayout";
import AttributeItemLayout from "../../layouts/AttributeItemLayout";
import AttributeValueLayout from "../../layouts/AttributeValueLayout";

export default {
name: "AttributeCVSS",
props: {
attribute_group: Object
},
data: () =>({
score: "score status",
calcValue: "",
status: "",
rules: {
vector: value => {
const pattern = /^CVSS:3\.1\/((AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])\/)*(AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])$/
return value == '' || pattern.test(value) || 'Invalid or Incomplete Vector String'
}
export default {
name: "AttributeCVSS",
props: {
attribute_group: Object
},
data: () => ({
score: "score status",
calcValue: "",
status: "",
rules: {
vector: value => {
const pattern = /(^CVSS:3\.1\/((AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])\/)*(AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])$)|(^(10(\.0+)?|[0-9](\.[0-9]+)?)$)/
return value == '' || pattern.test(value) || 'Invalid or Incomplete Vector String'
}
}),
mixins: [AttributesMixin,Cvss31Mixin],
components: {
CalculatorCVSS,
AttributeItemLayout,
AttributeValueLayout
},
computed: {
/*putValue() {
return this.values[0].value;
}*/
},
methods: {
updateValue(e) {
}
}),
mixins: [AttributesMixin, Cvss31Mixin],
components: {
CalculatorCVSS,
AttributeItemLayout,
AttributeValueLayout
},
computed: {
/*putValue() {
return this.values[0].value;
}*/
},
methods: {
updateValue(e) {
const value = parseFloat(e);
if (value >= 0 && value <= 10) {
this.calcValue = value;
setTimeout(() => {
this.values[0].value = this.score;
this.onEdit(0);
}, 200);
}
else {
this.calcValue = e;
this.score = this.clc.calculateCVSSFromVector(this.calcValue);
setTimeout(()=>{
setTimeout(() => {
this.values[0].value = e;
this.onEdit(0);
},200);
},
report(e) {
this.status = e;
},
directValueChange() {
}, 200);
}
},
report(e) {
this.status = e;
},
directValueChange() {
if (this.calcValue >= 0 && this.calcValue <= 10) {
this.values[0].value = this.calcValue;
this.onKeyUp(0);
}
else {
let vsReport = this.clc.calculateCVSSFromVector(this.calcValue);

if(vsReport.success) {
if (vsReport.success) {
this.score = vsReport;

this.values[0].value = this.calcValue;
this.onKeyUp(0);
}
}
}

},
mounted(){
if( this.values[0].value !== "" ) {
this.calcValue = this.values[0].value;
this.score = this.clc.calculateCVSSFromVector(this.calcValue);
} else {
this.calcValue = 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N';
}
},
mounted() {
if (this.values[0].value >= 0 && this.values[0].value <= 10) {
this.calcValue = this.values[0].value;
}
else if (this.values[0].value !== "") {
this.calcValue = this.values[0].value;
this.score = this.clc.calculateCVSSFromVector(this.calcValue);
}
else {
this.calcValue = 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N';
}
}
}
</script>
Loading