-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::net::IpAddr; | ||
|
||
use ratatui::{ | ||
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect}, | ||
style::{Color, Style, Stylize}, | ||
text::{Line, Span, Text}, | ||
widgets::{Block, BorderType, Borders, Padding}, | ||
Frame, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Firewall { | ||
rules: Vec<FirewallRule>, | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct FirewallRule { | ||
enabled: bool, | ||
ip: Option<IpAddr>, | ||
port: Option<u16>, | ||
} | ||
|
||
impl Firewall { | ||
pub fn new() -> Self { | ||
Self { rules: Vec::new() } | ||
} | ||
|
||
pub fn add_rule(&mut self, rule: FirewallRule) {} | ||
pub fn remove_rule(&mut self, rule: &FirewallRule) {} | ||
pub fn update_rule(&mut self) {} | ||
|
||
pub fn render(&self, frame: &mut Frame, block: Rect) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,7 @@ pub mod alerts { | |
pub mod alert; | ||
pub mod syn_flood; | ||
} | ||
|
||
pub mod firewall; | ||
|
||
pub mod mode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use ratatui::{ | ||
layout::{Alignment, Rect}, | ||
style::{Color, Style, Stylize}, | ||
text::{Line, Span}, | ||
widgets::{Block, BorderType, Borders, Padding}, | ||
Frame, | ||
}; | ||
#[derive(Debug, PartialEq)] | ||
pub enum Mode { | ||
Packet, | ||
Stats, | ||
Alerts, | ||
Firewall, | ||
} | ||
|
||
impl Mode { | ||
pub fn render(&self, frame: &mut Frame, area: Rect, alert_span: Span<'_>) { | ||
let header = match self { | ||
Self::Packet => { | ||
vec![ | ||
Span::styled( | ||
" Packet ", | ||
Style::default().bg(Color::Green).fg(Color::White).bold(), | ||
), | ||
Span::from(" Stats ").fg(Color::DarkGray), | ||
alert_span, | ||
Span::from(" Firewall ").fg(Color::DarkGray), | ||
] | ||
} | ||
|
||
Self::Stats => { | ||
vec![ | ||
Span::from(" Packet ").fg(Color::DarkGray), | ||
Span::styled( | ||
" Stats ", | ||
Style::default().bg(Color::Green).fg(Color::White).bold(), | ||
), | ||
alert_span, | ||
Span::from(" Firewall ").fg(Color::DarkGray), | ||
] | ||
} | ||
|
||
Self::Alerts => { | ||
vec![ | ||
Span::from(" Packet ").fg(Color::DarkGray), | ||
Span::from(" Stats ").fg(Color::DarkGray), | ||
alert_span.bold(), | ||
Span::from(" Firewall ").fg(Color::DarkGray), | ||
] | ||
} | ||
|
||
Self::Firewall => { | ||
vec![ | ||
Span::from(" Packet ").fg(Color::DarkGray), | ||
Span::from(" Stats ").fg(Color::DarkGray), | ||
alert_span, | ||
Span::styled( | ||
" Firewall ", | ||
Style::default().bg(Color::Green).fg(Color::White).bold(), | ||
), | ||
] | ||
} | ||
}; | ||
|
||
frame.render_widget( | ||
Block::default() | ||
.title(Line::from(header)) | ||
.title_alignment(Alignment::Left) | ||
.padding(Padding::top(2)) | ||
.borders(Borders::ALL) | ||
.style(Style::default()) | ||
.border_type(BorderType::default()) | ||
.border_style(Style::default().green()), | ||
area, | ||
); | ||
} | ||
} |