#!/bin/bash

HOME=/root

LOG=$(/sbin/e-smith/db configuration getprop squid-db-logd status || echo 'disabled')

if [ "$LOG" != "enabled" ]; then
    exit 0
fi

HOST=$(/sbin/e-smith/db configuration getprop squid-db-logd DbHost || echo 'localhost')

if [ "$HOST" != "localhost" ]; then
    exit 0
fi

RETENTION=$(/sbin/e-smith/db configuration getprop squid-db-logd Retention || echo 370)
DB=$(/sbin/e-smith/db configuration getprop squid-db-logd DbName || echo squid_log)

echo "delete from access_log where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY);" | /usr/bin/mysql $DB
echo "delete from deny_log where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY);" | /usr/bin/mysql $DB

