(PM) Ugly (but handy) debugging tool

Curtis Coleman (curtis.lst.portmaster.users@imap.pangea.ca)
Tue, 28 Jul 1998 00:26:19 -0700 (PDT)

Hi there,

I thought this might be of interest to somebody out there. It's a
little script that I use to associate different types of debug output
on the fly. Edit $DUMPDIR and $PASSWD and run something like this:

tele.pl pm3-1.foobar.com 23 &
tele.pl pm3-2.foobar.com 23 &
tele.pl pm3-3.foobar.com 23 &
.. etc ...

It runs continuously, and creates files like 8885551212 in the dump
dir after the end of each session, with output somewhat suitable for
Lucington's dring. I use it here with a modified version of dring to
allow tech staff to retroactively debug LCP/PPP/IPCP negotiations,
clearing the $DUMPDIR every night from cron.

Be warned, this script is experimental, is not supported by me or anyone
else, and will likely be non-trivial to get running. All I can say is
that it works for me, in this form, on a bunch of PM3s running 3.8b15,
with DMS-100 PRIs. You're on your own.

If anyone from the RABU would like to make a more useful version of
this, by my guest.

Curtis

#!/usr/bin/perl

# Tele - by Curtis Coleman, a while back. Hack as needed.
# If you write something better, or find something better out there,
# let me know!

$SIG{ALRM} = \&shutdown;
alarm(60);

$|=1;

$DUMPDIR="/var/www/htdocs/mydumpdir";
$PASSWD="foobar";

use Socket;
use Symbol;

$DOCK = $ARGV[0];
$PORT = $ARGV[1];

push @login, "ogin: ~!root\n";
push @login, "assword: ~$PASSWD\n";
push @login, "> ~set debug off\n";
push @login, "> ~set console\n";
push @login, "> ~set debug isdn on\n";
push @login, "> ~set debug isdn-d on\n";
push @login, "> ~set debug 0x51\n";
push @login, "> ~set debug mdp-max on\n";

$time = time(); print "$time: $DOCK ($PORT) startup\n";
&connectinit;
&connecttohost($DOCK, $PORT);
$time = time(); print "$time: $DOCK ($PORT) established\n";
for (;;) {
alarm(60);
$buf = "";
while ($buf !~ /\n$/) {
sysread($FH{$DOCK}, $buftmp, 9999);
$buf .= $buftmp;
}
foreach (split(/[\r\n]+/,$buf)) {
&processline($DOCK, $_);
}
}
exit 0;

sub connectinit {
chop($localhost = `hostname`);
($name,$aliases,$type,$len,$thisaddr) = gethostbyname($localhost);
$this = pack('S n a4 x8', AF_INET, 0, $thisaddr);
}

sub connecttohost {
my($host) = shift;
my($port) = shift;

($name,$aliases,$type,$len,$thataddr) = gethostbyname($host);
$that = pack('S n a4 x8', AF_INET, $port, $thataddr);
$FH{$host} = gensym();
socket($FH{$host}, AF_INET, SOCK_STREAM, 6) or die $!;
bind($FH{$host}, $this) or die $!;
connect($FH{$host}, $that) or die $!;

foreach $string (@login) {
($waitfor, $sendstring) = split(/~/, $string);
$buf = "";
while ($buf !~ /$waitfor/) {
sysread($FH{$host}, $buftmp, 9999);
$buf .= $buftmp;
}
syswrite($FH{$host}, $sendstring, length($sendstring));
}
$buf = "";
while ($buf !~ /Command> /) {
sysread($FH{$host}, $buftmp, 9999);
$buf .= $buftmp;
}
}

sub processline {
my($host) = shift;
my($line) = shift;

$_=$line;
if (/^D\d/) { # D-CHANNEL PROCESSING
if (/^D([01]): recv .. .. .. .. .. .. .. .. 05 04 03 .. .. .. .. .. .. .. (..) .. .. .. .. 3(. .. .. .. .. .. .. .. .. ..) .. .. .. 3(. .. .. .. .. .. ..)/) { # INCOMING CALL, SET %B
$BKEY = $host . ":" . $1 . ":" . (hex($2)-128);
$BVAL = join("",split(" 3",$3)) . ":" . join("",split(" 3",$4));
$B{$BKEY} = $BVAL;
}
} elsif (/^S(\d+)/) { # S-PORT PROCESSING
$BUFKEY = $host . ":" . $1;
$BUF{$BUFKEY} .= $_ . " \n";
if (/^S(\d+): Received Connect - B(\d+)/) { # INCOMING CALL, SET %S ASSOCIATION WITH %B
if ($1 >= 24) { $DCHAN=1; } else { $DCHAN=0; }
$BKEY = $host . ":" . $DCHAN . ":" . $2;
$BVAL = $B{$BKEY};
$SKEY = $host . ":" . $1;
$START{$SKEY} = time();
$SVAL = $BKEY;
$S{$SKEY} = $SVAL;
$ztime = time();
open(OUTLOG,">>quicklog");
print OUTLOG "TELE:". localtime($ztime) . " $time \$S{$SKEY}, \$B{$SVAL} = $B{$SVAL}\n";
close(OUTLOG);
} elsif (/^S(\d+): Modem M(\d+) connecting/) {
$SKEY = $host . ":" . $1;
$MKEY = $2;
$MVAL = $SKEY;
$M{$MKEY} = $MVAL;
$SM{$1} = $2;
} elsif (/^S(\d+): Received Clear Conf/) {
$SKEY = $host . ":" . $1;
$END{$SKEY} = time();
$BKEY = $S{$SKEY};
$BUFKEY = $host . ":" . $1;
$SMKEY = $1;
$MKEY = $SM{$SMKEY};

if ($B{$BKEY}) {
($THEM, $US) = split(/:/,$B{$BKEY});
umask 077;
open(OUT,">>$DUMPDIR/$THEM");
print OUT "*\n";
print OUT "************************************************************************ \n";
print OUT "THEIR PHONE NUMBER: $THEM \n";
print OUT "NUMBER THEY DIALED: $US \n";
print OUT "DOCK THEY CONNECTED TO: $host \n";
print OUT "TIME THE SESSION STARTED: " . localtime($START{$SKEY}) . " \n";
print OUT "TIME THE SESSION ENDED: " . localtime($END{$SKEY}) . " \n";
print OUT "$BUF{$BUFKEY}\n";
close(OUT);
}

delete $BUF{$BUFKEY};
delete $B{$BKEY};
delete $S{$SKEY};
delete $M{$MKEY};
delete $SM{$SMKEY};
} elsif (/port S(\d+)/) {
$BUFKEY = $host . ":" . $1;
$DOCKSTATE{$host} = $BUFKEY;
$BUF{$BUFKEY} .= $_;
}
} elsif (/^\d/) {
if ($DOCKSTATE{$host} ne "IGNORE") {
$BUFKEY = $DOCKSTATE{$host};
if ($BUFKEY) {
$BUF{$BUFKEY} .= $_ . "\n";
}
}
} elsif (/^M(\d+)/) {
if ($M{$1}) {
$BUFKEY = $M{$1};
$BUF{$BUFKEY} .= $_ . " \n";
}
} elsif (/port S(\d+)/) {
$BUFKEY = $host . ":" . $1;
$DOCKSTATE{$host} = $BUFKEY;
$BUF{$BUFKEY} .= $_;
}
} elsif (/^\d/) {
if ($DOCKSTATE{$host} ne "IGNORE") {
$BUFKEY = $DOCKSTATE{$host};
if ($BUFKEY) {
$BUF{$BUFKEY} .= $_ . "\n";
}
}
} elsif (/^M(\d+)/) {
if ($M{$1}) {
$BUFKEY = $M{$1};
$BUF{$BUFKEY} .= $_ . " \n";
}
} elsif (/port S(\d+)/) {
$BUFKEY = $host . ":" . $1;
$DOCKSTATE{$host} = $BUFKEY;
$BUF{$BUFKEY} .= $_ . "\n";
}
}

sub shutdown {
$time = time();
print "$time: $DOCK ($PORT) shutdown\n";
exit(0);
}

-
To unsubscribe, email 'majordomo@livingston.com' with
'unsubscribe portmaster-users' in the body of the message.
Searchable list archive: <URL:http://www.livingston.com/Tech/archive/>