#!/bin/bash

source "/etc/asl/config"
export LANG="en_US.UTF-8"

if [ "$CONFIGURED" ==  "yes" ]; then

  # Automatic Updates
  if [ "$AUTOMATIC_UPDATES" ==  "weekly" ]; then
    /var/asl/bin/aum -u >/dev/null 2>&1
  fi

  # Clear old alerts
  if [ $MODSEC_CLEAN_ALERT -gt 0 ]; then
     /usr/bin/find /var/asl/data/audit/ -maxdepth 2 \
	-type d -ctime +$MODSEC_CLEAN_ALERT -exec /bin/rm -rf {} \; >/dev/null 2>&1
  fi

  # Clean old updates
  /usr/bin/find /var/asl/updates -maxdepth 1 \
	-type f -ctime +7 -exec /bin/rm -f {} \; >/dev/null 2>&1

  # Clean old state files
  if [ -d /var/ossec/queue/diff ]; then
  	/usr/bin/find /var/ossec/queue/diff/*/533 -maxdepth 1 \
		-type f -ctime +1 -exec /bin/rm -f {} \; >/dev/null 2>&1
  fi


  # Run DB rotate script
  if [ -f /var/asl/bin/asl_db_rotate ]; then
  	/var/asl/bin/asl_db_rotate >/dev/null 2>&1
  fi

else
  echo "Error: ASL has not been configured"
  exit 1
fi

