fixed update_blocklist function
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
bdedca78e7
commit
e71d8f7cd4
@ -172,25 +172,30 @@ impl Context {
|
|||||||
pub async fn update_blocklist(&mut self, ipevent: &IpEvent) -> Option<IpEvent> {
|
pub async fn update_blocklist(&mut self, ipevent: &IpEvent) -> Option<IpEvent> {
|
||||||
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)
|
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
|
||||||
&& self.hostname == ipevent.hostname
|
.unwrap()
|
||||||
&& ipevent.mode == "file".to_string()
|
.with_timezone(&chrono::Local);
|
||||||
{
|
let blocktime = set.blocktime;
|
||||||
let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap();
|
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;
|
block.tryfail += 1;
|
||||||
if block.tryfail >= set.tryfail {
|
if block.tryfail >= set.tryfail {
|
||||||
return Some(ipevent.clone());
|
return Some(ipevent.clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
|
|
||||||
.unwrap()
|
|
||||||
.with_timezone(&chrono::Local);
|
|
||||||
let blocktime = set.blocktime;
|
|
||||||
self.blocklist
|
self.blocklist
|
||||||
.entry(ipevent.ipdata.ip.to_string())
|
.entry(ipevent.ipdata.ip.to_string())
|
||||||
.or_insert(BlockIpData {
|
.or_insert(BlockIpData {
|
||||||
ipdata: ipevent.ipdata.clone(),
|
ipdata: ipevent.ipdata.clone(),
|
||||||
tryfail: 0,
|
tryfail: set.tryfail,
|
||||||
starttime,
|
starttime,
|
||||||
blocktime,
|
blocktime,
|
||||||
});
|
});
|
||||||
|
@ -100,7 +100,6 @@ pub async fn run() {
|
|||||||
|
|
||||||
// send ip list to ws and zmq sockets
|
// send ip list to ws and zmq sockets
|
||||||
if let Some(ipevent) = filtered_ipevent {
|
if let Some(ipevent) = filtered_ipevent {
|
||||||
println!("{}",ipevent.ipdata);
|
|
||||||
if received_ip.msgtype != "init" {
|
if received_ip.msgtype != "init" {
|
||||||
println!("sending {} to ws and zmq", ipevent.ipdata.ip);
|
println!("sending {} to ws and zmq", ipevent.ipdata.ip);
|
||||||
let event = IpEvent{
|
let event = IpEvent{
|
||||||
|
Loading…
Reference in New Issue
Block a user