2023-06-18 16:19:59 +00:00
|
|
|
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<()>{
|
2023-06-18 16:33:39 +00:00
|
|
|
let users = vec!["silver", "evanc", "eoghanconlon73"];
|
2023-06-18 16:45:33 +00:00
|
|
|
update_group(config,"skynet-admins", &users, true).await?;
|
|
|
|
// admins automatically get added as users
|
|
|
|
update_group(config,"skynet-users", &users, false).await?;
|
2023-06-18 16:33:39 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-06-18 16:45:33 +00:00
|
|
|
async fn update_group(config: &Config, group: &str, users: &Vec<&str>, replace: bool) -> tide::Result<()>{
|
2023-06-18 16:19:59 +00:00
|
|
|
let mut ldap = LdapConn::new(&config.ldap_host)?;
|
|
|
|
|
|
|
|
// use the admin account
|
|
|
|
ldap.simple_bind(&config.ldap_admin, &config.ldap_admin_pw)?.success()?;
|
2023-06-18 16:33:39 +00:00
|
|
|
|
|
|
|
let dn_skynet_admins = format!("cn={},ou=groups,dc=skynet,dc=ie", group);
|
2023-06-18 16:19:59 +00:00
|
|
|
let skynet_admins = users.clone().into_iter().map(|uid| uid_to_dn(uid)).collect();
|
2023-06-18 16:45:33 +00:00
|
|
|
let mods = if replace {
|
|
|
|
vec![Mod::Replace("member".to_string(), skynet_admins)]
|
|
|
|
} else {
|
|
|
|
vec![Mod::Add("member".to_string(), skynet_admins)]
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(x) = ldap.modify(&dn_skynet_admins, mods) {
|
|
|
|
println!("{:?}", x);
|
|
|
|
}
|
2023-06-18 16:33:39 +00:00
|
|
|
|
|
|
|
let dn_skynet_admins_linux = format!("cn={}-linux,ou=groups,dc=skynet,dc=ie", group);
|
2023-06-18 16:19:59 +00:00
|
|
|
let skynet_admins_linux = users.clone().into_iter().map(|uid| uid.to_string()).collect();
|
2023-06-18 16:45:33 +00:00
|
|
|
let mods = if replace {
|
|
|
|
vec![Mod::Replace("memberUid".to_string(), skynet_admins_linux)]
|
|
|
|
} else {
|
|
|
|
vec![Mod::Add("memberUid".to_string(), skynet_admins_linux)]
|
|
|
|
};
|
|
|
|
if let Err(x) = ldap.modify(&dn_skynet_admins_linux, mods){
|
|
|
|
println!("{:?}", x);
|
|
|
|
};
|
2023-06-18 16:19:59 +00:00
|
|
|
|
|
|
|
ldap.unbind()?;
|
2023-06-18 16:33:39 +00:00
|
|
|
|
2023-06-18 16:19:59 +00:00
|
|
|
Ok(())
|
|
|
|
}
|