line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache::DBILogger; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.004; |
4
|
1
|
|
|
1
|
|
918
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
1755
|
use Apache::Constants qw( :common ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use DBI; |
7
|
|
|
|
|
|
|
use Date::Format; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$Apache::DBILogger::revision = sprintf("%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/o); |
10
|
|
|
|
|
|
|
$Apache::DBILogger::VERSION = "0.93"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub reconnect($$) { |
13
|
|
|
|
|
|
|
my ($dbhref, $r) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$$dbhref->disconnect; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$r->log_error("Reconnecting to DBI server"); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$$dbhref = DBI->connect($r->dir_config("DBILogger_data_source"), $r->dir_config("DBILogger_username"), $r->dir_config("DBILogger_password")); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
unless ($$dbhref) { |
22
|
|
|
|
|
|
|
$r->log_error("Apache::DBILogger could not connect to ".$r->dir_config("DBILogger_data_source")." - ".$DBI::errstr); |
23
|
|
|
|
|
|
|
return DECLINED; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub logger { |
28
|
|
|
|
|
|
|
my $r = shift->last; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $s = $r->server; |
31
|
|
|
|
|
|
|
my $c = $r->connection; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my %data = ( |
34
|
|
|
|
|
|
|
'server' => $s->server_hostname, |
35
|
|
|
|
|
|
|
'bytes' => $r->bytes_sent, |
36
|
|
|
|
|
|
|
'filename' => $r->filename || '', |
37
|
|
|
|
|
|
|
'remotehost'=> $c->remote_host || '', |
38
|
|
|
|
|
|
|
'remoteip' => $c->remote_ip || '', |
39
|
|
|
|
|
|
|
'status' => $r->status || '', |
40
|
|
|
|
|
|
|
'urlpath' => $r->uri || '', |
41
|
|
|
|
|
|
|
'referer' => $r->header_in("Referer") || '', |
42
|
|
|
|
|
|
|
'useragent' => $r->header_in('User-Agent') || '', |
43
|
|
|
|
|
|
|
'timeserved'=> time2str("%Y-%m-%d %X", time), |
44
|
|
|
|
|
|
|
'contenttype' => $r->content_type || '' |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if (my $user = $c->user) { |
48
|
|
|
|
|
|
|
$data{user} = $user; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$data{usertrack} = $r->notes('cookie') || ''; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $dbh = DBI->connect($r->dir_config("DBILogger_data_source"), $r->dir_config("DBILogger_username"), $r->dir_config("DBILogger_password")); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
unless ($dbh) { |
56
|
|
|
|
|
|
|
$r->log_error("Apache::DBILogger could not connect to ".$r->dir_config("DBILogger_data_source")." - ".$DBI::errstr); |
57
|
|
|
|
|
|
|
return DECLINED; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my @valueslist; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
foreach (keys %data) { |
63
|
|
|
|
|
|
|
$data{$_} = $dbh->quote($data{$_}); |
64
|
|
|
|
|
|
|
push @valueslist, $data{$_}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $table = $r->dir_config("DBILogger_table") || 'requests'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $statement = "insert into $table (". join(',', keys %data) .") VALUES (". join(',', @valueslist) .")"; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $tries = 0; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
TRYAGAIN: my $sth = $dbh->prepare($statement); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
unless ($sth) { |
76
|
|
|
|
|
|
|
$r->log_error("Apache::DBILogger could not prepare sql query ($statement): $DBI::errstr"); |
77
|
|
|
|
|
|
|
return DECLINED; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $rv = $sth->execute; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
unless ($rv) { |
83
|
|
|
|
|
|
|
$r->log_error("Apache::DBILogger had problems executing query ($statement): $DBI::errstr"); |
84
|
|
|
|
|
|
|
# unless ($tries++ > 1) { |
85
|
|
|
|
|
|
|
# &reconnect(\$dbh, $r); |
86
|
|
|
|
|
|
|
# goto TRYAGAIN; |
87
|
|
|
|
|
|
|
# } |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$sth->finish; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$dbh->disconnect; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
OK; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# #perl pun: windows is for users who can't handle the power of the mac. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub handler { |
101
|
|
|
|
|
|
|
shift->post_connection(\&logger); |
102
|
|
|
|
|
|
|
return OK; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |