Compare commits

..

No commits in common. 'f67292fd9023fef8499da69a2c85a3e8447306c9' and '0b5175f90a9679ba8402a40091c52d5ef0a79f08' have entirely different histories.

@ -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, process::Command}; use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
// --- Loading and setup --- // --- Loading and setup ---
@ -46,7 +46,6 @@ 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()
@ -62,22 +61,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let primary_note_lines: Vec<&str> = primary_note.content.lines().collect(); let primary_note_lines: Vec<&str> = primary_note.content.lines().collect();
debug!("input: {:#?}", primary_note_lines);
let mut unchecked: Vec<String> = vec![]; let mut unchecked: Vec<String> = vec![];
let mut checked: Vec<String> = vec![]; let mut checked: Vec<String> = vec![];
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") {
debug!("send summary flag caught");
do_email_summary = true; do_email_summary = true;
continue; continue;
} }
if line.starts_with("- [x] Restart Headscale :(") {
debug!("restart headscale flag caught");
do_headscale_reset = true;
continue;
}
if line.starts_with("- [ ] Send Summary") { if line.starts_with("- [ ] Send Summary") {
continue; continue;
} }
@ -204,14 +195,9 @@ 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_checkboxes(&cfg); reset_email_checkbox(&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(())
} }
@ -257,15 +243,11 @@ 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_checkboxes(config: &Config) { fn reset_email_checkbox(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/{}",
@ -286,8 +268,6 @@ fn reset_checkboxes(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