Index: [Article Count Order] [Thread]

Date:  Thu, 25 Nov 2004 11:20:37 +0100
From:  =?us-ascii?Q?Trond_Huso?= <tr-huso (at mark) online.no>
Subject:  [coba-e:01611] How to: Make webalizer to work
To:  <coba-e (at mark) bluequartz.org>
Message-Id:  <001401c4d2d8$6941b7e0$0201a8c0@mainpc>
X-Mail-Count: 01611

As we got webalizer to work thanks to the great work of Leigh Blackwell, I
put the whole code and tips from Blackwell and put it in one file. And added
those late fixes. Maybe someone can post this on some site and remember to
credit Blackwell (And buy him a beer - or any drink he prefers - whenever
you see him)


Step1:
You need a modified copy of the webalizer.pl perl script as on older Raqs
pkgs..

<start /usr/bin/webalizer.pl>
#!/usr/bin/perl
#
# This script runs webalizer for every virtual site on a Cobalt RaQ3
# machine.  This depends on the configuration file /etc/webalizer.conf
# and several command-line switches including those for the LogFile and
# Hostname.
#
# PLEASE NOTE: The /stats directory created will be password protected
# allowing only site admins in for that site.
#
use Time::localtime;
# Where sites on a RaQ3/4 live
$prefix = "/home/sites";

# Status messages
my $messages;

chdir "$prefix" or die "Can't cd to $prefix??: $!\n";
opendir THEROOT, $prefix or die "Couldn't open $prefix?: $!\n";
@allsites = grep !/^\.\.?$/,  readdir THEROOT;

foreach $asite (@allsites)
{  
  if (-l "$asite")
  {
    $webpath = "$prefix/$asite/web";
    $thepath = "$prefix/$asite/webalizer";

    # Get the group id of the directory
    my $gid = (stat $webpath)[5];
    my $name = (getgrgid $gid)[0];

    # Create a directory /web/stats if it isn't there yet
    if (!-d $thepath)
    {
       mkdir $thepath, 775; 
       chown 0, $gid, $thepath;
       chmod 0755, $thepath;
    }
    if ( -e $prefix."/".$asite."/logs/web.log"){
    # Now just run webalizer
    $messages .=
       `/usr/bin/webalizer -p -n $asite -s $asite -r $asite  -T -o $thepath
$prefix/$asite/logs/web.log`;

    # Now change ownership of files for frontpage and non-frontpage enabled
sites 

    if (!-d $webpath . "/_vti_bin") {
        $messages .= `echo "Frontpage NOT ENABLED on $webpath"`;
        $messages .= `chown -R apache:$name $thepath`;
    } else {
        $messages .= `echo "Frontpage ENABLED on $webpath"`;
        $messages .= `chown -R nobody:$name $thepath`;
    }
   }else{

        $message .= "No log file for: " . $asite ."\n";

   }
  }
}
open(BOOK, ">>/home/webalizer.log");
print BOOK $messages;
close(BOOK);
exit 0;



</End of /usr/bin/webalizer.pl>


I put this file in /usr/bin/webalizer.pl with permissions 755 

Step2:

Sort out the rotate logs. 
Create the directory 
mkdir /home/tmp

remove the file
rm /etc/logrotate.d/httpd

Which conflicts with the following file:

/etc/logrotate.d/apache


<snip>
/var/log/httpd/access_log {
    daily
    prerotate
        rm -rf /home/tmp/.logrotate_apache_access >/dev/null 2>&1
        cp /var/log/httpd/access_log /home/tmp/.logrotate_apache_access
>/dev/null 2>&1
    endscript
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
        /usr/local/sbin/split_logs web < /home/tmp/.logrotate_apache_access
        /usr/bin/nohup /usr/bin/webalizer.pl &
        rm -f /home/tmp/.logrotate_apache_access >/dev/null 2>&1
    endscript
}

/var/log/httpd/agent_log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
    endscript
}

/var/log/httpd/error_log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
    endscript
}

/var/log/httpd/ssl_error_log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
    endscript
}


/var/log/httpd/referer_log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
    endscript
}

/var/log/httpd/ssl_request_log {
    missingok
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null ||
true
    endscript
}

</snip>


This should generate your webalizer stats for each site no new cron jobs are
required. As Htaccess doesn't work as on the old raqs. I have put the stats
into the bluequartz admin area this is achieved with the addition of two
files, and I think looks really cool.

Step 3.

/usr/sausalito/ui/menu/webalizer.xml

<item id="base_webalizer"
   label="Webalizer"
   description="Webalizer Statistics."
   url="/base/sitestats/webalizer.php?group=[[VAR.group]]" >
   <parent id="base_siteusage" order="20"/>
</item>


/usr/sausalito/ui/web/base/sitestats/webalizer.php

<?php

include_once('ServerScriptHelper.php');

$helper =& new ServerScriptHelper();
$factory =& $helper->getHtmlComponentFactory('base-ssl',
'/base/ssl/siteSSL.php');
$cce =& $helper->getCceClient();
$page = $factory->getPage();
$i18n =& $factory->getI18n();

if ($group)
{
    list($oid) = $cce->find('Vsite', array('name' => $group));
    $vsite_info = $cce->get($oid);
    $fqdn = $vsite_info['fqdn'];
}

if (!$file)
{
$file = "index.html";
}

$fullPath = "/home/sites/" . $vsite_info['fqdn'] . "/webalizer/" . $file;

if (preg_match('/html/', $file)){
print $page->toHeaderHtml();
}

if (file_exists($fullPath)){

        $fp = fopen ($fullPath, "r");

        $data = "";
        while(!feof($fp))
        {
                $string = fgets($fp, 4096);
                $string=str_replace("<A HREF=\"usage", "<A
HREF=\"webalizer.php?group=" . $group . "&file=usage", $string);
                $string=str_replace("<IMG SRC=\"", "<IMG
SRC=\"webalizer.php?group=" . $group . "&file=", $string);
                $data .= $string;
        }

        echo $data;

        @flose($fp);

}else{

        echo "<h4>Page not Found</h4>" . $fullPath;

}

if (preg_match('/html/', $file)){
print $page->toFooterHtml();
}

exit ();

?>

To make FTP to work 

/var/log/xferlog {
        missingok
        prerotate
                /usr/local/sbin/ftplog2commonlog < /var/log/xferlog | \
                        /usr/local/sbin/split_logs ftp
        endscript
        notifempty
        postrotate
                /usr/bin/kill -HUP `cat /var/run/proftpd.pid 2>/dev/null`
2>/dev/null || true
        endscript
}

To make mail logging work change /etc/logrotate.d/syslog

/var/log/messages /var/log/secure /var/log/spooler /var/log/boot.log
/var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null
|| true
    endscript
}

/var/log/maillog {
    prerotate
        /usr/local/sbin/maillog2commonlog.pl sendmail < /var/log/maillog | \
            /usr/local/sbin/split_logs mail
    endscript
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null
|| true
    endscript
    daily
}

in webalizer.conf change the lines:
HistoryName     /var/lib/webalizer/webalizer.hist
IncrementalName /var/lib/webalizer/webalizer.current

to:
HistoryName     webalizer.hist
IncrementalName webalizer.current

In httpd.conf check that the LogFormat-line looks like this:
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined LogFormat "%h %l %u %t \"%r\" %>s %b" common LogFormat "%{Referer}i
-> %U" referer LogFormat "%{User-agent}i" agent