feat: new users will immediately gain access to most services
Closes #13
This commit is contained in:
parent
56b2da1ae6
commit
38cbb440af
3 changed files with 51 additions and 45 deletions
44
src/lib.rs
44
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
pub mod methods;
|
||||
use chrono::{Datelike, SecondsFormat, Utc};
|
||||
use dotenvy::dotenv;
|
||||
use ldap3::{LdapConn, Mod};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use sqlx::{
|
||||
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
|
||||
|
@ -212,3 +213,46 @@ pub async fn get_wolves(db: &Pool<Sqlite>) -> Vec<AccountWolves> {
|
|||
.await
|
||||
.unwrap_or(vec![])
|
||||
}
|
||||
|
||||
pub async fn update_group(config: &Config, group: &str, users: &Vec<String>, replace: bool) -> tide::Result<()> {
|
||||
if users.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
||||
|
||||
// use the admin account
|
||||
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
|
||||
|
||||
let dn = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
||||
let members = users.iter().map(|uid| uid_to_dn(uid)).collect();
|
||||
let mods = if replace {
|
||||
vec![Mod::Replace("member".to_string(), members)]
|
||||
} else {
|
||||
vec![Mod::Add("member".to_string(), members)]
|
||||
};
|
||||
|
||||
if let Err(x) = ldap.modify(&dn, mods) {
|
||||
println!("{:?}", x);
|
||||
}
|
||||
|
||||
let dn_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group);
|
||||
let members_linux = users.iter().map(|uid| uid.to_string()).collect();
|
||||
let mods = if replace {
|
||||
vec![Mod::Replace("memberUid".to_string(), members_linux)]
|
||||
} else {
|
||||
vec![Mod::Add("memberUid".to_string(), members_linux)]
|
||||
};
|
||||
if let Err(x) = ldap.modify(&dn_linux, mods) {
|
||||
println!("{:?}", x);
|
||||
};
|
||||
|
||||
// tidy up
|
||||
ldap.unbind()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn uid_to_dn(uid: &str) -> String {
|
||||
format!("uid={},ou=users,dc=skynet,dc=ie", uid)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue