mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-08-28 04:26:35 +00:00
create struct Program and include program in connection details page
This commit is contained in:
parent
d8aae02fb0
commit
10ddbaa38f
7 changed files with 105 additions and 17 deletions
|
|
@ -34,6 +34,7 @@ use crate::translations::translations_2::{
|
|||
use crate::translations::translations_3::{
|
||||
copy_translation, messages_translation, service_translation,
|
||||
};
|
||||
use crate::translations::translations_5::program_translation;
|
||||
use crate::utils::formatted_strings::{get_formatted_timestamp, get_socket_address};
|
||||
use crate::utils::types::icon::Icon;
|
||||
use crate::{Language, Protocol, Sniffer, StyleType};
|
||||
|
|
@ -191,10 +192,15 @@ fn col_info<'a>(
|
|||
));
|
||||
|
||||
if !is_icmp && !is_arp {
|
||||
ret_val = ret_val.push(TextType::highlighted_subtitle_with_desc(
|
||||
service_translation(language),
|
||||
&val.service.to_string(),
|
||||
));
|
||||
ret_val = ret_val
|
||||
.push(TextType::highlighted_subtitle_with_desc(
|
||||
service_translation(language),
|
||||
&val.service.to_string(),
|
||||
))
|
||||
.push(TextType::highlighted_subtitle_with_desc(
|
||||
program_translation(language),
|
||||
&val.program.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
ret_val = ret_val.push(TextType::highlighted_subtitle_with_desc(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::networking::types::icmp_type::{IcmpType, IcmpTypeV4, IcmpTypeV6};
|
|||
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
|
||||
use crate::networking::types::info_traffic::InfoTraffic;
|
||||
use crate::networking::types::ip_blacklist::IpBlacklist;
|
||||
use crate::networking::types::program::Program;
|
||||
use crate::networking::types::service::Service;
|
||||
use crate::networking::types::service_query::ServiceQuery;
|
||||
use crate::networking::types::traffic_direction::TrafficDirection;
|
||||
|
|
@ -331,7 +332,7 @@ pub fn modify_or_insert_in_map(
|
|||
HashMap::new()
|
||||
},
|
||||
is_blacklisted,
|
||||
program: None,
|
||||
program: Program::NotApplicable,
|
||||
});
|
||||
|
||||
(new_info.traffic_direction, new_info.service)
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ use crate::networking::types::arp_type::ArpType;
|
|||
use crate::networking::types::data_info::DataInfo;
|
||||
use crate::networking::types::data_representation::DataRepr;
|
||||
use crate::networking::types::icmp_type::IcmpType;
|
||||
use crate::networking::types::program::Program;
|
||||
use crate::networking::types::traffic_direction::TrafficDirection;
|
||||
use crate::report::types::sort_type::SortType;
|
||||
use crate::utils::types::timestamp::Timestamp;
|
||||
use listeners::Process;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ pub struct InfoAddressPortPair {
|
|||
/// Whether the remote address is blacklisted
|
||||
pub is_blacklisted: bool,
|
||||
/// The program associated to this pair
|
||||
pub program: Option<Process>,
|
||||
pub program: Program,
|
||||
}
|
||||
|
||||
impl InfoAddressPortPair {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::networking::types::data_info_host::DataInfoHost;
|
|||
use crate::networking::types::data_representation::DataRepr;
|
||||
use crate::networking::types::host::Host;
|
||||
use crate::networking::types::info_address_port_pair::InfoAddressPortPair;
|
||||
use crate::networking::types::program::Program;
|
||||
use crate::networking::types::program_lookup::ProgramLookup;
|
||||
use crate::utils::types::timestamp::Timestamp;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -47,10 +48,10 @@ impl InfoTraffic {
|
|||
Entry::Occupied(mut o) => {
|
||||
if let Some(program_lookup) = program_lookup_opt
|
||||
&& let Some(local_port) = local_port
|
||||
&& o.get().program.is_none()
|
||||
&& !o.get().program.is_known()
|
||||
{
|
||||
let program = program_lookup.lookup(local_port, false);
|
||||
o.get_mut().program = program;
|
||||
let proc = program_lookup.lookup(local_port, false);
|
||||
o.get_mut().program = Program::from_proc(proc);
|
||||
}
|
||||
|
||||
o.get_mut().refresh(value);
|
||||
|
|
@ -61,8 +62,8 @@ impl InfoTraffic {
|
|||
if let Some(program_lookup) = program_lookup_opt
|
||||
&& let Some(local_port) = local_port
|
||||
{
|
||||
let program = program_lookup.lookup(local_port, true);
|
||||
new_value.program = program;
|
||||
let proc = program_lookup.lookup(local_port, true);
|
||||
new_value.program = Program::from_proc(proc);
|
||||
}
|
||||
|
||||
v.insert(new_value);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ pub mod ip_blacklist;
|
|||
pub mod ip_collection;
|
||||
pub mod my_device;
|
||||
pub mod my_link_type;
|
||||
pub mod program;
|
||||
pub mod program_lookup;
|
||||
pub mod protocol;
|
||||
pub mod service;
|
||||
|
|
|
|||
82
src/networking/types/program.rs
Normal file
82
src/networking/types/program.rs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
use listeners::Process;
|
||||
|
||||
/// Program / App.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
pub enum Program {
|
||||
/// A known program.
|
||||
Name(String),
|
||||
/// Not identified
|
||||
Unknown,
|
||||
/// Not applicable (ARP and ICMP)
|
||||
#[default]
|
||||
NotApplicable,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn to_string_with_equal_prefix(&self) -> String {
|
||||
match self {
|
||||
Program::Name(_) | Program::NotApplicable => ["=", &self.to_string()].concat(),
|
||||
Program::Unknown => self.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_known(&self) -> bool {
|
||||
matches!(self, Program::Name(_))
|
||||
}
|
||||
|
||||
pub fn from_proc(proc: Option<Process>) -> Self {
|
||||
proc.map_or(Program::Unknown, |proc| Program::Name(proc.name))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Program {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Program::Name(name) => write!(f, "{name}"),
|
||||
Program::Unknown => write!(f, "?"),
|
||||
Program::NotApplicable => write!(f, "-"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_program_display_unknown() {
|
||||
assert_eq!(Program::Unknown.to_string(), "?");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program_display_not_applicable() {
|
||||
assert_eq!(Program::NotApplicable.to_string(), "-");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program_display_known() {
|
||||
assert_eq!(
|
||||
Program::Name("Telegram".to_string()).to_string(),
|
||||
"Telegram"
|
||||
);
|
||||
assert_eq!(
|
||||
Program::Name("Google Chrome Helper".to_string()).to_string(),
|
||||
"Google Chrome Helper"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program_to_string_with_equal_prefix() {
|
||||
assert_eq!(
|
||||
Program::Name("Telegram".to_string()).to_string_with_equal_prefix(),
|
||||
"=Telegram"
|
||||
);
|
||||
assert_eq!(
|
||||
Program::Name("Google Chrome Helper".to_string()).to_string_with_equal_prefix(),
|
||||
"=Google Chrome Helper"
|
||||
);
|
||||
assert_eq!(Program::NotApplicable.to_string_with_equal_prefix(), "=-");
|
||||
// unknown should not have the prefix
|
||||
assert_eq!(Program::Unknown.to_string_with_equal_prefix(), "?");
|
||||
}
|
||||
}
|
||||
|
|
@ -199,10 +199,7 @@ impl FilterInputType {
|
|||
.asn
|
||||
.name
|
||||
.clone(),
|
||||
FilterInputType::Program => value
|
||||
.program
|
||||
.as_ref()
|
||||
.map_or(String::new(), |p| p.name.clone()),
|
||||
FilterInputType::Program => value.program.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +291,7 @@ impl FilterInputType {
|
|||
..search_params.clone()
|
||||
},
|
||||
FilterInputType::Program => SearchParameters {
|
||||
program: new_value,
|
||||
program: new_value.trim().to_string(),
|
||||
..search_params.clone()
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue