Subversion Repositories ALCASAR

Rev

Rev 2466 | Rev 2470 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
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
17
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2`		# Filter to limit users search (not used for now)
18
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2-`			# LDAP username used by ALCASAR to read the remote directory
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
2466 richard 48
		/usr/local/bin/alcasar-iptables.sh
2465 richard 49
		/usr/bin/systemctl restart radiusd.service
2447 richard 50
		;;
51
	--off | -off)
2465 richard 52
		$SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
53
		rm -f /etc/raddb/mods-enabled/ldap
2467 richard 54
		if [ -e /etc/raddb/sites-enabled/alcasar ]
55
		then
56
			rm /etc/raddb/sites-enabled/alcasar
57
		fi
58
		ln -s /etc/raddb/sites-available/alcasar /etc/raddb/sites-enabled/alcasar
2466 richard 59
		/usr/local/bin/alcasar-iptables.sh
2465 richard 60
		/usr/bin/systemctl restart radiusd.service
2447 richard 61
;;
62
	*)
63
		echo "Argument inconnu :$1";
64
		echo "$usage"
65
		exit 1
66
		;;
67
esac