#!/bin/sh
# Script to check a jail status
# Args $1 = IP
######################################################################

# Source our functions
PROGDIR="`pbreg get /PC-BSD/TheWarden/ProgDir`"

if [ -z "${PROGDIR}" ]
then
   echo "PROGDIR unset! Is The Warden installed properly?"
   exit 155
fi

# Source our variables
. ${PROGDIR}/conf/warden.conf


IP="$1"

if [ -z "$IP" ]
then
  echo "ERROR: You must specify an IP to check"
  exit 5
fi

if [ -z "${JDIR}" ]
then
  echo "ERROR: JDIR is unset!!!!"
  exit 5
fi

if [ ! -d "${JDIR}/${IP}" ]
then
  echo "ERROR: No jail located at $JDIR/$IP"
  exit 5
fi

# End of error checking, now see if the jail is active
#####################################################################

# Check if the jail is active
jls | grep ${IP} >/dev/null 2>/dev/null
if [ "$?" = "0" ]
then
  exit 0
else
  exit 1
fi



