2447 |
richard |
1 |
#!/bin/bash
|
|
|
2 |
|
|
|
3 |
# alcasar-ldap.sh
|
|
|
4 |
# by Rexy
|
|
|
5 |
# This script is distributed under the Gnu General Public License (GPL)
|
|
|
6 |
|
|
|
7 |
# activation / désactivation de l'authentification des utilisateurs via un serveur LDAP externe
|
|
|
8 |
# enable / disable authentication of users via an extern LDAP server
|
|
|
9 |
|
|
|
10 |
usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
|
|
|
11 |
SED="/bin/sed -i"
|
|
|
12 |
CONF_FILE="/usr/local/etc/alcasar.conf"
|
2465 |
richard |
13 |
LDAP_MODULE="/etc/raddb/mods-available/ldap-alcasar"
|
2467 |
richard |
14 |
LDAP_SERVER=`grep ^LDAP_SERVER= $CONF_FILE|cut -d"=" -f2` # IP address of the LDAP server
|
|
|
15 |
LDAP_BASE=`grep ^LDAP_BASE= $CONF_FILE|cut -d"=" -f2-` # Where to find the users (cn=**,dc=**,dc=**)
|
|
|
16 |
LDAP_UID=`grep ^LDAP_UID= $CONF_FILE|cut -d"=" -f2` # 'samaccuntname' for A.D. - 'UID' for LDAP
|
2474 |
tom.houday |
17 |
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2-` # Filter to limit users search (not used for now)
|
2467 |
richard |
18 |
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2-` # LDAP username used by ALCASAR to read the remote directory
|
2474 |
tom.houday |
19 |
LDAP_PASSWORD=`grep ^LDAP_PASSWORD= $CONF_FILE|cut -d"=" -f2-` # its password
|
2447 |
richard |
20 |
nb_args=$#
|
|
|
21 |
args=$1
|
|
|
22 |
if [ $nb_args -eq 0 ]
|
|
|
23 |
then
|
|
|
24 |
nb_args=1
|
|
|
25 |
args="-h"
|
|
|
26 |
fi
|
|
|
27 |
case $args in
|
|
|
28 |
-\? | -h* | --h*)
|
|
|
29 |
echo "$usage"
|
|
|
30 |
exit 0
|
|
|
31 |
;;
|
|
|
32 |
--on | -on)
|
2465 |
richard |
33 |
$SED "s/^LDAP=.*/LDAP=on/g" $CONF_FILE
|
2466 |
richard |
34 |
$SED "s/^server =.*/server = ldap:\/\/$LDAP_SERVER/g" $LDAP_MODULE
|
|
|
35 |
$SED "s/^identity =.*/identity = $LDAP_USER/g" $LDAP_MODULE
|
2465 |
richard |
36 |
$SED "s/^password =.*/password = $LDAP_PASSWORD/g" $LDAP_MODULE
|
2467 |
richard |
37 |
$SED "s/^base_dn =.*/base_dn = \"$LDAP_BASE\"/g" $LDAP_MODULE
|
|
|
38 |
$SED "s/^filter =.*/filter = \"($LDAP_UID=%{%{Stripped-User-Name}:-%{User-Name}})\"/g" $LDAP_MODULE
|
2466 |
richard |
39 |
if [ ! -e /etc/raddb/mods-enabled/ldap ]
|
|
|
40 |
then
|
|
|
41 |
ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
|
|
|
42 |
fi
|
2467 |
richard |
43 |
if [ -e /etc/raddb/sites-enabled/alcasar ]
|
|
|
44 |
then
|
|
|
45 |
rm /etc/raddb/sites-enabled/alcasar
|
|
|
46 |
fi
|
|
|
47 |
ln -s /etc/raddb/sites-available/alcasar-with-ldap /etc/raddb/sites-enabled/alcasar
|
2465 |
richard |
48 |
/usr/bin/systemctl restart radiusd.service
|
2447 |
richard |
49 |
;;
|
|
|
50 |
--off | -off)
|
2465 |
richard |
51 |
$SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
|
|
|
52 |
rm -f /etc/raddb/mods-enabled/ldap
|
2467 |
richard |
53 |
if [ -e /etc/raddb/sites-enabled/alcasar ]
|
|
|
54 |
then
|
|
|
55 |
rm /etc/raddb/sites-enabled/alcasar
|
|
|
56 |
fi
|
|
|
57 |
ln -s /etc/raddb/sites-available/alcasar /etc/raddb/sites-enabled/alcasar
|
2465 |
richard |
58 |
/usr/bin/systemctl restart radiusd.service
|
2474 |
tom.houday |
59 |
;;
|
2447 |
richard |
60 |
*)
|
2474 |
tom.houday |
61 |
echo "Argument inconnu : $1";
|
2447 |
richard |
62 |
echo "$usage"
|
|
|
63 |
exit 1
|
|
|
64 |
;;
|
|
|
65 |
esac
|