diff --git a/Cargo.toml b/Cargo.toml index 522deb4..06f4392 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name = "update_groups" + [dependencies] # for the ldap ldap3="0.11.1" diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs new file mode 100644 index 0000000..56c0247 --- /dev/null +++ b/src/bin/update_groups.rs @@ -0,0 +1,62 @@ +use std::collections::HashSet; +use sqlx::{Pool, Sqlite}; +use std::env; +use ldap3::{LdapConn, Mod}; +use tide::prelude::*; +use skynet_ldap_server::{Config, get_config}; + +/* +https://ticketbooking.dublincoach.ie/MobileAPI/MobileBooking/GetTrackToStageName?FromStage=University%20of%20Limerick +https://ticketbooking.dublincoach.ie/MobileAPI/MobileBooking/GetJourneyList?FromStageName=University%20of%20Limerick&ToStageName=Red%20Cow%20LUAS&JourneyType=0&RouteID=0&JrEndStageID=0&IsStageSelection=1 + + +From + University of Limerick +To + Dublin City + Ennis + Killarney + Tralee + */ + +#[async_std::main] +async fn main() -> tide::Result<()> { + let config = get_config(); + + //update_users(&config).await; + update_admin(&config).await?; + + Ok(()) +} + + +//async fn update_users(config: &Config) { + +//} +fn uid_to_dn(uid: &str) -> String{ + format!("uid={},ou=users,dc=skynet,dc=ie", uid) +} + +async fn update_admin(config: &Config) -> tide::Result<()>{ + let mut ldap = LdapConn::new(&config.ldap_host)?; + + // use the admin account + ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?; + + // read from config file + let users = vec!["silver", "evanc", "eoghanconlon73", "pio"]; + + let dn_skynet_admins = "cn=skynet-admins,ou=groups,dc=skynet,dc=ie"; + let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect(); + let mods = vec![Mod::Replace("member".to_string(), skynet_admins)]; + ldap.modify(&dn_skynet_admins, mods)?.success()?; + + let dn_skynet_admins_linux = "cn=skynet-admins-linux,ou=groups,dc=skynet,dc=ie"; + let skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect(); + let mods = vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)]; + ldap.modify(&dn_skynet_admins_linux, mods)?.success()?; + + ldap.unbind()?; + + Ok(()) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b54c601..587dce1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,9 +88,9 @@ pub struct State { #[derive(Debug, Clone)] pub struct Config { - ldap_host: String, - ldap_admin: String, - ldap_admin_pw: String, + pub ldap_host: String, + pub ldap_admin: String, + pub ldap_admin_pw: String, pub database: String, pub host_port: String, }