Previous Next Table of Contents

9. Poll-script and Unpacking

For polling I use the script ifmail/misc/contrib/ifpoll with small changes:


#!/bin/sh
# ver 0.7r
# ifpoll, poll my boss node or the node given as argument 1
#
# i start this shell script every day by crond, but you can
# start it also by hand :) start it as the owner of ifcico.
# rasca, berlin 1993 (Rasca Gmelch, 2:2410/305.4)
#
# Erweiterte Fassung von Roland Rosenfeld

# where "ifcico" and "ifpack" reside
FIDOPATH=/usr/local/lib/fnet

# logfile of ifcico
IFLOG=/var/log/fnet/ifmail
IFDEBUG=/var/log/fnet/ifdebug

# owner of "ifcico"
IFCICO_OWNER=uucp

# sysop of fido stuff
IFCICO_SYSOP=postmaster

# my boss node (default address to poll)
NODE="f111.n2450.z2"

# how often should i try to call NODE?
MaxTry=20

# delay between outgoing calls in seconds
DELAY=60

# where to log processing - file or tty/console
INFO_TTY=/dev/tty11

function GetConnectMessage () {
   grep 'chat got "CONNECT.*", continue' $IFLOG \
      | tail -n1 \
      | sed 's/.*chat got //;s/, continue//'
}

function GetNoConnectMessage () {
   grep 'chat got .*, aborting' $IFLOG \
      | tail -n1 \
      | sed 's/.*chat got //;s/, aborting//'
}

mv -f $IFDEBUG $IFDEBUG.old
touch $IFDEBUG

echo "`date \"+%b %d %T\"` ifpoll[$$]: starting" >> $INFO_TTY

# remember me, not to run as root..
#
if [ `whoami` != "$IFCICO_OWNER" ]; then
        echo "*** run $0 as the owner of ifcico ***"
        echo "`date \"+%b %d %T\"` ifpoll[$$]: wrong uid (rc 2)" >> $INFO_TTY
        exit 2
fi

# argv[1] is the optional node to call
#
if [ "$1" != "" ]; then
        if [ "$1" = "-?" ] || [ "$1" = "-h" ]; then
                echo "usage: ifpoll [node]"
                exit 3
        else
                NODE=$1
        fi
fi

# let's pack the fido stuff..
#

$FIDOPATH/fgpack

# loop until ifcico could connect the node or MaxTry is encountered
#
i=1; errlv=1
while let 'i <= MaxTry' && let 'errlv != 0'
do
        echo -n "`date \"+%b %d %T\"` ifpoll[$$]: $i. try ($NODE) " \
                >> $INFO_TTY
        #
        # start ifcico in master mode ..
        #
        $FIDOPATH/ifcico -r 1 $NODE
        errlv=$?
        if [ $errlv != "0" ]; then
                GetNoConnectMessage >> $INFO_TTY
                if [ $i != $MaxTry ]; then
                        sleep $DELAY
                fi
                let i=i+1
        else
                GetConnectMessage >> $INFO_TTY
        fi
done

# if the poll was fine, unpacking..
#
if [ $errlv = "0" ]; then
        echo "`date \"+%b %d %T\"` ifpoll[$$]: unpacking.. " >> $INFO_TTY
        $FIDOPATH/fgunpack $INFO_TTY
        # add here some additional lines for processing tic files or
        # incoming file-lists or simular..
        grep 'chat got .*, aborting' $IFLOG | \
                tail -n20 | \
                elm -s "ifpoll: failed" $IFCICO_SYSOP >/dev/null
fi

echo "`date \"+%b %d %T\"` ifpoll[$$]: finished (rc $errlv)" >> $INFO_TTY

# return the errorlevel of ifcico
exit $errlv

This script can be started without any parameters and then automatically calls my boss, or you start it with the node you want to call (in pfnz-format, e.g. ifpoll f111.n2450.z2). Of course one has to adjust this script to oneselfs needs (maybe not everybody has 12 consoles etc.)

This script is meant to call the packing-script:


#!/bin/sh 
# /usr/local/lib/fnet/fgpack 
# pack-script for FidoGate (together with ifcico)
#
# written by Roland Rosenfeld   19.08.94
#       roland@p13.flokiste.fido.de     (2:2450/111.13)
#

FNET=/var/spool/fnet
FTNPACK=/usr/local/lib/fidogate/ftnpack

PATH=/bin:/usr/bin:/usr/local/bin

topack=

for pkt in $FNET/*/????????.out $FNET/*/????????.pnt/????????.out
do
        if [ -s $pkt ] 
        then
                topack="$topack $pkt"
        fi
done
$FTNPACK $topack

By this the .out-files are packed together in ARCmail-files, thus they can be transmitted more efficiently.

You have to define the used packers in /usr/local/lib/fidogate/packing, so ftnpack can find them:


# /usr/local/lib/fidogate/packing
#
# FIDOGATE ftnpack config file
#
# Commands:
#
#     arc    NAME  "/PATH/PROG %s %s"
#     prog   NAME  "/PATH/PROG %s"
#
#     pack   NAME  NODES
#     rpack  NAME  TARGET NODES
#     fpack  NAME  TARGET NODES
#

arc     zip     "/usr/bin/zip -gkjq %s %s"
arc     arc     "/usr/local/bin/arc an %s %s"

prog    gate    "/usr/local/lib/fidogate/ftn2rfc %s"

######## P A C K I N G #######################################################

pack    zip     *

Of course the paths of the packers have to be adjusted to your own needs. After a successful call with ifcico the following unpack-script is started:


#!/bin/bash 
# usr/local/lib/fnet/fgunpack 
#
# unpack-script for FidoGate (together with ifcico)
#
# written by Roland Rosenfeld   12.06.94
#       roland@p13.flokiste.fido.de     (2:2450/111.13)
#
# corrected paths, usage of syslog, more packers, clean up, restructured
#       martin@erde.GUN.de (Martin Seine) <2:2448/413.100>
#

FNET=/usr/local/lib/fnet
FGATE=/usr/local/lib/fidogate
IFCFG=$FNET/config
IN=/var/spool/fnet/in

# Facility is the log-file facility, where syslog stores the messages
# if you're not using syslog, no need to change it
FACILITY=local0

# System-manager who receives notices, if there are unpacking errors
MANAGER=postmaster

PATH=/bin:/usr/bin:/usr/local/bin:$FGATE

if [ $1 ]
then
        INFO_TTY=$1
else
        INFO_TTY=/dev/console
fi

WEARE=`basename $0`

#
# get directory-names from $IFCFG
#
INBOUND=`grep -i "^[    ]*inbound" $IFCFG | awk '{ print $2 }'`
LOGFILE=`grep -i "^[    ]*logfile" $IFCFG | awk '{ print $2 }'`

if [ ! -d $INBOUND/bad ] ; then
   if [ -e $INBOUND/bad ] ; then
        rm -Rf $INBOUND/bad
   fi
   mkdir $INBOUND/bad
fi

CORRECT=true

function iflog() {
   if [ -S /dev/log ] ; then
        logger -i -p $FACILITY.info -t $WEARE $@
   else
        echo "`date \"+%y/%m/%d %T\"` $$ $WEARE:" $@ >> $LOGFILE
   fi
   echo "`date \"+%b %d %T\"` $WEARE [$$]:" $@ >> $INFO_TTY
}


function unpack_mail() {
   pushd $INBOUND >/dev/null
   EMPTY=true
   for f in *.mo? *.tu? *.we? *.th? *.fr? *.sa? *.su? *.pkt \
            *.MO? *.TU? *.WE? *.TH? *.FR? *.SA? *.SU? *.PKT
   do
        if [ -f $f ] ; then
                if [ $EMPTY = true ] ; then
                        rm -rf bak.oo
                        mv -f  bak.o  bak.oo >/dev/null
                        mv -f  bak    bak.o  >/dev/null
                        mkdir  bak
                fi
                mv -f  $f bak/
                ln -s -f $INBOUND/bak/$f $IN/$f
                EMPTY=false
        fi
   done

   # now all new packets lie in $INBOUND/bak

   if [ $EMPTY = true ]
   then
        iflog No new mail found in $INBOUND
        exit
   fi

   popd >/dev/null

   pushd $IN >/dev/null
   #
   # Analyze packer with file(1) and unpack them if possible
   #
   for f in *.mo? *.tu? *.we? *.th? *.fr? *.sa? *.su?
   do
       if [ -f $f ] ; then
          arc=`file -L $f | awk '{ print $2 }'`
          case $arc in
            ARJ) unarj e $f ;;
            ARC) arc e $f ;;
            ZIP) unzip -x $f < /dev/null ;;
            LHA) lha e $f ;;
            ZOO) zoo eq $f ;;
            RAR) unrar e $f ;;
              *) iflog unknown packer \'$arc\' for $f
                 false ;;
          esac
          if [ $? -gt 0 ] ; then
              iflog couldn\'t unpack $f \(moved to $INBOUND/bad\)
              cp -f $f $INBOUND/bad
              CORRECT=false
          else
              iflog unpacked $f \($arc\)-archive
              rm -f $f
          fi
       fi
   done
   popd >/dev/null
}

#
#
# main unpack-program
#
#

export FNET
cd $FNET
unpack_mail

iflog starting ftn2rfc
ftn2rfc -x ftninpost -l

if [ $CORRECT = false ] ; then
/usr/lib/sendmail $MANAGER <<END
Subject: Fido-packet errors
There occured errors while processing Fido-Packets.

Please check the logfiles

Your Gateway
END
fi

#iflog starting Linux-TIC-Processor
#/usr/local/lib/tic/process_tics.pl < /dev/null
#/usr/local/lib/tic/poster.pl Daily < /dev/null
#/usr/local/lib/tic/lister.pl < /dev/null

This script moves all mails arrived in /var/spool/fnet/inbound to /var/spool/fnet/inbound/bak whereas these directories are moved to bak.o and bak.oo, thus one has always the last three poll-results, to fix any problems afterwards. Next all *.pkt-files are copied to /var/spool/fnet/in and the archives are unpacked (the script automatically recognizes ZIP, ARJ, ARC and LHA). For this the following lines must be in /etc/magic (put it at the top of the file as the file is scanned from top to bottom):


# Some entries for the ifcico-shell-script
#
0       byte            0x1a            ARC Archive (maybe)
0       string          PK              ZIP Archive
2       string          -lh             LHA Archive
0       string          ZOO             ZOO Archive
0       short           0xea60          ARJ Archive

If this is done, ftn2rfc is called, which will convert the packets to mail/news and after this starts sendmail and rnews via ftninpost.

After this other tools can be started, e.g. a TIC-processor or a program that scans the news for user of the own system.


Previous Next Table of Contents