Subversion Repositories ALCASAR

Rev

Rev 2223 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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