Article View: news.software.nntp
Article #1722Re: User-Painless server change?
From: Evan Kirshenbaum
Date: Wed, 03 Mar 1993 19:41
Date: Wed, 03 Mar 1993 19:41
233 lines
6810 bytes
6810 bytes
In article <1n2n0hINNo8a@oac4.hsc.uth.tmc.edu> snewton@oac3.hsc.uth.tmc.edu (Steven E. Newton) writes:
>OK, so is there a tool out there that I haven't found so I don't
>reinvent the square wheel? What have you as a news admin done? Or will
>I be a hero by writing said tool?
Well, here's a perl script that I wrote when I wanted to do the same
thing. No warranties expressed or implied, but it seemed to do a
pretty good job. It may need a little bit of tweaking. It requires
that both servers be accessable at the same time.
Enjoy.
Evan Kirshenbaum +------------------------------------
HP Laboratories | He who will not reason, is a bigot;
3500 Deer Creek Road, Building 26U | he who cannot is a fool; and he who
Palo Alto, CA 94304 | dares not is a slave.
| Sir William Drummond
kirshenbaum@hpl.hp.com |
(415)857-7572
---------------------------Cut Here-------------------------
#!/usr/local/bin/perl
$oldServer = shift || die "No old nntp server specified";
$newServer = shift || die "No new nntp server specified";
$srcFile = shift || "/users/evan/.newsrc";
$newSrcFile = shift || ".newsrc.$newServer";
$unknownGroupFile = "unknown.$newServer";
open(SRCFILE, "<$srcFile") || die "Couldn't open $srcFile";
open(NEWFILE, ">$newSrcFile") || die "Couldn't open $newSrcFile";
open(UNKNOWN, ">$unknownGroupFile") || die "Couldn't open $unknownGroupFile";
$port = 119;
$sockaddr = 'S n a4 x8';
$DOMAIN = 2;
$STYLE = 1;
$rin = $rout = '';
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $oldhostaddr) = gethostbyname($oldServer);
$oldSock = pack($sockaddr, $DOMAIN, $port, $oldhostaddr);
socket(OS, $DOMAIN, $STYLE, $proto) || die $!;
connect(OS, $oldSock) || die $!;
select(OS); $| = 1; select(STDOUT);
vec($rin, fileno(OS), 1) = 1;
select($rout=$rin, undef, undef, undef);
$_ = <OS>;
if ($_ !~ /^2../)
{
print;
die "Service nntp on $oldServer unavailable";
}
$| = 1;
($name, $aliases, $type, $len, $newhostaddr) = gethostbyname($newServer);
$newSock = pack($sockaddr, $DOMAIN, $port, $newhostaddr);
socket(NS, $DOMAIN, $STYLE, $proto) || die $!;
connect(NS, $newSock) || die $!;
select(NS); $| = 1; select(STDOUT);
vec($rin, fileno(NS), 1) = 1;
select($rout=$rin, undef, undef, undef);
$_ = <NS>;
if ($_ !~ /^2../)
{
print;
die "Service nntp on $newServer unavailable";
}
LINE:
while($line=<SRCFILE>)
{
chop($line);
$line =~ /[:!]\s*/;
$group = $`;
$rangeDesc = $';
$subscribed = ($& =~ ":");
if ($rangeDesc =~ /^([0-9]+).*[,-]([0-9]+)$/)
{
$firstRead = $1;
$lastRead = $2;
}
else
{
$firstRead = $lastRead = $rangeDesc;
}
unless ($subscribed)
{
$rangeDesc = "$firstRead-$lastRead";
}
@ranges = split(/,/,$rangeDesc);
print STDERR <<EOS;
Group: $group
EOS
print NEWFILE $group, ($subscribed ? ": " : "! ");
&writeGroupData if &readGroupData;
print NEWFILE "\n";
# exit if ++$count > 4;
}
sub readGroupData
{
undef %msgIdRead;
undef @oldRead;
$firstId = "";
print OS "group $group\n";
$_ = <OS>;
($stat, $num, $first, $last) = split;
if ($stat !~ /^2../)
{
print;
warn "Group doesn't exist on $oldServer: $group";
return 0;
}
print OS "xhdr message-id $first-$last\n";
unless (/^2/)
{
print;
warn "Couldn't get ids: $group";
return 0;
}
&nextRange;
$someSeen = 0;
OLDID:
while (<OS>)
{
last if /^\./;
chop; chop;
($num,$id) = split(/ /,$_,2);
while ($num > $rangeEnd)
{
&nextRange;
}
$msgIdRead{$id} = "2" if $num>=$rangeStart;
$msgIdRead{$id} = "1" unless $num>=$rangeStart;
$someSeen = 1 if $msgIdRead{$id} == 2;
print STDERR $msgIdRead{$id};
}
return 1;
}
sub nextRange
{
($rangeStart,$rangeEnd) = split(/-/,shift(@ranges));
$rangeEnd = $rangeStart unless $rangeEnd;
$rangeStart = $rangeEnd = 100000000 unless $rangeEnd;
}
sub writeGroupData
{
$BEFORE = 0;
$READ = 1;
$UNREAD = 2;
$state = $BEFORE;
$range = "";
print STDERR "\n writing:";
print NS "group $group\n";
$_ = <NS>;
($stat, $num, $first, $last) = split;
if ($stat !~ /^2../)
{
print;
warn "Group doesn't exist on $newServer: $group";
print UNKNOWN "$group\n";
return 0;
}
unless ($someSeen)
{
print STDERR "<None seen>\n\n";
return 1;
}
$lastUnknown = $first-1;
print NS "xhdr message-id $first-$last\n";
$_ = <NS>;
unless (/^2/)
{
print;
warn "Couldn't get ids: $group";
return 0;
}
NEWID:
while (<NS>)
{
last if /^\./;
chop; chop;
$lastNum = $num;
($num,$id) = split(/ /,$_,2);
print STDERR $msgIdRead{$id} || "0";
if ($msgIdRead{$id}==2)
{
$rangeFirst=1 if ($state == $BEFORE);
$rangeFirst = $num if ($state == $UNREAD);
&addRange(1,$lastUnknown) if ($lastUnknown && $state == $UNREAD);
$lastUnknown = 0;
$lastRead = $num;
$state = $READ;
next NEWID;
}
if ($msgIdRead{$id}==1)
{
&addRange($rangeFirst,$lastNum) if ($state == $READ);
$state = $UNREAD;
next NEWID;
}
if ($msgIdRead{$id}==0)
{
next NEWID if ($state == $READ && $rangeFirst == 1);
$lastUnknown = $num if ($state == $BEFORE);
&addRange($rangeFirst,$lastNum) if ($state == $READ);
$state = $UNREAD if ($state == $READ);
next NEWID;
}
}
&addRange($rangeFirst,$lastRead) if ($state == $READ);
print NEWFILE "$range";
print STDERR "\n $range\n";
}
sub addRange
{
local($start,$end) = @_;
return unless $end>=$start;
print STDERR "[$start-$end]";
$range .= "," if $range;
$range .= "$start-$end" unless $start==$end;
$range .= "$start" if $start==$end;
}
Technical Details
Message-ID:
<1993Mar3.194129.19665@hplabsz.hpl.hp.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.admin.misc.mbox.zip!sparky!uunet!ferkel.ucsb.edu!taco!gatech!howland.reston.ans.net!wupost!sdd.hp.com!hpscit.sc.hp.com!hplextra!rigel!evanReferences:
<1n2n0hINNo8a@oac4.hsc.uth.tmc.edu>Show Full Headers
Complete Article Headers
Message-ID: <1993Mar3.194129.19665@hplabsz.hpl.hp.com> Subject: Re: User-Painless server change? Date: Wed, 3 Mar 1993 19:41:29 GMT From: evan@hplerk.hpl.hp.com (Evan Kirshenbaum) References: <1n2n0hINNo8a@oac4.hsc.uth.tmc.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.admin.misc.mbox.zip!sparky!uunet!ferkel.ucsb.edu!taco!gatech!howland.reston.ans.net!wupost!sdd.hp.com!hpscit.sc.hp.com!hplextra!rigel!evan Newsgroups: news.admin.misc,news.software.nntp,news.software.readers Sender: news@hplabsz.hpl.hp.com (News Subsystem (Rigel)) Nntp-Posting-Host: hplerk.hpl.hp.com Organization: Hewlett-Packard Laboratories Lines: 232