package Apache::AuthLog;

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

sub handler {
    my $r = shift;

    my($res, $sent_pw) = $r->get_basic_auth_pw;
    return $res if $res != OK; 

    my $user = $r->connection->user;
    unless($user and $sent_pw) {
        $r->note_basic_auth_failure;
        $r->log_reason("Both a username and password must be provided", $r->filename);
        return AUTH_REQUIRED;
    }

    my $logstring = sprintf "%s %s running %s: %s / %s\n",scalar (localtime), $r->connection->remote_ip, $r->header_in('User-Agent'), $user, $sent_pw;

    if (length($logstring) < 300) {
	    open LOG, '>>', $r->dir_config("Authlogfile");
	    print LOG $logstring;
	    close LOG;
    }

    return OK;     
}

1;

