home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / cgi-bin / rawlog.pm < prev    next >
Encoding:
Text File  |  2004-05-20  |  4.5 KB  |  127 lines

  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.4 $ - $Author: joker $ - $Date: 2004/05/20 20:38:42 $
  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.  
  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. 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.     # Show form
  85.     &_ShowForm($Filter);
  86.  
  87.     # Precompiled regex Filter to speed up scan
  88.     if ($Filter) { $Filter=qr/$Filter/i; }
  89.  
  90.     print "<hr />\n";
  91.     
  92.     # Show raws
  93.     my $xml=($BuildReportFormat eq 'xhtml');
  94.     open(LOG,"$LogFile") || error("Couldn't open server log file \"$LogFile\" : $!");
  95.     binmode LOG;    # Avoid premature EOF due to log files corrupted with \cZ or bin chars
  96.     my $i=0;
  97.     print "<pre>";
  98.     while (<LOG>) {
  99.         chomp $_; $_ =~ s/\r//;
  100.         if ($Filter && $_ !~ /$Filter/o) { next; }
  101.         print ($xml?XMLEncode("$_"):"$_");
  102.         print "\n";
  103.         if (++$i >= $MAXLINE) { last; }
  104.     }
  105.     print "</pre><br />\n<b>$i lines.</b><br />";
  106.     return 1;
  107.     # ----->
  108. }
  109.  
  110. sub _ShowForm {
  111.     my $Filter=shift||'';
  112.     print "<br />\n";
  113.     print "<form action=\"$AWScript\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\">\n";
  114.     print "<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
  115.     print "<tr><td>";
  116.     print "<table class=\"aws_data\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
  117.     print "<tr><td><span dir=\"ltr\"><b>Show content of file '$LogFile' ($MAXLINE first lines):</b></span></td></tr>\n";
  118.     print "<tr><td>$Message[79]: <input type=\"text\" name=\"filterrawlog\" value=\"$Filter\" />       Max Number of Lines: <input type=\"text\" name=\"rawlog_maxlines\" size=\"5\" value=\"$MAXLINE\" />       <input type=\"submit\" value=\"List\" class=\"aws_button\" />\n";
  119.     print "<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" /><input type=\"hidden\" name=\"framename\" value=\"$FrameName\" /><input type=\"hidden\" name=\"pluginmode\" value=\"rawlog\" />";
  120.     print "</td></tr>\n";
  121.     print "</table>\n";
  122.     print "</td></tr></table>\n";
  123.     print "</form>\n";
  124. }
  125.  
  126. 1;    # Do not remove this line
  127.