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