home *** CD-ROM | disk | FTP | other *** search
- # -------------------------------------------------------------------------
- # This module presents an example PowerWeb Server++ WebScript.
- #
- # It is deliberately written as a module, not a package, to demonstrate
- # how you would write a WebPerl Script while developing and debugging it.
- # When development is complete, you would convert it into a package
- # with a subroutine, as demonstrated by the "sample.pm" package.
- #
- # BROWSERS - Analyzes the user agent log by browser and OS
- #
- # ACKNOWLEDGEMENT:
- # Original Author: Jon Udell, Byte Magazine
- #
- # COPYRIGHT:
- # CompuSource (Pty) Ltd
- # Licensed Materials - Property of CompuSource (Pty) Ltd
- # (C) Copyright CompuSource (Pty) Ltd 1994-1996.
- # All Rights Reserved
- # Use, duplication, or disclosure restricted by international
- # copyright law.
- #
- # -------------------------------------------------------------------------
-
- use WebPerl;
-
- my ($Mozilla, $Mosaic, $Microsoft, $Lynx, $WebExplorer, $NetCruiser) = (0, 0, 0, 0, 0, 0);
- my ($Windows, $Macintosh, $UnixGUI, $UnixText, $OS2) = (0, 0, 0, 0, 0);
- my ($links, $hits) = (0, 0);
- my ($date, $time, $tz, $ip, $browser);
- my ($first_date, $last_date);
- my %BrowserList;
- my ($parcel) = WebPerl::GetParcel();
- my ($logfile) = WebPerl::ReadText($parcel, "Config:/ServerRoot");
-
- WebPerl::Print '<html><head><title>Browser Stats</title></head>';
- WebPerl::Print '<body background=/icons/textures/paper.jpg>';
-
- $logfile = $logfile . '/logs/http.ag1';
-
- if (!open (HITS, $logfile)) {
- WebPerl::Print "
- <h3>Error:</h3>The log file $logfile was not found.<p>
- You either do not have
- <a href=/!admin/servers/http/audit>User-Agent logging</a> enabled,
- or you have not <a href=/admin/svrlog.htm>rotated</a> your log file.<p>";
- }
- else {
- while (<HITS>)
- {
- chop;
-
- if (/Mozilla/ && !/MSIE/) # watch out for "cloaked" MSIE!
- {$Mozilla++;}
- elsif (/Mosaic/)
- {$Mosaic++;}
- elsif (/Microsoft/ || /MSIE/)
- {$Microsoft++;}
- elsif (/Lynx/)
- {$Lynx++;}
- elsif (/WebExplorer/)
- {$WebExplorer++;}
- elsif (/NetCruiser/)
- {$NetCruiser++;}
-
- if (/Windows|Microsoft|Win32|Quarterdeck|Chameleon|AIR_Mosaic|SPRY_Mosaic|Win16|WinNT|WindowsNT|Win95/)
- {$Windows++;}
- elsif (/Macintosh/)
- {$Macintosh++;}
- elsif (/X11|X Window/)
- {$UnixGUI++;}
- elsif (/Lynx/)
- {$UnixText++;}
- elsif (/WebExplorer/)
- {$OS2++;}
-
- if (/\[(.*?):(.*)\s(.*)\]\s(.*)\s:\s(.*)/) {
- ($date, $time, $tz, $ip, $browser) = ($1, $2, $3, $4, $5);
- $BrowserList{$browser}++;
-
- if (!$first_date) {
- $first_date = $date;
- }
- }
- $links++;
- }
-
- close(HITS);
-
- $last_date = $date;
-
- $hits = 0;
- foreach $browser (sort keys %BrowserList)
- {
- $hits += $BrowserList{$browser};
- }
-
- WebPerl::Print "<h3>Browser Stats from $first_date to $last_date</h3>";
-
- WebPerl::Print '<table border cellpadding=4>';
- WebPerl::Print '<caption><b>Browser summary</b></caption>';
- WebPerl::Print '<tr><th><b>Browser</b></th><th><b>Hits</b></th><th><b>%</b></th></tr>';
- WebPerl::Print sprintf ('<tr align=right><td align=left>Netscape</td><td align=right>%d</td><td><b><b>%.0f</b></td></tr>', $Mozilla, 100*$Mozilla/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Mosaic</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $Mosaic, 100*$Mosaic/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Microsoft</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $Microsoft, 100*$Microsoft/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Lynx</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $Lynx, 100*$Lynx/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>WebExplorer</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $WebExplorer, 100*$WebExplorer/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>NetCruiser</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $NetCruiser, 100*$NetCruiser/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Accounted for</td><td align=right>%d</td><td><b>%.0f</b></td></tr>',
- $Mozilla+$Mosaic+$Microsoft+$Lynx+$WebExplorer+$NetCruiser,
- 100*($Mozilla+$Mosaic+$Microsoft+$Lynx+$WebExplorer+$NetCruiser)/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left><b>Total</b></td><td align=right><b>%d</b></td><td><b>100</b></td></tr>', $hits);
- WebPerl::Print '</table>';
-
- WebPerl::Print '<p><table border cellpadding=4>';
- WebPerl::Print '<caption><b>Platform summary</b></caption>';
- WebPerl::Print '<tr><th><b>Platform</b></th><th><b>Hits</b></th><th><b>%</b></th></tr>';
- WebPerl::Print sprintf ('<tr align=right><td align=left>Windows</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $Windows, 100*$Windows/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>UnixGUI</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $UnixGUI, 100*$UnixGUI/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>UnixText</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $UnixText, 100*$UnixText/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Macintosh</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $Macintosh, 100*$Macintosh/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>OS/2</td><td align=right>%d</td><td><b>%.0f</b></td></tr>', $OS2, 100*$OS2/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left>Accounted for</td><td align=right>%d</td><td><b>%.0f</b></td></tr>',
- $Windows+$Macintosh+$UnixGUI+$UnixText+$OS2,
- ($Windows+$Macintosh+$UnixGUI+$UnixText+$OS2)/$hits);
- WebPerl::Print sprintf ('<tr align=right><td align=left><b>Total</b></td><td align=right><b>%d</b></td><td><b>100</b></td></tr>', $hits);
- WebPerl::Print '</table>';
-
- WebPerl::Print '<p><table border cellpadding=4>';
- WebPerl::Print '<caption><b>Browser Details</b></caption>';
- WebPerl::Print '<tr><th><b>Browser</b></th><th><b>Hits</b></th></tr>';
- foreach $browser (sort keys %BrowserList)
- {
- WebPerl::Print "<tr align=right><td align=left>$browser</td><td>$BrowserList{$browser}</td></tr>";
- }
- WebPerl::Print '</table>';
- }
-
- WebPerl::Print '</body></html>';
-
- 0;
-
-