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

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

display_header "Alerts management"
echo

CRONFILE=/etc/cron.d/charon

if test `id -u` -ne 0
then
  tput bold
  echo "Must be root !"
  tput sgr0
  Press_Enter
  echo
  exit 1
fi

#-----------------------------------------------------------------------------
# Files and values definition
#-----------------------------------------------------------------------------
test -d ${CHARONDIR}/utils/events || mkdir ${CHARONDIR}/utils/events
MAILTOFILE="${CHARONDIR}/utils/charon_check.mailto"
MAILFRFILE="${CHARONDIR}/utils/charon_check.mailfrom"
MAILFTFILE="${CHARONDIR}/utils/charon_check.mailfooter"
WALLOFFFILE="/root/.charonwalloff"
ALCMDFILE="${CHARONDIR}/utils/charon_check.alertcmd"
CHKEVENT=/root/.charonlogevent
ALERTLOG=${CHARONDIR}/log/charon_alerts.log
test -e ${ALERTLOG} || touch ${ALERTLOG}
ALERTEXPLOGFILE="/root/.charon.expiration.alertsfromlog"
HWSPECWARNIGNORE="/root/.charon.hwspecwarning.ignore"
LESSWARNONREMOVAL="/root/.charon.less.warn.on.dongle.removal"
DISABLEMONUSBALRT="/root/.charon.disable.monusb.immediate.alert"
MONBUGCHECK="/root/.charon.logmon.no.bugcheck"
MONCPUHALTED="/root/.charon.logmon.no.cpuhalted"

LOGEVENT0="None"
LOGEVENT1="INFORMATION + WARNING + ERROR"
LOGEVENT2="WARNING + ERROR"
LOGEVENT3="ERROR"


#-----------------------------------------------------------------------------
# Pre-init & checks
#-----------------------------------------------------------------------------
if test ! -x /opt/charon/utils/charon_check.alertcmd
then
  cp -f charon_check.alertcmd.example charon_check.alertcmd
  chmod 744 charon_check.alertcmd
  echo "Mail script initialized."
  echo
fi

if test ! -e ${MAILTOFILE}
then
  cat >${MAILTOFILE} <<EOF
#---------------------------------------------------------------
# CHARON alertcmd mail recipients list / one recipient per line
#---------------------------------------------------------------
EOF
fi

#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
function set_mail_mode
{
  echo
  MAILMODE=`cat /root/.charonmailmode 2>/dev/null`
  test "${MAILMODE}" != "TEXT" && MAILMODE="HTML"
  case "${MAILMODE}"
  in
    "TEXT")
      echo HTML >/root/.charonmailmode
      test $? = 0 && echo "Switched to HTML alerts" || echo "Failed to copy!"
      ;;
    "HTML")
      echo TEXT >/root/.charonmailmode
      test $? = 0 && echo "Switched to TEXT alerts" || echo "Failed to copy!"
      ;;
  esac
  echo
  if test -e ${MAILTOFILE}
  then
    if test `grep -v ^# ${MAILTOFILE} | wc -l` -gt 0
    then
      while test 1
      do
        MAILTO=`grep -v ^# ${CHARONDIR}/utils/charon_check.mailto | sort -u | tr "\n" ","|sed "s=,$==g"`
        echo -n "Do you want to send a test mail to ${MAILTO} (y/n) ? "
        read ANS
        echo
        case "${ANS}"
        in
          y)
            TM="${CHARONDIR}/utils/templates/TESTMAIL.mail"
            if test -s ${TM}
            then
              echo "Sending mail, please check your mailbox."
              ${CHARONDIR}/utils/charon_check.alertcmd TESTMAIL
            else
              tput bold
              echo "The test mail template does not exist. Please check"
              tput sgr0
              echo "Excepted file: ${TM}"
            fi
            sleep 2
            break
            ;;
          n)
            break
            ;;
          *)
            tput cuu1;tput el
            ;;
        esac
      done
    fi
  fi
}

function set_recipients_list
{
  echo
  tput bold;tput smul
  echo "Current list of recipients"
  tput rmul;tput sgr0
  if test `grep -v ^# ${MAILTOFILE} | wc -l` -eq 0
  then
    echo "Empty."
  else
    grep -v ^# ${MAILTOFILE}
  fi

  ask_editor
  if test -n "${EDI}"
  then
    echo
    echo "Updating file using '`basename ${EDI}`'..."
    if test -z "`echo ${EDI}|grep vim`"
    then
      ${EDI} ${MAILTOFILE} 2>/dev/null
    else
      ${EDI} -u ${CHARONDIR}/utils/charonrecipient.vimrc ${MAILTOFILE} 2>/dev/null
    fi
    >${MAILTOFILE}.tmp
    cat ${MAILTOFILE} | while read L
    do
      test -n "$L" && echo $L >>${MAILTOFILE}.tmp
    done
    mv -f ${MAILTOFILE}.tmp ${MAILTOFILE}
  fi
}

function set_mailfrom
{
  MAILFROM=`cat ${MAILFRFILE} 2>/dev/null`
  echo
  while test 1
  do
    echo -n "Enter the mail sender (From:) name [${MAILFROM}] ('r' to reset): "
    read ANS
    case "${ANS}"
    in
      "")
        break
        ;;
      "r")
        MAILFROM=""
        echo "${MAILFROM}" >${MAILFRFILE}
        break
        ;;
      *)
        MAILFROM="${ANS}"
        echo "${MAILFROM}" >${MAILFRFILE}
        break
        ;;
    esac
  done
}

function set_mail_footer
{
  cat <<EOF

[1mMail footer can contain the following HTML tags:[0m
- new line: <br>
- bold: <b> </b>
- fonts: <font ...> </font>

In case the mail format is switched to TEXT, these tags will be removed.

EOF

  ask_editor
  test -e ${MAILFTFILE} || touch ${MAILFTFILE}
  if test -n "${EDI}"
  then
    echo
    echo "Updating file using '`basename ${EDI}`'..."
    ${EDI} ${MAILFTFILE} 2>/dev/null
  fi
}

function reinstall_script
{
  cp ${ALCMDFILE}.example ${ALCMDFILE}
  if test $? = 0
  then
    echo "${FGBLUE}Script reinstalled/initialized from example provided.[0m"
  else
    tput bold
    echo "[31mFailed to copy script example! Please check or contact support.[0m"
    tput sgr0
  fi
}

function set_alert_script
{
  echo
  if test ! -e ${ALCMDFILE}
  then
    if test -e ${ALCMDFILE}.example
    then
      reinstall_script
    fi
  else
    if test -e ${ALCMDFILE}.example
    then
      if test -n "`diff ${ALCMDFILE} ${ALCMDFILE}.example`"
      then
        while test 1
        do
          echo "Do you want to reinstall the alert script from the kit ?"
          echo -n "If you customized it, it will be saved and overwritten (y/n) : "
          read ANS
          case "${ANS}"
          in
            y)
              echo
              mkdir -p ${CHARONDIR}/archive 2>/dev/null
              ADAT=`date +%Y%m%d-%H%M%S`
              echo "${FGBLUE}Archiving current alert script file to[0m"
              echo "${CHARONDIR}/archive/`basename ${ALCMDFILE}`.${ADAT}"

              cp ${ALCMDFILE} ${CHARONDIR}/archive/`basename ${ALCMDFILE}`.${ADAT}
              test $? = 0 && echo "Done." || echo "Failed!"
              echo
              reinstall_script
              break
              ;;
            n)
              break
              ;;
            *)
              tput cuu1
              tput cuu1;tput el
              ;;
          esac
        done
      fi
    fi
  fi

  chmod u+x ${ALCMDFILE}

  ask_editor
  if test -n "${EDI}"
  then
    echo
    echo "Updating file using '`basename ${EDI}`'..."
    ${EDI} ${ALCMDFILE} 2>/dev/null
  fi
}

function set_log_alert_level
{
  while test 1
  do
    cat <<EOF

[44m[37mAvailable levels[0m
0 = None
1 = INFORMATION + WARNING + ERROR
2 = WARNING + ERROR
3 = ERROR

EOF
    echo -n "Select the alerts level you want to receive from the log files [${LVLEVENT}] : "
    read ANS
    echo
    test -z "${ANS}" && ANS=${LVLEVENT}

    case "${ANS}"
    in
      0)
        echo ${ANS} >${CHKEVENT}
        break
        ;;
      1|2|3)
        echo ${ANS} >${CHKEVENT}
        CHK=`cat ${CRONFILE} 2>/dev/null | grep ${CHARONDIR}/utils/charon_logevent | grep -v ^#`
        if test -z "${CHK}"
        then
          tput bold
          echo "Schedule (crontab) not set for charon log events!"
          echo "Please update schedule using menu option 'Manage recursive jobs'"
          tput sgr0
          echo
          echo "Add a line as below to run every 1 minute:"
          echo
          echo "* * * * * root /opt/charon/utils/charon_logevent"
          Press_Enter
        fi
        break
        ;;
      *)
        tput cuu1;tput el
        ;;
    esac
  done
}

function tail_alertslog
{
  tput clear
  echo "[44m[37m Continuous view of ${ALERTLOG} [0m"
  if test ! -e ${WALLOFFFILE}
  then
    echo
    tput bold
    echo "Note: It is recommended to disable wall alert messages before using this view"
    tput sgr0
    sleep 1
  fi
  echo "[31mPress CTRL-C to stop[0m"
  if test "${SEMIGRAPH}" = "enabled"
  then
    tput smacs
    echo "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
    tput rmacs
  else
    echo "--------------------------------------------------------------------------------"
  fi
  typeset -i L2=0
  typeset -i LN=0
  typeset -i TAILN=0
  L2=`grep -n ":ALERT:" ${ALERTLOG} | tail -2 | head -1 | cut -f1 -d:`
  if test ${L2} -eq 0
  then
    TAILN=0
  else
    LN=`wc -l ${ALERTLOG} | awk '{print $1}'`
    TAILN=${LN}-${L2}+1
  fi

  trap 'echo;echo "[44m[37m Continuous view of ${ALERTLOG} aborted [0m";sleep 1;echo' 1 2 9 14 15
  tail -Fn${TAILN} --retry ${ALERTLOG} | while read LINE
  do
    if test "`echo ${LINE} | cut -c1-6`" != "------"
    then
      if test "`echo ${LINE} | cut -f3 -d:`" = "ALERT"
      then
        LC="[44m[37m"
        test -n "`echo ${LINE} | grep -w started$`" && LC="[42m[30m"
        test -n "`echo ${LINE} | grep -w failed$`"  && LC="[40m[31m"
        test -n "`echo ${LINE} | grep -w stopped$`" && LC="[41m[37m"
        test -n "`echo ${LINE} | grep -w removed$`" && LC="[45m[37m"
        echo "${LC}${LINE}[0m"
      else
        echo "${LINE}" | sed -e "s=INFORMATIONAL=[36mINFORMATIONAL[0m=g" \
                             -e "s=CRITICAL=[31m[1mCRITICAL[0m=g" \
                             -e "s=MAJOR=[31mMAJOR[0m=g" \
                             -e "s=MINOR=[35mMINOR[0m=g" \
                             -e "s=WARNING=[35mWARNING[0m=g" -e "s=WARN=[35mWARN[0m=g" \
                             -e "s=ERROR=[31mERROR[0m=g"
      fi
    else
      echo
    fi
  done
  trap 'exit' 1 2 9 14 15
}

function view_alerts
{
  echo
  if test -x ${CHARONDIR}/utils/charon_check.alertcmd
  then
    if test -z "`grep '>>${ALERTLOG}' ${CHARONDIR}/utils/charon_check.alertcmd`"
    then
      echo "[31m[1mThe alert script does not contain the required lines:"
      tput sgr0
      cat <<EOF
If you have not customized the script, please use the menu option
'Update/reinstall common alert script' and reinstall from the example
provided in the kit

EOF
      echo
      Press_Enter
      return
    fi
  else
    echo "[31m[1mThe alert script is not found or not executable:"
    tput sgr0
    echo 
    echo -n "# "
    tput bold
    echo "ls -l ${CHARONDIR}/utils/charon_check.alertcmd"
    tput sgr0
    ls -l ${CHARONDIR}/utils/charon_check.alertcmd
    echo
    Press_Enter
    return
  fi

  while test 1
  do
    while test 1
    do
      display_header "Alerts management"
      NBAL=`grep ":ALERT:" ${ALERTLOG} 2>/dev/null | wc -l`
      cat <<EOF

${FGBLUE}Number of alerts:[0m ${NBAL} at `date +"%d-%b-%Y %H:%M:%S"`

1 - Continuous view of alerts log
2 - View alerts log (using editor)
q - quit

EOF
      echo -n "Enter your choice: "
      read ANS
      case "${ANS}"
      in
        1)
          tail_alertslog
          break
          ;;
        2)
          if test -s ${ALERTLOG}
          then
            ask_editor
            if test -n "${EDI}"
            then
              ${EDI} ${ALERTLOG} 2>/dev/null
            fi        
          else
            echo "Log file is currently empty or does not exist."
            Press_Enter
          fi
          break
          ;;
        q)
          break 2
          ;;
        *)
          ;;
      esac
    done
  done
}

function alerts_simulator
{
  test -d ${CHARONDIR}/utils/events || mkdir ${CHARONDIR}/utils/events

  if test `grep -v ^# ${MAILTOFILE} | wc -l` -gt 0
  then
    while test 1
    do
      typeset -i A=1
      echo
      if test "${SEMIGRAPH}" = "enabled"
      then
        echo -n "${FGBLUEBOLD}"
        echo "No Code             Subject / Description"
        tput smacs
        echo "qq qqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
        tput rmacs
      else
        echo "No Code             Subject / Description"
        echo "-- ---------------- ------------------------------------------------------------"
      fi
      tput sgr0
      printf "%2d %-16s %s\n" ${A} "LOGEVENT" "Alerts found in Charon VM log"
      grep ^#SUBJECT: ${CHARONDIR}/utils/templates/*.mail | while read L
      do
        A=A+1
        ALCOD=`echo $L | cut -f1 -d ':'`
        ALCOD=`basename ${ALCOD} | sed "s=\.mail==g"`
        ALSBJ=`echo $L | cut -f3 -d ':' | sed "s={.}=<TEST>=g"`
        printf "%2d %-16s %s\n" ${A} ${ALCOD} "${ALSBJ}"
      done

      while test 1
      do
        echo -n "${FGBLUEBOLD}Enter the code number to send a simulated alert ('q' to quit) : [0m"
        read ANS
        case "${ANS}"
        in
          q|Q)
            break 2
            ;;
          1)
            DT=`date +"%Y%m%d:%H%M%S"`
            OUTFILE="${CHARONDIR}/utils/events/simulation.partlog"
            echo "${DT}:INFO :0:00000000:falsealert(0001):  This is a simulated information alert"  >${OUTFILE}
            echo "${DT}:WARN :1:00000000:falsealert(0002):  This is a simulated warning alert"     >>${OUTFILE}
            echo "${DT}:ERROR:2:00000000:falsealert(0003):  This is a simulated error alert"       >>${OUTFILE}
            echo "Alert sent. The cron job charon_logevent will need a few time to send the alert"
            Press_Enter
            break
            ;;
          [2-9]|[1-9][0-9])
            typeset -i B=${ANS}-1
            ALFIL=`grep -l ^#SUBJECT: ${CHARONDIR}/utils/templates/*.mail | head -${B} | tail -1`
            ALCOD=`basename ${ALFIL} | sed "s=\.mail==g"`
            ALSIM=`grep ^#SIMUL: ${ALFIL}`
            if test -z "${ALSIM}"
            then
              echo ${CHARONDIR}/utils/charon_check.alertcmd ${ALCOD} | at now >/dev/null 2>&1
            else
              ALSI1=`echo ${ALSIM} | cut -c8- | cut -f1 -d '|'`
              ALSI2=`echo ${ALSIM} | cut -c8- | cut -f2 -d '|'`
              ALSI3=`echo ${ALSIM} | cut -c8- | cut -f3 -d '|'`
              ALSI4=`echo ${ALSIM} | cut -c8- | cut -f4 -d '|'`
              ALSI5=`echo ${ALSIM} | cut -c8- | cut -f5 -d '|'`
              ALSI6=`echo ${ALSIM} | cut -c8- | cut -f6 -d '|'`
              ALSI7=`echo ${ALSIM} | cut -c8- | cut -f7 -d '|'`
              echo ${CHARONDIR}/utils/charon_check.alertcmd ${ALCOD} \"${ALSI1}\" \"${ALSI2}\" \"${ALSI3}\" \
                  \"${ALSI4}\" \"${ALSI5}\" \"${ALSI6}\" \"${ALSI7}\" \"${ALSI8}\" | at now >/dev/null 2>&1
            fi
            echo "Alert sent. Please check your mailbox."
            Press_Enter
            break
            ;;
          *)
            tput cuu1;tput el
            ;;
        esac
      done
    done
  else
    echo
    echo "No email recipient defined. Cannot send alerts!"
    Press_Enter
  fi
}


#-----------------------------------------------------------------------------
# Main menu
#-----------------------------------------------------------------------------
while test 1
do
  get_preferences
  display_header "Alerts management"
  echo
  if test "${SEMIGRAPH}" = "enabled"
  then
    echo -n "${FGBLUEBOLD}"
    echo "No  Parameter                           Current value(s)[0m"
    tput smacs
    echo "qq  qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
    tput rmacs
  else
    echo "No  Parameter                           Current value(s)"
    echo "--  ----------------------------------- ----------------------------------------"
  fi

  MAILMODE=`cat /root/.charonmailmode 2>/dev/null`
  test "${MAILMODE}" != "TEXT" && MAILMODE="HTML"

  echo -n "1 - Mail mode (text/html)               "
  test "${MAILMODE}" = "HTML" && echo -n "${FGBLUE}"
  echo "${MAILMODE}[0m"

  echo -n "2 - Mail recipients list                "
  if test `grep -v ^# ${MAILTOFILE} 2>/dev/null | wc -l` -eq 0
  then
    echo "Empty."
  else
    L1=0
    grep -v ^# ${MAILTOFILE} | head -4 | while read L
    do
      test ${L1} = 1 && tput hpa 40
      test ${L1} = 0 && L1=1
      echo ${L}
    done
    if test `grep -v ^# ${MAILTOFILE} | wc -l` -gt 4
    then
      tput hpa 40
      echo "(more...)"
    fi
  fi

  echo -n "3 - Mail sender (optional)              "
  MAILFROM=`cat ${MAILFRFILE} 2>/dev/null`
  if test -z "${MAILFROM}"
  then
    echo "[35m(default)[0m"
  else
    echo "${FGBLUE}${MAILFROM}[0m"
  fi

  echo -n "4 - Create/Update alert mail footer     "
  if test -s ${MAILFTFILE}
  then
    echo -n "${FGBLUE}"
    L1=0
    head -4 ${MAILFTFILE} | while read L
    do
      test ${L1} = 1 && tput hpa 40
      test ${L1} = 0 && L1=1
      echo ${L} | cut -c1-40
    done
    if test `cat ${MAILFTFILE} | wc -l` -gt 4
    then
      tput hpa 40
      echo "(more...)"
    fi
  else
    echo "Not defined"
  fi
  tput sgr0

  echo -n "5 - 'wall' alert messages               "
  if test -e ${WALLOFFFILE}
  then
    echo "[31mDisabled[0m"
  else
    echo "[32mEnabled[0m"
  fi

  echo -n "6 - Update/reinstall alert script       "
  if test -e ${ALCMDFILE}
  then
    if test -e ${ALCMDFILE}.example
    then
      if test -n "`diff ${ALCMDFILE} ${ALCMDFILE}.example`"
      then
        echo "${FGBLUE}Customized"
        tput sgr0
        tput hpa 40
        A1=`ls -l --full-time ${ALCMDFILE}`
        A2=`echo ${A1} | awk '{print $6,$7}' | awk -F '.' '{print $1}'`
        echo -n "Last update: ${FGBLUE}"
        date +"%a %d-%b-%Y %H:%M:%S" -d "${A2}"
      else
        echo "[32mInstalled (from example)"
      fi
    else
      echo "[32mInstalled/Customized"
      tput sgr0
      tput hpa 40
      A1=`ls -l --full-time ${ALCMDFILE}`
      A2=`echo ${A1} | awk '{print $6,$7}' | awk -F '.' '{print $1}'`
      echo -n "Last update: ${FGBLUE}"
      date +"%a %d-%b-%Y %H:%M:%S" -d "${A2}"
    fi
  else
    if test -e ${ALCMDFILE}.example
    then
      cp -f ${ALCMDFILE}.example ${ALCMDFILE}
      test $? = 0 && echo "[32mInstalled (just now)" || echo "[31mFailed to install"
    else
      echo "[31m[1mSource not found!"
    fi
  fi
  tput sgr0

  echo -n "7 - Select guests log alert level       "
  test -e ${CHKEVENT} || echo 2 >${CHKEVENT}
  LVLEVENT=`cat ${CHKEVENT}`
  eval LOGEVENT=\${LOGEVENT${LVLEVENT}}
  test ${LVLEVENT:-0} = 0 && echo -n "[31m"
  echo ${LOGEVENT}
  tput sgr0

  NBAL=`grep ":ALERT:" ${ALERTLOG} 2>/dev/null | wc -l`
  echo -n "8 - View alerts history (${NBAL} alerts)"
  tput hpa 40
  A1=`ls -l --full-time ${ALERTLOG} 2>/dev/null`
  if test -n "${A1}"
  then
    A2=`echo ${A1} | awk '{print $6,$7}' | awk -F '.' '{print $1}'`
    echo -n "Last update: ${FGBLUE}"
    date +"%a %d-%b-%Y %H:%M:%S" -d "${A2}"
  else
    echo "-"
  fi
  tput sgr0

  echo -n "9 - Lic. expiration alerts from guests  "
  if test -e ${ALERTEXPLOGFILE}
  then
    echo "[32mEnabled[0m"
  else
    echo "[31mDisabled[0m"
  fi
  echo    "    (for Charon-AXP & VAX < V4.9)"

  echo    "10- Alerts simulator"

  echo -n "11- Hardware specs warning message      "
  if test -e ${HWSPECWARNIGNORE}
  then
    echo "[31mDisabled[0m"
  else
    echo "[32mEnabled[0m"
  fi

  echo -n "12- Immediate alert on dongle removal   "
  if test ! -e ${DISABLEMONUSBALRT}
  then
    echo "[32mEnabled[0m"
  else
    echo "[31mDisabled[0m"
  fi

  INSBLD=`rpm -q charon-license 2>/dev/null | cut -f4 -d'-' | cut -f1 -d'.'`
  if test ${INSBLD:-0} -ge 19103
  then
    echo -n "13- Reduce WARN msgs on dongle removal  "
    if test -e ${LESSWARNONREMOVAL}
    then
      echo "[32mEnabled[0m"
    else
      echo "[31mDisabled[0m"
    fi
  fi

  echo -n "14- Consider BUGCHECK msgs as WARNING   "
  if test ! -e ${MONBUGCHECK}
  then
    echo "[32mEnabled[0m"
  else
    echo "[31mDisabled[0m"
  fi

  echo -n "15- Consider CPU Halted msgs as WARNING "
  if test ! -e ${MONCPUHALTED}
  then
    echo "[32mEnabled[0m"
  else
    echo "[31mDisabled[0m"
  fi

  echo
  echo -n "${FGBLUEBOLD}Enter your choice ('q' to quit): [0m"
  read ANS
  case "${ANS}"
  in
    1)
      #--- Mail mode (text/html)
      set_mail_mode
      ;;
    2)
      #--- Mail recipients list
      set_recipients_list
      ;;
    3)
      #--- Mail sender
      set_mailfrom
      ;;
    4)
      #--- Create/Update alert mail footer
      set_mail_footer
      ;;
    5)
      #--- Enable/disable wall alert messages
      if test -e ${WALLOFFFILE}
      then
        rm -f ${WALLOFFFILE}
      else
        touch ${WALLOFFFILE}
      fi
      ;;
    6)
      #--- Update/reinstall alert script
      set_alert_script
      ;;
    7)
      #--- Select guests log alert level
      set_log_alert_level
      ;;
    8)
      #--- View alerts history
      view_alerts
      ;;
    9)
      #--- License expiration alerts from log
      if test -e ${ALERTEXPLOGFILE}
      then
        rm -f ${ALERTEXPLOGFILE}
      else
        touch ${ALERTEXPLOGFILE}
      fi
      ;;
    10)
      #--- Alerts simulator
      alerts_simulator
      ;;
    11)
      #--- Hardware specifications warning messages
      if test -e ${HWSPECWARNIGNORE}
      then
        rm -f ${HWSPECWARNIGNORE}
      else
        touch ${HWSPECWARNIGNORE}
        echo
        echo "Messages could be still present in the log file depending on Charon"
        echo "version but alerts won't be sent."
        echo
        Press_Enter
      fi
      ;;
    12)
      if test -e ${DISABLEMONUSBALRT}
      then
        rm -f ${DISABLEMONUSBALRT}
      else
        touch ${DISABLEMONUSBALRT}
      fi
      ;;
    13)
      if test ${INSBLD:-0} -ge 19103
      then
        if test -e ${LESSWARNONREMOVAL}
        then
          rm -f ${LESSWARNONREMOVAL}
        else
          touch ${LESSWARNONREMOVAL}
          cat <<EOF12

The following messages will not generate an alert:

- :0000024D:licenseman(1830): Unable to log in to the key "XXXXXXXX", feature X.
- :0000024D:licenseman(1830): HASP runtime (7): Sentinel protection key not available.
- :0000024D:licenseman(1830): Failed to login at the Sentinel HASP key: "XXXXXXXX".

EOF12
          Press_Enter
        fi
      fi
      ;;
    14)
      if test -e ${MONBUGCHECK}
      then
        rm -f ${MONBUGCHECK}
      else
        touch ${MONBUGCHECK}
      fi
      ;;
    15)
      if test -e ${MONCPUHALTED}
      then
        rm -f ${MONCPUHALTED}
      else
        touch ${MONCPUHALTED}
      fi
      ;;
    q|Q)
      break
      ;;
    *)
      tput cuu1;tput el
      ;;
  esac
done

exit
