As I have multiple websites which I like to utilise AWStats for (there are still benefits to server based logging over Google Analytics, however I like to use them together) I scp all of the Apache/httpd log files onto my awstats server. Below is a little PHP page which parses the AWStats config directory to generate an index page to make it easier to identify and navigate to each statistics page.

<!DOCTYPE html>
<html>
<head><title>AWStats listing</title>

<style type="text/css">
        body {
                font: 14px verdana, arial, helvetica, sans-serif;
                background-color: #eee;
                margin-top: 0;
                margin-bottom: 0;
        }
        a { font: 14px verdana, arial, helvetica, sans-serif; }
        a:link    { color: #0011BB; text-decoration: none; }
        a:visited { color: #0011BB; text-decoration: none; }
        a:hover   { color: #605040; text-decoration: underline; }
        #container {
                background-color: #fff;
                text-align: center;
                position:absolute;
                width:400px;
                z-index:15;
                top:40%;
                left:50%;
                margin:-100px 0 0 -200px;
                border: 2px solid #CCD;
        }
        ul {
                text-align: left;
        }
</style>
</head>
<body>
        <div id="container">
                <p><img src="/awstatsicons/other/awstats_logo6.png" border="0" width="90px" /></p>
                <p>Available AWStats for websites on this server:</p>
                <ul>
<?php

# Page by Sam Osborne
# 28-04-14
$directory = '/etc/awstats/';
$scanned_directory = array_diff(scandir($directory), array('..', '.', 'awstats.localhost.localdomain.conf', 'awstats.model.conf')); #array of files to exclude
foreach($scanned_directory as $file){
        if(substr($file, -4) != ".bak"){ #don't list .bak files
                $fileshort = substr(substr($file, 8), 0, -5);#Remove the awstats. (8 chars) from the front and .conf (5) from the end of the string
                echo '                  <li><a href="/awstats/awstats.pl?config='.$fileshort.'">'.$fileshort.'</a></li>'."\n";
        }
}
?>
                </ul>
        </div>
</body>
</html>

You may need to adjust the A HREF URL if you installation is different.

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *