#! /usr/bin/perl -w

# vim:syntax=perl

# $Id: dlf2combined.in,v 1.3 2009/01/17 11:54:27 vanbaal Exp $
# $Source: /cvsroot/logreport/service/www/script/dlf2combined.in,v $

# Copyright (C) 2008 Joost van Baal
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License, as published by the Free Software
# Foundation, either version 2 of the License, or (at your option) any later
# version.  There is NO warranty.  A copy of the GNU GPL is available from
# http://www.gnu.org/licenses/.

# This script converts a Lire www DLF on stdin to the combined log format on
# stdout.  This script is used by merge2combined.

use strict;
use POSIX qw(strftime);

sub call2CLFtime {
    my $time = shift or die "call2CLFtime needs one argument\n";
    my @t = localtime($time);
    return strftime "[%d/%b/%Y:%H:%M:%S %z]", @t;
}

while (<>) {
    my ($d, $e, $client_host, $who, $http_result, $requested_page_size,
      $http_action, $requested_page, $http_protocol, $time, $referer,
      $useragent, $f, $g) = split;

    my $clftime = call2CLFtime($time);

    $useragent =~ s/_/ /g;

    print "$client_host - - $clftime \"$http_action $requested_page $http_protocol\" $http_result - \"-\" \"$useragent\"\n";
}


