v1.0.0
This commit is contained in:
commit
83aab7d071
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
ldap.conf
|
||||
5
.vscode/settings.json
vendored
Executable file
5
.vscode/settings.json
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"editor.fontSize": 13,
|
||||
"terminal.integrated.fontSize": 13,
|
||||
"window.zoomLevel": 1.4,
|
||||
}
|
||||
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Description
|
||||
Groups scripts for managing an openldap directory
|
||||
## Installation
|
||||
```bash
|
||||
git clone https://gitweb.dyndns.org/scripts/ldap-tools.git
|
||||
```
|
||||
## Configuration
|
||||
Copy `ldap.conf.dist` to `ldap.conf`
|
||||
Edit the `ldap.conf` and set the parameters according to your configuration (the parameters are commented in file)
|
||||
|
||||
## Scripts list
|
||||
|script|description|usage|
|
||||
|:-----|:----------|-----|
|
||||
|list_user.sh|List directory users|`./list_user.sh --help`|
|
||||
|
||||
## Changelog
|
||||
#### [1.0.0] - 2024-12-27
|
||||
##### Added
|
||||
- Config file ldap.conf.dist
|
||||
- Functions scripts
|
||||
- List_user script (v1.0.0)
|
||||
- README.md
|
||||
- Initial version by [GMo](mailto:gilles.mouchet@gmail.com)
|
||||
20
functions.sh
Normal file
20
functions.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
function readConfig {
|
||||
confDir=.
|
||||
cfgFile=${confDir}/config.conf
|
||||
if [ ! -f $cfgFile ]; then
|
||||
echo "The conf file '$cfgFile' does not exist !"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read config file
|
||||
. $cfgFile
|
||||
}
|
||||
|
||||
# check if ldapsearch exist
|
||||
ldapsearch_path=$(command -v ldapsearch)
|
||||
if [ "$?" == "1" ]; then
|
||||
echo "ldapsearch doesn't exist. Please install openldap-client package"
|
||||
exit 1
|
||||
fi
|
||||
12
ldap.conf.dist
Normal file
12
ldap.conf.dist
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# directory base
|
||||
LDAP_BASE="dc=gmolab,dc=net"
|
||||
|
||||
# openldap server
|
||||
LDAP_SRV=ldap://kleenex.gmolab.net
|
||||
|
||||
# openldap manager username and password
|
||||
LDAP_MANAGER_USER="cn=Admin LDAP,ou=people,$LDAP_BASE"
|
||||
LDAP_MANAGER_PASS=secret
|
||||
|
||||
119
list_user.sh
Executable file
119
list_user.sh
Executable file
@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
############################################################
|
||||
# Decription: list user in directory
|
||||
#
|
||||
# Author: Gilles Mouchet (gilles.mouchet@gmail.com)
|
||||
# Creation Date: 27-Dec-2024
|
||||
# Version: 1.0
|
||||
# Install:
|
||||
# see README.md
|
||||
# Usage: ./list_user.sh --help
|
||||
# Changelog:
|
||||
# V1.0 - 27-Dec-2024 - GMo
|
||||
# Added
|
||||
# - Creation of script from scratch
|
||||
#
|
||||
############################################################
|
||||
|
||||
# debug
|
||||
#set -x
|
||||
|
||||
# Function to print help
|
||||
function print_usage {
|
||||
|
||||
/bin/cat << EOF
|
||||
|
||||
Usage: $progName [options]
|
||||
|
||||
Options:
|
||||
-a,--all Show all existing users in the directory
|
||||
-n <user_cn>,--cn=<user_cn> Show seleted user
|
||||
-h,--help Show this help
|
||||
-v,--version Show version
|
||||
|
||||
Examples:
|
||||
Show all user
|
||||
$progName -a
|
||||
|
||||
Show user Gilles Mouchet
|
||||
$progName --cn="Gilles Mouchet"
|
||||
|
||||
Show all user with Mouchet in CN
|
||||
$progName --cn="*Mouchet*"
|
||||
|
||||
Show all user with Gilles in CN
|
||||
$progName -n "Gilles*"
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# version
|
||||
version="v1.0.0"
|
||||
# script name
|
||||
progName="./$(/bin/basename $0)"
|
||||
# read all functios
|
||||
source functions.sh
|
||||
# read config
|
||||
readConfig
|
||||
|
||||
#-------------------
|
||||
# MAIN
|
||||
#-------------------
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
-a|--all*)
|
||||
ldap_arg="objectClass=inetOrgPerson"
|
||||
shift
|
||||
;;
|
||||
-n|--cn*)
|
||||
# --cn parameter
|
||||
if [[ $1 =~ cn= ]]; then
|
||||
_TAG="$(echo $1 | cut -f2 -d=)"
|
||||
if [ -z "${_TAG}" ]; then
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
ldap_arg="cn=$_TAG"
|
||||
shift
|
||||
# -n parameter
|
||||
else
|
||||
# check if argument from -n exist
|
||||
if [ -z "$2" ]; then
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
_TAG="$2"
|
||||
ldap_arg="cn=$_TAG"
|
||||
shift 2
|
||||
#fi
|
||||
fi
|
||||
;;
|
||||
-h|--help|help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
-v|--version)
|
||||
echo "2022-$(date +Y) $progName $version"
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
echo "${progName}: invalid option -- '$1'!"
|
||||
echo -e "Try '$progName help' for more information.\n"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo $ldap_arg
|
||||
if [ -z "${ldap_arg}" ]; then
|
||||
print_usage
|
||||
else
|
||||
#echo "ldapsearch -x -LLL -H $LDAP_SRV -b \"$LDAP_BASE\" -D \"$LDAP_MANAGER_USER\" -w $LDAP_MANAGER_PASS $ldap_arg"
|
||||
# check that the search result is not null
|
||||
result=$(ldapsearch -x -LLL -H $LDAP_SRV -b "$LDAP_BASE" -D "$LDAP_MANAGER_USER" -w $LDAP_MANAGER_PASS "$ldap_arg")
|
||||
if [ -z "${result}" ]; then
|
||||
echo "Search with $ldap_arg parameter returned no results"
|
||||
else
|
||||
ldapsearch -x -LLL -H $LDAP_SRV -b "$LDAP_BASE" -D "$LDAP_MANAGER_USER" -w $LDAP_MANAGER_PASS "$ldap_arg"
|
||||
fi
|
||||
fi
|
||||
Loading…
x
Reference in New Issue
Block a user