Subversion Repositories ALCASAR

Rev

Rev 2223 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2223 tom.houday 1
#!/bin/bash
63 franck 2
# $Id: alcasar-logout.sh 2412 2017-09-17 12:11:23Z tom.houdayer $
3
 
672 richard 4
# alcasar-logout.sh
790 richard 5
# by Rexy
672 richard 6
# This script is distributed under the Gnu General Public License (GPL)
7
 
8
# Déconnexion d'un ou de tous les usagers
840 richard 9
# Logout one user (or all users)
672 richard 10
 
2412 tom.houday 11
PASSWD_FILE="/root/ALCASAR-passwords.txt"
12
RADIUS_SECRET=$(grep '^secret_radius=' $PASSWD_FILE | cut -d'=' -f 2-)
597 richard 13
OLDIFS=$IFS
14
IFS=$'\n'
1 root 15
 
597 richard 16
usage="Usage: alcasar-logout.sh {user_name} | {all}"
1 root 17
nb_args=$#
18
args=$1
19
if [ $nb_args -eq 0 ]
20
then
21
	nb_args=1
22
	args="-h"
23
fi
24
case $args in
25
	-\? | -h* | --h*)
26
		echo "$usage"
27
		exit 0
28
		;;
597 richard 29
	all)
840 richard 30
# Compute each equipments known by chilli
597 richard 31
		for system in `/usr/sbin/chilli_query list |grep -v "\.0\.0\.0"`
32
		do
840 richard 33
			logout_users=""
597 richard 34
			active_session=`echo $system |cut -d" " -f5`
840 richard 35
			active_user=`echo $system|cut -d" " -f6`
597 richard 36
			active_mac=`echo $system | cut -d" " -f1`
840 richard 37
# Logout only authenticated users 
597 richard 38
			if [[ $(expr $active_session) -eq 1 ]]
39
			then
840 richard 40
# Don't logout MAC authenticated 
41
				if [ "$active_mac" != "$active_user" ]
789 richard 42
				then
840 richard 43
					logout_users=$logout_users" $active_user"
789 richard 44
					/usr/sbin/chilli_query logout $active_mac
45
				fi
597 richard 46
			fi
47
		done
840 richard 48
		echo "All users are now logout : ($logout_users)"
597 richard 49
		;;
1 root 50
	*)
2412 tom.houday 51
		echo "User-Name = $args" | /usr/bin/radclient 127.0.0.1:3799 40 $RADIUS_SECRET
1 root 52
		;;
53
esac
597 richard 54
IFS=$OLDIFS
1 root 55