#!/bin/sh

#
# Create a fresh vuls report on a daily basis
#
# daily_vuls_enable		- enable nightly vuls reports
# daily_vuls_results_dir	- modify results dir from the default /var/db/vuls/reports
# daily_vuls_http_url		- send resports to a central repository running a vuls server
# 				  for example. http://localhost:5155/vuls
# daily_vuls_flags		- additionals flags for `vuls report'
#
# daily_vuls_user		- Set user to run vuls
#				  Default is "vuls"

# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

: ${daily_vuls_enable:=NO}
: ${daily_vuls_results_dir:=/var/db/vuls/results}
: ${daily_vuls_user:=vuls}

case "${daily_vuls_enable}" in
    [Yy][Ee][Ss])
	mkdir -p /var/log/vuls
	su -fm vuls \
	    -c "/usr/bin/env HOME=/var/db/vuls /usr/local/bin/vuls scan -results-dir=${daily_vuls_results_dir}" \
	    >> /var/log/vuls/vuls_scan.log 2>&1
	if [ -n "${daily_vuls_http_url}" ]; then
	    flags="-to-http"
	else
	    flags="-to-localfile"
	fi
	flags="${flags} ${daily_vuls_flags}"
	su -fm ${daily_vuls_user} \
	    -c "/usr/bin/env HOME=/var/db/vuls VULS_HTTP_URL=\"${daily_vuls_http_url}\" /usr/local/bin/vuls report -results-dir=${daily_vuls_results_dir} ${flags}" \
	    >> /var/log/vuls/vuls_scan.log 2>&1
esac
