#?SuikaWikiConfig/2.0 Plugin: @Name: RequestLog @Description: @@@: HTTP Request Logging @@lang:en @License: %%Perl%% @Author: @@Name: @@@@: Wakaba @@@lang:ja @@@script:Latn @@Mail[list]: w@suika.fam.cx @Date.RCS: $Date: 2004/05/01 03:51:13 $ @Use: use Message::Util::Error; @Namespace: @@log: http://suika.fam.cx/~wakaba/-temp/2004/05/01/reqlog# @RequiredPlugin[list]: WikiLinking PluginConst: @NS_XHTML1: http://www.w3.org/1999/xhtml FormattingRule: @Category[list]: view view-resource form-input @Name: rl--log @Parameter: @@Name: name @@Type: name @@Default:#REQUIRED @@Description: @@@: Log category name @@lang: en @Formatting: __ATTRTEXT:%name__; my $rlist; my $sub = []; try { my $page = $p->{name}; $page ||= $o->{wiki}->{input}->parameter ('rl--for') if $o->{wiki}->{input}; $page = $o->{wiki}->name ($page); unshift @$page, @{$o->{wiki}->{config}->{page}->{}||[]}; $rlist = $o->{wiki}->{db}->get ('log__http_request', $page); $sub->[0] = [$o->{wiki}->{db}->keys ('log__http_request', -ns => $page)]; $sub->[1] = [$o->{wiki}->{db}->keys ('log__http_request', -ns => $page, -type => 'ns')]; } catch SuikaWiki::DB::Util::Error with { my $err = shift; $err->throw if $err->{-type} eq 'ERROR_REPORTED'; }; if ($rlist and keys %$rlist) { my $list = $p->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'ol'); for (sort {$rlist->{$b} <=> $rlist->{$a} or $a cmp $b} keys %$rlist) { $list->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'li') ->append_text (sprintf '{%d} %s', $rlist->{$_}, $_); } } for my $i (0, 1) { if (@{$sub->[$i]}) { my $list = $p->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'ul'); my $template = $o->{wiki}->{plugin}->module_package ('WikiResource') ->get_text (name => 'RequestLog:List:'.[qw/Leaf Node/]->[$i], o => $o, wiki => $o->{wiki}); for (sort {$a->[$#$a] cmp $b->[$#$b]} @{$sub->[$i]}) { $o->{wiki}->{plugin}->module_package ('WikiLinking') ->to_wikipage_in_html ({ label => $template, } => { page_name => $o->{wiki}->{var}->{page}, param => { 'rl--for' => $o->{wiki}->name ($_)->stringify (wiki => $o->{wiki}), }, }, { parent => $list->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'li'), o => $o, }); } }} Function: @Name: http_request_log @Main: my (undef, %opt) = @_; return if not $opt{wiki}->{db} or not $opt{wiki}->{input}; $opt{prop} ||= 'log__http_request'; $opt{ns} ||= [@{$opt{wiki}->{config}->{page}->{}||[]}, (gmtime)[5] + 1900]; ## From HTTP_* CGI meta variables for (qw/ Accept Accept-Charset Accept-Encoding Accept-Language Accept-Geo Accept-Features AcceptLanguage X-Awg-Client-Protocol-Version X-Awg-Client-Version Blonde-Hunter Cache-Control X-Cache-ID Cache-Info Connection Xonnection Cneonction Proxy-Connection Xroxy-Connection Content-Disposition Content-Language Content-Transfer-Encoding Content-Encoding Content-Feature Date Extension X-EGZ From X-Filtergate-Request X-IBM-RCA-Request If-Modified-Since Unless-Modified-Since If-Match If-None-Match If-Range Keep-Alive X-Locking MAX-Forwards MIME-Version Novinet Npfrefr Npfvoid Pragma ProbixpbContext ProbixpbSignature ProbixpbVersion Proxy----------- User-Agent Proxy-Agent Wser-Agent X-ICAP-Version X-HTX-Agent Dweb-Client Range Request-Range Referrer Weferer Server-Lover X-Sister TE Transfer-Encoding UA-Color UA-CPU UA-OS UA-Pixels X-UP-Subno XXXXX XXXXXXX XXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX ------- ---------- --------------- /) { (my $mv = uc $_) =~ tr/-/_/; __FUNCPACK__->_log_add (%opt, value => scalar $opt{wiki}->{input}->meta_variable ('HTTP_'.$mv), key => [@{$opt{ns}}, $_]); } __FUNCPACK__->_log_add (%opt, value => scalar $opt{wiki}->{input}->meta_variable ('CONTENT_TYPE'), key => [@{$opt{ns}}, 'Content-Type']); __FUNCPACK__->_log_add (%opt, value => scalar $opt{wiki}->{input}->meta_variable ('REQUEST_METHOD'), key => [@{$opt{ns}}, ':request-method']); ## Request header field list my $key = [@{$opt{ns}}, ':header-field']; my $list = $opt{wiki}->{db}->get ($opt{prop}, $key); for (grep s/^HTTP_//, $opt{wiki}->{input}->meta_variable_list) { (my $v = ucfirst lc $_) =~ tr/_/-/; $v =~ s/(?<=-)([a-z])/uc $1/ge; $list->{$v}++; } $opt{wiki}->{db}->set ($opt{prop}, $key => $list); my $list = $opt{wiki}->{db}->get ($opt{prop}, $key); Function: @Name: _log_add @Main: my (undef, %opt) = @_; return unless length $opt{value}; for ($opt{value}) { s/([^\x20-\x24\x26-\x5A\x5C-\x7E])/sprintf '%%%02X', unpack 'C', $1/ge; s/(bypass-client=\d+\.\d+\.)(\d+)\.(\d+)/$1.'[VAR['.('*' x length $2).']].[VAR['.('*' x length $3).']]'/ge; s/[0-5]\d:[0-5]\d:[0-5]\d GMT/[VAR[**]]:[VAR[**]]:[VAR[**]] GMT/g; s/, (?:[012]\d|3[01])(?=[ -][JFMASOND])/, [VAR[**]]/g; s/; length=([0-9]+)/'; length=[VAR['.('*' x length $1).']]'/ge; } my $list = $opt{wiki}->{db}->get ($opt{prop}, $opt{key}); $list->{$opt{value}}++; $opt{wiki}->{db}->set ($opt{prop}, $opt{key} => $list); FormattingRule: @Category[list]: page-link @Name: rl--for-param @Formatting: $p->{-parent}->append_text ($o->{link}->{dest}->{param}->{'rl--for'}); Resource: @RequestLog:List:Leaf: %link-to-it ( label => {%rl--for-param;}p, ); @RequestLog:List:Node: %link-to-it ( label => {%rl--for-param;}p, );