Skip to content

Commit

Permalink
tjs plus
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Sep 29, 2024
1 parent c94047e commit d48ab33
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 17 deletions.
32 changes: 29 additions & 3 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ use std::{
time::Duration,
};

use crate::filters::{
direction::TrafficDirection, filter::Filter, fuzzy::Fuzzy, start_menu::StartMenuBlock,
update_menu::UpdateFilterMenuBlock,
use crate::{
ebpf::Ebpf,
event::Event,
filters::{
direction::TrafficDirection, filter::Filter, fuzzy::Fuzzy, start_menu::StartMenuBlock,
update_menu::UpdateFilterMenuBlock,
},
};

use crate::help::Help;
Expand Down Expand Up @@ -123,6 +127,28 @@ impl App {
}
}

pub fn load_ingress(&self, sender: &kanal::Sender<Event>) {
{
Ebpf::load_ingress(
self.interface.selected_interface.name.clone(),
sender.clone(),
self.data_channel_sender.clone(),
self.filter.ingress_channel.receiver.clone(),
self.filter.traffic_direction.terminate_ingress.clone(),
);
}
}
pub fn load_egress(&self, sender: &kanal::Sender<Event>) {
{
Ebpf::load_egress(
self.interface.selected_interface.name.clone(),
sender.clone(),
self.data_channel_sender.clone(),
self.filter.egress_channel.receiver.clone(),
self.filter.traffic_direction.terminate_egress.clone(),
);
}
}
pub fn render(&mut self, frame: &mut Frame) {
// Setup
match self.focused_block.clone() {
Expand Down
27 changes: 26 additions & 1 deletion oryx-tui/src/filters/start_menu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::app::{App, FocusedBlock};

use crate::event::Event;
use crate::mode::Mode;
use crate::ScrollableMenuComponent;
use crossterm::event::{KeyCode, KeyEvent};

Expand All @@ -11,6 +13,8 @@ use ratatui::{
};
use tui_big_text::{BigText, PixelSize};

use super::direction::TrafficDirection;

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum StartMenuBlock {
Interface,
Expand Down Expand Up @@ -80,7 +84,12 @@ impl StartMenuBlock {
}
}

pub fn handle_key_events(&mut self, key_event: KeyEvent, app: &mut App) {
pub fn handle_key_events(
&mut self,
key_event: KeyEvent,
app: &mut App,
sender: kanal::Sender<Event>,
) {
match key_event.code {
KeyCode::Tab => self.next(app),
KeyCode::BackTab => self.previous(app),
Expand All @@ -90,7 +99,23 @@ impl StartMenuBlock {
Some(p) => p.select(),
_ => {}
},
KeyCode::Enter => {
app.filter.network.apply();
app.filter.transport.apply();
app.filter.link.apply();
app.filter.traffic_direction.apply();

let traffic_dir = &app.filter.traffic_direction.applied_direction;
if traffic_dir.contains(&TrafficDirection::Ingress) {
app.load_ingress(&sender);
}
if traffic_dir.contains(&TrafficDirection::Egress) {
app.load_egress(&sender);
}

app.start_sniffing = true;
app.focused_block = FocusedBlock::Main(Mode::Packet);
}
_ => {}
}
}
Expand Down
3 changes: 2 additions & 1 deletion oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn handle_key_events(
if !app.is_editing {
match key_event.code {
KeyCode::Char('?') => {
app.previous_focused_block = app.focused_block.clone();
app.focused_block = FocusedBlock::Help;
return Ok(());
}
Expand Down Expand Up @@ -48,7 +49,7 @@ pub fn handle_key_events(
match app.focused_block.clone() {
FocusedBlock::Help => handle_key_events_help(key_event, app),
FocusedBlock::StartMenuBlock(mut start_block) => {
start_block.handle_key_events(key_event, app)
start_block.handle_key_events(key_event, app, sender)
}
FocusedBlock::UpdateFilterMenuBlock(mut update_block) => {
update_block.handle_key_events(key_event, app)
Expand Down
20 changes: 9 additions & 11 deletions oryx-tui/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,29 @@ pub enum Mode {
}

impl Mode {
pub fn next(&mut self) {
*self = match *self {
pub fn next(&self, app: &mut App) {
let x = match self {
Mode::Packet => Mode::Stats,
Mode::Stats => Mode::Alerts,
Mode::Alerts => Mode::Firewall,
Mode::Firewall => Mode::Packet,
}
};
app.focused_block = FocusedBlock::Main(x);
}
pub fn previous(&mut self) {
*self = match *self {
pub fn previous(&self, app: &mut App) {
let x = match self {
Mode::Packet => Mode::Firewall,
Mode::Stats => Mode::Packet,
Mode::Alerts => Mode::Stats,
Mode::Firewall => Mode::Alerts,
};
app.focused_block = FocusedBlock::Main(x);
}

pub fn handle_key_events(&mut self, key_event: KeyEvent, app: &mut App) {
match key_event.code {
KeyCode::Tab => {
self.next();
}
KeyCode::BackTab => {
self.previous();
}
KeyCode::Tab => self.next(app),
KeyCode::BackTab => self.previous(app),

_ => {
match self {
Expand Down
2 changes: 1 addition & 1 deletion oryx-tui/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ratatui::Frame;

use crate::app::{App, FocusedBlock};
use crate::app::App;

pub fn render(app: &mut App, frame: &mut Frame) {
app.render(frame);
Expand Down

0 comments on commit d48ab33

Please sign in to comment.