Skip to content

Commit

Permalink
WebUI: Evidence and Worker download buttons (#1532)
Browse files Browse the repository at this point in the history
* Add button next to evidence name to download

* Update icon add if statement

* Add button to view worker logs

* Update download worker logs
  • Loading branch information
wajihyassine committed Aug 23, 2024
1 parent 97cc48e commit 4831195
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/_build/
/_sources/
/.tox
charts/

# And don't care about the 'egg'.
/turbinia.egg-info
Expand Down
2 changes: 1 addition & 1 deletion turbinia/api/routes/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def get_turbinia_logs(
return JSONResponse(content={'detail': 'Invalid hostname'}, status_code=404)

if 'NODE_NAME' in os.environ:
log_name = f'{hostname}.{os.environ["NODE_NAME"]!s}'
log_name = f'{hostname}.{os.environ["NODE_NAME"]!s}.log'
else:
log_name = f'{hostname}.log'
log_path = Path(config.LOG_DIR, log_name)
Expand Down
60 changes: 59 additions & 1 deletion web/src/components/TaskDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ limitations under the License.
<div v-else>N/A</div>
</v-list-item>
<v-list-item title="Evidence Name:">
<template v-if="taskDetails.evidence_name" v-slot:append>
<v-tooltip location="top" text="Download Evidence output">
<template v-slot:activator="{ props: tooltip }">
<v-btn icon="mdi-magnify-plus" v-bind="tooltip" @click="downloadEvidence(taskDetails.evidence_id)">
</v-btn>
</template>
</v-tooltip>
</template>
<v-snackbar v-model="evidenceSnackbar" color="primary" location="top" height="55" timeout="2000">
Evidence output is downloading...
</v-snackbar>
<v-snackbar v-model="notCopyable" color="red" location="top" height="55" timeout="2000">
Evidence type is not supported for downloading.
</v-snackbar>
<div v-if="taskDetails.evidence_name">
{{ taskDetails.evidence_name }}
</div>
Expand All @@ -123,6 +137,14 @@ limitations under the License.
<div v-else>N/A</div>
</v-list-item>
<v-list-item title="Worker:">
<template v-if="taskDetails.worker_name" v-slot:append>
<v-tooltip location="top" text="Download Worker Logs (defaults to most recent 500 entries)">
<template v-slot:activator="{ props: tooltip }">
<v-btn icon="mdi-database-outline" v-bind="tooltip" @click="downloadWorkerLogs(taskDetails.worker_name)">
</v-btn>
</template>
</v-tooltip>
</template>
<div v-if="taskDetails.worker_name">
{{ taskDetails.worker_name }}
</div>
Expand Down Expand Up @@ -170,7 +192,10 @@ export default {
return {
openGroups: ['ids', 'details'],
markdownReport: '',
currentTaskID: ''
currentTaskID: '',
evidenceSnackbar: false,
notCopyable: false,
openReportDialog: false,
}
},
methods: {
Expand Down Expand Up @@ -205,6 +230,39 @@ export default {
console.error(e)
})
},
downloadEvidence: function (evidence_id) {
ApiClient.downloadEvidence(evidence_id)
.then(({ data }) => {
this.evidenceSnackbar = true
const downloadObj = window.URL.createObjectURL(new Blob([data]))
const link = document.createElement('a')
link.href = downloadObj
link.setAttribute('download', evidence_id)
document.body.appendChild(link)
link.click()
link.remove()
})
.catch((e) => {
console.error(e)
this.evidenceSnackbar = false
this.notCopyable = true
})
},
downloadWorkerLogs: function (worker_name) {
ApiClient.getWorkerLogs(worker_name)
.then(({ data }) => {
const downloadObj = window.URL.createObjectURL(new Blob([data]))
const link = document.createElement('a')
link.href = downloadObj
link.setAttribute('download', worker_name + '.log')
document.body.appendChild(link)
link.click()
link.remove()
})
.catch((e) => {
console.error(e)
})
},
},
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/TaskList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
<div>
<v-list density="compact">
<v-empty-state v-if="taskList.length === 0"
text="No Tasks are available. Try adjusting your filters."
text="No Tasks are available. Try adjusting your filters.">
</v-empty-state>
<v-virtual-scroll :items="taskList" :item-height="40" :height="400" v-else>
<template v-slot:default="{ item }">
Expand Down
10 changes: 10 additions & 0 deletions web/src/utils/RestApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export default {
return RestApiClient.get('/api/result/task/' + task_id, { responseType: 'blob' })
},

// Download Evidence
downloadEvidence(evidence_id) {
return RestApiClient.get('/api/evidence/download/' + evidence_id, { responseType: 'blob' })
},

// Get Worker Logs
getWorkerLogs(worker_name) {
return RestApiClient.get('/api/logs/' + worker_name)
},

// Jobs List
getAvailableJobs() {
return RestApiClient.get('/api/jobs/')
Expand Down

0 comments on commit 4831195

Please sign in to comment.