/[pub]/suikawiki/script/misc/plugins/RequestLog.wps
Suika

Contents of /suikawiki/script/misc/plugins/RequestLog.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.3 - (show annotations) (download)
Tue Oct 26 08:28:08 2004 UTC (21 years, 2 months ago) by wakaba
Branch: branch-suikawiki-1
Changes since 1.1.2.2: +44 -1 lines
Unknown

1 Name:
2 RequestLog
3 FullName:
4 Logging HTTP Header Field Body Value in the Request
5 URI:
6 IW:SuikaWiki:"Wiki//Log"
7
8 Description:
9 Implementation of this module is temporary.
10 Reimplementation is needed!
11
12 MODULE:
13 our $LoggingName;
14 sub add ($$) {
15 my ($name, $s) = @_;
16 return unless length $s;
17 $s =~ s/([^\x20-\x24\x26-\x5A\x5C-\x7E])/sprintf '%%%02X', unpack 'C', $1/ge;
18 $s =~ s/(bypass-client=\d+\.\d+\.)(\d+)\.(\d+)/$1.'[VAR['.('*' x length $2).']].[VAR['.('*' x length $3).']]'/ge;
19 $s =~ s/[0-5]\d:[0-5]\d:[0-5]\d GMT/[VAR[**]]:[VAR[**]]:[VAR[**]] GMT/g;
20 $s =~ s/, (?:[012]\d|3[01])(?=[ -][JFMASOND])/, [VAR[**]]/g;
21 $s =~ s/; length=([0-9]+)/'; length=[VAR['.('*' x length $1).']]'/ge;
22 my %ua;
23 for (split /\n/, $main::database{$main::PageName{'Log_'.$name}}) {
24 if (/^-\{(\d+)\} (.+)$/) {
25 my ($t, $n) = ($1, $2);
26 $n =~ tr/\x0A\x0D//d;
27 $ua{$n} = $t;
28 }
29 }
30 $ua{$s}++;
31 my $s = qq(#?SuikaWiki/0.9 interactive="yes"\n);
32 for (sort {$ua{$a} <=> $ua{$b}} keys %ua) {
33 $s .= sprintf qq(-{%d} %s\n), $ua{$_}, $_;
34 }
35 SuikaWiki::Plugin->_database->STORE ($main::PageName{'Log_'.$name} => $s, -touch => 0);
36 }
37
38 my $year = (gmtime)[5] + 1900;
39 my @fields = (
40 [qw/ACCEPT AcceptType/],
41 [qw/ACCEPT_CHARSET AcceptCharset/],
42 [qw/ACCEPT_ENCODING AcceptEncoding/],
43 [qw/ACCEPT_LANGUAGE AcceptLanguage/],
44 [qw/TE AcceptTransferEncoding/],
45 [qw/CONNECTION Connection/],
46 [qw/ACCEPT_GEO AcceptGeo/],
47 [qw/KEEP_ALIVE KeepAlive/],
48 [qw/MIME_VERSION MIMEVersion/],
49 [qw/UA_COLOR UserAgentDisplayColor/],
50 [qw/UA_CPU UserAgentCPU/],
51 [qw/UA_OS UserAgentOS/],
52 [qw/UA_PIXELS UserAgentDisplaySize/],
53 [qw/CACHE_CONTROL CacheControl/],
54 [qw/PRAGMA Pragma/],
55 [qw/IF_MODIFIED_SINCE IMS/],
56 [qw/XONNECTION Xonnection:/],
57 [qw/XROXY_CONNECTION Xroxy-Connection:/],
58 [qw/UNLESS_MODIFIED_SINCE Unless-Modified-Since/],
59 [qw/XXXXX XXXXX/],
60 [qw/XXXXXXXXXX XXXXXXXXXX/],
61 [qw/XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX:/],
62 [qw/XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX:/],
63 [qw/RANGE Range:/],
64 [qw/REQUEST_RANGE Request-Range/],
65 [qw/FROM From:/],
66 [qw/DATE Date:/],
67 [qw/CONTENT_TRANSFER_ENCODING CTE/],
68 [qw/CONTENT_LANGUAGE Content-Language/],
69 [qw/CONTENT_DISPOSITION Content-Disposition/],
70 [qw/REFERRER Referrer/],
71 [qw/CONTENT_ENCODING Content-Encoding/],
72 [qw/CONTENT_FEATURES Content-Feature/],
73 [qw/ACCEPT_FEATURES Accept-Features/],
74 [qw/TRANSFER_ENCODING Transfer-Encoding/],
75 [qw/CONTENT_VERSION Content-Version/],
76 [qw/DERIVED_FROM Derived-From/],
77 [qw/IF_MATCH If-Match/],
78 [qw/IF_NONE_MATCH If-None-Match/],
79 [qw/EXTENSION Extension/],
80 [qw/_______ -------/], # 7
81 [qw/__________ ----------/], # 10
82 [qw/_______________ ---------------/],
83 [qw/PROBIXPBVERSION Probixpbversion/],
84 [qw/PROBIXPBCONTEXT Probixpbcontext/],
85 [qw/PROBIXPBSIGNATURE Probixpbsignature/],
86 [qw/WEFERER Weferer/],
87 [qw/X_LOCKING X-Locking/],
88 [qw/X_CACHE_ID X-Cache-ID/],
89 [qw/X_ICAP_VERSION X-ICAP-Version/],
90 [qw/PROXY_AGENT Proxy-Agent/],
91 [qw/PROXY___________ Proxy-----------/],
92 [qw/WSER_AGENT Wser-Agent/],
93 [qw/CACHE_INFO Cache-Info/],
94 [qw/PROBIXPBVERSION ProbixpbVersion/],
95 [qw/MAX_FORWARDS Max-Forwards/],
96 [qw/CNEONCTION Cneonction/],
97 [qw/ACCEPTLANGUAGE AcceptLanguage:/],
98 [qw/BLONDE_HUNTER Blonde-Hunter/],
99 [qw/X_EGZ X-EGZ/],
100 [qw/NPFVOID Npfvoid/],
101 [qw/SERVER_LOVER Server-Lover/],
102 [qw/X_HTX_AGENT X-HTX-Agent/],
103 [qw/NOVINET Novinet/],
104 [qw/X_IBM_RCA_REQUEST X-IBM-RCA-Request/],
105 # [qw/ /],
106 # [qw/ /],
107 # [qw/ /],
108 # [qw/ /],
109 # [qw/ /],
110 # [qw/ /],
111 # [qw/ /],
112 # [qw/ /],
113 # [qw/ /],
114 # [qw/ /],
115 # [qw/ /],
116 # [qw/ /],
117 # [qw/ /],
118 # [qw/ /],
119 # [qw/ /],
120 # [qw/ /],
121 # [qw/ /],
122 # [qw/ /],
123 # [qw/ /],
124 );
125 for (@fields) {
126 $main::PageName{'Log_'.$_->[0]} = 'Wiki//Log//'.$_->[1].'//'.$year;
127 }
128 $main::PageName{Log_CONTENT_TYPE} = 'Wiki//Log//ContentType//'.$year;
129 $main::PageName{Log_REQUEST_METHOD} = 'Wiki//Log//RequestMethod//'.$year;
130 $main::PageName{Log_HeaderField} = 'Wiki//Log//HeaderField//'.$year;
131
132 push @{$SuikaWiki::Plugin::On{WikiDatabaseLoaded}}, sub {
133 for (map {$_->[0]} @fields) {
134 my $v = $main::ENV{'HTTP_'.$_};
135 add ($_ => $v);
136 }
137 add ('CONTENT_TYPE' => $main::ENV{CONTENT_TYPE});
138 add ('REQUEST_METHOD' => $main::ENV{REQUEST_METHOD});
139
140 for (grep s/^HTTP_//, keys %main::ENV) {
141 (my $name = ucfirst lc $_) =~ s/_([a-z])/-\U$1/g;
142 $name =~ tr/_/-/;
143 add ('HeaderField' => $name);
144 }
145 };
146
147
148
149
150 POD:TO DO:
151 - better storing format
152
153 - Logging method should be more customizable (what mode? what's except?...)
154 POD:LICENSE:
155 Copyright 2003 Wakaba <w@suika.fam.cx>
156
157 %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24