How to add menu to AWStats web-interface

I have described a simple way to configure AWStats web-interface last month, so I will continue this topic further and tell you how to add a menu to quickly switch between configured sites.

You need to set to true the UseFramesWhenCGI AWStats configuration directive. Then, the whole process is based on left frame modification, which can be achieved by editing HTMLTopBanner function located in /usr/lib/cgi-bin/awstats.pl file.

Simple menu

The difference between before and after applying modifications.

AWStats - Simple menu

The following modification provides small and simple static menu.

--- awstats.pl  2016-05-04 21:30:39.689655190 +0000
+++ awstats.simple.pl   2016-05-04 21:16:59.327708554 +0000
@@ -9835,6 +9835,14 @@
                        print "</td>";
                }
                print "$lt;/tr>\n";
+               print "$lt;tr>";
+                print "$lt;td class=\"aws\">";
+                print "Other: ";
+                print "[$lt;a target=\"_parent\" href=\"/awstats.pl?config=sleeplessbeastie.eu\">www</a>] ";
+                print "[$lt;a target=\"_parent\" href=\"/awstats.pl?config=blog.sleeplessbeastie.eu\">blog</a>] ";
+                print "[$lt;a target=\"_parent\" href=\"/awstats.pl?config=repository.sleeplessbeastie.eu\">repo</a>]";
+                print "$lt;/td>";
+                print "$lt;/tr>";
        }
        if ( $FrameName ne 'mainleft' ) {
 

Advanced menu

The difference between before and after applying modifications.

AWStats - Advanced menu

The following modification provides more advanced menu without duplicated entries.

--- awstats.pl  2016-05-04 21:30:39.689655190 +0000
+++ awstats.advanced.pl 2016-05-04 21:30:12.386589742 +0000
@@ -9835,6 +9835,13 @@
                        print "</td>";
                }
                print "</tr>\n";
+               print "<tr>";
+                print "<td class=\"aws\">";
+                foreach my $tempSite ('sleeplessbeastie.eu', 'blog.sleeplessbeastie.eu', 'repository.sleeplessbeastie.eu', 'survey.sleeplessbeastie.eu', 'debian.sleeplessbeastie.eu') {
+                       if ( $SiteDomain ne $tempSite ) { print "<a target=\"_parent\" href=\"/awstats.pl?config=$tempSite\">$tempSite</a><br/>"; }
+                }
+                print "</td>";
+                print "</tr>";
        }
        if ( $FrameName ne 'mainleft' ) {
 

You can apply these patches using patch utility against awstats 7.2 (build 1.992).

Downloads

awstats.simple.patch

awstats.advanced.patch

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu