#!/bin/ksh
#
# sudo2uls
#
# sudo2uls sorgt dafuer, dass /etc/profile eingelesen wird, um nach
# einem sudo die "normale" Umgebung zu setzen und sendet Protokoll
# an ULS.
#####################################################################
#
if tty -s
 then
  :
else
  echo "No Terminal connected!"
  exit 1
fi
#
if [ -f /etc/uls/uls.conf ]
 then
  . /etc/uls/uls.conf
fi
if [ -z "$ULSHOSTNAME" ]
 then
  ULSHOSTNAME=`hostname`
fi
#
stoptouls()
{
  DE="`date '+%Y-%m-%d %H:%M:%S'`"
  #
  /usr/local/bin/send_test_value -S -s adm Security Dialog Start-Stop $ULSDT "Stop $DE" '{T}'
  exit 0
}
#
typeset -r SUDO_USER
typeset -r SUDO_TO_USER=$USER
#
if [ -f /etc/profile ]
 then
  . /etc/profile
fi
cd
if [ -f .profile ]
 then
  . ./.profile
fi
#
anl=""
while [ -z "$anl" ]
 do
  echo "Veranlassung: \c"
  read anl
done
#
trap 'stoptouls' 1 2 3 6 9 14 15
#
typeset -r ANLASS="$anl"
#
typeset -r ULSDT="`date '+%Y-%m-%d %H:%M:%S'`"
#
/usr/local/bin/send_test_value -S -s adm Security Dialog Start-Stop $ULSDT "Start $ULSDT" '{T}'
/usr/local/bin/send_test_zeile -S -s adm Security Dialog $ULSDT "User:$SUDO_USER: " "To:$SUDO_TO_USER: "
/usr/local/bin/send_test_value -S -s adm Security Dialog "Veranlassung" $ULSDT "$ANLASS" " "
#
/usr/local/bin/script2uls "$SUDO_USER" "$ULSHOSTNAME" Security Dialog Dialog "$ULSDT"
#
stoptouls
