(file) Return to rawlog.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / wwwroot / cgi-bin / plugins

  1 rizwank 1.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.15 $ - $Author: eldy $ - $Date: 2004/08/16 19:56:00 $
 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 rizwank 1.1 # <-----
 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 rizwank 1.1 	my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
 44             
 45             	# <-----
 46             	# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
 47             	debug(" Plugin rawlog: InitParams=$InitParams",1);
 48             
 49             	if ($QueryString =~ /rawlog_maxlines=(\d+)/i) { $MAXLINE=&DecodeEncodedString("$1"); }
 50             	else { $MAXLINE=5000; }
 51             
 52             	# ----->
 53             
 54             	return ($checkversion?$checkversion:"$PluginHooksFunctions");
 55             }
 56             
 57             
 58             
 59             #-----------------------------------------------------------------------------
 60             # PLUGIN FUNTION: AddHTMLBodyHeader_pluginname
 61             # UNIQUE: NO (Several plugins using this function can be loaded)
 62             # Function called to Add HTML code at beginning of BODY section.
 63             #-----------------------------------------------------------------------------
 64 rizwank 1.1 sub AddHTMLBodyHeader_rawlog {
 65             	# <-----
 66             	# Show form only if option -staticlinks not used
 67             	if (! $StaticLinks) { &_ShowForm(''); }
 68             	return 1;
 69             	# ----->
 70             }
 71             
 72             
 73             #-----------------------------------------------------------------------------
 74             # PLUGIN FUNTION: BuildFullHTMLOutput_pluginname
 75             # UNIQUE: NO (Several plugins using this function can be loaded)
 76             # Function called to output an HTML page completely built by plugin instead
 77             # of AWStats output
 78             #-----------------------------------------------------------------------------
 79             sub BuildFullHTMLOutput_rawlog {
 80             	# <-----
 81             	my $Filter='';
 82             	if ($QueryString =~ /filterrawlog=([^&]+)/i) { $Filter=&DecodeEncodedString("$1"); }
 83             
 84                 # A security check
 85 rizwank 1.1 	if ($QueryString =~ /logfile=/i) { 
 86             	    print "<br>Option logfile is not allowed while building rawlog output.<br>";
 87                     return 0;
 88             	}
 89             
 90             	# Show form
 91             	&_ShowForm($Filter);
 92             
 93             	# Precompiled regex Filter to speed up scan
 94             	if ($Filter) { $Filter=qr/$Filter/i; }
 95             
 96             	print "<hr />\n";
 97             	
 98             	# Show raws
 99             	my $xml=($BuildReportFormat eq 'xhtml');
100             	open(LOG,"$LogFile") || error("Couldn't open server log file \"$LogFile\" : $!");
101             	binmode LOG;	# Avoid premature EOF due to log files corrupted with \cZ or bin chars
102             	my $i=0;
103             	print "<pre>";
104             	while (<LOG>) {
105             		chomp $_; $_ =~ s/\r//;
106 rizwank 1.1 		if ($Filter && $_ !~ /$Filter/o) { next; }
107             		print ($xml?XMLEncode("$_"):"$_");
108             		print "\n";
109             		if (++$i >= $MAXLINE) { last; }
110             	}
111             	print "</pre><br />\n<b>$i lines.</b><br />";
112             	return 1;
113             	# ----->
114             }
115             
116             sub _ShowForm {
117             	my $Filter=shift||'';
118             	print "<br />\n";
119             	print "<form action=\"$AWScript\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\">\n";
120             	print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
121             	print "<tr><td>";
122             	print "<table class=\"aws_data\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
123             	print "<tr><td><span dir=\"ltr\"><b>Show content of file '$LogFile' ($MAXLINE first lines):</b></span></td></tr>\n";
124             	print "<tr><td>$Message[79]: <input type=\"text\" name=\"filterrawlog\" value=\"$Filter\" /> &nbsp; &nbsp; &nbsp; Max Number of Lines: <input type=\"text\" name=\"rawlog_maxlines\" size=\"5\" value=\"$MAXLINE\" /> &nbsp; &nbsp; &nbsp; <input type=\"submit\" value=\"List\" class=\"aws_button\" />\n";
125             	print "<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" /><input type=\"hidden\" name=\"framename\" value=\"$FrameName\" /><input type=\"hidden\" name=\"pluginmode\" value=\"rawlog\" />";
126             	print "</td></tr>\n";
127 rizwank 1.1 	print "</table>\n";
128             	print "</td></tr></table>\n";
129             	print "</form>\n";
130             }
131             
132             1;	# Do not remove this line

Rizwan Kassim
Powered by
ViewCVS 0.9.2