diff --git a/Cargo.lock b/Cargo.lock index 855bac7d8..6b72abb92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1203,7 +1203,7 @@ dependencies = [ [[package]] name = "common" -version = "0.11.0" +version = "0.11.2" dependencies = [ "aes-gcm-siv", "ahash 0.8.11", @@ -1813,7 +1813,7 @@ dependencies = [ [[package]] name = "directory" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "argon2", @@ -2135,7 +2135,7 @@ dependencies = [ [[package]] name = "event_macro" -version = "0.11.0" +version = "0.11.2" dependencies = [ "proc-macro2", "quote", @@ -3219,7 +3219,7 @@ checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" [[package]] name = "imap" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "common", @@ -3245,7 +3245,7 @@ dependencies = [ [[package]] name = "imap_proto" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "chrono", @@ -3469,7 +3469,7 @@ dependencies = [ [[package]] name = "jmap" -version = "0.11.0" +version = "0.11.2" dependencies = [ "aes", "aes-gcm", @@ -3551,7 +3551,7 @@ dependencies = [ [[package]] name = "jmap_proto" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "fast-float", @@ -3925,7 +3925,7 @@ dependencies = [ [[package]] name = "mail-server" -version = "0.11.0" +version = "0.11.2" dependencies = [ "common", "directory", @@ -3945,7 +3945,7 @@ dependencies = [ [[package]] name = "managesieve" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "bincode", @@ -4223,7 +4223,7 @@ dependencies = [ [[package]] name = "nlp" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "bincode", @@ -4782,7 +4782,7 @@ dependencies = [ [[package]] name = "pop3" -version = "0.11.0" +version = "0.11.2" dependencies = [ "common", "directory", @@ -4940,7 +4940,7 @@ dependencies = [ [[package]] name = "proc_macros" -version = "0.11.0" +version = "0.11.2" dependencies = [ "proc-macro2", "quote", @@ -6434,7 +6434,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smtp" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "bincode", @@ -6523,7 +6523,7 @@ dependencies = [ [[package]] name = "spam-filter" -version = "0.11.0" +version = "0.11.2" dependencies = [ "common", "decancer", @@ -6577,7 +6577,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stalwart-cli" -version = "0.11.0" +version = "0.11.2" dependencies = [ "clap", "console", @@ -6608,7 +6608,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "store" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "arc-swap", @@ -6817,7 +6817,7 @@ dependencies = [ [[package]] name = "tests" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "async-trait", @@ -7255,7 +7255,7 @@ dependencies = [ [[package]] name = "trc" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "base64 0.22.1", @@ -7502,7 +7502,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "utils" -version = "0.11.0" +version = "0.11.2" dependencies = [ "ahash 0.8.11", "base64 0.22.1", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 3cd25ea5a..ad4d388e9 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Stalwart Labs Ltd. "] license = "AGPL-3.0-only OR LicenseRef-SEL" repository = "https://github.com/stalwartlabs/cli" homepage = "https://github.com/stalwartlabs/cli" -version = "0.11.0" +version = "0.11.2" edition = "2021" readme = "README.md" resolver = "2" diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 51c6ca85c..7cdf81a99 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "common" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/common/src/config/network.rs b/crates/common/src/config/network.rs index f4056732f..392ab4ce5 100644 --- a/crates/common/src/config/network.rs +++ b/crates/common/src/config/network.rs @@ -7,6 +7,7 @@ use std::time::Duration; use crate::expr::{if_block::IfBlock, tokenizer::TokenMap}; +use ahash::AHashSet; use utils::config::{Config, Rate}; use super::*; @@ -14,6 +15,7 @@ use super::*; #[derive(Clone)] pub struct Network { pub node_id: u64, + pub roles: ClusterRoles, pub server_name: String, pub report_domain: String, pub security: Security, @@ -35,6 +37,15 @@ pub struct ContactForm { pub field_honey_pot: Option, } +#[derive(Clone)] +pub struct ClusterRoles { + pub purge_stores: bool, + pub purge_accounts: bool, + pub renew_acme: bool, + pub calculate_metrics: bool, + pub push_metrics: bool, +} + #[derive(Clone, Default)] pub enum AsnGeoLookupConfig { Resource { @@ -82,7 +93,7 @@ impl Default for Network { Self { security: Default::default(), contact_form: None, - node_id: 0, + node_id: 1, http_response_url: IfBlock::new::<()>( "server.http.url", [], @@ -92,6 +103,13 @@ impl Default for Network { asn_geo_lookup: AsnGeoLookupConfig::Disabled, server_name: Default::default(), report_domain: Default::default(), + roles: ClusterRoles { + purge_stores: true, + purge_accounts: true, + renew_acme: true, + calculate_metrics: true, + push_metrics: true, + }, } } } @@ -180,7 +198,7 @@ impl Network { }); let mut network = Network { - node_id: config.property("cluster.node-id").unwrap_or_default(), + node_id: config.property("cluster.node-id").unwrap_or(1), report_domain, server_name, security: Security::parse(config), @@ -190,6 +208,36 @@ impl Network { }; let token_map = &TokenMap::default().with_variables(HTTP_VARS); + // Node roles + for (value, key) in [ + ( + &mut network.roles.purge_stores, + "cluster.roles.purge.stores", + ), + ( + &mut network.roles.purge_accounts, + "cluster.roles.purge.accounts", + ), + (&mut network.roles.renew_acme, "cluster.roles.acme.renew"), + ( + &mut network.roles.calculate_metrics, + "cluster.roles.metrics.calculate", + ), + ( + &mut network.roles.push_metrics, + "cluster.roles.metrics.push", + ), + ] { + let node_ids = config + .properties::(key) + .into_iter() + .map(|(_, v)| v) + .collect::>(); + if !node_ids.is_empty() && !node_ids.contains(&network.node_id) { + *value = false; + } + } + for (value, key) in [ (&mut network.http_response_url, "server.http.url"), ( diff --git a/crates/directory/Cargo.toml b/crates/directory/Cargo.toml index 317005384..ddd6b2b67 100644 --- a/crates/directory/Cargo.toml +++ b/crates/directory/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "directory" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/imap-proto/Cargo.toml b/crates/imap-proto/Cargo.toml index cee8b94b8..0b8f5a514 100644 --- a/crates/imap-proto/Cargo.toml +++ b/crates/imap-proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "imap_proto" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/imap/Cargo.toml b/crates/imap/Cargo.toml index 09e720b74..04c2f007d 100644 --- a/crates/imap/Cargo.toml +++ b/crates/imap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "imap" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/jmap-proto/Cargo.toml b/crates/jmap-proto/Cargo.toml index ff094c764..3db4c0345 100644 --- a/crates/jmap-proto/Cargo.toml +++ b/crates/jmap-proto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jmap_proto" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/jmap/Cargo.toml b/crates/jmap/Cargo.toml index 386870b3a..029297519 100644 --- a/crates/jmap/Cargo.toml +++ b/crates/jmap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jmap" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/jmap/src/services/housekeeper.rs b/crates/jmap/src/services/housekeeper.rs index d6bc67adf..29262f5e7 100644 --- a/crates/jmap/src/services/housekeeper.rs +++ b/crates/jmap/src/services/housekeeper.rs @@ -78,41 +78,51 @@ pub fn spawn_housekeeper(inner: Arc, mut rx: mpsc::Receiver { - queue.schedule( - Instant::now() + renew_at, - ActionClass::Acme(provider.id.clone()), - ); - } - Err(err) => { - trc::error!(err.details("Failed to initialize ACME certificate manager.")); - } - }; + if server.core.network.roles.renew_acme { + for provider in server.core.acme.providers.values() { + match server.init_acme(provider).await { + Ok(renew_at) => { + queue.schedule( + Instant::now() + renew_at, + ActionClass::Acme(provider.id.clone()), + ); + } + Err(err) => { + trc::error!( + err.details("Failed to initialize ACME certificate manager.") + ); + } + }; + } } // SPDX-SnippetBegin @@ -431,50 +441,50 @@ pub fn spawn_housekeeper(inner: Arc, mut rx: mpsc::Receiver { - Collector::update_gauge( - MetricType::QueueCount, - total, - ); - } - Err(err) => { - trc::error!( - err.details("Failed to obtain queue size") - ); + if server.core.network.roles.calculate_metrics { + #[cfg(feature = "enterprise")] + if server.is_enterprise_edition() { + // Obtain queue size + match server.total_queued_messages().await { + Ok(total) => { + Collector::update_gauge( + MetricType::QueueCount, + total, + ); + } + Err(err) => { + trc::error!( + err.details("Failed to obtain queue size") + ); + } } } - } - if update_other_metrics { - match server.total_accounts().await { - Ok(total) => { - Collector::update_gauge( - MetricType::UserCount, - total, - ); + if update_other_metrics { + match server.total_accounts().await { + Ok(total) => { + Collector::update_gauge( + MetricType::UserCount, + total, + ); + } + Err(err) => { + trc::error!(err + .details("Failed to obtain account count")); + } } - Err(err) => { - trc::error!( - err.details("Failed to obtain account count") - ); - } - } - match server.total_domains().await { - Ok(total) => { - Collector::update_gauge( - MetricType::DomainCount, - total, - ); - } - Err(err) => { - trc::error!( - err.details("Failed to obtain domain count") - ); + match server.total_domains().await { + Ok(total) => { + Collector::update_gauge( + MetricType::DomainCount, + total, + ); + } + Err(err) => { + trc::error!(err + .details("Failed to obtain domain count")); + } } } } diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 264d902d6..57815e2ba 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://stalw.art" keywords = ["imap", "jmap", "smtp", "email", "mail", "server"] categories = ["email"] license = "AGPL-3.0-only OR LicenseRef-SEL" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/managesieve/Cargo.toml b/crates/managesieve/Cargo.toml index 080357a75..b21e779b4 100644 --- a/crates/managesieve/Cargo.toml +++ b/crates/managesieve/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "managesieve" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/nlp/Cargo.toml b/crates/nlp/Cargo.toml index f2cfdec84..1f7da7395 100644 --- a/crates/nlp/Cargo.toml +++ b/crates/nlp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nlp" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/pop3/Cargo.toml b/crates/pop3/Cargo.toml index 6c6975f6d..5de5e4399 100644 --- a/crates/pop3/Cargo.toml +++ b/crates/pop3/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pop3" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/smtp/Cargo.toml b/crates/smtp/Cargo.toml index 9b6d1fd87..76eaf9a20 100644 --- a/crates/smtp/Cargo.toml +++ b/crates/smtp/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://stalw.art/smtp" keywords = ["smtp", "email", "mail", "server"] categories = ["email"] license = "AGPL-3.0-only OR LicenseRef-SEL" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/spam-filter/Cargo.toml b/crates/spam-filter/Cargo.toml index a1215ac74..855c4283d 100644 --- a/crates/spam-filter/Cargo.toml +++ b/crates/spam-filter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spam-filter" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml index 537ab8055..2ec6807d9 100644 --- a/crates/store/Cargo.toml +++ b/crates/store/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "store" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/trc/Cargo.toml b/crates/trc/Cargo.toml index d6536a502..3990e755a 100644 --- a/crates/trc/Cargo.toml +++ b/crates/trc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trc" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/trc/event-macro/Cargo.toml b/crates/trc/event-macro/Cargo.toml index fe8f95d2a..b31e3ffce 100644 --- a/crates/trc/event-macro/Cargo.toml +++ b/crates/trc/event-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "event_macro" -version = "0.11.0" +version = "0.11.2" edition = "2021" [lib] diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 1596c9299..23ed2e109 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "utils" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2" diff --git a/crates/utils/proc-macros/Cargo.toml b/crates/utils/proc-macros/Cargo.toml index c40cd4c30..fd04ec02f 100644 --- a/crates/utils/proc-macros/Cargo.toml +++ b/crates/utils/proc-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proc_macros" -version = "0.11.0" +version = "0.11.2" edition = "2021" [lib] diff --git a/tests/Cargo.toml b/tests/Cargo.toml index a3053a983..7d5d87adb 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tests" -version = "0.11.0" +version = "0.11.2" edition = "2021" resolver = "2"