Subversion Repositories ALCASAR

Rev

Rev 2447 | Rev 2466 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2447 Rev 2465
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
3
# alcasar-ldap.sh
3
# alcasar-ldap.sh
4
# by Rexy
4
# by Rexy
5
# This script is distributed under the Gnu General Public License (GPL)
5
# This script is distributed under the Gnu General Public License (GPL)
6
 
6
 
7
# activation / désactivation de l'authentification des utilisateurs via un serveur LDAP externe
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
8
# enable / disable authentication of users via an extern LDAP server
9
 
9
 
10
# TODO
10
# TODO
11
#		- modif files "site-enabled/alcasar" + "mods-available/ldap"
11
#		- modif files "site-enabled/alcasar" + "mods-available/ldap"
12
#		- add / remove "ln -s mods-available/ldap mods-enabled/ldap"
12
#		- add / remove "ln -s mods-available/ldap mods-enabled/ldap"
13
#       - /usr/local/bin/alcasar-iptables.sh");
13
#       - /usr/local/bin/alcasar-iptables.sh");
14
#       - /usr/bin/systemctl restart radiusd");
14
#       - /usr/bin/systemctl restart radiusd");
15
 
15
 
16
# Modif "sites-enabled/alcasar"
16
# Modif "sites-enabled/alcasar"
17
#	Configure autorize section with:
17
#	Configure autorize section with:
18
#		ldap  { 
18
#		ldap  { 
19
#			fail=1
19
#			fail=1
20
#		}
20
#		}
21
#	Configure authenticate section with
21
#	Configure authenticate section with
22
#		Auth-Type LDAP {
22
#		Auth-Type LDAP {
23
#			ldap
23
#			ldap
24
#		}
24
#		}
25
 
25
 
26
# Modif "mods-available/ldap"
26
# Modif "mods-available/ldap"
27
#	host = $ldap_server;
27
#	host = $ldap_server;
28
#	identity = $ldap_user;
28
#	identity = $ldap_user;
29
#	password = $ldap_password;
29
#	password = $ldap_password;
30
#	basedn = $ldap_base_dn;
30
#	basedn = $ldap_base_dn;
31
#	filter = $ldap_filter;
31
#	filter = $ldap_filter;
32
#	uid = $ldap_filter;
32
#	uid = $ldap_filter;
33
#	base_filter = $ldap_base_filter;
33
#	base_filter = $ldap_base_filter;
34
 
34
 
35
usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
35
usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
36
SED="/bin/sed -i"
36
SED="/bin/sed -i"
37
CONF_FILE="/usr/local/etc/alcasar.conf"
37
CONF_FILE="/usr/local/etc/alcasar.conf"
-
 
38
LDAP_MODULE="/etc/raddb/mods-available/ldap-alcasar"
38
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`				# INTernal InterFace
39
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`				# INTernal InterFace
-
 
40
LDAP_SERVER=`grep ^LDAP_SERVER= $CONF_FILE|cut -d"=" -f2`
-
 
41
LDAP_BASE=`grep ^LDAP_BASE= $CONF_FILE|cut -d"=" -f2`
-
 
42
LDAP_UID=`grep ^LDAP_UID= $CONF_FILE|cut -d"=" -f2`
-
 
43
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2`
-
 
44
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2`
-
 
45
LDAP_PASSWORD=`grep ^LDAP_PASSWORD= $CONF_FILE|cut -d"=" -f2`
39
 
-
 
40
nb_args=$#
46
nb_args=$#
41
args=$1
47
args=$1
42
if [ $nb_args -eq 0 ]
48
if [ $nb_args -eq 0 ]
43
then
49
then
44
	nb_args=1
50
	nb_args=1
45
	args="-h"
51
	args="-h"
46
fi
52
fi
47
case $args in
53
case $args in
48
	-\? | -h* | --h*)
54
	-\? | -h* | --h*)
49
		echo "$usage"
55
		echo "$usage"
50
		exit 0
56
		exit 0
51
		;;
57
		;;
52
	--on | -on)	
58
	--on | -on)	
-
 
59
		$SED "s/^LDAP=.*/LDAP=on/g" $CONF_FILE
-
 
60
		$SED "s/^server =.*/server = ldap://$LDAP_SERVER/g" $LDAP_MODULE
-
 
61
		$SED "s/^identity =.*/identity = $LDAP_UID/g" $LDAP_MODULE
-
 
62
		$SED "s/^password =.*/password = $LDAP_PASSWORD/g" $LDAP_MODULE
-
 
63
		$SED "s/^base_dn =.*/base_dn = $LDAP_BASE/g" $LDAP_MODULE
-
 
64
		$SED "s/^filter =.*/filter = ($LDAP_UID=%{%{Stripped-User-Name}:-%{User-Name}})/g" $LDAP_MODULE
-
 
65
		ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
-
 
66
		/usr/bin/systemctl restart radiusd.service
53
		;;
67
		;;
54
	--off | -off)
68
	--off | -off)
-
 
69
		$SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
-
 
70
		rm -f /etc/raddb/mods-enabled/ldap
-
 
71
		/usr/bin/systemctl restart radiusd.service
55
;;
72
;;
56
	*)
73
	*)
57
		echo "Argument inconnu :$1";
74
		echo "Argument inconnu :$1";
58
		echo "$usage"
75
		echo "$usage"
59
		exit 1
76
		exit 1
60
		;;
77
		;;
61
esac
78
esac
62
 
79