Skip to content

Commit

Permalink
add process column to inspect page table
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Feb 14, 2025
1 parent bbaec98 commit cf98f49
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/gui/pages/inspect_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn inspect_page(sniffer: &Sniffer) -> Container<Message, StyleType> {
.align_y(Alignment::Center)
.align_x(Alignment::Center)
.padding(Padding::new(7.0).top(10).bottom(3))
.width(1042)
.width(1042 + 221 - 95)
.class(ContainerType::BorderedRound),
);

Expand Down
13 changes: 7 additions & 6 deletions src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub fn modify_or_insert_in_map(
let now = Local::now();
let mut traffic_direction = TrafficDirection::default();
let mut service = Service::Unknown;
let mut process = "-".to_string();

if !info_traffic_mutex.lock().unwrap().map.contains_key(key) {
// first occurrence of key
Expand Down Expand Up @@ -252,12 +253,11 @@ pub fn modify_or_insert_in_map(
// determine process
if let Some(local_port) = get_local_port(&key, traffic_direction) {
let processes = listeners::get_processes_by_port(local_port);
if let Ok(processes) = processes {
println!("Processes listening on port {local_port}:");
for process in processes {
println!("\t--> {process}");
}
}
process = processes
.iter()
.flatten()
.next()
.map_or("?".to_string(), |p| p.name.to_owned());
}
};

Expand Down Expand Up @@ -287,6 +287,7 @@ pub fn modify_or_insert_in_map(
initial_timestamp: now,
final_timestamp: now,
service,
process,
traffic_direction,
icmp_types: if key.protocol.eq(&Protocol::ICMP) {
HashMap::from([(icmp_type, 1)])
Expand Down
2 changes: 2 additions & 0 deletions src/networking/types/info_address_port_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct InfoAddressPortPair {
pub final_timestamp: DateTime<Local>,
/// Upper layer service carried by the associated address:port pair.
pub service: Service,
/// Process using the local port of this connection.
pub process: String,
/// Determines if the connection is incoming or outgoing
pub traffic_direction: TrafficDirection,
/// Types of the ICMP messages exchanged, with the relative count (this is empty if not ICMP)
Expand Down
13 changes: 10 additions & 3 deletions src/report/types/report_col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum ReportCol {
DstPort,
Proto,
Service,
Process,
Bytes,
Packets,
}
Expand All @@ -37,8 +38,9 @@ impl ReportCol {
ReportCol::DstPort,
ReportCol::Proto,
ReportCol::Service,
ReportCol::Process,
ReportCol::Bytes,
ReportCol::Packets,
// ReportCol::Packets,
];

pub(crate) const FILTER_COLUMNS_WIDTH: f32 = 4.0 * SMALL_COL_WIDTH + 2.0 * LARGE_COL_WIDTH;
Expand All @@ -49,6 +51,7 @@ impl ReportCol {
ReportCol::SrcPort | ReportCol::DstPort => port_translation(language).to_string(),
ReportCol::Proto => protocol_translation(language).to_string(),
ReportCol::Service => service_translation(language).to_string(),
ReportCol::Process => "Process".to_string(),
ReportCol::Bytes => {
let mut str = bytes_translation(language).to_string();
str.remove(0).to_uppercase().to_string() + &str
Expand Down Expand Up @@ -92,14 +95,15 @@ impl ReportCol {
}
ReportCol::Proto => key.protocol.to_string(),
ReportCol::Service => val.service.to_string(),
ReportCol::Process => val.process.clone(),
ReportCol::Bytes => ByteMultiple::formatted_string(val.transmitted_bytes),
ReportCol::Packets => val.transmitted_packets.to_string(),
}
}

pub(crate) fn get_width(&self) -> f32 {
match self {
ReportCol::SrcIp | ReportCol::DstIp => LARGE_COL_WIDTH,
ReportCol::SrcIp | ReportCol::DstIp | ReportCol::Process => LARGE_COL_WIDTH,
_ => SMALL_COL_WIDTH,
}
}
Expand All @@ -113,7 +117,9 @@ impl ReportCol {
1
};
match self {
ReportCol::SrcIp | ReportCol::DstIp => LARGE_COL_MAX_CHARS / reduction_factor,
ReportCol::SrcIp | ReportCol::DstIp | ReportCol::Process => {
LARGE_COL_MAX_CHARS / reduction_factor
}
_ => SMALL_COL_MAX_CHARS / reduction_factor,
}
}
Expand All @@ -126,6 +132,7 @@ impl ReportCol {
ReportCol::DstPort => FilterInputType::PortDst,
ReportCol::Proto => FilterInputType::Proto,
ReportCol::Service => FilterInputType::Service,
ReportCol::Process => FilterInputType::Process,
ReportCol::Bytes | ReportCol::Packets => FilterInputType::Country, // just to not panic...
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/report/types/search_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct SearchParameters {
pub proto: String,
/// Service
pub service: String,
/// Process
pub process: String,
/// Country
pub country: String,
/// Domain
Expand Down Expand Up @@ -103,19 +105,21 @@ pub enum FilterInputType {
PortDst,
Proto,
Service,
Process,
Country,
Domain,
AsName,
}

impl FilterInputType {
pub const ALL: [FilterInputType; 9] = [
pub const ALL: [FilterInputType; 10] = [
Self::AddressSrc,
Self::PortSrc,
Self::AddressDst,
Self::PortDst,
Self::Proto,
Self::Service,
Self::Process,
Self::Country,
Self::Domain,
Self::AsName,
Expand Down Expand Up @@ -151,6 +155,7 @@ impl FilterInputType {
FilterInputType::PortDst => &search_params.port_dst,
FilterInputType::Proto => &search_params.proto,
FilterInputType::Service => &search_params.service,
FilterInputType::Process => &search_params.process,
FilterInputType::Country => &search_params.country,
FilterInputType::Domain => &search_params.domain,
FilterInputType::AsName => &search_params.as_name,
Expand Down Expand Up @@ -182,6 +187,7 @@ impl FilterInputType {
}
FilterInputType::Proto => key.protocol.to_string(),
FilterInputType::Service => value.service.to_string(),
FilterInputType::Process => value.process.clone(),
FilterInputType::Country => r_dns_host.unwrap().1.country.to_string(),
FilterInputType::Domain => r_dns_host.unwrap().0.to_string(),
FilterInputType::AsName => r_dns_host.unwrap().1.asn.name.to_string(),
Expand Down Expand Up @@ -214,6 +220,10 @@ impl FilterInputType {
service: String::new(),
..search_params.clone()
},
FilterInputType::Process => SearchParameters {
process: String::new(),
..search_params.clone()
},
FilterInputType::Domain => SearchParameters {
domain: String::new(),
..search_params.clone()
Expand Down Expand Up @@ -259,6 +269,10 @@ impl FilterInputType {
service: new_value.trim().to_string(),
..search_params.clone()
},
FilterInputType::Process => SearchParameters {
process: new_value,
..search_params.clone()
},
FilterInputType::Domain => SearchParameters {
domain: new_value.trim().to_string(),
..search_params.clone()
Expand Down

0 comments on commit cf98f49

Please sign in to comment.