#!/bin/sh

#
# $Id: fvudu,v 1.1.1.1 2008/03/17 09:18:45 raptor Exp $
#
# fvudu v0.1 - Unix X.25 NUA Scanner
# Copyright (c) 2001 Raptor <raptor@0xdeadbeef.eu.org>
#
# Fvudu is a slight modification of my original Vudu
# X.25 NUA scanner for Unix systems. This time NUAs
# are not generated on-the-fly, but instead taken from
# the specified data file. It's a small hack to a very 
# simple shell script, neverthless it works very fast.
# FOR EDUCATIONAL PURPOSES ONLY.
#
# Tested on Solaris (but should be easily portable).
#
# Usage example: ./fvudu NUA.TXT
#


# Some vars (change them if needed)
tmp=fvudu.tmp
valid=fvudu.nua
pad=./pad

# Response codes (optimized for Sun pad)
com=Connected
dte=DTE
der="Out Of Order"
rpe="Remote Procedure Error"
na="Access Barred"
occ="Number Busy"

# Command line
filename="$1"
if [ "$filename" = "" ]; then 
	echo "err: specify a filename"
	exit 1
fi

# Input control
if [ "`cat $filename 2>/dev/null`" = "" ]; then
	echo "err: corrupted input file"
	exit 1
fi

# Interactive logging
echo ""
echo "*** VUDU X.25 Scanner for Unix ***"
echo ""
echo "[ Starting reading data from: ${filename} ]"

# Perform the scan
for current in `cat $filename`
do

        $pad $current >$tmp 2>$tmp
       
# COM (valid NUA)
        if fgrep $com $tmp > /dev/null; then
                echo "${current}  (OK)"
                echo "${current}  (OK)" >> $valid
# DTE
        elif fgrep $dte $tmp > /dev/null; then
		echo "${current}  DTE"
		echo "${current}  DTE" >> $valid
# DER (out of order)
	elif fgrep "$der" $tmp > /dev/null; then
		echo "${current}  DER"
		echo "${current}$ DER" >> $valid
# RPE (remote procedure error)
	elif fgrep "$rpe" $tmp > /dev/null; then
		echo "${current}  RPE"
		echo "${current}  RPE" >> $valid
# NA (access barred)
	elif fgrep "$na" $tmp > /dev/null; then
		echo "${current}  N/A"
		echo "${current}  N/A" >> $valid
# OCC (number busy)
	elif fgrep "$occ" $tmp > /dev/null; then
		echo "${current}  OCC"
		echo "${current}  OCC" >> $valid
	else
                echo "${current}"
        fi
       
done

rm $tmp
echo "[ Ended scan from file: ${filename} ]"
echo ""
