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,28 +23,35 @@ pub fn confirm_action(token: &str) -> Result<(), Error> {
|
||||||
Ok(key) => key,
|
Ok(key) => key,
|
||||||
Err(_) => return Err(Error::DeserializeData),
|
Err(_) => return Err(Error::DeserializeData),
|
||||||
};
|
};
|
||||||
match key.action() {
|
if Utc::now().timestamp() - key.timestamp() > SETTINGS.max_age {
|
||||||
Action::Add => {
|
match fs::remove_file(pending_path) {
|
||||||
let cert = parse_pem(key.data())?;
|
Ok(_) => Err(Error::MissingPending),
|
||||||
let domain = match get_email_from_cert(&cert)?.split('@').last() {
|
Err(_) => Err(Error::Inaccessible),
|
||||||
Some(domain) => domain.to_string(),
|
}
|
||||||
None => return Err(Error::ParseEmail),
|
} else {
|
||||||
};
|
match key.action() {
|
||||||
match sequoia_net::wkd::insert(
|
Action::Add => {
|
||||||
&SETTINGS.folder_structure.root_folder,
|
let cert = parse_pem(key.data())?;
|
||||||
domain,
|
let domain = match get_email_from_cert(&cert)?.split('@').last() {
|
||||||
SETTINGS.variant,
|
Some(domain) => domain.to_string(),
|
||||||
&cert,
|
None => return Err(Error::ParseEmail),
|
||||||
) {
|
};
|
||||||
Ok(_) => (),
|
match sequoia_net::wkd::insert(
|
||||||
Err(_) => return Err(Error::AddingKey),
|
&SETTINGS.folder_structure.root_folder,
|
||||||
}
|
domain,
|
||||||
|
SETTINGS.variant,
|
||||||
|
&cert,
|
||||||
|
) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => return Err(Error::AddingKey),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Action::Delete => delete_key(key.data())?,
|
||||||
|
}
|
||||||
|
match fs::remove_file(&pending_path) {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err(Error::Inaccessible),
|
||||||
}
|
}
|
||||||
Action::Delete => delete_key(key.data())?,
|
|
||||||
}
|
|
||||||
match fs::remove_file(&pending_path) {
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err(Error::Inaccessible),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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