Compare commits
No commits in common. "f0cb50e79742951bfec60b05cbd22bfb22a6e6da" and "ebb6e5ec6d2be681bc59aba0d98e457b822ba201" have entirely different histories.
f0cb50e797
...
ebb6e5ec6d
@ -103,12 +103,12 @@ impl Context {
|
|||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
let req = match resp {
|
let req = match resp {
|
||||||
Ok(o) => o,
|
Ok(re) => re,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
let data: Discovery = match req.json().await {
|
let data: Discovery = match req.json().await {
|
||||||
Ok(o) => o,
|
Ok(res) => res,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
@ -127,8 +127,8 @@ impl Context {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error loading config: {e}, retrying in {CONFIG_RETRY_INTERVAL}s");
|
println!("error loading config: {err}, retrying in {CONFIG_RETRY_INTERVAL}s");
|
||||||
last_in_err = true;
|
last_in_err = true;
|
||||||
sleep_s(CONFIG_RETRY_INTERVAL).await;
|
sleep_s(CONFIG_RETRY_INTERVAL).await;
|
||||||
}
|
}
|
||||||
@ -365,12 +365,12 @@ impl Config {
|
|||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
let req = match resp {
|
let req = match resp {
|
||||||
Ok(o) => o,
|
Ok(re) => re,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
let data: GlobalConfigV2 = match req.json::<GlobalConfigV2>().await {
|
let data: GlobalConfigV2 = match req.json::<GlobalConfigV2>().await {
|
||||||
Ok(o) => o,
|
Ok(res) => res,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
for d in data.sets {
|
for d in data.sets {
|
||||||
@ -400,13 +400,13 @@ impl Config {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
let req = match resp {
|
let req = match resp {
|
||||||
Ok(o) => o,
|
Ok(re) => re,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
let data: Vec<IpData> = match req.json::<Vec<IpData>>().await {
|
let data: Vec<IpData> = match req.json::<Vec<IpData>>().await {
|
||||||
Ok(o) => o,
|
Ok(res) => res,
|
||||||
Err(e) => return Err(e),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
@ -417,8 +417,8 @@ impl Config {
|
|||||||
for trustnet in &self.trustnets {
|
for trustnet in &self.trustnets {
|
||||||
match trustnet.parse() {
|
match trustnet.parse() {
|
||||||
Ok(net) => trustnets.push(net),
|
Ok(net) => trustnets.push(net),
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error parsing {trustnet}, error: {e}");
|
println!("error parsing {trustnet}, error: {err}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
21
src/ipblc.rs
21
src/ipblc.rs
@ -11,7 +11,6 @@ use chrono::prelude::*;
|
|||||||
use chrono::prelude::{DateTime, Local};
|
use chrono::prelude::{DateTime, Local};
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use nix::sys::inotify::{InitFlags, Inotify, InotifyEvent};
|
use nix::sys::inotify::{InitFlags, Inotify, InotifyEvent};
|
||||||
use sd_notify::*;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||||
@ -22,13 +21,6 @@ const BL_CHAN_SIZE: usize = 32;
|
|||||||
const WS_CHAN_SIZE: usize = 64;
|
const WS_CHAN_SIZE: usize = 64;
|
||||||
const LOOP_MAX_WAIT: u64 = 5;
|
const LOOP_MAX_WAIT: u64 = 5;
|
||||||
|
|
||||||
macro_rules! log_with_systemd {
|
|
||||||
($msg:expr) => {
|
|
||||||
println!("{}", $msg);
|
|
||||||
notify(false, &[NotifyState::Status(format!("{}", $msg).as_str())]).unwrap();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run() {
|
pub async fn run() {
|
||||||
let inotify = Inotify::init(InitFlags::empty()).unwrap();
|
let inotify = Inotify::init(InitFlags::empty()).unwrap();
|
||||||
let globalctx = Context::new(&inotify).await;
|
let globalctx = Context::new(&inotify).await;
|
||||||
@ -39,7 +31,7 @@ pub async fn run() {
|
|||||||
let pkgversion = format!("{}@{}", env!("CARGO_PKG_VERSION"), GIT_VERSION);
|
let pkgversion = format!("{}@{}", env!("CARGO_PKG_VERSION"), GIT_VERSION);
|
||||||
|
|
||||||
let mut last_cfg_reload: DateTime<Local> = Local::now().trunc_subsecs(0);
|
let mut last_cfg_reload: DateTime<Local> = Local::now().trunc_subsecs(0);
|
||||||
log_with_systemd!(format!("Launching {}, version {}", PKG_NAME, pkgversion));
|
println!("Launching {}, version {}", PKG_NAME, pkgversion);
|
||||||
fwglobalinit();
|
fwglobalinit();
|
||||||
|
|
||||||
let ctxapi = Arc::clone(&ctxarc);
|
let ctxapi = Arc::clone(&ctxarc);
|
||||||
@ -68,8 +60,6 @@ pub async fn run() {
|
|||||||
compare_files_changes(&ctxclone, &mut blrx, &ipeventclone).await;
|
compare_files_changes(&ctxclone, &mut blrx, &ipeventclone).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
notify(false, &[NotifyState::Ready]).unwrap();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut ret: Vec<String> = Vec::new();
|
let mut ret: Vec<String> = Vec::new();
|
||||||
|
|
||||||
@ -104,7 +94,7 @@ pub async fn run() {
|
|||||||
// send ip list to api and ws sockets
|
// send ip list to api and ws sockets
|
||||||
if let Some(ipevent) = filtered_ipevent {
|
if let Some(ipevent) = filtered_ipevent {
|
||||||
if received_ip.msgtype != "init" {
|
if received_ip.msgtype != "init" {
|
||||||
log_with_systemd!(format!("sending {} to api and ws", ipevent.ipdata.clone().unwrap().ip));
|
println!("sending {} to api and ws", ipevent.ipdata.clone().unwrap().ip);
|
||||||
let ipe = ipevent!("add","ws",gethostname(true),ipevent.ipdata);
|
let ipe = ipevent!("add","ws",gethostname(true),ipevent.ipdata);
|
||||||
send_to_ipbl_api(&server.clone(), &ipe).await;
|
send_to_ipbl_api(&server.clone(), &ipe).await;
|
||||||
if !send_to_ipbl_websocket(&mut wssocketrr, &ipe).await {
|
if !send_to_ipbl_websocket(&mut wssocketrr, &ipe).await {
|
||||||
@ -129,8 +119,7 @@ pub async fn run() {
|
|||||||
|
|
||||||
// log lines
|
// log lines
|
||||||
if ret.len() > 0 {
|
if ret.len() > 0 {
|
||||||
let result = ret.join(", ");
|
println!("{ret}", ret = ret.join(", "));
|
||||||
log_with_systemd!(format!("{result}"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctxclone = Arc::clone(&ctxarc);
|
let ctxclone = Arc::clone(&ctxarc);
|
||||||
@ -189,8 +178,8 @@ async fn handle_fwblock(ctxclone: Arc<RwLock<Context>>, ret: &mut Vec<String>, f
|
|||||||
// apply firewall blocking
|
// apply firewall blocking
|
||||||
match fwblock(&toblock, ret, fwlen) {
|
match fwblock(&toblock, ret, fwlen) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("err: {e}, unable to push firewall rules, use super user")
|
println!("Err: {err}, unable to push firewall rules, use super user")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
|
|||||||
let ctxarc = ctxarc.clone();
|
let ctxarc = ctxarc.clone();
|
||||||
let addr: String = { ctxarc.read().await.cfg.api.parse().unwrap() };
|
let addr: String = { ctxarc.read().await.cfg.api.parse().unwrap() };
|
||||||
let listener = match TcpListener::bind(addr).await {
|
let listener = match TcpListener::bind(addr).await {
|
||||||
Ok(o) => o,
|
Ok(l) => l,
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error: {e}");
|
println!("Error: {err}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -29,13 +29,13 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
|
|||||||
match socket.try_read(&mut buf) {
|
match socket.try_read(&mut buf) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("error: {e}");
|
println!("{e}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("error: {e}");
|
println!("{e}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +49,8 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
|
|||||||
|
|
||||||
match socket.write_all(res.as_bytes()).await {
|
match socket.write_all(res.as_bytes()).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error: {e}");
|
println!("ee {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ use tokio::time::{sleep, Duration};
|
|||||||
|
|
||||||
pub fn read_lines(filename: &String, offset: u64) -> Option<Box<dyn Read>> {
|
pub fn read_lines(filename: &String, offset: u64) -> Option<Box<dyn Read>> {
|
||||||
let mut file = match File::open(filename) {
|
let mut file = match File::open(filename) {
|
||||||
Ok(o) => o,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error: {e}");
|
println!("{err}");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,8 +15,8 @@ pub async fn send_to_ipbl_api(server: &str, ip: &IpEvent) {
|
|||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
println!("error: {e}");
|
println!("{err}");
|
||||||
sleep_s(1).await;
|
sleep_s(1).await;
|
||||||
if try_req == MAX_FAILED_API_RATE {
|
if try_req == MAX_FAILED_API_RATE {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user