# Audit Setup 

SECFILE=/etc/slossec.conf

log "Continuing with Auto Slos-Security. Source $SECFILE"
$DIALOG --backtitle "$BT" --title "SLOS Security" --infobox "\n Auto-setup... " $H1 $W1
sleep $autoTO


auditsetup() {
SECFILE=/etc/slossec.conf
[ -f "$SECFILE" ] && source ${SECFILE} 
if [[ $audit -eq 1 ]] ; then
    log "SLOSSecurity: audit setup"
    $DIALOG --backtitle "$BT" --title "Audit" --infobox "Audit Setup" $H1 $W1
    sleep $autoTO

    if ! rpm -q --quiet audit; then
        yum -y install audit
        if [ $? -ne 0 ] ; then
            log "SLOSSecurity: Failed to install audit pkg's"
            return
        fi
    fi 

    # Correct the form of default kernel command line in GRUB
    if /usr/bin/grep -q '^GRUB_CMDLINE_LINUX=.*audit=.*"'  /etc/default/grub ; then
        # modify the GRUB command-line if an audit= arg already exists
        /usr/bin/sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)audit=[^[:space:]]*\(.*"\)/\1 audit=1 \2/'  /etc/default/grub
    else
        # no audit=arg is present, append it
        /usr/bin/sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)"/\1 audit=1"/' /etc/default/grub
    fi

    systemctl enable auditd
    systemctl start auditd
    if [ $? -ne 0 ] ; then
         log "SLOSSecurity: Failed to start auditd"
         return
    fi

    show "SLOSSecurity: Audit Setup Completed"
    sed -i "s/audit=1/audit=0/g" $SECFILE 2>/dev/null

else
    log "SLOSSecurity: Audit Setup not performed"
fi

}

auditsetup
