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

Duplication Fixes, Improvements #423

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ <h2 id="detection-title" @click="startEdit('detection-title', 'title')" v-if="!i
<v-btn id="detection-create-create" text small color="primary" class="align-self-end" @click="saveDetection(true)" data-aid="detection_new_save">
{{ i18n.create }}
</v-btn>
<v-btn id="detection-create-convert" v-if="detect.language === 'sigma'" text small color="primary" class="align-self-end" @click="convertDetection(detect.content)" data-aid="detection_convert">
<v-btn id="detection-create-convert" v-if="canConvert()" text small color="primary" class="align-self-end" @click="convertDetection()" data-aid="detection_convert">
{{ i18n.convert }}
</v-btn>
</div>
Expand Down Expand Up @@ -1265,7 +1265,7 @@ <h3 class="text--primary">{{ i18n.commentAddDetection }}</h3>
</div>
<div class="d-flex align-center align-self-end justify-end text-body-2 mt-2">
<div class="d-inline-flex justify-end">
<v-btn v-if="detect.engine === 'elastalert'" id="detection-convert" text small color="primary" class="align-self-end" @click="convertDetection(detect.content)" data-aid="detection_source_convert">
<v-btn v-if="canConvert()" id="detection-convert" text small color="primary" class="align-self-end" @click="convertDetection()" data-aid="detection_source_convert">
{{ i18n.convert }}
</v-btn>
<v-btn id="detection-cancel" v-if="!detect.isCommunity" text small color="primary" class="align-self-end" @click="cancelDetection()" data-aid="detection_source_cancel">
Expand Down
39 changes: 18 additions & 21 deletions html/js/routes/detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,7 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {

try {
const response = await this.$root.papi.get('detection/' + encodeURIComponent(this.$route.params.id));

this.detect = response.data;
delete this.detect.kind;

this.tagOverrides();
this.loadAssociations();
this.extractDetection(response);
} catch (error) {
if (error.response != undefined && error.response.status == 404) {
this.$root.showError(this.i18n.notFound);
Expand All @@ -193,6 +188,14 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {

this.$root.stopLoading();
},
extractDetection(response) {
this.detect = response.data;
delete this.detect.kind;

this.tagOverrides();
this.loadAssociations();
this.origDetect = Object.assign({}, this.detect);
},
loadAssociations() {
this.extractSummary();
this.extractReferences();
Expand Down Expand Up @@ -632,12 +635,7 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
index = this.expanded[0].index;
}

this.detect = response.data;
delete this.detect.kind;

this.tagOverrides();
this.loadAssociations();
this.origDetect = Object.assign({}, this.detect);
this.extractDetection(response);

if (response.status === 206) {
this.$root.showWarning(this.i18n.disabledFailedSync);
Expand All @@ -657,7 +655,9 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
},
async duplicateDetection() {
const response = await this.$root.papi.post('/detection/' + encodeURIComponent(this.$route.params.id) + '/duplicate');
this.$router.push({name: 'detection', params: {id: response.data.id}});
this.extractDetection(response);

this.$router.push({ name: 'detection', params: { id: response.data.id } });
},
async deleteDetection() {
try {
Expand Down Expand Up @@ -1002,6 +1002,10 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
canAddOverride() {
return this.detect.engine !== 'strelka';
},
canConvert() {
let lang = this.detect.language || '';
return lang.toLowerCase() === 'sigma';
},
tagOverrides() {
if (this.detect.overrides) {
for (let i = 0; i < this.detect.overrides.length; i++) {
Expand Down Expand Up @@ -1167,15 +1171,8 @@ routes.push({ path: '/detection/:id', name: 'detection', component: {
},
async convertDetection(content) {
this.$root.startLoading();

let payload = this.detect;
if (this.isNew()) {
payload = {
content: this.content,
}
}
try {
const response = await this.$root.papi.post('detection/convert', payload);
const response = await this.$root.papi.post('detection/convert', this.detect);
if (response && response.data) {
this.convertedRule = response.data.query;
this.showSigmaDialog = true;
Expand Down
Loading