<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#
# Lager grafer over agent_log fila (hvilke browsere som brukes)
# Skriver ut en HTML fil til $HTML_OUTPUT
#

# Log filen
$AGENT_LOG = '/var/lib/httpd/logs/almashriq/agent_log';

# Hvor utskriften skal gaa.
$HTML_OUTPUT = '/www/almashriq/htdocs/base/statistics/agent_log.html';

# Hvor lang er lengste grafen
$MAX_PIXELS = 300;

# Hvis en brower har færre req. enn dette, så regnes den under 'other'.
$OTHER_LIMIT = 20;

# Fellesnavn på alle browsere som har under $OTHER_LIMIT requests.
$OTHER_STRING = "Other browsers";


###########################################################################

# Omdirigerer utskriften
open OUT, "&gt;$HTML_OUTPUT";
select( OUT );

# Hvilken måned var det for 15 dager siden (beregner altså forrige måned)
$month = `date --date '-15 day' '+%b %Y'`;

print "&lt;html&gt;";
print "&lt;body bgcolor=\"FFFFFF\"&gt;";
print "&lt;center&gt;";
print "&lt;a href=\"/\"&gt;";
print "&lt;img src=\"/sys/almashriq-pan-head.gif\" border=0&gt;";
print "&lt;/a&gt;";
print "&lt;h3&gt;Browser statistics for $month&lt;/h3&gt;\n";
print "&lt;font size=-1&gt;(Numbers based on requests)&lt;/font&gt;&lt;br&gt;";
print "&lt;p&gt;";
print "&lt;table border=0 width=528&gt;\n";  # Skriv ut som tabell


#Leser inn logfila. Og teller opp
open LOG, $AGENT_LOG;
while( &lt;LOG&gt; ) {
	if( $_ =~ /MSIE/ ) { $_ =~ s/Mozilla/MSIE/; } #Skill "MSIE-Mozilla" fra Mozilla
	$agent = (split / /, $_)[0];            #Trekk ut browsernavn
	$agent =~ s/(\/\d+)?\..*/$1\.xx/;	#Kutt vekk sekundaer ver. (1.3.2 -&gt; 1.xx)
	chomp $agent;
	$count{$agent}++;			#Tell
}
close LOG;

# Legg sammen browsere som har mindre enn $OTHER_LIMIT req.
foreach (keys %count) {
	if( $count{$_}&lt;$OTHER_LIMIT ) {
		$count{'Other browsers'} += $count{$_};
		delete $count{$_};
	}
}


# Finn hoeyeste antall requests ($top_req)
foreach (keys %count) {
	$top_req = $count{$_} if( $count{$_} &gt; $top_req );
}

# Brukes til aa sortere %count. Hoeyeste verdi foerst
sub req_sort {
	$count{$b} &lt;=&gt; $count{$a};
}

# Sorter %top_browsers, og skriv ut
foreach (sort req_sort keys %count) {
	next if( $_ eq $OTHER_STRING ); #Ikke skriv ut 'other'
	$pix = int( $count{$_}/$top_req*$MAX_PIXELS );	#Hvor lang 'bar'/graf?

	print "&lt;tr&gt;&lt;td align=\"left\"&gt;$_&lt;/td&gt;\n";
	print "&lt;td align=\"left\"&gt;";
	print "&lt;img src=\"/sys/pixel-brown.gif\" height=8 width=$pix&gt;" unless ($pix == 0);
	print "&lt;/td&gt;\n";
	print "&lt;td align=\"left\"&gt;(".$count{$_}.")&lt;/td&gt;&lt;/tr&gt;\n";
}

# Skriv ut 'other' til sist
$pix = int( $count{$OTHER_STRING}/$top_req*$MAX_PIXELS ); #Hvor lang 'bar'/graf?

print "&lt;tr&gt;&lt;td colspan=3&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;\n";

print "&lt;tr&gt;&lt;td align=\"left\"&gt;$OTHER_STRING&lt;/td&gt;\n";
print "&lt;td align=\"left\"&gt;";
print "&lt;img src=\"/sys/pixel-brown.gif\" height=8 width=$pix&gt;" unless ($pix == 0);
print "&lt;/td&gt;\n";
print "&lt;td align=\"left\"&gt;(".$count{$OTHER_STRING}.")&lt;/td&gt;&lt;/tr&gt;\n";
print "&lt;/table&gt;\n";

#sist oppdatert
$date =`date '+%y%m%d'`;

print "&lt;a href=\"./\"&gt;";
print "&lt;img src=\"/sys/almashriq-bottom-line.gif\" border=0&gt;";
print "&lt;/a&gt;&lt;br&gt;\n";
print "&lt;a href=\"/base/mailpage.html\"&gt;al\@mashriq&lt;/a&gt;&lt;p&gt;";
print "&lt;font size=-1&gt;$date&lt;/font&gt;";
print "&lt;/body&gt;&lt;/html&gt;";

close OUT;













</pre></body></html>