for testing
This commit is contained in:
parent
b2eac5bfe0
commit
c2eff44009
@ -167,32 +167,42 @@ impl Context {
|
||||
res
|
||||
}
|
||||
|
||||
pub async fn update_blocklist(&mut self, ipdata: &IpData) -> IpData {
|
||||
pub async fn update_blocklist(&mut self, ipdata: &IpData) -> Option<IpData> {
|
||||
if self.blocklist.contains_key(&ipdata.ip) {
|
||||
let mut a = self.blocklist.get_mut(&ipdata.ip).unwrap();
|
||||
a.tryfail += 1;
|
||||
return a.ipdata.clone();
|
||||
let mut block = self.blocklist.get_mut(&ipdata.ip).unwrap();
|
||||
block.tryfail += 1;
|
||||
let set = self.cfg.sets.get(&ipdata.src.to_string()).unwrap();
|
||||
if block.tryfail >= set.tryfail {
|
||||
return Some(block.ipdata.clone());
|
||||
}
|
||||
return None;
|
||||
} else {
|
||||
let mut tryfail = 0;
|
||||
if ipdata.mode == "zmq".to_string() {
|
||||
tryfail = 100;
|
||||
}
|
||||
let mut send = false;
|
||||
let starttime: DateTime<FixedOffset> =
|
||||
DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap();
|
||||
match self.cfg.sets.get(&ipdata.src) {
|
||||
Some(set) => {
|
||||
self.blocklist
|
||||
.entry(ipdata.ip.to_string())
|
||||
.or_insert(BlockIpData {
|
||||
if ipdata.mode == "zmq".to_string() {
|
||||
tryfail = 100;
|
||||
send = true;
|
||||
}
|
||||
self.blocklist.insert(
|
||||
ipdata.ip.to_string(),
|
||||
BlockIpData {
|
||||
ipdata: ipdata.clone(),
|
||||
tryfail,
|
||||
starttime,
|
||||
blocktime: set.blocktime,
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
return ipdata.clone();
|
||||
match send {
|
||||
true => return Some(ipdata.clone()),
|
||||
false => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ pub async fn process(ctx: &Arc<Mutex<Context>>) {
|
||||
let begin: DateTime<Local> = Local::now().trunc_subsecs(0);
|
||||
|
||||
// wait for logs parse and zmq channel receive
|
||||
let mut received_ip = ipdatarx.recv().await.unwrap();
|
||||
let received_ip = ipdatarx.recv().await.unwrap();
|
||||
|
||||
// lock the context mutex
|
||||
let ctxarc = Arc::clone(&ctx);
|
||||
@ -75,13 +75,13 @@ pub async fn process(ctx: &Arc<Mutex<Context>>) {
|
||||
}
|
||||
|
||||
// refresh context blocklist
|
||||
ctx.update_blocklist(&received_ip).await;
|
||||
let filtered_ip = ctx.update_blocklist(&received_ip).await;
|
||||
ctx.gc_blocklist().await;
|
||||
|
||||
// send ip list to ws and zmq sockets
|
||||
if received_ip.hostname == ctx.hostname && received_ip.mode != "zmq" {
|
||||
send_to_ipbl_ws(&ctx, &received_ip, &mut ret).await;
|
||||
send_to_ipbl_zmq(&reqsocket, &mut received_ip).await;
|
||||
if let Some(ip) = filtered_ip {
|
||||
send_to_ipbl_ws(&ctx, &ip, &mut ret).await;
|
||||
send_to_ipbl_zmq(&reqsocket, &ip).await;
|
||||
}
|
||||
|
||||
// apply firewall blocking
|
||||
|
@ -23,7 +23,7 @@ impl std::fmt::Debug for FileEvent {
|
||||
}
|
||||
}
|
||||
|
||||
async fn send_to_ipbl_zmq(reqsocket: &zmq::Socket, ip: &mut IpData) {
|
||||
async fn send_to_ipbl_zmq(reqsocket: &zmq::Socket, ip: &IpData) {
|
||||
let msg = format!("{value}", value = serde_json::to_string(&ip).unwrap());
|
||||
match reqsocket.send(&msg, 0) {
|
||||
Ok(_) => {}
|
||||
|
Loading…
Reference in New Issue
Block a user