Skip to content

Commit

Permalink
Merge pull request #423 from Security-Onion-Solutions/cogburn/duplica…
Browse files Browse the repository at this point in the history
…tion-fixes

Duplication Fixes, Improvements
  • Loading branch information
coreyogburn authored Apr 10, 2024
2 parents bd41f5b + 0b76812 commit 12dd5a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
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

0 comments on commit 12dd5a3

Please sign in to comment.