1
0

updating logs

This commit is contained in:
midefos 2024-09-22 03:49:35 +02:00
parent 6de6033205
commit 1c414e204e
2 changed files with 6 additions and 7 deletions

View File

@ -1,4 +1,3 @@
use std::path::PathBuf;
use structopt::StructOpt; use structopt::StructOpt;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]

View File

@ -78,11 +78,11 @@ async fn main() {
async fn start_ban_server() -> std::io::Result<()> { async fn start_ban_server() -> std::io::Result<()> {
let seconds_iptables = Duration::from_secs(60); let seconds_iptables = Duration::from_secs(60);
info!("saving IPTables every {} secs", seconds_iptables.as_secs()); info!("Saving IPTables every {} secs", seconds_iptables.as_secs());
spawn(move || loop { spawn(move || loop {
sleep(seconds_iptables); sleep(seconds_iptables);
iptables_save::save_iptables(); iptables_save::save_iptables().expect("Failed to save IPTables");
}); });
let mut child: Child = Command::new("journalctl") let mut child: Child = Command::new("journalctl")
@ -92,11 +92,11 @@ async fn start_ban_server() -> std::io::Result<()> {
.arg("ssh") .arg("ssh")
.arg("-f") .arg("-f")
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn()?; .spawn()
.expect("Failed to start journalctl");
let stdout = child.stdout.as_mut().expect("Failed to capture stdout"); let stdout = child.stdout.as_mut().expect("Failed to capture stdout");
let mut reader = std::io::BufReader::new(stdout); let mut reader = std::io::BufReader::new(stdout);
let iptables = iptables::new(false).unwrap(); let iptables = iptables::new(false).unwrap();
let mut login_attempts: HashMap<String, usize> = HashMap::new(); let mut login_attempts: HashMap<String, usize> = HashMap::new();
@ -117,8 +117,8 @@ async fn start_ban_server() -> std::io::Result<()> {
if let Some(login_attempt) = LoginAttempt::capture(&line) { if let Some(login_attempt) = LoginAttempt::capture(&line) {
info!( info!(
"login attempt from {}@{}:{}", "Login attempt from {} using {} user",
login_attempt.user, login_attempt.ip, login_attempt.port login_attempt.ip, login_attempt.user
); );
match login_attempts.get_mut(&login_attempt.ip) { match login_attempts.get_mut(&login_attempt.ip) {