mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 00:37:00 +08:00
130 lines
3.1 KiB
Bash
Executable File
130 lines
3.1 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (C) 2014 Red Hat
|
|
#
|
|
# This file is part of ocserv.
|
|
#
|
|
# ocserv is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by the
|
|
# Free Software Foundation; either version 2 of the License, or (at
|
|
# your option) any later version.
|
|
#
|
|
# ocserv is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with ocserv; if not, write to the Free Software Foundation,
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
srcdir=${srcdir:-.}
|
|
|
|
PORT_OCSERV=443
|
|
#this test can only be run as root
|
|
id|grep root >/dev/null 2>&1
|
|
if [ $? != 0 ];then
|
|
exit 77
|
|
fi
|
|
|
|
CONFIG="radius-config"
|
|
IMAGE=ocserv-radius-test-config
|
|
IMAGE_NAME=test_ocserv_radius_config
|
|
TMP=$IMAGE_NAME.tmp
|
|
. ./docker-common.sh
|
|
|
|
$DOCKER run -e OCCTL_PAGER=cat -P --privileged=true --tty=false -d --name $IMAGE_NAME $IMAGE
|
|
if test $? != 0;then
|
|
echo "Cannot run docker image"
|
|
exit 1
|
|
fi
|
|
|
|
echo "ocserv image was run"
|
|
#wait for ocserv to server
|
|
sleep 5
|
|
|
|
IP=`$DOCKER inspect $IMAGE_NAME | grep IPAddress | cut -d '"' -f 4`
|
|
if test -z "$IP";then
|
|
echo "Detected IP is null!"
|
|
stop
|
|
fi
|
|
echo "Detected IP: $IP"
|
|
|
|
if test ! -z "$QUIT_ON_INIT";then
|
|
exit 0
|
|
fi
|
|
|
|
echo "Trying with correct password"
|
|
echo "test" >pass-radius$TMP
|
|
$OPENCONNECT $IP:$PORT_OCSERV -b -u testtime --passwd-on-stdin -v --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --pid-file ${srcdir}/pid1.$$ <pass-radius$TMP
|
|
if test $? != 0;then
|
|
echo "Cannot connect to server"
|
|
stop
|
|
fi
|
|
|
|
#wait for openconnect
|
|
sleep 5
|
|
|
|
rm -f pass-radius$TMP
|
|
|
|
if [ ! -f ${srcdir}/pid1.$$ ];then
|
|
echo "It was not possible to establish session!"
|
|
stop
|
|
fi
|
|
PID=`cat ${srcdir}/pid1.$$`
|
|
|
|
# The client IP depends on the username so it shouldn't change.
|
|
ping -w 5 192.168.66.1
|
|
if test $? != 0;then
|
|
kill $PID
|
|
echo "Cannot ping ocserv"
|
|
stop
|
|
fi
|
|
|
|
#check whether the routes have been applied
|
|
retrieve_route_info testtime '10.154.92.0/24'
|
|
|
|
echo "Waiting for accounting report"
|
|
|
|
sleep 75
|
|
|
|
FILE=`$DOCKER exec $IMAGE_NAME ls /var/log/radius/radacct/127.0.0.1/`
|
|
|
|
OCTETS=`$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE"|grep Acct-Input-Octets|tail -1|sed 's/Acct-Input-Octets = //g'`
|
|
if test -z "$OCTETS" || test "$OCTETS" = 0;then
|
|
kill $PID
|
|
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE"
|
|
echo "Interim update showed no data!"
|
|
stop
|
|
fi
|
|
|
|
#wait until sec-mod has cleaned up its entries
|
|
echo "Waiting for disconnection report"
|
|
sleep 75
|
|
|
|
rm -f out$TMP
|
|
$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE" >out$TMP
|
|
|
|
DISC=`cat out$TMP|grep "Acct-Status-Type = Start"|tail -1`
|
|
if test -z "$DISC";then
|
|
kill $PID
|
|
cat out$TMP
|
|
echo "No connect status was detected!"
|
|
stop
|
|
fi
|
|
|
|
DISC=`cat out$TMP|grep "Acct-Terminate-Cause = Session-Timeout"|tail -1`
|
|
if test -z "$DISC";then
|
|
cat out$TMP
|
|
kill -INT $PID
|
|
echo "No disconnect was detected!"
|
|
stop
|
|
fi
|
|
|
|
$DOCKER stop $IMAGE_NAME
|
|
$DOCKER rm $IMAGE_NAME
|
|
|
|
rm -f out$TMP
|
|
|
|
exit $ret
|