mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2026-03-29 23:20:23 -04:00
feat: added functions to remove, add and lsit acls (with filtering)
This commit is contained in:
parent
f1d725c842
commit
13e497936f
3 changed files with 52 additions and 5 deletions
|
|
@ -1,9 +1,12 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use tracing::warn;
|
||||
use url::Host;
|
||||
|
||||
use crate::{service::acl::{Data, AclDatabaseEntry, AclMode}, KeyValueDatabase};
|
||||
|
||||
impl Data for KeyValueDatabase {
|
||||
fn check_acl(&self,host: &url::Host<String> ) -> crate::Result<Option<AclMode>> {
|
||||
fn check_acl(&self,host: &Host<String> ) -> crate::Result<Option<AclMode>> {
|
||||
let thing = self.acl_list.get(host.to_string().as_bytes())?;
|
||||
if let Some(thing) = thing {
|
||||
match thing.first() {
|
||||
|
|
@ -27,7 +30,32 @@ impl Data for KeyValueDatabase {
|
|||
})
|
||||
}
|
||||
|
||||
fn remove_acl(&self,host: url::Host<String>) -> crate::Result<()> {
|
||||
fn remove_acl(&self,host: Host<String>) -> crate::Result<()> {
|
||||
self.acl_list.remove(host.to_string().as_bytes())
|
||||
}
|
||||
|
||||
fn get_all_acls(&self) -> HashSet<AclDatabaseEntry> {
|
||||
let mut set = HashSet::new();
|
||||
|
||||
self.acl_list.iter().for_each(|it| {
|
||||
let Ok(key) = String::from_utf8(it.0) else {
|
||||
return;
|
||||
};
|
||||
let Ok(parsed_host) = Host::parse(&key) else {
|
||||
warn!("failed to parse host {}", key);
|
||||
return;
|
||||
};
|
||||
let mode = match it.1.first() {
|
||||
Some(0x1) => AclMode::Allow,
|
||||
Some(0x0) => AclMode::Block,
|
||||
Some(invalid) => {
|
||||
warn!("found invalid value for mode byte in value {}, probably db corruption", invalid);
|
||||
return;
|
||||
}
|
||||
None => return,
|
||||
};
|
||||
set.insert(AclDatabaseEntry { mode: mode, hostname: parsed_host });
|
||||
});
|
||||
set
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue