~ubuntu-branches/ubuntu/jaunty/awstats/jaunty-updates

« back to all changes in this revision

Viewing changes to wwwroot/cgi-bin/plugins/rawlog.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2004-05-05 05:12:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040505051207-wfi8hydpa89pvuoi
Tags: upstream-6.0
ImportĀ upstreamĀ versionĀ 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#-----------------------------------------------------------------------------
 
3
# Rawlog AWStats plugin
 
4
# This plugin adds a form in AWStats main page to allow users to see raw
 
5
# content of current log files. A filter is also available.
 
6
#-----------------------------------------------------------------------------
 
7
# Perl Required Modules: None
 
8
#-----------------------------------------------------------------------------
 
9
# $Revision: 1.12 $ - $Author: eldy $ - $Date: 2003/12/12 19:25:08 $
 
10
 
 
11
 
 
12
# <-----
 
13
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES.
 
14
# ----->
 
15
use strict;no strict "refs";
 
16
 
 
17
 
 
18
 
 
19
#-----------------------------------------------------------------------------
 
20
# PLUGIN VARIABLES
 
21
#-----------------------------------------------------------------------------
 
22
# <-----
 
23
# ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 
24
# AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
 
25
my $PluginNeedAWStatsVersion="5.7";
 
26
my $PluginHooksFunctions="AddHTMLBodyHeader BuildFullHTMLOutput";
 
27
# ----->
 
28
 
 
29
# <-----
 
30
# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 
31
use vars qw/
 
32
$MAXLINE
 
33
/;
 
34
# ----->
 
35
 
 
36
 
 
37
 
 
38
#-----------------------------------------------------------------------------
 
39
# PLUGIN FUNCTION: Init_pluginname
 
40
#-----------------------------------------------------------------------------
 
41
sub Init_rawlog {
 
42
        my $InitParams=shift;
 
43
        my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
 
44
 
 
45
        # <-----
 
46
        # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
 
47
        debug(" InitParams=$InitParams",1);
 
48
        $MAXLINE=5000;
 
49
        # ----->
 
50
 
 
51
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
 
52
}
 
53
 
 
54
 
 
55
 
 
56
#-----------------------------------------------------------------------------
 
57
# PLUGIN FUNTION: AddHTMLBodyHeader_pluginname
 
58
# UNIQUE: NO (Several plugins using this function can be loaded)
 
59
# Function called to Add HTML code at beginning of BODY section.
 
60
#-----------------------------------------------------------------------------
 
61
sub AddHTMLBodyHeader_rawlog {
 
62
        # <-----
 
63
        # Show form only if option -staticlinks not used
 
64
        if (! $StaticLinks) { &_ShowForm(''); }
 
65
        return 1;
 
66
        # ----->
 
67
}
 
68
 
 
69
 
 
70
#-----------------------------------------------------------------------------
 
71
# PLUGIN FUNTION: BuildFullHTMLOutput_pluginname
 
72
# UNIQUE: NO (Several plugins using this function can be loaded)
 
73
# Function called to output an HTML page completely built by plugin instead
 
74
# of AWStats output
 
75
#-----------------------------------------------------------------------------
 
76
sub BuildFullHTMLOutput_rawlog {
 
77
        # <-----
 
78
        my $Filter='';
 
79
        if ($QueryString =~ /filterrawlog=([^&]+)/i) { $Filter=&DecodeEncodedString("$1"); }
 
80
 
 
81
        # Show form
 
82
        &_ShowForm($Filter);
 
83
 
 
84
        # Precompiled regex Filter to speed up scan
 
85
        if ($Filter) { $Filter=qr/$Filter/i; }
 
86
 
 
87
        print "<hr />\n";
 
88
        
 
89
        # Show raws
 
90
        open(LOG,"$LogFile") || error("Couldn't open server log file \"$LogFile\" : $!");
 
91
        binmode LOG;    # Avoid premature EOF due to log files corrupted with \cZ or bin chars
 
92
        my $i=0;
 
93
        while (<LOG>) {
 
94
                chomp $_; $_ =~ s/\r//;
 
95
                if ($Filter && $_ !~ /$Filter/o) { next; }
 
96
                print "$_<br />\n";
 
97
                if (++$i > $MAXLINE) { last; }
 
98
        }
 
99
        print "<br>\n<b>$i lines.</b><br />";
 
100
        return 1;
 
101
        # ----->
 
102
}
 
103
 
 
104
sub _ShowForm {
 
105
        my $Filter=shift||'';
 
106
        print "<br />\n";
 
107
        print "<form action=\"$AWScript\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\">\n";
 
108
        print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
 
109
        print "<tr><td>";
 
110
        print "<table class=\"aws_data\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
 
111
        print "<tr><td><span dir=\"ltr\"><b>Show content of file '$LogFile' ($MAXLINE first lines):</b></span></td></tr>\n";
 
112
        print "<tr><td>$Message[79]: <input type=\"text\" name=\"filterrawlog\" value=\"$Filter\" /><input type=\"submit\" value=\"List\" class=\"aws_button\" />\n";
 
113
        print "<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" /><input type=\"hidden\" name=\"framename\" value=\"$FrameName\" /><input type=\"hidden\" name=\"pluginmode\" value=\"rawlog\" />";
 
114
        print "</td></tr>\n";
 
115
        print "</table>\n";
 
116
        print "</td></tr></table>\n";
 
117
        print "</form>\n";
 
118
}
 
119
 
 
120
1;      # Do not remove this line