#!/bin/sh -eu
# sendreport - Email a website report to an email address.
# Usage: sendreport TO_ADDRESS WEBSITE

to="$1"
website="$2"

tmpdir="$(mktemp -d)"
trap "rm -rf $tmpdir" EXIT
report="$tmpdir/report.html"

goaccess "/var/www/logs/$website.log" -o "$report"

(
	echo "From: $USER"
	echo "To: $to"
	echo "Subject: GoAccess Report for $website"
	echo "Content-Type: text/html"
	echo "MIME-Version: 1.0"
	echo
	cat "$report"
) | sendmail -t
