2020-05-03 17:24:51 +02:00
|
|
|
#![forbid(unsafe_code)]
|
2020-07-14 23:44:01 +02:00
|
|
|
#![cfg_attr(feature = "unstable", feature(ip))]
|
2021-01-19 17:55:21 +01:00
|
|
|
#![recursion_limit = "512"]
|
2018-10-10 20:40:39 +02:00
|
|
|
|
2020-06-04 01:21:30 +02:00
|
|
|
extern crate openssl;
|
2018-12-30 23:34:31 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
#[macro_use]
|
2021-01-31 20:07:42 +01:00
|
|
|
extern crate serde;
|
2018-12-30 23:34:31 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel_migrations;
|
2020-03-16 17:53:22 +01:00
|
|
|
|
2021-04-06 22:55:28 +02:00
|
|
|
use job_scheduler::{Job, JobScheduler};
|
2018-12-30 23:34:31 +01:00
|
|
|
use std::{
|
2019-12-06 22:19:07 +01:00
|
|
|
fs::create_dir_all,
|
2020-06-15 23:40:39 +02:00
|
|
|
panic,
|
2018-12-30 23:34:31 +01:00
|
|
|
path::Path,
|
|
|
|
process::{exit, Command},
|
2019-12-06 22:19:07 +01:00
|
|
|
str::FromStr,
|
2020-06-15 23:40:39 +02:00
|
|
|
thread,
|
2021-04-03 05:16:49 +02:00
|
|
|
time::Duration,
|
2018-12-30 23:34:31 +01:00
|
|
|
};
|
2018-02-10 01:00:55 +01:00
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
#[macro_use]
|
|
|
|
mod error;
|
2018-02-10 01:00:55 +01:00
|
|
|
mod api;
|
|
|
|
mod auth;
|
2019-01-25 18:23:51 +01:00
|
|
|
mod config;
|
2018-12-30 23:34:31 +01:00
|
|
|
mod crypto;
|
2020-08-18 17:15:44 +02:00
|
|
|
#[macro_use]
|
2018-12-30 23:34:31 +01:00
|
|
|
mod db;
|
2018-08-15 08:32:19 +02:00
|
|
|
mod mail;
|
2018-12-30 23:34:31 +01:00
|
|
|
mod util;
|
2018-02-10 01:00:55 +01:00
|
|
|
|
2019-01-25 18:23:51 +01:00
|
|
|
pub use config::CONFIG;
|
2019-02-14 02:03:37 +01:00
|
|
|
pub use error::{Error, MapResult};
|
2021-02-27 04:40:12 +01:00
|
|
|
pub use util::is_running_in_docker;
|
2019-01-25 18:23:51 +01:00
|
|
|
|
2018-02-10 01:00:55 +01:00
|
|
|
fn main() {
|
2020-03-02 20:57:06 +01:00
|
|
|
parse_args();
|
2019-02-20 20:59:37 +01:00
|
|
|
launch_info();
|
|
|
|
|
2019-12-06 22:19:07 +01:00
|
|
|
use log::LevelFilter as LF;
|
|
|
|
let level = LF::from_str(&CONFIG.log_level()).expect("Valid log level");
|
|
|
|
init_logging(level).ok();
|
|
|
|
|
2021-03-27 15:03:07 +01:00
|
|
|
let extra_debug = matches!(level, LF::Trace | LF::Debug);
|
2018-12-06 20:35:25 +01:00
|
|
|
|
2021-02-27 04:40:12 +01:00
|
|
|
check_data_folder();
|
2018-05-12 22:55:18 +02:00
|
|
|
check_rsa_keys();
|
2018-09-13 20:59:51 +02:00
|
|
|
check_web_vault();
|
2018-02-10 01:00:55 +01:00
|
|
|
|
2019-11-06 20:21:47 +01:00
|
|
|
create_icon_cache_folder();
|
|
|
|
|
2021-04-03 05:16:49 +02:00
|
|
|
let pool = create_db_pool();
|
|
|
|
schedule_jobs(pool.clone());
|
|
|
|
launch_rocket(pool, extra_debug); // Blocks until program termination.
|
2018-02-10 01:00:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 20:10:40 +01:00
|
|
|
const HELP: &str = "\
|
2021-04-27 23:18:32 +02:00
|
|
|
Alternative implementation of the Bitwarden server API written in Rust
|
2021-03-27 15:03:07 +01:00
|
|
|
|
2021-02-07 20:10:40 +01:00
|
|
|
USAGE:
|
2021-04-27 23:18:32 +02:00
|
|
|
vaultwarden
|
2021-03-27 15:03:07 +01:00
|
|
|
|
2021-02-07 20:10:40 +01:00
|
|
|
FLAGS:
|
|
|
|
-h, --help Prints help information
|
|
|
|
-v, --version Prints the app version
|
|
|
|
";
|
|
|
|
|
2020-03-02 20:57:06 +01:00
|
|
|
fn parse_args() {
|
2021-02-07 20:10:40 +01:00
|
|
|
const NO_VERSION: &str = "(Version info from Git not present)";
|
|
|
|
let mut pargs = pico_args::Arguments::from_env();
|
|
|
|
|
|
|
|
if pargs.contains(["-h", "--help"]) {
|
2021-04-27 23:18:32 +02:00
|
|
|
println!("vaultwarden {}", option_env!("BWRS_VERSION").unwrap_or(NO_VERSION));
|
2021-02-07 20:10:40 +01:00
|
|
|
print!("{}", HELP);
|
|
|
|
exit(0);
|
|
|
|
} else if pargs.contains(["-v", "--version"]) {
|
2021-04-27 23:18:32 +02:00
|
|
|
println!("vaultwarden {}", option_env!("BWRS_VERSION").unwrap_or(NO_VERSION));
|
2020-03-02 20:57:06 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-20 20:59:37 +01:00
|
|
|
fn launch_info() {
|
|
|
|
println!("/--------------------------------------------------------------------\\");
|
2021-04-27 23:18:32 +02:00
|
|
|
println!("| Starting Vaultwarden |");
|
2019-02-20 20:59:37 +01:00
|
|
|
|
2020-03-22 16:13:34 +01:00
|
|
|
if let Some(version) = option_env!("BWRS_VERSION") {
|
2019-02-20 20:59:37 +01:00
|
|
|
println!("|{:^68}|", format!("Version {}", version));
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("|--------------------------------------------------------------------|");
|
|
|
|
println!("| This is an *unofficial* Bitwarden implementation, DO NOT use the |");
|
|
|
|
println!("| official channels to report bugs/features, regardless of client. |");
|
2020-05-13 21:29:47 +02:00
|
|
|
println!("| Send usage/configuration questions or feature requests to: |");
|
2021-04-30 22:40:12 +02:00
|
|
|
println!("| https://vaultwarden.discourse.group/ |");
|
2020-05-13 21:29:47 +02:00
|
|
|
println!("| Report suspected bugs/issues in the software itself at: |");
|
2021-04-27 23:18:32 +02:00
|
|
|
println!("| https://github.com/dani-garcia/vaultwarden/issues/new |");
|
2019-02-20 20:59:37 +01:00
|
|
|
println!("\\--------------------------------------------------------------------/\n");
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:19:07 +01:00
|
|
|
fn init_logging(level: log::LevelFilter) -> Result<(), fern::InitError> {
|
2018-12-06 20:35:25 +01:00
|
|
|
let mut logger = fern::Dispatch::new()
|
2019-12-06 22:19:07 +01:00
|
|
|
.level(level)
|
|
|
|
// Hide unknown certificate errors if using self-signed
|
|
|
|
.level_for("rustls::session", log::LevelFilter::Off)
|
|
|
|
// Hide failed to close stream messages
|
|
|
|
.level_for("hyper::server", log::LevelFilter::Warn)
|
|
|
|
// Silence rocket logs
|
|
|
|
.level_for("_", log::LevelFilter::Off)
|
|
|
|
.level_for("launch", log::LevelFilter::Off)
|
|
|
|
.level_for("launch_", log::LevelFilter::Off)
|
|
|
|
.level_for("rocket::rocket", log::LevelFilter::Off)
|
|
|
|
.level_for("rocket::fairing", log::LevelFilter::Off)
|
2020-12-08 17:33:15 +01:00
|
|
|
// Never show html5ever and hyper::proto logs, too noisy
|
|
|
|
.level_for("html5ever", log::LevelFilter::Off)
|
|
|
|
.level_for("hyper::proto", log::LevelFilter::Off)
|
2021-05-16 15:29:13 +02:00
|
|
|
.level_for("hyper::client", log::LevelFilter::Off)
|
|
|
|
// Prevent cookie_store logs
|
|
|
|
.level_for("cookie_store", log::LevelFilter::Off)
|
2019-12-06 22:19:07 +01:00
|
|
|
.chain(std::io::stdout());
|
|
|
|
|
2020-11-18 12:07:08 +01:00
|
|
|
// Enable smtp debug logging only specifically for smtp when need.
|
|
|
|
// This can contain sensitive information we do not want in the default debug/trace logging.
|
|
|
|
if CONFIG.smtp_debug() {
|
2021-03-31 22:18:35 +02:00
|
|
|
println!(
|
|
|
|
"[WARNING] SMTP Debugging is enabled (SMTP_DEBUG=true). Sensitive information could be disclosed via logs!"
|
|
|
|
);
|
2020-11-18 12:07:08 +01:00
|
|
|
println!("[WARNING] Only enable SMTP_DEBUG during troubleshooting!\n");
|
|
|
|
logger = logger.level_for("lettre::transport::smtp", log::LevelFilter::Debug)
|
|
|
|
} else {
|
|
|
|
logger = logger.level_for("lettre::transport::smtp", log::LevelFilter::Off)
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:19:07 +01:00
|
|
|
if CONFIG.extended_logging() {
|
|
|
|
logger = logger.format(|out, message, record| {
|
2018-12-30 23:34:31 +01:00
|
|
|
out.finish(format_args!(
|
2020-07-23 06:50:49 +02:00
|
|
|
"[{}][{}][{}] {}",
|
|
|
|
chrono::Local::now().format(&CONFIG.log_timestamp_format()),
|
2018-12-30 23:34:31 +01:00
|
|
|
record.target(),
|
|
|
|
record.level(),
|
|
|
|
message
|
|
|
|
))
|
2019-12-06 22:19:07 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
logger = logger.format(|out, message, _| out.finish(format_args!("{}", message)));
|
|
|
|
}
|
2018-12-06 20:35:25 +01:00
|
|
|
|
2019-01-25 18:23:51 +01:00
|
|
|
if let Some(log_file) = CONFIG.log_file() {
|
2018-12-06 20:35:25 +01:00
|
|
|
logger = logger.chain(fern::log_file(log_file)?);
|
|
|
|
}
|
|
|
|
|
2019-04-26 22:08:26 +02:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
if cfg!(feature = "enable_syslog") || CONFIG.use_syslog() {
|
2019-03-29 20:27:20 +01:00
|
|
|
logger = chain_syslog(logger);
|
|
|
|
}
|
|
|
|
}
|
2018-12-06 20:35:25 +01:00
|
|
|
|
|
|
|
logger.apply()?;
|
|
|
|
|
2020-02-25 14:10:52 +01:00
|
|
|
// Catch panics and log them instead of default output to StdErr
|
|
|
|
panic::set_hook(Box::new(|info| {
|
2020-03-16 17:53:22 +01:00
|
|
|
let thread = thread::current();
|
|
|
|
let thread = thread.name().unwrap_or("unnamed");
|
|
|
|
|
|
|
|
let msg = match info.payload().downcast_ref::<&'static str>() {
|
|
|
|
Some(s) => *s,
|
|
|
|
None => match info.payload().downcast_ref::<String>() {
|
|
|
|
Some(s) => &**s,
|
|
|
|
None => "Box<Any>",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-08-12 18:45:26 +02:00
|
|
|
let backtrace = backtrace::Backtrace::new();
|
|
|
|
|
2020-03-16 17:53:22 +01:00
|
|
|
match info.location() {
|
|
|
|
Some(location) => {
|
|
|
|
error!(
|
2020-08-12 18:45:26 +02:00
|
|
|
target: "panic", "thread '{}' panicked at '{}': {}:{}\n{:?}",
|
2020-03-16 17:53:22 +01:00
|
|
|
thread,
|
|
|
|
msg,
|
|
|
|
location.file(),
|
|
|
|
location.line(),
|
2020-08-12 18:45:26 +02:00
|
|
|
backtrace
|
2020-03-16 17:53:22 +01:00
|
|
|
);
|
|
|
|
}
|
2020-06-15 23:40:39 +02:00
|
|
|
None => error!(
|
|
|
|
target: "panic",
|
2020-08-12 18:45:26 +02:00
|
|
|
"thread '{}' panicked at '{}'\n{:?}",
|
2020-06-15 23:40:39 +02:00
|
|
|
thread,
|
|
|
|
msg,
|
2020-08-12 18:45:26 +02:00
|
|
|
backtrace
|
2020-06-15 23:40:39 +02:00
|
|
|
),
|
2020-03-16 17:53:22 +01:00
|
|
|
}
|
2020-02-25 14:10:52 +01:00
|
|
|
}));
|
|
|
|
|
2018-12-06 20:35:25 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-03-29 20:27:20 +01:00
|
|
|
#[cfg(not(windows))]
|
2018-12-06 20:35:25 +01:00
|
|
|
fn chain_syslog(logger: fern::Dispatch) -> fern::Dispatch {
|
|
|
|
let syslog_fmt = syslog::Formatter3164 {
|
|
|
|
facility: syslog::Facility::LOG_USER,
|
|
|
|
hostname: None,
|
2021-04-27 23:18:32 +02:00
|
|
|
process: "vaultwarden".into(),
|
2018-12-06 20:35:25 +01:00
|
|
|
pid: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
match syslog::unix(syslog_fmt) {
|
|
|
|
Ok(sl) => logger.chain(sl),
|
|
|
|
Err(e) => {
|
|
|
|
error!("Unable to connect to syslog: {:?}", e);
|
|
|
|
logger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 04:40:12 +01:00
|
|
|
fn create_dir(path: &str, description: &str) {
|
|
|
|
// Try to create the specified dir, if it doesn't already exist.
|
|
|
|
let err_msg = format!("Error creating {} directory '{}'", description, path);
|
|
|
|
create_dir_all(path).expect(&err_msg);
|
|
|
|
}
|
|
|
|
|
2019-11-06 20:21:47 +01:00
|
|
|
fn create_icon_cache_folder() {
|
2021-02-27 04:40:12 +01:00
|
|
|
create_dir(&CONFIG.icon_cache_folder(), "icon cache");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_data_folder() {
|
|
|
|
let data_folder = &CONFIG.data_folder();
|
|
|
|
let path = Path::new(data_folder);
|
|
|
|
if !path.exists() {
|
|
|
|
error!("Data folder '{}' doesn't exist.", data_folder);
|
|
|
|
if is_running_in_docker() {
|
|
|
|
error!("Verify that your data volume is mounted at the correct location.");
|
|
|
|
} else {
|
|
|
|
error!("Create the data folder and try again.");
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-11-06 20:21:47 +01:00
|
|
|
}
|
|
|
|
|
2018-02-17 01:13:02 +01:00
|
|
|
fn check_rsa_keys() {
|
|
|
|
// If the RSA keys don't exist, try to create them
|
2019-01-25 18:23:51 +01:00
|
|
|
if !util::file_exists(&CONFIG.private_rsa_key()) || !util::file_exists(&CONFIG.public_rsa_key()) {
|
2018-12-06 20:35:25 +01:00
|
|
|
info!("JWT keys don't exist, checking if OpenSSL is available...");
|
2018-02-17 01:13:02 +01:00
|
|
|
|
2019-02-20 20:59:37 +01:00
|
|
|
Command::new("openssl").arg("version").status().unwrap_or_else(|_| {
|
2020-03-02 20:57:06 +01:00
|
|
|
info!(
|
|
|
|
"Can't create keys because OpenSSL is not available, make sure it's installed and available on the PATH"
|
|
|
|
);
|
2018-02-17 01:13:02 +01:00
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
|
2018-12-06 20:35:25 +01:00
|
|
|
info!("OpenSSL detected, creating keys...");
|
2018-02-17 01:13:02 +01:00
|
|
|
|
2019-02-20 20:59:37 +01:00
|
|
|
let key = CONFIG.rsa_key_filename();
|
|
|
|
|
|
|
|
let pem = format!("{}.pem", key);
|
|
|
|
let priv_der = format!("{}.der", key);
|
|
|
|
let pub_der = format!("{}.pub.der", key);
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
let mut success = Command::new("openssl")
|
2019-02-20 20:59:37 +01:00
|
|
|
.args(&["genrsa", "-out", &pem])
|
|
|
|
.status()
|
2018-12-30 23:34:31 +01:00
|
|
|
.expect("Failed to create private pem file")
|
|
|
|
.success();
|
|
|
|
|
|
|
|
success &= Command::new("openssl")
|
2019-02-20 20:59:37 +01:00
|
|
|
.args(&["rsa", "-in", &pem, "-outform", "DER", "-out", &priv_der])
|
|
|
|
.status()
|
2018-12-30 23:34:31 +01:00
|
|
|
.expect("Failed to create private der file")
|
|
|
|
.success();
|
|
|
|
|
|
|
|
success &= Command::new("openssl")
|
2019-02-20 20:59:37 +01:00
|
|
|
.args(&["rsa", "-in", &priv_der, "-inform", "DER"])
|
|
|
|
.args(&["-RSAPublicKey_out", "-outform", "DER", "-out", &pub_der])
|
|
|
|
.status()
|
2018-12-30 23:34:31 +01:00
|
|
|
.expect("Failed to create public der file")
|
|
|
|
.success();
|
2018-02-17 01:13:02 +01:00
|
|
|
|
|
|
|
if success {
|
2018-12-06 20:35:25 +01:00
|
|
|
info!("Keys created correctly.");
|
2018-02-17 01:13:02 +01:00
|
|
|
} else {
|
2018-12-06 20:35:25 +01:00
|
|
|
error!("Error creating keys, exiting...");
|
2018-02-17 01:13:02 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:38:23 +02:00
|
|
|
fn check_web_vault() {
|
2019-01-25 18:23:51 +01:00
|
|
|
if !CONFIG.web_vault_enabled() {
|
2018-06-12 21:09:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:23:51 +01:00
|
|
|
let index_path = Path::new(&CONFIG.web_vault_folder()).join("index.html");
|
2018-04-24 22:38:23 +02:00
|
|
|
|
|
|
|
if !index_path.exists() {
|
2021-03-31 22:18:35 +02:00
|
|
|
error!(
|
|
|
|
"Web vault is not found at '{}'. To install it, please follow the steps in: ",
|
|
|
|
CONFIG.web_vault_folder()
|
|
|
|
);
|
2021-04-27 23:18:32 +02:00
|
|
|
error!("https://github.com/dani-garcia/vaultwarden/wiki/Building-binary#install-the-web-vault");
|
2019-12-29 15:29:46 +01:00
|
|
|
error!("You can also set the environment variable 'WEB_VAULT_ENABLED=false' to disable it");
|
2018-04-24 22:38:23 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 05:16:49 +02:00
|
|
|
fn create_db_pool() -> db::DbPool {
|
|
|
|
match util::retry_db(db::DbPool::from_config, CONFIG.db_connection_retries()) {
|
2020-08-18 17:15:44 +02:00
|
|
|
Ok(p) => p,
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error creating database pool: {:?}", e);
|
|
|
|
exit(1);
|
|
|
|
}
|
2021-04-03 05:16:49 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-22 19:57:35 +01:00
|
|
|
|
2021-04-03 05:16:49 +02:00
|
|
|
fn launch_rocket(pool: db::DbPool, extra_debug: bool) {
|
2020-02-19 06:27:00 +01:00
|
|
|
let basepath = &CONFIG.domain_path();
|
|
|
|
|
|
|
|
// If adding more paths here, consider also adding them to
|
2019-12-06 22:19:07 +01:00
|
|
|
// crate::utils::LOGGED_ROUTES to make sure they appear in the log
|
2020-06-15 23:40:39 +02:00
|
|
|
let result = rocket::ignite()
|
2020-02-19 06:27:00 +01:00
|
|
|
.mount(&[basepath, "/"].concat(), api::web_routes())
|
|
|
|
.mount(&[basepath, "/api"].concat(), api::core_routes())
|
|
|
|
.mount(&[basepath, "/admin"].concat(), api::admin_routes())
|
|
|
|
.mount(&[basepath, "/identity"].concat(), api::identity_routes())
|
|
|
|
.mount(&[basepath, "/icons"].concat(), api::icons_routes())
|
|
|
|
.mount(&[basepath, "/notifications"].concat(), api::notifications_routes())
|
2020-08-18 17:15:44 +02:00
|
|
|
.manage(pool)
|
2019-02-20 20:59:37 +01:00
|
|
|
.manage(api::start_notification_server())
|
2019-09-01 13:00:12 +02:00
|
|
|
.attach(util::AppHeaders())
|
2021-03-27 15:26:32 +01:00
|
|
|
.attach(util::Cors())
|
2020-06-15 23:40:39 +02:00
|
|
|
.attach(util::BetterLogging(extra_debug))
|
|
|
|
.launch();
|
2019-02-20 20:59:37 +01:00
|
|
|
|
|
|
|
// Launch and print error if there is one
|
|
|
|
// The launch will restore the original logging level
|
2020-06-15 23:40:39 +02:00
|
|
|
error!("Launch error {:#?}", result);
|
2019-01-11 14:18:13 +01:00
|
|
|
}
|
2021-04-03 05:16:49 +02:00
|
|
|
|
|
|
|
fn schedule_jobs(pool: db::DbPool) {
|
|
|
|
if CONFIG.job_poll_interval_ms() == 0 {
|
|
|
|
info!("Job scheduler disabled.");
|
|
|
|
return;
|
|
|
|
}
|
2021-04-06 22:55:28 +02:00
|
|
|
thread::Builder::new()
|
|
|
|
.name("job-scheduler".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
let mut sched = JobScheduler::new();
|
|
|
|
|
|
|
|
// Purge sends that are past their deletion date.
|
|
|
|
if !CONFIG.send_purge_schedule().is_empty() {
|
|
|
|
sched.add(Job::new(CONFIG.send_purge_schedule().parse().unwrap(), || {
|
|
|
|
api::purge_sends(pool.clone());
|
|
|
|
}));
|
|
|
|
}
|
2021-04-03 05:16:49 +02:00
|
|
|
|
2021-04-06 22:55:28 +02:00
|
|
|
// Purge trashed items that are old enough to be auto-deleted.
|
|
|
|
if !CONFIG.trash_purge_schedule().is_empty() {
|
|
|
|
sched.add(Job::new(CONFIG.trash_purge_schedule().parse().unwrap(), || {
|
|
|
|
api::purge_trashed_ciphers(pool.clone());
|
|
|
|
}));
|
|
|
|
}
|
2021-04-03 05:52:15 +02:00
|
|
|
|
2021-04-06 22:55:28 +02:00
|
|
|
// Periodically check for jobs to run. We probably won't need any
|
|
|
|
// jobs that run more often than once a minute, so a default poll
|
|
|
|
// interval of 30 seconds should be sufficient. Users who want to
|
|
|
|
// schedule jobs to run more frequently for some reason can reduce
|
|
|
|
// the poll interval accordingly.
|
|
|
|
loop {
|
|
|
|
sched.tick();
|
|
|
|
thread::sleep(Duration::from_millis(CONFIG.job_poll_interval_ms()));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.expect("Error spawning job scheduler thread");
|
2021-04-03 05:16:49 +02:00
|
|
|
}
|