added headscale restart option

main
Nickiel12 12 months ago
parent 0b5175f90a
commit 1a1ffede6d

@ -8,7 +8,7 @@ use lettre::{
use log::{debug, error}; use log::{debug, error};
use reqwest::blocking::Client; use reqwest::blocking::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::{path::PathBuf, process::Command};
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
// --- Loading and setup --- // --- Loading and setup ---
@ -46,6 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// --- END Loading and setup --- // --- END Loading and setup ---
let mut do_email_summary: bool = false; let mut do_email_summary: bool = false;
let mut do_headscale_reset: bool = false;
// --- Get checked and unchecked --- // --- Get checked and unchecked ---
let primary_note = Client::new() let primary_note = Client::new()
@ -69,6 +70,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
do_email_summary = true; do_email_summary = true;
continue; continue;
} }
if line.starts_with("- [x] Restart Headscale :(") {
do_headscale_reset = true;
}
if line.starts_with("- [ ] Send Summary") { if line.starts_with("- [ ] Send Summary") {
continue; continue;
} }
@ -195,9 +199,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if do_email_summary { if do_email_summary {
debug!("Send email selected"); debug!("Send email selected");
reset_email_checkbox(&cfg); reset_checkboxes(&cfg);
send_email_summary(&cfg, body_content, &args); send_email_summary(&cfg, body_content, &args);
} }
if do_headscale_reset {
debug!("Restarting Headscale");
reset_checkboxes(&cfg);
reset_headscale();
}
Ok(()) Ok(())
} }
@ -243,11 +252,15 @@ struct CliArgs {
debug: bool, debug: bool,
} }
fn reset_headscale() {
let _ = Command::new("systemctl").arg("restart").arg("headscale").output();
}
// All unwraps are unrecoverable errors // All unwraps are unrecoverable errors
// All calls after depend on the success of the one before, and cannot run // 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 // without. So it would be too much work to make an error type to handle an error
// that would cause a crash anyways // that would cause a crash anyways
fn reset_email_checkbox(config: &Config) { fn reset_checkboxes(config: &Config) {
let primary_note = Client::new() let primary_note = Client::new()
.get(format!( .get(format!(
"https://{}/index.php/apps/notes/api/v1/notes/{}", "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() { for line in primary_note_lines.iter() {
if line.starts_with("- [x] Send Summary") { if line.starts_with("- [x] Send Summary") {
body_content.push("- [ ] Send Summary"); body_content.push("- [ ] Send Summary");
} else if line.starts_with("- [x] Restart Headscale :(") {
body_content.push("- [ ] Restart Headscale :(")
} else { } else {
body_content.push(line); body_content.push(line);
} }

Loading…
Cancel
Save