#!/system/bin/sh

if [ "$1"x = "-h"x -o "$1"x = "--help"x ] ; then
  echo "Usage: $0 [status]"
  echo
  echo "Without parameter the script starts the VPN if it is not running or stops the VPN if it is running"
  echo
  exit 0
elif [ "$1"x = "status"x ] ; then
  netstat -rn | grep "^0.0.0.0" | grep tun0 >/dev/null
  if [ $? -eq 0 ] ; then
    echo "The VPN is running "
    exit 0
  else
    echo "The VPN is not running"
    exit 1
  fi
elif [ $# -ne 0 ] ; then
  echo "ERROR: Unknown parameter found: \"$*\"  "
  exit 5
else
  tty -s && P="-i" || P=""
  su - $P  -c sh /data/adb/modules/openvpn/action.sh
fi

