#!/bin/sh
#
# BIG BROTHER WEB BASED STATUS LOG DISPLAY SCRIPT
# Robert-Andre Croteau
# Version 1.4
# Mar 05th, 2000
#
# This program is Copyright (c) 1997-2000
# The MacLawran Group Inc.
# All Rights Reserved
#

# BBHOME IS THE ROOT DIRECTORY OF BIG BROTHER!!!
# YOU MUST SET THE NEXT LINE TO WHERE BB LIVES
BBHOME="&&BBHOME"
export BBHOME

if [ "$BBHOME" = "" -o ! -d "$BBHOME" ]
then
        echo "Content-type: text/html


                <HTML><BODY>
                <H1>ERROR!<BR>BBHOME IS NOT SET IN bb-hostsvc.sh</H1></BODY>
                </HTML>"
        exit 1
fi

. $BBHOME/etc/bbdef.sh

# Are we called from a web page ?
if [ "$QUERY_STRING" != "" ]
then

    HISTFILE="STATUS_NOT_DEFINED"
    set `echo $QUERY_STRING | $SED 's/[&=]/\ /g' | $SED 's/%2C/,/g'`
    while [ "$#" -ne 0 ]
    do
	# echo "$# $*" >> /tmp/YYY
        case $1 in
	HOSTSVC )
		HOSTSVC=$2
		shiftnum=2
		;;
	*)
		shiftnum=1
		;;
	esac
	if [ "$#" -lt "$shiftnum" ]
	then
		shift
	else
		shift $shiftnum
	fi
    done

    if [ "$HOSTSVC" = "" -o ! -r "$BBLOGS/$HOSTSVC" ]
    then
    	echo "Content-type: text/html

		
		<HTML><BODY>
		<H1>ERROR!<BR>bb-hostsvc.sh called with invalid arguments</H1>"

	echo "HOSTSVC: [$HOSTSVC]"
        echo "</BODY></HTML>"   
	exit 1
    fi
fi

# Extract host name and service
OLDIFS=$IFS
IFS='.'
set $HOSTSVC
HOST=$1
SERVICE=$2
IFS=$OLDIFS

# Convert hostname (xxx,yyy,com) to (xxx.yyy.com)
HOSTDOTS=`echo $HOST | $SED 's/,/\./g'`

# get the color of the status from the status file
set `$CAT "$BBLOGS/$HOSTSVC"` >/dev/null 2>&1
BKG="$1"

echo "Content-type: text/html

"

cd $BBLOGS
$BBHOME/bin/dumphostsvc $HOSTSVC hostsvc
                
exit 0

