package Apache::Footer;

use strict;
use Apache::Constants qw(:common);
use Apache::File ();

sub handler {
    my $r = shift;
    return DECLINED unless $r->content_type() eq 'text/html';

    my $file = $r->filename;

    unless (-e $r->finfo) {
	$r->log_error("File does not exist: $file");	
	return NOT_FOUND;
    }
    unless (-r _) {
	$r->log_error("File permissions deny access: $file");	
	return FORBIDDEN;
    }

    my $modtime = localtime((stat _)[9]);

    my $fh;
    unless ($fh = Apache::File->new($file)) {
	$r->log_error("Couldn't open $file for reading: $!");
	return SERVER_ERROR;
    }
    my $footer = <<END;
<hr>
&copy; 1998 <a href="http://www.ora.com/">O'Reilly &amp; Associates</a><br>
<em>Last Modified: $modtime</em>
END

    $r->send_http_header;
    
    while (<$fh>) {
	s!(</BODY>)!$footer$1!oi;
    } continue {
	$r->print($_);
    }

    return OK;
}

1;
__END__
