#!/bin/sh --norc


###############################################################################
# Ce programme lance une fenetre graphique ("/usr/X11R6/bin/rxvt"), et affiche
# la fin du fichier de log demande par l'utilisateur. L'affichage sera
# rafraichit a toute modification du fichier  ("tail -f")
#
# Version $VERSION  Creation date: 2001/07/28         Last modified: 2004/02/01
###############################################################################
VERSION="1.3.7b"


##### Fichier de log #####
# Alias
log_file_a[0]="messages"
log_file_a[1]="ftp"
log_file_a[2]="mail"
log_file_a[3]="mail-error"
log_file_a[4]="mail-warnings"
log_file_a[5]="ip-local"
log_file_a[6]="fetchmail"
log_file_a[7]="http_access"
log_file_a[8]="http_error"
log_file_a[9]="http_perl_error"
log_file_a[10]="auth"
log_file_a[11]="samba-smb"
log_file_a[12]="samba-nmb"
log_file_a[13]="privoxy"
log_file_a[14]="syslog"
log_file_a[15]="mysql"
log_file_a[16]="mysql-error"
log_file_a[17]="ppp-script"
log_file_a[18]="netfilter_cfg"
log_file_a[19]="to"
log_file_a[20]="netfilter"
log_file_a[21]="jabber-error"
log_file_a[22]="jabber-record"

# Fichier
log_file_f[0]="/var/log/messages"
log_file_f[1]="/var/log/proftpd/all.log"
log_file_f[2]="/var/log/mail/info"
log_file_f[3]="/var/log/mail/errors"
log_file_f[4]="/var/log/mail/warnings"
log_file_f[5]="/var/log/ip-local.log"
log_file_f[6]="$HOME/var/log/fetchmail.log"
log_file_f[7]="/var/log/httpd/access_log"
log_file_f[8]="/var/log/httpd/error_log"
log_file_f[9]="/var/log/httpd/perl-error_log"
log_file_f[10]="/var/log/auth.log"
log_file_f[11]="/var/log/samba/log.smbd"
log_file_f[12]="/var/log/samba/log.nmbd"
log_file_f[13]="/home/privoxy/var/log/logfile"
log_file_f[14]="/var/log/syslog"
log_file_f[15]="/home/mysql/phoenix.log"
log_file_f[16]="/home/mysql/phoenix.sky.net.err"
log_file_f[17]="/var/log/ppp-script.log"
log_file_f[18]="/var/log/netfilter_cfg"
log_file_f[19]="/usr/local/games/tacticalops/tacticalops.log"
log_file_f[20]="/var/log/ulogd.syslogemu"
log_file_f[21]="/var/log/jabber/error.log"
log_file_f[22]="/var/log/jabber/record.log"

# Titre
log_file_t[0]="Linux messages log"
log_file_t[1]="Ftp log"
log_file_t[2]="Mail log"
log_file_t[3]="Mail error log"
log_file_t[4]="Mail warning log"
log_file_t[5]="Script ip-up/down.local"
log_file_t[6]="Fetchmail log"
log_file_t[7]="HTTP access log"
log_file_t[8]="HTTP error log"
log_file_t[9]="HTTP perl error log"
log_file_t[10]="Authentification log"
log_file_t[11]="Samba smb log"
log_file_t[12]="Samba nmb log"
log_file_t[13]="Privoxy log"
log_file_t[14]="System log"
log_file_t[15]="MySQL log"
log_file_t[16]="MySQL error log"
log_file_t[17]="Script PPP log"
log_file_t[18]="Configuration de Netfilter log"
log_file_t[19]="TO server log"
log_file_t[20]="Firewall log"
log_file_t[21]="Jabber error log"
log_file_t[22]="Jabber record log"

##### Routines #####

# Affiche l'aide
AfficheAide ()
{ 
  echo -e "\n\n\t\tRXVT log $VERSION\n"
  echo -e "UTILISATION:"
  echo -e "\t$0 <alias du fichier log>\n"
  echo -e "EXEMPLE:"
  echo -e "\t$0 messages"
  echo -e "Lance un rxvt, et affiche la fin du fichier de log '/var/log/messages'\n"
  echo -e "ALIAS:"

  log_file_num=0
  for I in `echo ${log_file_a[@]}`; do
      echo -e "  - '${log_file_a[$log_file_num]}' -> ${log_file_f[$log_file_num]} $log_file_num"
      log_file_num=$(($log_file_num + 1))
  done

  echo
  exit; 
}


##### Programme principal #####

log_file_num=0

# Analyse du parametre
if [ -z "$1" ]
  then
    AfficheAide

  else
    while [ -n "${log_file_a[$log_file_num]}" ]
      do
        if [ "$1" = "${log_file_a[$log_file_num]}" ]
          then
            break
        fi
        log_file_num=$(($log_file_num + 1))
    done

    # Verification du parametre
    if [ -z "${log_file_a[$log_file_num]}" ]
      then
         echo -e "##### ERREUR:"
         echo -e "\tAlias '$1' inconnu !"
         echo -e "\tChoisissez un alias parmis la liste ci-dessous !!"
         AfficheAide

      else
         #echo -e "+ Affichage du log de ${log_file_f[$log_file_num]} (${log_file_a[$log_file_num]})"
         exec /usr/X11R6/bin/rxvt -bg 0 -g 210x20 -fn 6x10 -T "${log_file_t[$log_file_num]} (${log_file_a[$log_file_num]}: ${log_file_f[$log_file_num]})"  -exec tail -f -n 100 ${log_file_f[$log_file_num]} &
    fi
fi

