Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
2896 rexy 1
#! /bin/bash
2
# script test&debug.sh
3
# by Rexy
4
# This script is distributed under the Gnu General Public License (GPL)
5
 
6
# This script tests the following behaviour :
7
# - Retreive 3 special attributes of a user ('test' by default). It Retrieves theses attributes from default group, then from user's group, then from its account 
8
# - test if the attribute "Alcasar-Status-Page-Must-Stay-Open" is set to "2", then retrieve the "expiration" attribute
2971 rexy 9
# - (todo) if the "expiration" attribute exists then create a new user (login = user's @MAC) and duplicates all user's attributes 
2896 rexy 10
 
11
 
12
PASSWD_FILE="/root/ALCASAR-passwords.txt"
13
USER_NAME="test"
14
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
15
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`
16
 
17
# Retrieve 3 ALCASAR special radius attributes (search order : default group, then user's group, then user)
18
db_query="SELECT attribute, value FROM ( \
19
 	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) UNION \
20
	( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ORDER BY ug.priority ) UNION \
21
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) \
22
) attrs GROUP BY attribute;"
23
db_radreply_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)
24
 
25
filter=$(echo "$db_radreply_res"             | awk '$1 == "Alcasar-Filter"                     { print $2 }')
26
filterProto=$(echo "$db_radreply_res"        | awk '$1 == "Alcasar-Protocols-Filter"           { print $2 }')
27
statusOpenRequired=$(echo "$db_radreply_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
28
echo "USER_NAME = $USER_NAME; filter = $filter; filterproto = $filterProto; statusOpenRequired = $statusOpenRequired";
29
 
30
# If status page isn't required :
31
if [ "$statusOpenRequired" == '2' ]; then	# Status page is not required
32
	echo ""
33
# Retrieve "expiration" attribute from radcheck
34
db_query="SELECT attribute, value FROM ( \
35
 	( SELECT attribute, value FROM radcheck WHERE username = '$USER_NAME' AND attribute = 'Expiration' ) UNION \
36
	( SELECT attribute, value FROM radgroupcheck gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' AND attribute = 'Expiration' ORDER BY ug.priority ) UNION \
37
	( SELECT attribute, value FROM radgroupcheck WHERE groupname = 'default' AND attribute = 'Expiration' ) \
38
	) attrs GROUP BY attribute;"
39
db_radcheck_expiration_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns) 
40
# if a expiration date exists we retrieve all radreply attributes
41
	if [ `echo $db_radcheck_expiration_res|wc -l` == '1' ]; then
42
		echo "###########################"
2971 rexy 43
		echo "## Radreply attributes"
2896 rexy 44
		db_query="SELECT attribute, value FROM ( \
45
 			( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' ) UNION \
46
			( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' ORDER BY ug.priority ) UNION \
47
			( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' ) \
48
			) attrs GROUP BY attribute;"
2971 rexy 49
		mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns |  while IFS= read -r loop
2896 rexy 50
		do
51
			attr=`echo $loop|cut -d" " -f1`
52
			attr_value=`echo $loop|cut -d" " -f2-`
53
			echo "$attr = $attr_value"
54
		done 
55
# if a expiration date exists we retrieve all radcheck attributes
2971 rexy 56
		echo "## Radcheck attributes"
2896 rexy 57
		db_query="SELECT attribute, value FROM ( \
58
		( SELECT attribute, value FROM radcheck WHERE username = '$USER_NAME' ) UNION \
59
		( SELECT attribute, value FROM radgroupcheck gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' ORDER BY ug.priority ) UNION \
60
		( SELECT attribute, value FROM radgroupcheck WHERE groupname = 'default' ) \
61
		) attrs GROUP BY attribute;"
2971 rexy 62
		mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns |  while IFS= read -r loop
2896 rexy 63
		do
64
			attr=`echo $loop|cut -d" " -f1`
65
			attr_value=`echo $loop|cut -d" " -f2-`
66
			echo "$attr = $attr_value"
67
		done
68
	fi	
69
fi