From 3cc515614b8aeaad9779683325981520eee030ae Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 25 Sep 2024 12:41:39 +0200 Subject: [PATCH] blink when attack is detected --- oryx-tui/src/app.rs | 54 ++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/oryx-tui/src/app.rs b/oryx-tui/src/app.rs index 1cd6d54..399ba97 100644 --- a/oryx-tui/src/app.rs +++ b/oryx-tui/src/app.rs @@ -113,6 +113,7 @@ pub struct App { pub packet_index: Option, pub syn_flood_map: Arc>>, pub syn_flood_attck_detected: Arc, + pub alert_flash_count: usize, } impl Default for App { @@ -286,6 +287,7 @@ impl App { packet_index: None, syn_flood_map, syn_flood_attck_detected, + alert_flash_count: 1, } } @@ -938,14 +940,17 @@ impl App { Style::default().bg(Color::Green).fg(Color::White).bold(), ), Span::from(" Stats ").fg(Color::DarkGray), - Span::from({ + { if self.syn_flood_attck_detected.load(Ordering::Relaxed) { - " Alert  " + if self.alert_flash_count % 12 == 0 { + Span::from(" Alert 󰐼 ").fg(Color::White).bg(Color::Red) + } else { + Span::from(" Alert 󰐼 ").fg(Color::Red) + } } else { - " Alert " + Span::from(" Alert ").fg(Color::DarkGray) } - }) - .fg(Color::DarkGray), + }, ]) }) .title_alignment(Alignment::Left) @@ -1055,14 +1060,17 @@ impl App { " Stats ", Style::default().bg(Color::Green).fg(Color::White).bold(), ), - Span::from({ + { if self.syn_flood_attck_detected.load(Ordering::Relaxed) { - " Alert  " + if self.alert_flash_count % 12 == 0 { + Span::from(" Alert 󰐼 ").fg(Color::White).bg(Color::Red) + } else { + Span::from(" Alert 󰐼 ").fg(Color::Red) + } } else { - " Alert " + Span::from(" Alert ").fg(Color::DarkGray) } - }) - .fg(Color::DarkGray), + }, ]) }) .title_alignment(Alignment::Left) @@ -1095,16 +1103,20 @@ impl App { Line::from(vec![ Span::from(" Packet ").fg(Color::DarkGray), Span::from(" Stats ").fg(Color::DarkGray), - Span::styled( - { - if self.syn_flood_attck_detected.load(Ordering::Relaxed) { - " Alert  " + { + if self.syn_flood_attck_detected.load(Ordering::Relaxed) { + if self.alert_flash_count % 12 == 0 { + Span::from(" Alert 󰐼 ").fg(Color::White).bg(Color::Red) } else { - " Alert " + Span::from(" Alert 󰐼 ").bg(Color::Red) } - }, - Style::default().bg(Color::Green).fg(Color::White).bold(), - ), + } else { + Span::styled( + " Alert ", + Style::default().bg(Color::Green).fg(Color::White).bold(), + ) + } + }, ]) }) .title_alignment(Alignment::Left) @@ -1247,6 +1259,12 @@ impl App { pub fn tick(&mut self) { self.notifications.iter_mut().for_each(|n| n.ttl -= 1); self.notifications.retain(|n| n.ttl > 0); + + if self.syn_flood_attck_detected.load(Ordering::Relaxed) { + self.alert_flash_count += 1; + } else { + self.alert_flash_count = 1; + } } pub fn quit(&mut self) {