Un grande grazie a Bai Borko per aver fornito le istruzioni su cui si basa quanto segue e per lo script perl.
AWStats è uno strumento libero e potente che genera statistiche per vari servizi per il web. Questo analizzatore di log funziona via CGI o dalla linea di comando e mostra tutte le informazioni possibili contenute nei log per mezzo di grafici in delle pagine web.
Prima di tutto definiamo alcune variabili di modo che possiamo soddisfare le impostazioni di varie piattaforme e le personalizzazioni di ciascuno.
# versione AWStats AWSTATS_VERSION=7.9 # dove vogliamo estrarre il pacchetto AWStats AWSTATS_PREFIX=/var/www/htdocs # cartella di configurazione AWSTATS_CONF_DIR=/etc/awstats # cartella contenente i dati DATA_DIR=/var/www/htdocs/stats # dominio da usare nel titolo del sito DOMAIN=mx.domain.tld # Alias del dominio (per le expressioni regolari, non cancellare gli slash) HOST_ALIAS=domain\\.tld # utente apache: apache o www-data o l'utente con il quale il web server viene lanciato APACHE_USR=apache # gruppo apache APACHE_GRP=$APACHE_USR # file contenente la password di apache APACHE_PWD_FILE=/etc/httpd/httpdpwd/awstats.passwd
Scaricare ed estrarre:
cd /usr/local/src
wget https://prdownloads.sourceforge.net/awstats/awstats-${AWSTATS_VERSION}.tar.gz
tar -zxf awstats-${AWSTATS_VERSION}.tar.gz -C $AWSTATS_PREFIX
ln -s ${AWSTATS_PREFIX}/awstats-${AWSTATS_VERSION} ${AWSTATS_PREFIX}/awstats
Creare il file di configurazione (controllare il dominio, che comunque sarà impostato dinamicamente):
mkdir $AWSTATS_CONF_DIR
cat > ${AWSTATS_CONF_DIR}/awstats.mail.conf << __EOF__
LogFile="sudo ${AWSTATS_CONF_DIR}/qstatsaw.pl|"
LogType=M
LogFormat="%time2 %email %email_r %host %url %protocol %code %bytesd"
SiteDomain="${DOMAIN}"
HostAliases="localhost 127.0.0.1 REGEX[${HOST_ALIAS}]"
DirData="${DATA_DIR}"
DirCgi="/awstats"
DefaultFile="index.html"
LogoLink="/awstats.pl?config=mail"
Logo="awstats_logo6.png"
DirIcons="/awstatsicons"
DNSLookup=0
#AllowAccessFromWebToFollowingIPAddresses="192.168.0.2-192.168.0.240"
AllowToUpdateStatsFromBrowser=1
LevelForBrowsersDetection=0 # 0 disables Browsers detection.
LevelForOSDetection=0 # 0 disables OS detection.
LevelForRefererAnalyze=0 # 0 disables Origin detection.
LevelForRobotsDetection=0 # 0 disables Robots detection.
LevelForSearchEnginesDetection=0 # 0 disables Search engines detection.
LevelForKeywordsDetection=0 # 0 disables Keyphrases/Keywords detection.
LevelForFileTypesDetection=0 # 0 disables File types detection.
ShowMenu=1
ShowSummary=HBM
ShowMonthStats=HBM
ShowDaysOfMonthStats=HBM
ShowDaysOfWeekStats=HBM
ShowHoursStats=HBM
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowWormsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowOSStats=0
ShowBrowsersStats=0
ShowScreenSizeStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1
ShowClusterStats=0
AddDataArrayMonthStats=1
AddDataArrayShowDaysOfMonthStats=1
AddDataArrayShowDaysOfWeekStats=1
AddDataArrayShowHoursStats=1
IncludeInternalLinksInOriginSection=0
SkipHosts=""
SkipUserAgents=""
SkipFiles=""
SkipReferrersBlackList=""
OnlyHosts=""
OnlyUserAgents=""
OnlyFiles=""
__EOF__
Scaricare lo script che andrà a processare i log:
wget -O ${AWSTATS_CONF_DIR}/qstatsaw.pl https://notes.sagredo.eu/files/qmail/qstatsaw.pl
Aggiungere i permessi di esecuzione
chmod 755 ${AWSTATS_CONF_DIR}/qstatsaw.pl
Aggiungere questa riga al file sudoers
> visudo apache ALL=(ALL:ALL) NOPASSWD: /etc/awstats/qstatsaw.pl
Impostare un cron job per l'aggiornamento della statistiche di AWStats
cat > /etc/cron.d/awstats << __EOF__
# Update AWStats
*/10 * * * * ${AWSTATS_PREFIX}/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail -output> ${DATA_DIR}/index.html > /dev/null 2>&1
__EOF__
Creare la cartella che conterrà i dati e assegnare i privilegi di scittura ad apache
mkdir $DATA_DIR
# if set AllowToUpdateStatsFromBrowser=1, stats directory must be writable for apache user
chown -R ${APACHE_USR}:${APACHE_GRP} $DATA_DIR
Creare il file con le credenziali di accesso e assegnare i privilegi di lettura all'utente con cui gira il web server (si può usare qui lo stesso file già usato per vQadmin):
htpasswd -bc ${APACHE_PWD_FILE} admin [password]
chown ${APACHE_USR}:${APACHE_GRP} ${APACHE_PWD_FILE}
chmod o-r ${APACHE_PWD_FILE}
Lanciare manualmente lo script AWStats:
${AWSTATS_PREFIX}/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail -output> ${DATA_DIR}/index.html
Configurare apache. Questo è il mio virtual host dedicato.
Define HTDOCS /var/www/htdocs
Define LOGDIR /var/www/error
Define AUTH_DIR /etc/httpd/httpdpwd
Define AWSTATS ${HTDOCS}/awstats
Define DATA_DIR ${HTDOCS}/stats
<VirtualHost *:80>
ServerName qstats.domain.tld
DocumentRoot ${AWSTATS}/wwwroot
ScriptAlias /cgi-bin/ ${AWSTATS}/cgi-bin/
AddHandler cgi-script .pl
Alias /awstatsclasses ${AWSTATS}/wwwroot/classes/
Alias /awstatscss ${AWSTATS}/wwwroot/css/
Alias /awstatsicons ${AWSTATS}/wwwroot/icon/
ScriptAlias / ${AWSTATS}/wwwroot/cgi-bin/
ErrorLog ${LOGDIR}/awstats_error.log
CustomLog ${LOGDIR}/awstats_access.log common
<DirectoryMatch ${AWSTATS}|${DATA_DIR}>
AllowOverride AuthConfig
AuthType Basic
AuthUserFile ${AUTH_DIR}/awstats.passwd
AuthName "Qstats"
Require ip 10.0.0.0/24
Require valid-user
</DirectoryMatch>
</VirtualHost>
Ora navigare su http://qstats.domain.tld/awstats.pl?config=mail e il gioco è fatto.

