fixed update_blocklist function
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2023-01-16 00:38:35 +01:00
parent bdedca78e7
commit e71d8f7cd4
2 changed files with 15 additions and 11 deletions

View File

@ -172,25 +172,30 @@ impl Context {
pub async fn update_blocklist(&mut self, ipevent: &IpEvent) -> Option<IpEvent> {
match self.cfg.sets.get(&ipevent.ipdata.src) {
Some(set) => {
if self.blocklist.contains_key(&ipevent.ipdata.ip)
&& self.hostname == ipevent.hostname
&& ipevent.mode == "file".to_string()
{
let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap();
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
.unwrap()
.with_timezone(&chrono::Local);
let blocktime = set.blocktime;
if ipevent.mode == "file".to_string() && self.hostname == ipevent.hostname {
let mut block = self
.blocklist
.entry(ipevent.ipdata.ip.to_string())
.or_insert(BlockIpData {
ipdata: ipevent.ipdata.clone(),
tryfail: 0,
starttime,
blocktime,
});
block.tryfail += 1;
if block.tryfail >= set.tryfail {
return Some(ipevent.clone());
}
} else {
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
.unwrap()
.with_timezone(&chrono::Local);
let blocktime = set.blocktime;
self.blocklist
.entry(ipevent.ipdata.ip.to_string())
.or_insert(BlockIpData {
ipdata: ipevent.ipdata.clone(),
tryfail: 0,
tryfail: set.tryfail,
starttime,
blocktime,
});

View File

@ -100,7 +100,6 @@ pub async fn run() {
// send ip list to ws and zmq sockets
if let Some(ipevent) = filtered_ipevent {
println!("{}",ipevent.ipdata);
if received_ip.msgtype != "init" {
println!("sending {} to ws and zmq", ipevent.ipdata.ip);
let event = IpEvent{