mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2024-09-20 07:16:18 +08:00
This commit is contained in:
parent
794b8f2e50
commit
3912fd0084
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use jmap_proto::types::collection::Collection;
|
use store::{Store, Stores};
|
||||||
use store::{BitmapKey, Store, Stores};
|
|
||||||
use trc::{EventType, MetricType, TOTAL_EVENT_COUNT};
|
use trc::{EventType, MetricType, TOTAL_EVENT_COUNT};
|
||||||
use utils::config::{
|
use utils::config::{
|
||||||
cron::SimpleCron,
|
cron::SimpleCron,
|
||||||
|
@ -19,7 +18,10 @@ use utils::config::{
|
||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::expr::{tokenizer::TokenMap, Expression};
|
use crate::{
|
||||||
|
expr::{tokenizer::TokenMap, Expression},
|
||||||
|
total_accounts,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
license::LicenseValidator, AlertContent, AlertContentToken, AlertMethod, Enterprise,
|
license::LicenseValidator, AlertContent, AlertContentToken, AlertMethod, Enterprise,
|
||||||
|
@ -40,17 +42,13 @@ impl Enterprise {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match data
|
match total_accounts(data).await {
|
||||||
.get_bitmap(BitmapKey::document_ids(u32::MAX, Collection::Principal))
|
Ok(total) if total > license.accounts as u64 => {
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(Some(bitmap)) if bitmap.len() > license.accounts as u64 => {
|
|
||||||
config.new_build_warning(
|
config.new_build_warning(
|
||||||
"enterprise.license-key",
|
"enterprise.license-key",
|
||||||
format!(
|
format!(
|
||||||
"License key is valid but only allows {} accounts, found {}.",
|
"License key is valid but only allows {} accounts, found {}.",
|
||||||
license.accounts,
|
license.accounts, total
|
||||||
bitmap.len()
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -21,7 +21,6 @@ use config::{
|
||||||
};
|
};
|
||||||
use directory::{core::secret::verify_secret_hash, Directory, Principal, QueryBy, Type};
|
use directory::{core::secret::verify_secret_hash, Directory, Principal, QueryBy, Type};
|
||||||
use expr::if_block::IfBlock;
|
use expr::if_block::IfBlock;
|
||||||
use jmap_proto::types::collection::Collection;
|
|
||||||
use listener::{
|
use listener::{
|
||||||
blocked::{AllowedIps, BlockedIps},
|
blocked::{AllowedIps, BlockedIps},
|
||||||
tls::TlsManager,
|
tls::TlsManager,
|
||||||
|
@ -31,7 +30,7 @@ use mail_send::Credentials;
|
||||||
use sieve::Sieve;
|
use sieve::Sieve;
|
||||||
use store::{
|
use store::{
|
||||||
write::{DirectoryClass, QueueClass, ValueClass},
|
write::{DirectoryClass, QueueClass, ValueClass},
|
||||||
BitmapKey, IterateParams, LookupStore, ValueKey,
|
IterateParams, LookupStore, ValueKey,
|
||||||
};
|
};
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use trc::AddContext;
|
use trc::AddContext;
|
||||||
|
@ -343,12 +342,7 @@ impl Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn total_accounts(&self) -> trc::Result<u64> {
|
pub async fn total_accounts(&self) -> trc::Result<u64> {
|
||||||
self.storage
|
total_accounts(&self.storage.data).await
|
||||||
.data
|
|
||||||
.get_bitmap(BitmapKey::document_ids(u32::MAX, Collection::Principal))
|
|
||||||
.await
|
|
||||||
.caused_by(trc::location!())
|
|
||||||
.map(|bitmap| bitmap.map_or(0, |b| b.len()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn total_domains(&self) -> trc::Result<u64> {
|
pub async fn total_domains(&self) -> trc::Result<u64> {
|
||||||
|
@ -376,6 +370,30 @@ impl Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn total_accounts(store: &store::Store) -> trc::Result<u64> {
|
||||||
|
let mut total = 0;
|
||||||
|
store
|
||||||
|
.iterate(
|
||||||
|
IterateParams::new(
|
||||||
|
ValueKey::from(ValueClass::Directory(DirectoryClass::NameToId(vec![]))),
|
||||||
|
ValueKey::from(ValueClass::Directory(DirectoryClass::NameToId(vec![
|
||||||
|
u8::MAX;
|
||||||
|
10
|
||||||
|
]))),
|
||||||
|
)
|
||||||
|
.ascending(),
|
||||||
|
|_, value| {
|
||||||
|
if matches!(value.last(), Some(0u8 | 4u8)) {
|
||||||
|
total += 1;
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.caused_by(trc::location!())
|
||||||
|
.map(|_| total)
|
||||||
|
}
|
||||||
|
|
||||||
trait CredentialsUsername {
|
trait CredentialsUsername {
|
||||||
fn login(&self) -> &str;
|
fn login(&self) -> &str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,10 +239,9 @@ impl EventType {
|
||||||
ConfigEvent::DefaultApplied
|
ConfigEvent::DefaultApplied
|
||||||
| ConfigEvent::MissingSetting
|
| ConfigEvent::MissingSetting
|
||||||
| ConfigEvent::UnusedSetting
|
| ConfigEvent::UnusedSetting
|
||||||
| ConfigEvent::ParseWarning
|
|
||||||
| ConfigEvent::BuildWarning
|
|
||||||
| ConfigEvent::AlreadyUpToDate
|
| ConfigEvent::AlreadyUpToDate
|
||||||
| ConfigEvent::ExternalKeyIgnored => Level::Debug,
|
| ConfigEvent::ExternalKeyIgnored => Level::Debug,
|
||||||
|
ConfigEvent::ParseWarning | ConfigEvent::BuildWarning => Level::Warn,
|
||||||
ConfigEvent::ImportExternal => Level::Info,
|
ConfigEvent::ImportExternal => Level::Info,
|
||||||
},
|
},
|
||||||
EventType::Resource(cause) => match cause {
|
EventType::Resource(cause) => match cause {
|
||||||
|
|
Loading…
Reference in a new issue