#!/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 # # Notes: # # If you use the inn2.x storage api, then set $STORAGEAPI to 1 # In this case, we will use the "sm" program to get access. # Ensure proper path in $sm and $perl. # # We expect [-m] (|) [] on the cmdline # # The optional "-m" will make us call rpost to issue "mode reader" # TOKEN or articlepath show us the way to the article # SERVERFQDN is the full FQDN (or IP address) of the server to post at # PORT may be specified if special port (aside from 119) is to be used # # 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.2"; $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 # New: [-m] -s [-p ] OR # -b [-m] -s [-p ] $port = 119; while ($#ARGV>=0) { $nextarg=shift @ARGV; if ($nextarg eq "-m") { $modereader=1; } elsif ($nextarg eq "-b") { $batchmode=1; } elsif ($nextarg eq "-s") { $server = shift @ARGV; } elsif ($nextarg eq "-p") { $port = 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); }