From ea960e532088f93e03232b44ee4613631e754b3b Mon Sep 17 00:00:00 2001 From: TheHackdes Date: Mon, 4 May 2026 20:41:53 +0200 Subject: [PATCH] feat(main.sh): add functionality to add users to a group This commit introduces the ability to add one or more users to a group using the main script. The user is prompted to select this option from the menu, and if chosen, the action/add\_user\_to\_group.sh script is sourced to perform the operation. If an unrecognized choice is made, an error message is displayed and the script exits with a status of 1. --- actions/add_user_in_group·sh | 20 -------------------- actions/add_user_to_group·sh | 34 ++++++++++++++++++++++++++++++++++ main.sh | 16 +++++++++++++--- 3 files changed, 47 insertions(+), 23 deletions(-) delete mode 100755 actions/add_user_in_group·sh create mode 100755 actions/add_user_to_group·sh diff --git a/actions/add_user_in_group·sh b/actions/add_user_in_group·sh deleted file mode 100755 index e1abb1b..0000000 --- a/actions/add_user_in_group·sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -source ./sources/functions.sh - -banner "Adding user in group" - -sleep 1 - -log info "Search all users..." -sleep 1 -SELECTED_USER=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(objectClass=inetOrgPerson)" dn | grep '^dn' | sed 's/dn: //g' | fzf --height=10 --reverse --cycle --prompt="❯ Choix : " -m) - -if [ -z "$SELECTED_USER" ]; then - log error "No user selected" -else - log success "User selected : " - for i in $SELECTED_USER; do - echo -e " - ${i}" - done -fi diff --git a/actions/add_user_to_group·sh b/actions/add_user_to_group·sh new file mode 100755 index 0000000..c294d18 --- /dev/null +++ b/actions/add_user_to_group·sh @@ -0,0 +1,34 @@ +#!/bin/bash + +source ./sources/functions.sh + +banner "Adding user in group" +sleep 1 + +log info "Search all users..." +sleep 1 + +SELECTED_USER=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(objectClass=inetOrgPerson)" dn | grep '^dn' | sed 's/dn: //g' | fzf --height=10 --reverse --cycle --prompt="❯ Choix : " -m) + +if [ -z "$SELECTED_USER" ]; then + log error "No user selected" +else + log success "List of selected users :" + for i in $SELECTED_USER; do + log info "User : ${i}" + done +fi + +SELECTED_GROUP=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(|(objectClass=groupOfNames)(objectClass=groupOfUniqueNames)(objectClass=posixGroup))" dn | + grep '^dn' | + sed 's/dn: //g' | + fzf --height=10 --reverse --cycle --prompt="❯ Groupe : " -m) + +if [ -z "$SELECTED_GROUP" ]; then + log error "No group selected" +else + log success "List of selected groups :" + for i in $SELECTED_GROUP; do + log info "Group : ${i}" + done +fi diff --git a/main.sh b/main.sh index d3ca716..5d2e59c 100755 --- a/main.sh +++ b/main.sh @@ -5,12 +5,10 @@ source ./sources/functions.sh banner "Manage OpenLDAP" CHOIX=( - "1. Ajouter un nouveau utilisateur" - "2. Supprimer un utilisateur" + "1. Ajouter un ou plusieurs utilisateurs a un groupe" ) select_option() { - local choice choice=$(printf "%s\n" "${CHOIX[@]}" | fzf --height=4 --reverse --cycle --prompt="❯ Choix : " --layout=reverse) log info "Selection - ${choice}" } @@ -18,3 +16,15 @@ select_option() { sleep 1.5 select_option + +case $choice in +"1. Ajouter un ou plusieurs utilisateurs a un groupe") + log success "Ajouter un ou plusieurs utilisateurs a un groupe" + sleep 1 + source ./actions/add_user_to_group·sh + ;; +*) + log error "Choice non reconnue" + exit 1 + ;; +esac