forked from mandiant/gocrack-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordTable.vue
More file actions
155 lines (136 loc) · 3.61 KB
/
PasswordTable.vue
File metadata and controls
155 lines (136 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<div>
<div class="alert alert-info" role="alert" v-if="loading">
<span>{{ $t('shared.loading') }}</span>
</div>
<div class="row">
<div class="col col-md-8">
<h3>{{ $t('task_status.cracked_passwords_header') }}</h3>
</div>
<div class="col-6 col-md-4">
<ul class="action-toolbar list-inline">
<li class="list-inline-item"><button type="button" :disabled="!canCSVBeGenerated" v-on:click="exportPasswords" class="btn btn-primary">{{ $t('task_status.download_results') }}</button></li>
</ul>
</div>
</div>
<v-client-table :data="crackedPasswords" :columns="columns" :options="options"></v-client-table>
<PasswordLengthBarGraph></PasswordLengthBarGraph>
</div>
</template>
<style>
table.passwords {
table-layout: fixed;
white-space: nowrap;
}
table.passwords td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script>
import PasswordLengthBarGraph from '@/components/PasswordLengthBarGraph'
import csvHelpers from '@/helpers/generate_csv'
import helpers from '@/helpers'
var defaultCounter = {
get: (target, name) => {
return target.hasOwnProperty(name) ? target[name] : 0
}
}
export default {
components: {
PasswordLengthBarGraph
},
data () {
return {
data: [],
counter: new Proxy({}, defaultCounter),
loading: false,
hasLoaded: false,
columns: ['hash', 'value', 'cracked_at'],
options: {
skin: 'table-bordered table-hover passwords',
sortIcon: {base: 'fa', up: 'fa-sort-asc', down: 'fa-sort-desc'},
orderBy: {
column: 'cracked_at',
ascending: false
}
}
}
},
props: {
taskid: {
type: String,
required: true
},
// This is a hack but because nesting this component in another will most likely have an unexpected parent.
parent: {
required: true
}
},
computed: {
crackedPasswords () {
return this.data
}
},
created () {
this.parent.$on('load_passwords', (taskid) => {
console.log(`Fetching passwords for ${taskid}`)
this.getPasswords()
})
this.parent.$on('download_passwords', (taskid) => {
console.log('Generate Password file', taskid)
if (this.hasLoaded && this.data.length > 0) {
this.exportPasswords()
}
})
},
methods: {
exportPasswords () {
let filename = `cracked_${this.taskid}.csv`
csvHelpers.generateCSV(filename, this.data)
},
generateStats (data) {
let keys = Object.keys(this.counter)
// Clear the stats counter if we're refreshing the stats
if (keys.length > 0) {
for (const prop of keys) {
delete this.counter[prop]
}
}
data.forEach((crackedPassword) => {
this.counter[crackedPassword.value.length]++
})
this.$emit('passwordLengthStatsGenerated', {
labels: Object.keys(this.counter),
datasets: [
{
label: 'This Task',
data: Object.values(this.counter)
}
]
})
},
getPasswords () {
this.loading = true
this.data = []
return this.$gocrack.getPasswords(this.taskid).then((data) => {
this.loading = false
this.hasLoaded = true
this.data = data
this.generateStats(data)
}).catch((error) => {
this.loading = false
let vm = this
helpers.componentToastError(vm, error)
})
},
canCSVBeGenerated () {
if (this.loading || this.data.length === 0) {
return false
}
return true
}
}
}
</script>