#!/usr/bin/perl # # rpostarticle v1.1 # This is rpostarticle.pl # a helper to rpost articles from inn2.x with storage-api # # History # # 1999 02 19 v1.0 elmi@newsbone.org (Elmar K. Bins) # started hacking away :-) # # 1999 02 20 v1.1 elmi@newsbone.org (Elmar K. Bins) # includes date in log, uses innshellvars.pl # # 1999 02 22 v1.2 elmi@newsbone.org (Elmar K. Bins) # batching enabled; ATTN: cmdline syntax has changed # # 1999 02 22 v1.3 elmi@newsbone.org (Elmar K. Bins) # ATTN: storageapi is cmdline option now. # # Notes: # # If you use the inn2.x storage api, then don't forget the "-a". # # In this case, we will use the "sm" program to get access. # Ensure proper path for $sm. # #--- # # Commandline syntax and semantics: # [-m] [-a] -s [-p ] OR # -b [-m] [-a] -s [-p ] # # -m (optional) lets rpost issue a "mode reader" first # -a (optional) enables STORAGEAPI; otherwise traditional spool is assumed # -s (required) tells us what server to post to # -p (optional) uses a port different from 119 # -b (optional) enables batchmode # # token or path show us the way to the article # batchfile (if "-b") tells us which batch to use # (relative to $inn::batch or absolute # #--- # # NOTE: You must have rpost installed, which is part of the "suck" package. # This may be found at ftp://nethammer.qad.org/usenet/ # # The current version can be found via http://detebe.org/~news/software/ # # Do you use the storage api for groups being fed here? $STORAGEAPI = 1; # Version and copyright stuff $version = "1.3"; $date = "1999 02 22"; $authors = "elmi\@newsbone.org (Elmar K. Bins)"; $copyright = "-- \nrpostarticle.pl v$version $date $authors\n"; # System dependent stuff $mv = "/bin/mv"; $grep = "/bin/grep"; $cat = "/bin/cat"; $date = "/bin/date"; $now = `$date "+%a %b %d %Y %T %z (%Z)"`; chomp($now); # Installation dependent stuff (pathnames) require "/usr/local/inn/lib/innshellvars.pl"; $sm = join("/",$inn::pathbin,"sm") if ($STORAGEAPI); $logfile = join("/",$inn::most_logs,"rpost.log"); $rpost = join("/",$inn::pathnews,"contrib/rpost"); $batchdir = $inn::batch; # Configuration # usually, NNTP-Posting.* and the Xref:-Header should be filtered. # beware: This will filter lines beginning with these from the body too... $filterpatterns = "!^NNTP-Posting.*: #!^Xref: "; #----------------------------------# # 0. Get cmd line arguments # # 1. Get the article drop command # # 2. If desired, filter # # 3. Call rpost and feed article # #----------------------------------# #-------------------------- # 0. Get cmd line arguments $port = 119; &usage() if ($#ARGV<0); while ($#ARGV>=0) { $nextarg=shift @ARGV; if ($nextarg eq "-a") { $storageapi=1; } elsif ($nextarg eq "-b") { $batchmode=1; } elsif ($nextarg eq "-h") { &usage(); } elsif ($nextarg eq "-m") { $modereader=1; } elsif ($nextarg eq "-p") { $port = shift @ARGV; } elsif ($nextarg eq "-s") { $server = shift @ARGV; } else { if ($batchmode) { $batchfile = $nextarg; } else { $article = $nextarg; } } } if ($batchmode && ($batchfile !~ m!^/!)) { $batchfile = join("/",$batchdir,$batchfile); } if ($debug) { print "CMD line args:\n"; print "--------------\n"; print "modereader: $modereader\n"; print "batchmode: $batchmode\n"; print "batchfile: $batchfile\n"; print "article: $article\n"; print "server: $server\n"; print "port: $port\n"; } die("No server given.\nLeaving") if (!$server); #-------------------------------- # 1. Get the article drop command if ($storageapi) { $getarticletmpl = "$sm %s"; } else { exit 2 if (! -f $article); $getarticletmpl = "$cat %s"; } #------------------------------- # 2. If desired, generate filter $filterline = ""; if ($filterpatterns ne "") { @filter = split("#",$filterpatterns); foreach $pattern (@filter) { $no = ""; if ($pattern =~ m/^\!(.*)/) { $no = " -v"; $pattern = $1; } $filterline .= "|$grep -i $no '$pattern'"; } } $getarticletmpl .= $filterline; #-------------------------------- # 2. Work on the articles if ($batchmode) { exit 0 if (!-f $batchfile); # nothing to do die("$batchfile.work exists.\nLeaving") if (-f "$batchfile.work"); # work in progress or faulty system("$mv -f $batchfile $batchfile.work"); open(BATCH, "<$batchfile.work") || exit 1; my @batch = ; close(BATCH); foreach $article (@batch) { chomp($article); $getarticle = sprintf($getarticletmpl,$article); &rpostonearticle($getarticle); } unlink("$batchfile.work"); } else { if (!$storageapi) { exit 1 if (! -f $article); } $getarticle = sprintf($getarticletmpl,$article); &rpostonearticle($getarticle); } exit 0; #-------------------------------------------------------------------------------- sub rpostonearticle { my ($getarticle) = @_; $rpostflags = ""; $rpostflags .= " -N $port" if ($port); $rpostflags .= " -M" if ($modereader); open(LOG,">>$logfile"); print LOG "\nDATE [$now]\n"; print LOG "ARTICLE [$article]\n"; print LOG "RPOST TO [$server]\n"; print LOG "-----------------------------------------------------------------------\n"; $result = `($getarticle) | $rpost $server $rpostflags`; print LOG "$result\n"; print LOG "-----------------------------------------------------------------------\n"; close(LOG); } sub usage { print < [-p ] OR -b [-m] [-a] -s [-p ] -m (optional) lets rpost issue a "mode reader" first -a (optional) enables STORAGEAPI; otherwise traditional spool is assumed -s (required) tells us what server to post to -p (optional) uses a port different from 119 -b (optional) enables batchmode or show us the way to the article (if "-b") tells us which batch to use (relative to $inn::batch or absolute EOU exit 1; }