🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by Brad Knowles Thu, 25 Mar 1999 00:00
Unsupported release: newsdiff
#36179
Author: Brad Knowles
Date: Thu, 25 Mar 1999 00:00
313 lines
10489 bytes
Folks,

    Okay, I've actually cooked up another hopefully useful tool to help
debug news server problems.  It requires NNTP access at a reference and
target news server, and that they both support XOVER.

    It will grab all the message-ids on both servers and compare the byte
sizes of the messages.  If there are any articles on the reference but not
the target, it will tell you.  If there are any articles that are of
differing sizes, it will tell you.  You can also request that it tell you
if there are any articles on the target but not the reference, and if you
want to be really verbose you can ask that it tell you if they exist on
both servers and are the same size.

    You can also get it to display either the headers or the entire
articles for those articles that are on the reference but not the target
or where the sizes differ.  Note that these options are turned off by
default, since this will seriously exercise the overview database on the
reference system, and could result in a large number of messages being
displayed.


    Please be gentle, this is only the second Perl program I've ever
written from the ground-up.  ;-)

    In particular, I'd like to get any comments you may have about Perl
programming style or better use of the Net::NNTP module.


    Given what this thing is loading and the fact that I make very liberal
use of multi-dimensional hashes, it will take a while to start up and will
chew some serious amounts of RAM.


#!/usr/bin/perl

# newsdiff -- Compare newsgroups (by individual message-id)
#   between reference & target newservers
#
#   Author: Brad Knowles <blk@skynet.be>
#     Date: Wed Mar 24 19:54:15 MET 1999
#
# Inspired by discussions with Forrest J. Cavalier III and
#   Curt Welch, with Net::NNTP xover code borrowed
#   liberally from Greg Bacon (author of Net::NNTP).
#   Perl programming assistance from James "Thomas" Goltz
#============================================================
# Copyright (c) 1999 by Belgacom Skynet, all rights reserved.
#
# This program is provided as-is, with absolutely no
# warranty or suitability for any purpose implied.
#
# This program is not even guaranteed to run or compile, and
# you use it entirely at your own risk!
#
# No support will be provided, although comments and
# suggestions are appreciated, and attempts will be made to
# fold in improvements and make them available under the
# same terms as the rest of the program.
#
# This program is provided as freely available and
# distributable Perl source code only, and you are free
# to make whatever modifications you like, so long as you
# contribute them back to me and do not make the modified
# versions available to other persons without express prior
# consent.
#============================================================

############################################################
############################################################
###                                                      ###
### NO MODIFICATIONS BELOW THIS LINE SHOULD BE NECESSARY ###
###                                                      ###
############################################################
############################################################

$nntp_port||=119;
# Standard port number for NNTP.

use Getopt::Std;
use Net::NNTP;

getopts('r:t:g:ahvV');

if ($#ARGV != -1)
{
    usage();
    exit 1;
}

if (defined $opt_r)
{
    $reference = $opt_r;
}
else
{
    usage();
    exit 1;
}

if (defined $opt_t)
{
    $target = $opt_t;
}
else
{
    usage();
    exit 1;
}

if (defined $opt_g)
{
    @groups=split /,/, $opt_g;
}
else
{
    usage();
    exit 1;
}

if (defined $opt_a)
{
    $show_missing_articles = $opt_a;
}

if (defined $opt_h)
{
    $show_missing_headers = $opt_h;
}

if (defined $opt_v)
{
    $verbose = $opt_v;
}

if (defined $opt_V)
{
    $verbose = $veryverbose = $opt_v;
}

%ref = get_over($reference, @groups);
%targ = get_over($target, @groups);

foreach $group (@groups)
{
    printf "Newsgroup: $group\n";
    foreach $message_id (keys %{$total_message_ids{$group}})
    {
        if (!defined($targ{$group}{$message_id}))
        {
            printf "- $message_id   $ref{$group}{$message_id}{bytes}\n";
            if (defined ($show_missing_headers) || defined
($show_missing_articles))
            {
                $retrieve{$group}{$message_id} = $ref{$group}{$message_id}
            }
        }
        elsif ($targ{$group}{$message_id}{bytes} !=
$ref{$group}{$message_id}{bytes})
        {
            printf "! $message_id   $ref{$group}{$message_id}{bytes} !=
$targ{$group}{$message_id}{bytes}\n";
            if (defined ($show_missing_headers) || defined
($show_missing_articles))
            {
                $retrieve{$group}{$message_id} = $ref{$group}{$message_id}
            }
        }
        elsif (defined ($verbose) && !defined($ref{$group}{$message_id}))
        {
            printf "+ $message_id   $targ{$group}{$message_id}{bytes}\n";
        }
        elsif (defined ($veryverbose) && $targ{$group}{$message_id}{bytes}
== $ref{$group}{$message_id}{bytes})
        {
            printf "= $message_id   $ref{$group}{$message_id}{bytes} ==
$targ{$group}{$message_id}{bytes}\n";
        }
    }
}

if (defined $show_missing_headers)
{
    $NntpPtr = Net::NNTP->new("$reference")
        or die "Failed to open NNTP connection to $reference\n";
    foreach $group (@groups)
    {
        my ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname);
        ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname) =
            $NntpPtr->group($group);
        printf "\n\nShow missing headers\nNewsgroup: $group\n";
        foreach $message_id (keys %{$retrieve{$group}})
        {
            my $hdr = $NntpPtr->head($message_id);
            foreach $line (@{$hdr})
            {
                printf "$line";
            }
            printf "\n\n";
        }
    }
    $NntpPtr->quit;
}
elsif (defined $show_missing_articles)
{
    $NntpPtr = Net::NNTP->new("$reference")
        or die "Failed to open NNTP connection to $reference\n";
    foreach $group (@groups)
    {
        my ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname);
        ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname) =
            $NntpPtr->group($group);
        printf "\n\nShow missing articles\nNewsgroup: $group\n";
        foreach $message_id (keys %{$retrieve{$group}})
        {
            my $art = $NntpPtr->head($message_id);
            foreach $line (@{$art})
            {
                printf "$line\n";
            }
            printf "\n\n";
        }
    }
    $NntpPtr->quit;
}

sub get_over
{

    my ($site, @groups) = @_;
    my (%data);

    $NntpPtr = Net::NNTP->new("$site")
    or die "Failed to open NNTP connection to $site\n";

    my (%oview_fmt);
    my $i = 0;
    for ( @{ $NntpPtr->overview_fmt } )
    {
        $oview_fmt{$_} = $i++;
    }

    foreach $group (@groups)
    {
        my ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname);
        ($NumArts, $NumFirstArt, $NumLastArt, $XGroupname) =
            $NntpPtr->group($group);
        my($xoverdata) = $NntpPtr->xover("$NumFirstArt-$NumLastArt");

        while (my($num,$head) = each %$xoverdata)
        {
            my ($message_id) = $head->[$oview_fmt{"Message-ID:"}];
            my ($bytes) = $head->[$oview_fmt{"Bytes:"}];
            $data{$group}{$message_id} = $message_id;
            $data{$group}{$message_id}{bytes} = $bytes;
            if (!defined($total_message_ids{$group}{$message_id}))
            {
                $total_message_ids{$group}{$message_id} = $message_id;
            }
        }
    }

    $NntpPtr->quit;

    return %data;

}

sub usage
{
    my @prog=split(/\//, $0);
    my $prog=$prog[$#prog];
    print "Usage: $prog -r <reference> -t <target> -g <groups> [-ahvV]\n";
    print "\n";
    print "Where:\n";
    print "<reference> is the hostname of a reference news server\n";
    print "<target>    is the hostname of the target news server\n";
    print "<groups>    is a newsgroup or comma separated list of
newsgroups to compare\n";
    print "\n";
    print "Message-ids found on <reference> but not on <target> are
indicated with a \"-\"\n";
    print "at the start of the line.  Message-ids that refer to messages
with differing\n";
    print "sizes according to <reference> and <target> are indicated with
a \"!\"\n";
    print "\n";
    print "Use -v to indicate message-ids on <target> but not on
<reference> with \"+\"\n";
    print "Use -V to also indicate message-ids of articles on <target> for
messages\n";
    print "that are the same size as the corresponding message on
<reference> with \"=\"\n";
    print "\n";
    print "Use -a to display ARTICLE BODIES on reference but not on target\n";
    print "Use -h to display HEADERS of ARTICLES on reference but not on
target\n";
    print "\n";
    print "WARNING!!!  Use of -h is very intensive on <reference>, as
articles\n";
    print "are referenced by message-id.  Use of -a is even *MORE*
intensive, as it\n";
    print "displays entire articles and not just article headers!!!\n";
}

-- 
Brad Knowles <brad@shub-internet.org> <http://www.shub-internet.org/brad/>
    <http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0xE38CCEF1>

Are you looking for a news feed from a site in the Freenix Top 200?
If so, contact me via private e-mail for details.

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads