#!/bin/sh
#
# showcfg: Displays the IP settings for this Coyote Gateway computer.
# Changed by: Claudio Roberto Cussuol - 08-07-2004

if [ "$1" != "-w" ]; then
clear
RED=`echo -en "\\033[1;31m"`
YELLOW=`echo -en "\\033[1;33m"`
GREEN=`echo -en "\\033[1;32m"`
NORM=`echo -en "\\033[0;39m"`
fi

echo "Coyote running configuration display utility."
echo

# Load the master coyote configuration file
if [ -f /etc/coyote/coyote.conf ]; then
	. /etc/coyote/coyote.conf
else
	echo "${YELLOW}ERROR${NORM}: Unable to load Coyote configuration file."
	exit
fi

# Check the status of the network subsystems
if [ -f /tmp/netsubsys.state ]; then
	. /tmp/netsubsys.state
else
	echo "${YELLOW}ERROR${NORM}: Unable to determine the state of the network subsystems."
	exit
fi

status () {
case $1 in
	LAN) case $LOCAL_UP in
		UP) STATUS="$GREEN";;
		DOWN) STATUS="$RED";;
		*) STATUS="$YELLOW";;
	     esac;;
	DMZ) case $DMZ_UP in
		UP) STATUS="$GREEN";;
		DOWN) STATUS="$RED";;
		*) STATUS="$YELLOW";;
	     esac;;
	WAN) case $INET_UP in
		UP) STATUS="$GREEN";;
		DOWN) STATUS="$RED";;
		*) STATUS="$YELLOW";;
	     esac;;
	  *) STATUS="$YELLOW";;
esac
}

status WAN; echo "Internet    (${IF_INET}): ${STATUS}${INET_UP}${NORM}"
status LAN; echo "LAN network (${IF_LOCAL}): ${STATUS}${LOCAL_UP}${NORM}"
[ ! -z $DMZ_IPADDR ] && status DMZ && echo "DMZ network (${IF_DMZ}): ${STATUS}${DMZ_UP}${NORM}"
echo

if [ "${INET_UP}" != "UP" ] || [ "${LOCAL_UP}" != "UP" ] || [ ! -z "$DMZ_IPADDR" -a "${DMZ_UP}" != "UP" ]; then
	echo "${YELLOW}ERROR${NORM}: One or more of the following network subsystems are down."
	echo
	#exit
fi

UPTIME=`uptime`

# status WAN; echo "----------------${STATUS}WAN configuration${NORM}----------------"
status WAN; echo "-------------${STATUS}Internet configuration${NORM}--------------"
# If the DHCP configuration file exists, load it
case "$INETTYPE" in
	"ETHERNET_DHCP")
		if [ -f /etc/dhcpc/$IF_INET.info ]; then
			. /etc/dhcpc/$IF_INET.info 2>/dev/null
			echo "IP Address   ${dhcp_ip} (DHCP Assigned)"
			eval `ipcalc -m ${dhcp_ip}/${dhcp_mask}`
			echo "Netmask      ${NETMASK}"
			echo "Gateway      ${dhcp_router}"
		else
			echo "ERROR: Unable to load DHCP client information."
			exit
		fi
		;;
	"ETHERNET_STATIC")
		if [ ! -z ${IPADDR2} ] || [ ! -z ${IPADDR3} ]; then
			echo "IP Address   ${IPADDR} / ${NETMASK} (Static)"
		else
			echo "IP Address   ${IPADDR} (Static)"
		fi
		[ ! -z ${IPADDR2} ] && echo "Secondary IP ${IPADDR2} / ${NETMASK2}"
		[ ! -z ${IPADDR3} ] && echo "Secondary IP ${IPADDR3} / ${NETMASK3}"
		[ ! -z ${IPADDR2} ] || [ ! -z ${IPADDR3} ] || echo "Netmask      ${NETMASK}"
		echo "Gateway      ${GATEWAY}"
		;;
	"PPP"|"PPPOE")
		PPPIP=`getifaddr ppp0`
		if [ $? = 0 ]; then
			echo "PPP Assigned IP Address: $PPPIP"
			[ -n "$CONNECTTIME" ]   && echo "Connected Since........: $CONNECTTIME"
			[ -n "$CONNECTSTRING" ] && echo "Connect String.........: $CONNECTSTRING"
		else
			echo "Unable to obtain IP Address for PPP Interface, it may currently be offline."
		fi
		;;

	*)
		echo "Your Internet connection type ( ${INETTYPE} ) is not currently supported by this utility."
		;;
esac

status LAN; echo "----------------${STATUS}LAN configuration${NORM}----------------"
if [ ! -z ${LOCAL_IPADDR2} ] || [ ! -z ${LOCAL_IPADDR3} ]; then
	echo "IP Address   ${LOCAL_IPADDR} / ${LOCAL_NETMASK}"
else
	echo "IP Address   ${LOCAL_IPADDR}"
fi
[ ! -z ${LOCAL_IPADDR2} ] && echo "Secondary IP ${LOCAL_IPADDR2} / ${LOCAL_NETMASK2}"
[ ! -z ${LOCAL_IPADDR3} ] && echo "Secondary IP ${LOCAL_IPADDR3} / ${LOCAL_NETMASK3}"
[ ! -z ${LOCAL_IPADDR2} ] || [ ! -z ${LOCAL_IPADDR3} ] || echo "Netmask      ${LOCAL_NETMASK}"
echo "Broadcast    ${LOCAL_BROADCAST}"

if [ ! -z $DMZ_IPADDR ]; then
status DMZ; echo "----------------${STATUS}DMZ configuration${NORM}----------------"
if [ ! -z ${DMZ_IPADDR2} ] || [ ! -z ${DMZ_IPADDR3} ]; then
	echo "IP Address   ${DMZ_IPADDR} / ${DMZ_NETMASK}"
else
	echo "IP Address   ${DMZ_IPADDR}"
fi
[ ! -z ${DMZ_IPADDR2} ] && echo "Secondary IP ${DMZ_IPADDR2} / ${DMZ_NETMASK2}"
[ ! -z ${DMZ_IPADDR3} ] && echo "Secondary IP ${DMZ_IPADDR3} / ${DMZ_NETMASK3}"
[ ! -z ${DMZ_IPADDR2} ] || [ ! -z ${DMZ_IPADDR3} ] || echo "Netmask      ${DMZ_NETMASK}"
echo "Broadcast    ${DMZ_BROADCAST}"
fi

status WAN; echo "----------------${STATUS}DNS configuration${NORM}----------------"
RESOLVFILE="/etc/resolv.conf"
if [ "$USE_DNS_CACHE" = "YES" ] ; then
	RESOLVFILE="/etc/resolv.dns"
	echo "Using Coyote DNS Cache"
fi
cat $RESOLVFILE | grep domain
cat $RESOLVFILE | grep nameserver
echo "-------------------------------------------------"

echo $UPTIME

