1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/usr/bin/perl
#
# Author: James Brister <brister@vix.com> -- berkeley-unix --
# Start Date: Wed Jan 3 00:09:01 1996
# Project: INN -- innfeed
# File: testListener.pl
# RCSId: $Id: testListener.pl 8290 2009-01-17 08:15:31Z iulius $
# Description: Generate news files for testing the innfeed feeder.
#
# Run like this:
#
# testListener.pl -t 30 -d tmp | innfeed
#
# or like this:
#
# innfeed -s 'perl testListener.pl -t 30 -d tmp'
#
$0 =~ s!.*/!! ;
use Getopt::Std;
$usage = "$0 [ -a -b name -d directory -c count -t sleep-amt -r -u ] peers\n" .
" -a is for duplicate article id's periodically\n" .
" -u is for random unlinking of article\n" .
" -b add bogus peername periodically\n" .
" -d is the directory where articles show be written.\n" .
" -c is how many articles to create (0 the default meamns no limit)\n" .
" -t is the number of seconds to sleep between each article.\n" .
" -r is to have articles be created in NNTP ready format\n" ;
getopts ("a:b:c:d:t:rl:h:") || die $usage ;
die $usage if $opt_h ;
$total = $opt_c ;
$sleepAmt = 1 ;
$sleepAmt = $opt_t if ($opt_t =~ /^[\d\.]+/) ;
$lineCount = 50 ;
$lineCount = $opt_l if ($opt_l =~ /^\d+$/) ;
$directory = "." ;
$directory = $opt_d if $opt_d ;
$bogus = $opt_b ;
if ( $bogus && $bogus !~ /^[a-zA-Z]+$/ ) {
print "The bogus peername must contain only letters\n" ;
}
$cr = ($opt_r ? "\r" : "") ;
$SIG{'INT'} = 'IGNORE' ;
$SIG{'TERM'} = 'sigHup' ;
$SIG{'QUIT'} = 'sigHup' ;
$SIG{'HUP'} = 'sigHup' ;
sub sigHup {
exit (1) ;
}
$monstr = "JanFebMarAprMayJunJulAugSepOctNovDec" ;
$letstr = "abcdefghijklmnopqrstuvwxyz" ;
sub createArticle {
local ($counter) = @_ ;
local ($filename,$msgid,$i) ;
local ($time) = $^T ;
local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
= gmtime($time);
local ($index) = $counter ;
if ($opt_a && ((int (rand (4)) % 2) == 0)) {
$index = int ($index / 2) ;
}
$msgid = "<$index.$$.$time\@home.octet.com.au>" ;
$filename = sprintf ("%s/SampleArticle.%06d",$directory,$index) ;
open (ARTICLE,">$filename") ||
die "open ($filename): $!\n" ;
print ARTICLE "Path: home.octet.com.au!not-for-mail$cr\n" ;
print ARTICLE "From: brister\@home.octet.com.au$cr\n" ;
print ARTICLE "Newsgroups: junk,local.test$cr\n" ;
print ARTICLE "Subject: Test$cr\n" ;
print ARTICLE "Date: " ;
printf ARTICLE "%d %s %d %02d:%02d:%02d UTC$cr\n",
$mday, substr($monstr,$mon * 3, 3), $year + 1900,
$hour, $min, $sec ;
print ARTICLE "Organization: None that I can think of$cr\n" ;
print ARTICLE "Lines: 5$cr\n" ;
print ARTICLE "Distribution: world$cr\n" ;
print ARTICLE "Message-ID: $msgid$cr\n" ;
print ARTICLE "NNTP-Posting-Host: localhost$cr\n" ;
print ARTICLE "$cr\n" ;
for ($i = 0 ; $i < $lineCount ; $i++) {
print ARTICLE "x" x ($lineCount + 1), "$cr\n";
}
print ARTICLE ".This line has a leading dot.$cr\n" ;
print ARTICLE "And the next line only has a dot.$cr\n" ;
if ($opt_r) {
print ARTICLE "..$cr\n" ;
} else {
print ARTICLE ".$cr\n" ;
}
print ARTICLE "And the next line has just two dots...$cr\n" ;
print ARTICLE "...$cr\n" ;
print ARTICLE "foo$cr\n" ;
print ARTICLE "And the next line is the last line of the article$cr\n" ;
print ARTICLE "and it only has a single dot on it.$cr\n" ;
if ($opt_r) {
print ARTICLE "..$cr\n" ;
} else {
print ARTICLE ".$cr\n" ;
}
close (ARTICLE) ;
return ($msgid, $filename) ;
}
srand ;
$| = 1 ;
if ( ! -t STDERR ) {
open (STDERR,">>/tmp/TESTLISTENER.LOG") || die ;
}
srand ;
$sleepAmt = 1 if ($sleepAmt < 0) ;
foreach $peer ( @ARGV ) {
$PEERS{$peer} = 1 ;
}
die "Must give peernames on command line:\n$usage" if ( ! @ARGV ) ;
for ( $i = 0 ; $total == 0 || $i < $total ; $i++ ) {
($msgid,$filename) = &createArticle ($i) ;
if ($opt_a && ((rand (3) % 3) == 0)) {
print TTY "Removing file $filename\n" ;
unlink ($filename) if $opt_u ;
}
print "$filename $msgid @ARGV" ;
print " $bogus" if ($bogus && (rand (5) % 5) == 0) ;
print "\n" ;
select (undef,undef,undef,(rand ($sleepAmt-1) + 1)) if $sleepAmt ;
}
sleep 11500 unless -f STDOUT ;
|