0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 03:05:51 +01:00

Improve Settings

This commit is contained in:
Delta1925 2023-04-14 01:05:27 +02:00
parent 291e0070c4
commit de617dbbf2
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25
3 changed files with 33 additions and 22 deletions

View file

@ -1,3 +1,5 @@
use chrono::Utc;
use crate::errors::Error;
use crate::management::{delete_key, Action, Pending};
use crate::pending_path;
@ -21,6 +23,12 @@ pub fn confirm_action(token: &str) -> Result<(), Error> {
Ok(key) => key,
Err(_) => return Err(Error::DeserializeData),
};
if Utc::now().timestamp() - key.timestamp() > SETTINGS.max_age {
match fs::remove_file(pending_path) {
Ok(_) => Err(Error::MissingPending),
Err(_) => Err(Error::Inaccessible),
}
} else {
match key.action() {
Action::Add => {
let cert = parse_pem(key.data())?;
@ -45,6 +53,7 @@ pub fn confirm_action(token: &str) -> Result<(), Error> {
Err(_) => Err(Error::Inaccessible),
}
}
}
pub fn send_confirmation_email(email: &str, action: &Action, token: &str) {
println!("Email sent to {email}");

View file

@ -36,7 +36,7 @@ struct Email {
async fn main() -> std::io::Result<()> {
fs::create_dir_all(pending_path!())?;
task::spawn(async {
let mut metronome = time::interval(time::Duration::from_secs(60 * 60 * 3));
let mut metronome = time::interval(time::Duration::from_secs(SETTINGS.cleanup_interval));
loop {
metronome.tick().await;
clean_stale(SETTINGS.max_age).unwrap();

View file

@ -9,6 +9,7 @@ pub struct Settings {
#[serde(with = "VariantDef")]
pub variant: Variant,
pub max_age: i64,
pub cleanup_interval: u64,
pub port: u16,
pub folder_structure: FolderStructure,
pub smtp_settings: MailSettings,
@ -38,6 +39,7 @@ pub enum VariantDef {
}
fn get_settings() -> Settings {
println!("Reaing settings...");
let content = fs::read_to_string("wkd.toml").unwrap();
toml::from_str(&content).unwrap()
}