Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Awstats browsers and resetting statistics

I want to improve the browser user agent capture of my statistics. The main browsers I use (and that I project onto my audience) include palemoon and LibreWolf, so I wanted to show those different version numbers like Firefox and Chrome. I modified a few important files:

File /usr/share/awstats/wwwroot/cgi-bin/awstats.pl:

--- /usr/share/awstats/wwwroot/cgi-bin/awstats.pl.2022-04-29.01 2020-12-30 22:19:32.000000000 +0000
+++ /usr/share/awstats/wwwroot/cgi-bin/awstats.pl   2022-04-29 20:40:51.521656143 +0000
@@ -18110,6 +18110,9 @@
    my $regvermsie11      = qr/trident\/7\.\d*\;([a-zA-Z;+_ ]+|)rv:([\d\.]*)/i;
    my $regvernetscape    = qr/netscape.?\/([\d\.]*)/i;
    my $regverfirefox     = qr/firefox\/([\d\.]*)/i;
+   my $regverlibrewolf   = qr/librewolf\/([\d\.]*)/i;
+   my $regvernewmoon     = qr/newmoon\/([\d\.]*)/i;
+   my $regverpalemoon    = qr/palemoon\/([\d\.]*)/i;
    # For Opera:
    # OPR/15.0.1266 means Opera 15 
    # Opera/9.80 ...... Version/12.16 means Opera 12.16
@@ -19745,6 +19748,33 @@
                            if ($PageBool) { $_browser_p{"firefox$1"}++; }
                            $TmpBrowser{$UserAgent} = "firefox$1";
                        }
+                       
+                       # LibreWolf ?
+                       elsif ( $UserAgent =~ /$regverlibrewolf/o
+                           && $UserAgent !~ /$regnotfirefox/o )
+                       {
+                           $_browser_h{"librewolf$1"}++;
+                           if ($PageBool) { $_browser_p{"librewolf$1"}++; }
+                           $TmpBrowser{$UserAgent} = "librewolf$1";
+                       }
+                       
+                       # newmoon ?
+                       elsif ( $UserAgent =~ /$regvernewmoon/o
+                           && $UserAgent !~ /$regnotfirefox/o )
+                       {
+                           $_browser_h{"newmoon$1"}++;
+                           if ($PageBool) { $_browser_p{"newmoon$1"}++; }
+                           $TmpBrowser{$UserAgent} = "newmoon$1";
+                       }
+                       
+                       # palemoon ?
+                       elsif ( $UserAgent =~ /$regverpalemoon/o
+                           && $UserAgent !~ /$regnotfirefox/o )
+                       {
+                           $_browser_h{"palemoon$1"}++;
+                           if ($PageBool) { $_browser_p{"palemoon$1"}++; }
+                           $TmpBrowser{$UserAgent} = "palemoon$1";
+                       }

                        # Chrome ?
                        elsif ( $UserAgent =~ /$regverchrome/o ) {

I also modified file /usr/share/awstats/lib/browsers.pm to have relevant entries to my target audience's tastes.

--- /usr/share/awstats/lib/browsers.pm.2022-04-29.01    2017-02-20 23:35:50.000000000 +0000
+++ /usr/share/awstats/lib/browsers.pm  2022-04-29 20:40:16.032063869 +0000
@@ -25,10 +25,10 @@

 # Relocated from main file for easier editing
 %BrowsersFamily = (
-   'msie'      => 1,
-   'edge'      => 2,
-   'firefox'   => 3,
-   'netscape'  => 4,
+   'librewolf' => 1,
+   'newmoon'   => 2,
+   'palemoon'  => 3,
+   'firefox'   => 4,
    'svn'       => 5,
    'opera'     => 6,
    'safari'    => 7,
@@ -52,6 +52,10 @@
 'links',
 'lynx',
 'omniweb',
+'librewolf',
+'palemoon',
+'newmoon',
+'webbrowser',
 # Other standard web browsers
 '22acidownload',
 'abrowse',
@@ -264,6 +268,10 @@
 %BrowsersHashIDLib = (
 # Common web browsers text, included the ones hard coded in awstats.pl
 # firefox, opera, chrome, safari, konqueror, svn, msie, netscape
+'librewolf','LibreWolf', # must happen before Firefox
+'palemoon','Pale Moon',
+'newmoon','newmoon',
+'webbrowser','web browser',
 'firefox','Firefox',
 'opera','Opera',
 'chrome','Google Chrome',
@@ -525,6 +533,10 @@
 'svn','subversion',
 'msie','msie',
 'edge','edge',
+'palemoon','newmoon',
+'newmoon','newmoon',
+'librewolf','librewolf',
+'webbrowser','web browser',
 'netscape','netscape',

 'firebird','phoenix',

I also added the relevant icon files:

/usr/share/awstats/wwwroot/icon/browser/librewolf.png
/usr/share/awstats/wwwroot/icon/browser/newmoon.png

Reload statistics

I had to develop this step to rebuild my stats with these browsers to look for, as well as to catch an IP address block I added near the start of this month.

To clear out the compiled statistics Reference 1. You might want to archive your statistics beforehand, of course, but the simple version is just to delete the files.

rm /var/lib/awstats/regular/awstats*

And now rebuild statistics (with the -update) and generate new static pages per month and year. My stats started in September 2021.

time sudo /usr/share/awstats/tools/awstats_buildstaticpages.pl -update -config=doc7-01a -configdir=/etc/awstats -dir=/var/lib/awstats/static -builddate="2021-09" -year="2021" -month="09"

And now the rest of the months, and then by years:

time for d in 2021-{10..12} 2022-{01..04} ; do Y="$( echo "${d}" | awk -F'-' '{print $1}' )" ; M="$( echo "${d}" | awk -F'-' '{print $2}' )" ; sudo /usr/share/awstats/tools/awstats_buildstaticpages.pl -config=doc7-01a -configdir=/etc/awstats -dir=/var/lib/awstats/static -builddate="${Y}-${M}" -year="${Y}" -month="${M}" ; done
time for d in 202{1..2} ; do Y="$( echo "${d}" | awk -F'-' '{print $1}' )" ; sudo /usr/share/awstats/tools/awstats_buildstaticpages.pl -config=doc7-01a -configdir=/etc/awstats -dir=/var/lib/awstats/static -builddate="${Y}" -year="${Y}" -month="all" ; done

References

  1. https://awstats.sourceforge.io/docs/awstats_faq.html#RESET

Comments