Subversion Repositories ALCASAR

Rev

Rev 2466 | Rev 2474 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

#!/bin/bash

# alcasar-ldap.sh
# by Rexy
# This script is distributed under the Gnu General Public License (GPL)

# activation / désactivation de l'authentification des utilisateurs via un serveur LDAP externe
# enable / disable authentication of users via an extern LDAP server

usage="Usage: alcasar-ldap.sh {--on or -on } | {--off or -off}"
SED="/bin/sed -i"
CONF_FILE="/usr/local/etc/alcasar.conf"
LDAP_MODULE="/etc/raddb/mods-available/ldap-alcasar"
LDAP_SERVER=`grep ^LDAP_SERVER= $CONF_FILE|cut -d"=" -f2`               # IP address of the LDAP server
LDAP_BASE=`grep ^LDAP_BASE= $CONF_FILE|cut -d"=" -f2-`                  # Where to find the users (cn=**,dc=**,dc=**)
LDAP_UID=`grep ^LDAP_UID= $CONF_FILE|cut -d"=" -f2`                             # 'samaccuntname' for A.D. - 'UID' for LDAP
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2`               # Filter to limit users search (not used for now)
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2-`                  # LDAP username used by ALCASAR to read the remote directory
LDAP_PASSWORD=`grep ^LDAP_PASSWORD= $CONF_FILE|cut -d"=" -f2`   # its password
nb_args=$#
args=$1
if [ $nb_args -eq 0 ]
then
        nb_args=1
        args="-h"
fi
case $args in
        -\? | -h* | --h*)
                echo "$usage"
                exit 0
                ;;
        --on | -on)     
                $SED "s/^LDAP=.*/LDAP=on/g" $CONF_FILE
                $SED "s/^server =.*/server = ldap:\/\/$LDAP_SERVER/g" $LDAP_MODULE
                $SED "s/^identity =.*/identity = $LDAP_USER/g" $LDAP_MODULE
                $SED "s/^password =.*/password = $LDAP_PASSWORD/g" $LDAP_MODULE
                $SED "s/^base_dn =.*/base_dn = \"$LDAP_BASE\"/g" $LDAP_MODULE
                $SED "s/^filter =.*/filter = \"($LDAP_UID=%{%{Stripped-User-Name}:-%{User-Name}})\"/g" $LDAP_MODULE
                if [ ! -e /etc/raddb/mods-enabled/ldap ]
                then
                        ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
                fi
                if [ -e /etc/raddb/sites-enabled/alcasar ]
                then
                        rm /etc/raddb/sites-enabled/alcasar
                fi
                ln -s /etc/raddb/sites-available/alcasar-with-ldap /etc/raddb/sites-enabled/alcasar
                /usr/local/bin/alcasar-iptables.sh
                /usr/bin/systemctl restart radiusd.service
                ;;
        --off | -off)
                $SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
                rm -f /etc/raddb/mods-enabled/ldap
                if [ -e /etc/raddb/sites-enabled/alcasar ]
                then
                        rm /etc/raddb/sites-enabled/alcasar
                fi
                ln -s /etc/raddb/sites-available/alcasar /etc/raddb/sites-enabled/alcasar
                /usr/local/bin/alcasar-iptables.sh
                /usr/bin/systemctl restart radiusd.service
;;
        *)
                echo "Argument inconnu :$1";
                echo "$usage"
                exit 1
                ;;
esac