From 1a1ffede6d6f5b1277de0c5cf01f02a4809b40a2 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 3 Dec 2023 14:48:50 -0800 Subject: [PATCH 1/5] added headscale restart option --- chrono_track/src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index 5bb244b..ed3210e 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -8,7 +8,7 @@ use lettre::{ use log::{debug, error}; use reqwest::blocking::Client; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{path::PathBuf, process::Command}; fn main() -> Result<(), Box> { // --- Loading and setup --- @@ -46,6 +46,7 @@ fn main() -> Result<(), Box> { // --- END Loading and setup --- let mut do_email_summary: bool = false; + let mut do_headscale_reset: bool = false; // --- Get checked and unchecked --- let primary_note = Client::new() @@ -69,6 +70,9 @@ fn main() -> Result<(), Box> { do_email_summary = true; continue; } + if line.starts_with("- [x] Restart Headscale :(") { + do_headscale_reset = true; + } if line.starts_with("- [ ] Send Summary") { continue; } @@ -195,9 +199,14 @@ fn main() -> Result<(), Box> { if do_email_summary { debug!("Send email selected"); - reset_email_checkbox(&cfg); + reset_checkboxes(&cfg); send_email_summary(&cfg, body_content, &args); } + if do_headscale_reset { + debug!("Restarting Headscale"); + reset_checkboxes(&cfg); + reset_headscale(); + } Ok(()) } @@ -243,11 +252,15 @@ struct CliArgs { debug: bool, } +fn reset_headscale() { + let _ = Command::new("systemctl").arg("restart").arg("headscale").output(); +} + // All unwraps are unrecoverable errors // All calls after depend on the success of the one before, and cannot run // without. So it would be too much work to make an error type to handle an error // that would cause a crash anyways -fn reset_email_checkbox(config: &Config) { +fn reset_checkboxes(config: &Config) { let primary_note = Client::new() .get(format!( "https://{}/index.php/apps/notes/api/v1/notes/{}", @@ -268,6 +281,8 @@ fn reset_email_checkbox(config: &Config) { for line in primary_note_lines.iter() { if line.starts_with("- [x] Send Summary") { body_content.push("- [ ] Send Summary"); + } else if line.starts_with("- [x] Restart Headscale :(") { + body_content.push("- [ ] Restart Headscale :(") } else { body_content.push(line); } From 9c5989f414529c40dd3ad6b2ac6f4924c97e615d Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 3 Dec 2023 15:34:30 -0800 Subject: [PATCH 2/5] added debug --- chrono_track/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index ed3210e..4efa47f 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -67,11 +67,14 @@ fn main() -> Result<(), Box> { for line in primary_note_lines.iter() { if line.starts_with("- [x] Send Summary") { + debug!("send summary flag caught"); do_email_summary = true; continue; } if line.starts_with("- [x] Restart Headscale :(") { + debug!("restart headscale flag caught"); do_headscale_reset = true; + continue; } if line.starts_with("- [ ] Send Summary") { continue; From 2861dab7bf0081999db00617a116617a0a1ea2fa Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 3 Dec 2023 15:39:14 -0800 Subject: [PATCH 3/5] testing debug --- chrono_track/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index 4efa47f..05739f9 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -282,6 +282,9 @@ fn reset_checkboxes(config: &Config) { let mut body_content: Vec<&str> = vec![]; for line in primary_note_lines.iter() { + if line.contains("Send Summary") { + debug!("summary line: '{}'", line); + } if line.starts_with("- [x] Send Summary") { body_content.push("- [ ] Send Summary"); } else if line.starts_with("- [x] Restart Headscale :(") { From 218871e060759be746d87be67912dabb0a0485b6 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 3 Dec 2023 15:45:27 -0800 Subject: [PATCH 4/5] logging input --- chrono_track/src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index 05739f9..e7e6448 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -112,6 +112,8 @@ fn main() -> Result<(), Box> { let logging_note_lines: Vec<&str> = logging_note.content.lines().collect(); + debug!("input: {:#?}", logging_note_lines); + for line in logging_note_lines { if line.starts_with("*Last Updated") { continue; @@ -282,9 +284,6 @@ fn reset_checkboxes(config: &Config) { let mut body_content: Vec<&str> = vec![]; for line in primary_note_lines.iter() { - if line.contains("Send Summary") { - debug!("summary line: '{}'", line); - } if line.starts_with("- [x] Send Summary") { body_content.push("- [ ] Send Summary"); } else if line.starts_with("- [x] Restart Headscale :(") { From f67292fd9023fef8499da69a2c85a3e8447306c9 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 3 Dec 2023 15:53:32 -0800 Subject: [PATCH 5/5] updated logging --- chrono_track/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index e7e6448..9eaf2ab 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -62,6 +62,8 @@ fn main() -> Result<(), Box> { let primary_note_lines: Vec<&str> = primary_note.content.lines().collect(); + debug!("input: {:#?}", primary_note_lines); + let mut unchecked: Vec = vec![]; let mut checked: Vec = vec![]; @@ -112,8 +114,6 @@ fn main() -> Result<(), Box> { let logging_note_lines: Vec<&str> = logging_note.content.lines().collect(); - debug!("input: {:#?}", logging_note_lines); - for line in logging_note_lines { if line.starts_with("*Last Updated") { continue;