Plesk: Web statistics authentication

You can setup Plesk to gather information about traffic coming to your domains.

It shows statisctics about the number of unique visitors, visits, page views, hits, bandwith on a montly, days of month, days of week, hours of day and more e.g.:

Plesk Web Statistics

In order to enable it you have to go to the Host Settings for this domain and scroll down to this part:

Plesk Web Statistics Enable

When disabled, the select box will show “None”. Choose AWStats instead to enable it.

The checkbox next to it enables authentication. If unchecked anybody can have a look at the statistics. When you check it, only authenticated users will be allowed to see the statistics.

If like me, you have migrated many sites without paying attention to this checkbox, you’ll need a long time to go through all the Hosting Settings pages of all domains and enabling authentication. Since I’m notoriously lazy, it was no option for me so I wrote the following script to switch on authentication for the web statistics of all sites where the web statistics are enabled:

#!/bin/sh
mysql -uadmin -p`cat /etc/psa/.psa.shadow` --skip-pager --skip-column-names --batch psa -e 'SELECT name FROM domains;' | while read d;do
        if [ "x`/opt/psa/bin/domain --info $d | grep 'Web statistics' | grep -v 'None' | awk '{print $3}'`" != "x" ]; then
                /opt/psa/bin/domain --update $d -webstat-protdir-access true
        fi
done

This scripts first reads all domains from the MySQL Plesk database (psa) and checks whether Web statistics are enabled. If yes, it sets the webstat-protdir-access to true, enabling authentication.

Since this script calls the domain script of Plesk twice per domain to update, it’s not really fast but it’s much less work than doing it manually.

Leave a Reply

Your email address will not be published.