added hostname field to ipevent
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2023-01-15 23:26:18 +01:00
parent 14192e1aef
commit af38ea1d84
3 changed files with 14 additions and 3 deletions

View File

@ -173,7 +173,7 @@ impl Context {
match self.cfg.sets.get(&ipevent.ipdata.src) { match self.cfg.sets.get(&ipevent.ipdata.src) {
Some(set) => { Some(set) => {
if self.blocklist.contains_key(&ipevent.ipdata.ip) if self.blocklist.contains_key(&ipevent.ipdata.ip)
&& self.hostname == ipevent.ipdata.hostname && self.hostname == ipevent.hostname
&& ipevent.mode == "file".to_string() && ipevent.mode == "file".to_string()
{ {
let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap(); let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap();
@ -529,6 +529,7 @@ mod test {
ctx.update_blocklist(&mut IpEvent { ctx.update_blocklist(&mut IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: String::from("localhost"),
ipdata: IpData { ipdata: IpData {
ip: "1.1.1.1".to_string(), ip: "1.1.1.1".to_string(),
hostname: "test1".to_string(), hostname: "test1".to_string(),
@ -543,6 +544,7 @@ mod test {
ctx.update_blocklist(&mut IpEvent { ctx.update_blocklist(&mut IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: String::from("localhost"),
ipdata: IpData { ipdata: IpData {
ip: "1.1.1.2".to_string(), ip: "1.1.1.2".to_string(),
hostname: "test2".to_string(), hostname: "test2".to_string(),
@ -556,6 +558,7 @@ mod test {
ctx.update_blocklist(&mut IpEvent { ctx.update_blocklist(&mut IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: String::from("localhost"),
ipdata: IpData { ipdata: IpData {
ip: "1.1.1.3".to_string(), ip: "1.1.1.3".to_string(),
hostname: "testgood".to_string(), hostname: "testgood".to_string(),
@ -568,6 +571,7 @@ mod test {
ctx.update_blocklist(&mut IpEvent { ctx.update_blocklist(&mut IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: String::from("localhost"),
ipdata: IpData { ipdata: IpData {
ip: "1.1.1.4".to_string(), ip: "1.1.1.4".to_string(),
hostname: "testgood".to_string(), hostname: "testgood".to_string(),
@ -580,6 +584,7 @@ mod test {
ctx.update_blocklist(&mut IpEvent { ctx.update_blocklist(&mut IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: String::from("localhost"),
ipdata: IpData { ipdata: IpData {
ip: "1.1.1.4".to_string(), ip: "1.1.1.4".to_string(),
hostname: "testgood".to_string(), hostname: "testgood".to_string(),

View File

@ -22,6 +22,7 @@ lazy_static! {
pub struct IpEvent { pub struct IpEvent {
pub msgtype: String, pub msgtype: String,
pub mode: String, pub mode: String,
pub hostname: String,
pub ipdata: IpData, pub ipdata: IpData,
} }

View File

@ -2,7 +2,7 @@ use crate::api::apiserver;
use crate::config::{Context, GIT_VERSION}; use crate::config::{Context, GIT_VERSION};
use crate::fw::{fwblock, fwinit}; use crate::fw::{fwblock, fwinit};
use crate::ip::{filter, IpData, IpEvent}; 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::ws::send_to_ipbl_ws;
use crate::zmqcom::{send_to_ipbl_zmq, zmqinit}; use crate::zmqcom::{send_to_ipbl_zmq, zmqinit};
@ -21,6 +21,7 @@ const ZMQ_CHAN_SIZE: usize = 64;
const API_CHAN_SIZE: usize = 64; const API_CHAN_SIZE: usize = 64;
pub async fn run() { pub async fn run() {
let fqdn = gethostname(true);
let globalctx = Context::new().await; let globalctx = Context::new().await;
let ctxarc = Arc::new(RwLock::new(globalctx)); let ctxarc = Arc::new(RwLock::new(globalctx));
let mut ret: Vec<String> = Vec::new(); let mut ret: Vec<String> = Vec::new();
@ -54,6 +55,7 @@ pub async fn run() {
let ipevent_bootstrap = IpEvent { let ipevent_bootstrap = IpEvent {
msgtype: String::from("bootstrap"), msgtype: String::from("bootstrap"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: fqdn.clone(),
ipdata: IpData { ipdata: IpData {
ip: "".to_string(), ip: "".to_string(),
src: "".to_string(), src: "".to_string(),
@ -85,6 +87,7 @@ pub async fn run() {
let ipe = IpEvent{ let ipe = IpEvent{
msgtype: String::from("init"), msgtype: String::from("init"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: fqdn.clone(),
ipdata: ip_to_send, ipdata: ip_to_send,
}; };
send_to_ipbl_zmq(&zmqreqsocket, &ipe, &mut ret).await; 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); println!("sending {} to ws and zmq", ip.ip);
let event = IpEvent{ let event = IpEvent{
msgtype: String::from("add"), msgtype: String::from("add"),
mode:String::from("zmq"), mode: String::from("zmq"),
hostname: fqdn.clone(),
ipdata: ip, ipdata: ip,
}; };
send_to_ipbl_ws(&ctx, &event, &mut ret).await; send_to_ipbl_ws(&ctx, &event, &mut ret).await;
@ -251,6 +255,7 @@ async fn compare_files_changes(
for ip in iplist { for ip in iplist {
let ipevent = IpEvent { let ipevent = IpEvent {
msgtype: String::from("add"), msgtype: String::from("add"),
hostname: gethostname(true),
mode: String::from("file"), mode: String::from("file"),
ipdata: ip, ipdata: ip,
}; };