#!/bin/bash
# Restart the proxies if they are not present
#
# Copyright (C) 2004 Networks Associates Technology Inc. All rights reserved.
# 
#
if [ -f $NETAWSS/.profile.vars ]; then 
    . $NETAWSS/.profile.vars 
else 
    . /var/NAIENV/.profile.vars 
fi 

restart()
{
	logger -t webshield "Proxy ${protocol} is ${STATE} - restarting"
	/usr/sbin/webshield proxy-restart
	echo $CURRENTTIME > /tmp/last_restart
	exit 0
}
LASTTIME=
if [ -f /tmp/last_restart ]
then
	LASTTIME=`cat /tmp/last_restart`
fi
for protocol in smtp ftp http pop3 icap
do
	STATE=`grep "^s.${protocol}.state " /tmp/realtime.txt | cut -f2 -d" "`
	if [ "T${STATE}" = "TNOTOK" ]
	then
		CURRENTTIME=`grep "^i.now " /tmp/realtime.txt | cut -f2 -d" "`
                if [ "${LASTTIME}" != "${CURRENTTIME}"  ]
		then
			restart
		fi
	fi
done
exit 0
