Subversion Repositories ALCASAR

Rev

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

#! /bin/bash
# script test&debug.sh
# by Rexy
# This script is distributed under the Gnu General Public License (GPL)

# This script tests the following behaviour :
# - 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 
# - test if the attribute "Alcasar-Status-Page-Must-Stay-Open" is set to "2", then retrieve the "expiration" attribute
# - (todo) if the "expiration" attribute exists then create a new user (login = user's @MAC) and duplicates all user's attributes 


PASSWD_FILE="/root/ALCASAR-passwords.txt"
USER_NAME="test"
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`

# Retrieve 3 ALCASAR special radius attributes (search order : default group, then user's group, then user)
db_query="SELECT attribute, value FROM ( \
        ( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) UNION \
        ( 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 \
        ( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) \
) attrs GROUP BY attribute;"
db_radreply_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)

filter=$(echo "$db_radreply_res"             | awk '$1 == "Alcasar-Filter"                     { print $2 }')
filterProto=$(echo "$db_radreply_res"        | awk '$1 == "Alcasar-Protocols-Filter"           { print $2 }')
statusOpenRequired=$(echo "$db_radreply_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
echo "USER_NAME = $USER_NAME; filter = $filter; filterproto = $filterProto; statusOpenRequired = $statusOpenRequired";

# If status page isn't required :
if [ "$statusOpenRequired" == '2' ]; then       # Status page is not required
        echo ""
# Retrieve "expiration" attribute from radcheck
db_query="SELECT attribute, value FROM ( \
        ( SELECT attribute, value FROM radcheck WHERE username = '$USER_NAME' AND attribute = 'Expiration' ) UNION \
        ( 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 \
        ( SELECT attribute, value FROM radgroupcheck WHERE groupname = 'default' AND attribute = 'Expiration' ) \
        ) attrs GROUP BY attribute;"
db_radcheck_expiration_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns) 
# if a expiration date exists we retrieve all radreply attributes
        if [ `echo $db_radcheck_expiration_res|wc -l` == '1' ]; then
                echo "###########################"
                echo "## Radreply attributes"
                db_query="SELECT attribute, value FROM ( \
                        ( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' ) UNION \
                        ( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' ORDER BY ug.priority ) UNION \
                        ( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' ) \
                        ) attrs GROUP BY attribute;"
                mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns |  while IFS= read -r loop
                do
                        attr=`echo $loop|cut -d" " -f1`
                        attr_value=`echo $loop|cut -d" " -f2-`
                        echo "$attr = $attr_value"
                done 
# if a expiration date exists we retrieve all radcheck attributes
                echo "## Radcheck attributes"
                db_query="SELECT attribute, value FROM ( \
                ( SELECT attribute, value FROM radcheck WHERE username = '$USER_NAME' ) UNION \
                ( SELECT attribute, value FROM radgroupcheck gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' ORDER BY ug.priority ) UNION \
                ( SELECT attribute, value FROM radgroupcheck WHERE groupname = 'default' ) \
                ) attrs GROUP BY attribute;"
                mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns |  while IFS= read -r loop
                do
                        attr=`echo $loop|cut -d" " -f1`
                        attr_value=`echo $loop|cut -d" " -f2-`
                        echo "$attr = $attr_value"
                done
        fi      
fi