Subversion Repositories ALCASAR

Rev

Rev 2447 | Rev 2466 | 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

# TODO
#               - modif files "site-enabled/alcasar" + "mods-available/ldap"
#               - add / remove "ln -s mods-available/ldap mods-enabled/ldap"
#       - /usr/local/bin/alcasar-iptables.sh");
#       - /usr/bin/systemctl restart radiusd");

# Modif "sites-enabled/alcasar"
#       Configure autorize section with:
#               ldap  { 
#                       fail=1
#               }
#       Configure authenticate section with
#               Auth-Type LDAP {
#                       ldap
#               }

# Modif "mods-available/ldap"
#       host = $ldap_server;
#       identity = $ldap_user;
#       password = $ldap_password;
#       basedn = $ldap_base_dn;
#       filter = $ldap_filter;
#       uid = $ldap_filter;
#       base_filter = $ldap_base_filter;

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"
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2`                           # INTernal InterFace
LDAP_SERVER=`grep ^LDAP_SERVER= $CONF_FILE|cut -d"=" -f2`
LDAP_BASE=`grep ^LDAP_BASE= $CONF_FILE|cut -d"=" -f2`
LDAP_UID=`grep ^LDAP_UID= $CONF_FILE|cut -d"=" -f2`
LDAP_FILTER=`grep ^LDAP_FILTER= $CONF_FILE|cut -d"=" -f2`
LDAP_USER=`grep ^LDAP_USER= $CONF_FILE|cut -d"=" -f2`
LDAP_PASSWORD=`grep ^LDAP_PASSWORD= $CONF_FILE|cut -d"=" -f2`
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_UID/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
                ln -s $LDAP_MODULE /etc/raddb/mods-enabled/ldap
                /usr/bin/systemctl restart radiusd.service
                ;;
        --off | -off)
                $SED "s/^LDAP=.*/LDAP=off/g" $CONF_FILE
                rm -f /etc/raddb/mods-enabled/ldap
                /usr/bin/systemctl restart radiusd.service
;;
        *)
                echo "Argument inconnu :$1";
                echo "$usage"
                exit 1
                ;;
esac