Subversion Repositories ALCASAR

Rev

Rev 2447 | Rev 2466 | 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
11
#		- modif files "site-enabled/alcasar" + "mods-available/ldap"
12
#		- add / remove "ln -s mods-available/ldap mods-enabled/ldap"
13
#       - /usr/local/bin/alcasar-iptables.sh");
14
#       - /usr/bin/systemctl restart radiusd");
15
 
16
# Modif "sites-enabled/alcasar"
17
#	Configure autorize section with:
18
#		ldap  { 
19
#			fail=1
20
#		}
21
#	Configure authenticate section with
22
#		Auth-Type LDAP {
23
#			ldap
24
#		}
25
 
26
# Modif "mods-available/ldap"
27
#	host = $ldap_server;
28
#	identity = $ldap_user;
29
#	password = $ldap_password;
30
#	basedn = $ldap_base_dn;
31
#	filter = $ldap_filter;
32
#	uid = $ldap_filter;
33
#	base_filter = $ldap_base_filter;
34
 
35
usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
36
SED="/bin/sed -i"
37
CONF_FILE="/usr/local/etc/alcasar.conf"
2465 richard 38
LDAP_MODULE="/etc/raddb/mods-available/ldap-alcasar"
2447 richard 39
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`				# INTernal InterFace
2465 richard 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`
2447 richard 46
nb_args=$#
47
args=$1
48
if [ $nb_args -eq 0 ]
49
then
50
	nb_args=1
51
	args="-h"
52
fi
53
case $args in
54
	-\? | -h* | --h*)
55
		echo "$usage"
56
		exit 0
57
		;;
58
	--on | -on)	
2465 richard 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
2447 richard 67
		;;
68
	--off | -off)
2465 richard 69
		$SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
70
		rm -f /etc/raddb/mods-enabled/ldap
71
		/usr/bin/systemctl restart radiusd.service
2447 richard 72
;;
73
	*)
74
		echo "Argument inconnu :$1";
75
		echo "$usage"
76
		exit 1
77
		;;
78
esac