#!/bin/sh 
# Licence : this is a free software under GNU GPL2 
# Version: 0.0.20060714
# Author(s) :
# - Xavier Bonnafous 2005 
# - Philippe Coval <http://rzr.online.fr/contribs.htm>


LOG=/var/log/apache2/access.log
[ ! -r $LOG ] && LOG=/var/log/apache/access.log

parse_()
{
    line=$*

    deb=$(echo $line | cut -d \" -f -2 | sed 's/HTTP\/1.*//' | sed 's/\"//' | sed "s/- -/-/") 

    end=$(echo $deb | cut -d - -f 2- ) 
    ip=$(echo $deb | cut -d - -f 1 ) 
    local=$(echo $ip | cut -d . -f -3) 
    
    if [ "$oip" != "$ip" ]; 
        then 
        host=$(host $ip | cut -d ' ' -f 5) 
        if [[ "$host" = "3(NXDOMAIN)" || "$host" = "2(SERVFAIL)" ]]; 
            then host=$ip 
        fi
    fi 

    if [ "$local" != "192.168.1" ]; 
        then 
        if [ "$oip" != "$ip" ]; 
            then 
            geo=$(geoiplookup $ip| cut -d : -f 2 | cut -d , -f 1 | cut -b -3 2> /dev/null ) 
        fi 
    fi   
    echo -e $geo $(echo -e $host"..................................................................." | cut -b -70) $end fi oip=$ip 
}




tail -f -n 100 $LOG \
    | while read line 
  do 
#  echo $line
  parse_ $line
done

# apt-get install geoip-bin
#eof "$Id: rzr --  -- philippe.coval@laposte.net $"