#!/bin/sh
#-------------------------------------------------------------------------------
# charon_menu_sacc
#-------------------------------------------------------------------------------
# Copyright (C) 2013-2022 STROMASYS.
# All rights reserved.
#
#set -x
VERSION=1.3

. `dirname $0`/charon_common
. `dirname $0`/charon_common_menu

echo
if test -z "${DISPLAY}"
then
  echo "\$DISPLAY is empty, cannot open the Sentinel Admin Control Center web page!"
  echo
  Press_Enter
else
  if test -z "`which firefox 2>/dev/null`"
  then
    echo "Firefox is not installed, cannot open the Sentinel Admin Control Center web page!"
    echo
    Press_Enter
  else
    FIRLOG=${CHARONDIR}/log/`basename $0`.log
    /usr/bin/firefox localhost:1947 2>${FIRLOG}
    if test $? != 0
    then
      if test -n "`grep 'Running Firefox as root' ${FIRLOG} | grep 'not supported'`"
      then
        #--- extracting the user in the error output file ("who am i" could also work)
        FIRUSR=`sed "s=\(^.* owned by \)\(.*\)\(\..$\)=\2=g" ${FIRLOG}`
        su ${FIRUSR} -c "/usr/bin/firefox localhost:1947"
      fi
    else
      echo "Firefox failed to execute:"
      cat ${FIRLOG}
      echo
      Press_Enter
    fi
  fi
fi

exit
