##############################################################################
#
# select which security policies (RPMS) should be installed
#

# set desired security defaults (only if not set via autoconf)
secDefault() {
   [ -z "$selinux" ]   && selinux=1
   [ -z "$fips" ]      && fips=1
   [ -z "$firewall" ]  && firewall=1
   [ -z "$aide" ]      && aide=0
   [ -z "$audit" ]     && audit=0
   [ -z "$scap" ]      && scap=0
   [ -z "$antivirus" ] && antivirus=0
   [ -z "$stig" ]      && stig=0
}

# set checkboxes according to autoconf
secSetVal() {
   [ "$selinux"   == "1" ] && pselinux="on"   || pselinux="off"
   [ "$fips"      == "1" ] && pfips="on"      || pfips="off"
   [ "$firewall"  == "1" ] && pfirewall="on"  || pfirewall="off"
   [ "$aide"      == "1" ] && paide="on"      || paide="off"
   [ "$audit"     == "1" ] && paudit="on"     || paudit="off"
   [ "$scap"      == "1" ] && pscap="on"      || pscap="off"
   [ "$antivirus" == "1" ] && pantivirus="on" || pantivirus="off"
   [ "$stig"      == "1" ] && pstig="on"      || pstig="off"
}

# enter use security selections
secCheckbox() {

   # if autoconf then just show results for a few second
   if [ "$AUTOINST" ] ; then                                                                                                             
      pTO="$autoTO"
   else
      pTO="$TO"
   fi
   
   # big checkbox of the 8 security options
   /usr/bin/dialog \
   --nocancel \
   --timeout $pTO \
   --clear \
   --backtitle "$BT" \
   --title " Security Policies " \
   --checklist "\nSelect Security Options:\n " \
   20 70 8 \
   SELinux   "Security-Enhanced Linux from NSA" "$pselinux" \
   FIPS      "Federal Information Processing Standards" "$pfips" \
   FirewallD "IPTables Managment Interface" "$pfirewall" \
   AIDE      "Advanced Intrusion Detection Enviornment" "$paide" \
   Audit     "Linux Auditing System" "$paudit" \
   SCAP  "Security Content Automation Protocol" "$pscap" \
   Antivirus "McAfee Antivirus File Scanner" "$pantivirus" \
   STIG      "Security Technical Implementation Guides" "$pstig" \
   2>$tempfile
   RC=$?
} # secCheckbox

# zero all values (before reading checkbox results)
secZero() {
   selinux=0
   fips=0
   firewall=0
   aide=0
   audit=0
   scap=0
   antivirus=0
   stig=0
}

# parse result of checkbox selections
# these env vars will be available throughout installer life
secParse() {
   if [ -e $tempfile ] ; then
      secZero
      for i in $(cat $tempfile); do
         case $i in
           SELinux)   selinux=1;;
           FIPS)      fips=1;;
           FirewallD) firewall=1;;
           AIDE)      aide=1;;
           Audit)     audit=1;;
           SCAP)      scap=1;;
           Antivirus) antivirus=1;;
           STIG)      stig=1;;
         esac
      done
   fi
} # secParse

# log values (grep log file for "security:")
secLog() {
   log  "security: checkbox  = $RC"
   log  "security: selinux   = $selinux"
   log  "security: fips      = $fips"
   log  "security: firewall  = $firewall"
   log  "security: aide      = $aide"
   log  "security: audit     = $audit"
   log  "security: scap      = $scap"
   log  "security: antivirus = $antivirus"
   log  "security: stig      = $stig"
}

# do everything to prompt & parse for security options
secMenu() {
   secDefault   # set defaults, in case no autoconf
   secSetVal    # set defaults from autoconf
   secCheckbox  # display checkbox prompt
   secParse     # parse results
   secLog       # log results
}

