#!/bin/bash

# vcelka-maja.sh is simple script usefull for testing of proxying of interal EAP identity.
#
# Author: Jan Tomášek <jan.tomasek@cesnet.cz>, <jan@tomasek.cz>
# Copyright (c) 2008, CESNET, z.s.p.o.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

# Load configuration
if [ ! -f /etc/vcelka-maja.conf ]
then
  echo "Missing configuration /etc/vcelka-maja.conf";
  exit 1;
fi

. /etc/vcelka-maja.conf

# Test if configuration is valid and that we have working rad_eap_test
# script available.

echo -n "Testing testing account: "
$RAD_EAP_TEST -H $SRV -P 1812 -S $SECRET -m WPA-EAP -e TTLS -u $TUSER -p $PASSWORD
if [ $? != 0 ]
then
  echo "Need correct testing account for operation. $TUSER/$PASSWORD isn't working."
  exit 1;
fi

# If posible, create random fake user identity which will be used in
# this run.

AID=`pwgen -n 20 1 2>/dev/null`

if [ "x$AID" == "x"  ]
then
  echo "Missing pwgen will use static fake username = vcelka-maja."
  AID="vcelka-maja"
fi

# Proceeed in testing - expecting realms to be passed on std input.

while read REALM
do
  echo -n "Testing TTLS $REALM: "
  $RAD_EAP_TEST -H $SRV -P 1812 -S $SECRET -m WPA-EAP -e TTLS -u $TUSER -p $PASSWORD -A $AID@$REALM -i "vcelka-maja test" -t 15
  sleep 2;
  echo -n "Testing PEAP $REALM: "
  $RAD_EAP_TEST -H $SRV -P 1812 -S $SECRET -m WPA-EAP -e PEAP -u $TUSER -p $PASSWORD -A $AID@$REALM -i "vcelka-maja test" -t 15
  sleep 2;
done