Кнопка для начала обработки pcap

This commit is contained in:
serega6531 2020-04-10 20:25:23 +03:00
parent 28169642b4
commit e789d52c4b
4 changed files with 41 additions and 2 deletions

View File

@ -129,6 +129,18 @@
this.$refs.navbar.$refs.patternsDropdown.togglePatternFromWs(parsed.value, false);
break;
}
case 'PCAP_STARTED': {
this.$store.commit('startPcap');
break;
}
case 'PCAP_STOPPED': {
this.$bvToast.toast(`All streams processed`, {
title: 'Notification',
variant: 'success',
autoHideDelay: 5000,
});
break;
}
default: {
console.error('[WS] Event is not implemented!', parsed);
break;

View File

@ -15,6 +15,10 @@
@click.stop.prevent="toggleHexdump">
<i :class="this.$store.state.hexdumpMode ? 'far fa-file-code' : 'fas fa-align-left'"/>
</button>
<button type="button" class="btn btn-sm btn-outline-warning" v-if="!this.$store.state.pcapStarted"
@click.stop.prevent="startPcap">
<i class="fas fa-arrow-circle-down"/>
</button>
<button type="button" class="btn btn-sm btn-outline-info" style="float: right;"
@click.stop.prevent="scrollUp">
<i class="fas fa-angle-double-up"/>
@ -163,6 +167,18 @@
toggleHexdump() {
this.$store.commit('toggleHexdumpMode');
},
startPcap() {
this.$http.post('pcap/start')
.then(() => {
this.$store.commit('startPcap');
}).catch(e => {
this.$bvToast.toast(`Failed to start pcap: ${e}`, {
title: 'Error',
variant: 'danger',
});
console.error('Failed to start pcap', e);
});
},
addStreamFromWs(stream) {
const currentPort = parseInt(this.$route?.params?.servicePort, 10);
if (currentPort && currentPort !== stream.service) return;
@ -191,6 +207,13 @@
},
mounted() {
document.addEventListener('keydown', this.navigationKeysCallback);
this.$http.get('pcap/started')
.then(r => this.$store.state.pcapStarted = r.data)
.catch(e => {
console.error('Failed to get pcap status, defaulting to true:', e);
this.$store.state.pcapStarted = true;
});
},
beforeDestroy() {
document.removeEventListener('keydown', this.navigationKeysCallback);

View File

@ -15,6 +15,7 @@ export default new Vuex.Store({
pageSize: 25,
displayFavoritesOnly: false,
pause: false,
pcapStarted: true,
hexdumpMode: false,
@ -34,6 +35,8 @@ export default new Vuex.Store({
// eslint-disable-next-line no-unused-vars
togglePause: (s, p) => s.pause = !s.pause,
// eslint-disable-next-line no-unused-vars
startPcap: (s, p) => s.pcapStarted = true,
// eslint-disable-next-line no-unused-vars
toggleHexdumpMode: (s, p) => s.hexdumpMode = !s.hexdumpMode,
setServiceModalName: (s, p) => s.serviceModalName = p,
@ -54,6 +57,7 @@ export default new Vuex.Store({
&& mName !== 'setServiceModalName'
&& mName !== 'setServiceModalId'
&& mName !== 'togglePause'
&& mName !== 'startPcap'
&& mName !== 'toggleHexdumpMode'
&& mName !== 'setPatterns'
&& mName !== 'addPattern';

View File

@ -59,7 +59,7 @@
this.reset();
this.$bvModal.hide('editServiceModal');
}).catch(e => {
this.$bvToast.toast(`Не удалось отредактировать сервис: ${e}`, {
this.$bvToast.toast(`Failed to edit service: ${e}`, {
title: 'Сбой',
variant: 'danger',
});
@ -77,7 +77,7 @@
this.reset();
this.$bvModal.hide('editServiceModal');
}).catch(e => {
this.$bvToast.toast(`Не удалось удалить сервис: ${e}`, {
this.$bvToast.toast(`Failed to remove service: ${e}`, {
title: 'Сбой',
variant: 'danger',
});