Subversion Repositories ALCASAR

Rev

Rev 2465 | Rev 2467 | 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
# TODO
2466 richard 11
#	- modif files "site-enabled/alcasar"
2447 richard 12
 
13
# Modif "sites-enabled/alcasar"
14
#	Configure autorize section with:
15
#		ldap  { 
16
#			fail=1
17
#		}
18
#	Configure authenticate section with
19
#		Auth-Type LDAP {
20
#			ldap
21
#		}
22
 
23
usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
24
SED="/bin/sed -i"
25
CONF_FILE="/usr/local/etc/alcasar.conf"
2465 richard 26
LDAP_MODULE="/etc/raddb/mods-available/ldap-alcasar"
2466 richard 27
LDAP_SERVER=`grep ^LDAP_SERVER= $CONF_FILE|cut -d"=" -f2`	# IP address of the LDAP server
28
LDAP_BASE=`grep ^LDAP_BASE= $CONF_FILE|cut -d"=" -f2-`		# Where to find the users (cn=**,dc=**,dc=**)
29
LDAP_UID=`grep ^LDAP_UID= $CONF_FILE|cut -d"=" -f2`		# 'samaccuntname' for A.D. - 'UID' for LDAP
30
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2`	# Filter to limit users search (not used for now)
31
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2`		# User name enable to list the directory
32
LDAP_PASSWORD=`grep ^LDAP_PASSWORD= $CONF_FILE|cut -d"=" -f2`	#
2447 richard 33
nb_args=$#
34
args=$1
35
if [ $nb_args -eq 0 ]
36
then
37
	nb_args=1
38
	args="-h"
39
fi
40
case $args in
41
	-\? | -h* | --h*)
42
		echo "$usage"
43
		exit 0
44
		;;
45
	--on | -on)
2465 richard 46
		$SED "s/^LDAP=.*/LDAP=on/g" $CONF_FILE
2466 richard 47
		$SED "s/^server =.*/server = ldap:\/\/$LDAP_SERVER/g" $LDAP_MODULE
48
		$SED "s/^identity =.*/identity = $LDAP_USER/g" $LDAP_MODULE
2465 richard 49
		$SED "s/^password =.*/password = $LDAP_PASSWORD/g" $LDAP_MODULE
50
		$SED "s/^base_dn =.*/base_dn = $LDAP_BASE/g" $LDAP_MODULE
51
		$SED "s/^filter =.*/filter = ($LDAP_UID=%{%{Stripped-User-Name}:-%{User-Name}})/g" $LDAP_MODULE
2466 richard 52
		if [ ! -e /etc/raddb/mods-enabled/ldap ]
53
		then
54
			ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
55
		fi
56
		/usr/local/bin/alcasar-iptables.sh
2465 richard 57
		/usr/bin/systemctl restart radiusd.service
2447 richard 58
		;;
59
	--off | -off)
2465 richard 60
		$SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
61
		rm -f /etc/raddb/mods-enabled/ldap
2466 richard 62
		/usr/local/bin/alcasar-iptables.sh
2465 richard 63
		/usr/bin/systemctl restart radiusd.service
2447 richard 64
;;
65
	*)
66
		echo "Argument inconnu :$1";
67
		echo "$usage"
68
		exit 1
69
		;;
70
esac