diff --git a/src/config.rs b/src/config.rs index 3fae15b..794ed8b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -173,7 +173,7 @@ impl Context { match self.cfg.sets.get(&ipevent.ipdata.src) { Some(set) => { if self.blocklist.contains_key(&ipevent.ipdata.ip) - && self.hostname == ipevent.ipdata.hostname + && self.hostname == ipevent.hostname && ipevent.mode == "file".to_string() { let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap(); @@ -529,6 +529,7 @@ mod test { ctx.update_blocklist(&mut IpEvent { msgtype: String::from("add"), mode: String::from("zmq"), + hostname: String::from("localhost"), ipdata: IpData { ip: "1.1.1.1".to_string(), hostname: "test1".to_string(), @@ -543,6 +544,7 @@ mod test { ctx.update_blocklist(&mut IpEvent { msgtype: String::from("add"), mode: String::from("zmq"), + hostname: String::from("localhost"), ipdata: IpData { ip: "1.1.1.2".to_string(), hostname: "test2".to_string(), @@ -556,6 +558,7 @@ mod test { ctx.update_blocklist(&mut IpEvent { msgtype: String::from("add"), mode: String::from("zmq"), + hostname: String::from("localhost"), ipdata: IpData { ip: "1.1.1.3".to_string(), hostname: "testgood".to_string(), @@ -568,6 +571,7 @@ mod test { ctx.update_blocklist(&mut IpEvent { msgtype: String::from("add"), mode: String::from("zmq"), + hostname: String::from("localhost"), ipdata: IpData { ip: "1.1.1.4".to_string(), hostname: "testgood".to_string(), @@ -580,6 +584,7 @@ mod test { ctx.update_blocklist(&mut IpEvent { msgtype: String::from("add"), mode: String::from("zmq"), + hostname: String::from("localhost"), ipdata: IpData { ip: "1.1.1.4".to_string(), hostname: "testgood".to_string(), diff --git a/src/ip.rs b/src/ip.rs index caeb47f..6d8b59c 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -22,6 +22,7 @@ lazy_static! { pub struct IpEvent { pub msgtype: String, pub mode: String, + pub hostname: String, pub ipdata: IpData, } diff --git a/src/ipblc.rs b/src/ipblc.rs index 112d16c..1d98576 100644 --- a/src/ipblc.rs +++ b/src/ipblc.rs @@ -2,7 +2,7 @@ use crate::api::apiserver; use crate::config::{Context, GIT_VERSION}; use crate::fw::{fwblock, fwinit}; use crate::ip::{filter, IpData, IpEvent}; -use crate::utils::{read_lines, sleep_ms}; +use crate::utils::{gethostname, read_lines, sleep_ms}; use crate::ws::send_to_ipbl_ws; use crate::zmqcom::{send_to_ipbl_zmq, zmqinit}; @@ -21,6 +21,7 @@ const ZMQ_CHAN_SIZE: usize = 64; const API_CHAN_SIZE: usize = 64; pub async fn run() { + let fqdn = gethostname(true); let globalctx = Context::new().await; let ctxarc = Arc::new(RwLock::new(globalctx)); let mut ret: Vec = Vec::new(); @@ -54,6 +55,7 @@ pub async fn run() { let ipevent_bootstrap = IpEvent { msgtype: String::from("bootstrap"), mode: String::from("zmq"), + hostname: fqdn.clone(), ipdata: IpData { ip: "".to_string(), src: "".to_string(), @@ -85,6 +87,7 @@ pub async fn run() { let ipe = IpEvent{ msgtype: String::from("init"), mode: String::from("zmq"), + hostname: fqdn.clone(), ipdata: ip_to_send, }; send_to_ipbl_zmq(&zmqreqsocket, &ipe, &mut ret).await; @@ -102,7 +105,8 @@ pub async fn run() { println!("sending {} to ws and zmq", ip.ip); let event = IpEvent{ msgtype: String::from("add"), - mode:String::from("zmq"), + mode: String::from("zmq"), + hostname: fqdn.clone(), ipdata: ip, }; send_to_ipbl_ws(&ctx, &event, &mut ret).await; @@ -251,6 +255,7 @@ async fn compare_files_changes( for ip in iplist { let ipevent = IpEvent { msgtype: String::from("add"), + hostname: gethostname(true), mode: String::from("file"), ipdata: ip, };