added headscale restart option
This commit is contained in:
parent
0b5175f90a
commit
1a1ffede6d
1 changed files with 18 additions and 3 deletions
|
@ -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<dyn std::error::Error>> {
|
||||
// --- Loading and setup ---
|
||||
|
@ -46,6 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// --- 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<dyn std::error::Error>> {
|
|||
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<dyn std::error::Error>> {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue