#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
# Maintain time, date, sara status file and GUI feedback.
#

require 'perllib/ctime.pl';
require $SARA_CF;

#
# Convert to time of day.
#
sub hhmmss {
	local($time) = @_;
	local($sec, $min, $hour);
	
	($sec, $min, $hour) = localtime($time);
	return sprintf "%02d:%02d:%02d", "$hour", "$min", "$sec";
}

sub yymmdd {
        local($time) = @_;
        local($sec,$min,$hour,$mday,$mon,$year);
	($sec,$min,$hour,$mday,$mon,$year) = localtime($time);
        $year = $year + 1900;
	$mon  = $mon  + 1;
        return sprintf "%02d/%02d/%02d", "$year", "$mon", "$mday";
}

sub update_status {
	local($text) = @_;

	$now_day = &hhmmss(time());
	$now_year= &yymmdd(time());

	# GUI feedback.
	print CLIENT "$now_year $now_day $text<br>\n" if $running_from_html;

	# Status file.
	die "Can't open status file $status_file\n" 
		unless open(STATUS, ">>$status_file");
	print STATUS "$now_year $now_day $text\n";
	close STATUS;
}
