#! /bin/sh
# asks pluto for current connection status
# Copyright (C) 2017  Samir Hussain
#
# This program 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program 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.
#

me="ipsec status"
case "$1" in
--help)		echo "Usage: ipsec status" ; exit 0	;;
--version)	echo "$me $IPSEC_VERSION"  ; exit 0	;;
esac

connection=$1

if [ -z ${connection} ];
then
    # if the user does not provide a connection name: e.g. ipsec status
    ipsec whack --status
else
    # if the user provides a connection name: e.g. ipsec status mytunnel
    ipsec whack --status | grep -wE "\"${connection}(/[0-9]+x[0-9]+)?\":"
fi

