mirror of
https://git.verdigado.com/NB-Public/simple-wkd.git
synced 2024-10-30 05:05:52 +01:00
Improve Settings
This commit is contained in:
parent
291e0070c4
commit
de617dbbf2
3 changed files with 33 additions and 22 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use chrono::Utc;
|
||||||
|
|
||||||
use crate::errors::Error;
|
use crate::errors::Error;
|
||||||
use crate::management::{delete_key, Action, Pending};
|
use crate::management::{delete_key, Action, Pending};
|
||||||
use crate::pending_path;
|
use crate::pending_path;
|
||||||
|
@ -21,6 +23,12 @@ pub fn confirm_action(token: &str) -> Result<(), Error> {
|
||||||
Ok(key) => key,
|
Ok(key) => key,
|
||||||
Err(_) => return Err(Error::DeserializeData),
|
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() {
|
match key.action() {
|
||||||
Action::Add => {
|
Action::Add => {
|
||||||
let cert = parse_pem(key.data())?;
|
let cert = parse_pem(key.data())?;
|
||||||
|
@ -44,6 +52,7 @@ pub fn confirm_action(token: &str) -> Result<(), Error> {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err(Error::Inaccessible),
|
Err(_) => Err(Error::Inaccessible),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_confirmation_email(email: &str, action: &Action, token: &str) {
|
pub fn send_confirmation_email(email: &str, action: &Action, token: &str) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct Email {
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
fs::create_dir_all(pending_path!())?;
|
fs::create_dir_all(pending_path!())?;
|
||||||
task::spawn(async {
|
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 {
|
loop {
|
||||||
metronome.tick().await;
|
metronome.tick().await;
|
||||||
clean_stale(SETTINGS.max_age).unwrap();
|
clean_stale(SETTINGS.max_age).unwrap();
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub struct Settings {
|
||||||
#[serde(with = "VariantDef")]
|
#[serde(with = "VariantDef")]
|
||||||
pub variant: Variant,
|
pub variant: Variant,
|
||||||
pub max_age: i64,
|
pub max_age: i64,
|
||||||
|
pub cleanup_interval: u64,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub folder_structure: FolderStructure,
|
pub folder_structure: FolderStructure,
|
||||||
pub smtp_settings: MailSettings,
|
pub smtp_settings: MailSettings,
|
||||||
|
@ -38,6 +39,7 @@ pub enum VariantDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_settings() -> Settings {
|
fn get_settings() -> Settings {
|
||||||
|
println!("Reaing settings...");
|
||||||
let content = fs::read_to_string("wkd.toml").unwrap();
|
let content = fs::read_to_string("wkd.toml").unwrap();
|
||||||
toml::from_str(&content).unwrap()
|
toml::from_str(&content).unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue