3 # yapfaq Version 0.7 by Thomas Hochstein
4 # (Original author: Marc Brockschmidt)
6 # This script posts any project described in its config-file. Most people
7 # will use it in combination with cron(8).
9 # Copyright (C) 2003 Marc Brockschmidt <marc@marcbrockschmidt.de>
10 # Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
12 # It can be redistributed and/or modified under the same terms under
13 # which Perl itself is published.
15 my $Version = "0.8-prelease";
17 # Please do not change this setting!
18 # You may override the default .rc file (.yapfaqrc) by using "-c .rc file"
19 my $RCFile = '.yapfaqrc';
20 # Valid configuration variables for use in a .rc file
21 my @ValidConfVars = ('NNTPServer','NNTPUser','NNTPPass','Sender','ConfigFile',
22 'UsePGP','pgp','PGPVersion','PGPSigner','PGPPass',
23 'PathtoPGPPass','pgpbegin','pgpend','pgptmpf','pgpheader');
25 ################################### Defaults ###################################
26 # Please do not change anything in here!
27 # Use a runtime configuration file (.yapfaqrc by default) to override defaults.
28 my %Config = (NNTPServer => "",
32 ConfigFile => "yapfaq.cfg",
35 ################################## PGP-Config #################################
36 pgp => '/usr/bin/pgp', # path to pgp
37 PGPVersion => '2', # Use 2 for 2.X, 5 for PGP > 2.X and GPG for GPG
38 PGPSigner => '', # sign as who?
39 PGPPass => '', # pgp2 only
40 PathtoPGPPass => '', # pgp2, pgp5 and gpg
41 pgpbegin => '-----BEGIN PGP SIGNATURE-----', # Begin of PGP-Signature
42 pgpend => '-----END PGP SIGNATURE-----', # End of PGP-Signature
43 pgptmpf => 'pgptmp', # temporary file for PGP.
44 pgpheader => 'X-PGP-Sig');
46 my @PGPSignHeaders = ('From', 'Newsgroups', 'Subject', 'Control',
47 'Supersedes', 'Followup-To', 'Date', 'Sender', 'Approved',
48 'Message-ID', 'Reply-To', 'Cancel-Lock', 'Cancel-Key',
49 'Also-Control', 'Distribution');
51 my @PGPorderheaders = ('from', 'newsgroups', 'subject', 'control',
52 'supersedes', 'followup-To', 'date', 'organization', 'lines',
53 'sender', 'approved', 'distribution', 'message-id',
54 'references', 'reply-to', 'mime-version', 'content-type',
55 'content-transfer-encoding', 'summary', 'keywords', 'cancel-lock',
56 'cancel-key', 'also-control', 'x-pgp', 'user-agent');
58 ################################# Main program #################################
62 use Net::Domain qw(hostfqdn);
63 use Date::Calc qw(Add_Delta_YM Add_Delta_Days Delta_Days Today);
64 use Fcntl ':flock'; # import LOCK_* constants
66 my ($TDY, $TDM, $TDD) = Today(); #TD: Today's date
68 # read commandline options
70 getopts('Vhvpdt:f:c:s:', \%Options);
71 # -V: print version / copyright information
73 print "$0 v $Version\nCopyright (c) 2003 Marc Brockschmidt <marc\@marcbrockschmidt.de>\nCopyright (c) 2010 Thomas Hochstein <thh\@inter.net>\n";
74 print "This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.\n";
77 # -h: feed myself to perldoc
83 my ($Faq) = $Options{'f'} if ($Options{'f'});
85 # read runtime configuration (configuration variables)
86 $RCFile = $Options{'c'} if ($Options{'c'});
88 readrc (\$RCFile,\%Config);
90 warn "$0: W: .rc file $RCFile does not exist!\n";
93 # read configuration (configured FAQs)
95 readconfig (\$Config{'ConfigFile'}, \@Config, \$Faq);
98 # - parse configuration
100 # - if FAQ is due: call postfaq()
102 my ($LPD,$LPM,$LPY) = (01, 01, 0001); #LP: Last posting-date
103 my ($NPY,$NPM,$NPD); #NP: Next posting-date
106 my ($ActName,$File,$PFreq,$Expire) =($$_{'name'},$$_{'file'},$$_{'posting-frequency'},$$_{'expires'});
107 my ($From,$Subject,$NG,$Fup2)=($$_{'from'},$$_{'subject'},$$_{'ngs'},$$_{'fup2'});
108 my ($MIDF,$ReplyTo,$ExtHea)=($$_{'mid-format'},$$_{'reply-to'},$$_{'extraheader'});
109 my ($Supersede) =($$_{'supersede'});
111 # -f: loop if not FAQ to post
112 next if (defined($Faq) && $ActName ne $Faq);
115 if (open (FH, "<$File.cfg")) {
117 if (/##;; Lastpost:\s*(\d{1,2})\.(\d{1,2})\.(\d{2}(\d{2})?)/){
118 ($LPD, $LPM, $LPY) = ($1, $2, $3);
119 } elsif (/^##;;\s*LastMID:\s*(<\S+@\S+>)\s*$/) {
125 warn "$0: W: Couldn't open $File.cfg: $!\n";
128 $SupersedeMID = "" unless $Supersede;
130 ($NPY,$NPM,$NPD) = calcdelta ($LPY,$LPM,$LPD,$PFreq);
132 # if FAQ is due: get it out
133 if (Delta_Days($NPY,$NPM,$NPD,$TDY,$TDM,$TDD) >= 0 or ($Options{'p'})) {
135 print "$ActName: Would be posted now (but running in simulation mode [$0 -d]).\n" if $Options{'v'};
137 postfaq(\$ActName,\$File,\$From,\$Subject,\$NG,\$Fup2,\$MIDF,\$ExtHea,\$Config{'Sender'},\$TDY,\$TDM,\$TDD,\$ReplyTo,\$SupersedeMID,\$Expire);
139 } elsif($Options{'v'}) {
140 print "$ActName: Nothing to do.\n";
146 #################################### readrc ####################################
147 # Takes a filename and the reference to an array which contains the valid options
150 my ($File, $Config) = @_;
152 print "Reading $$File.\n" if($Options{'v'});
154 open FH, "<$$File" or die "$0: Can't open $$File: $!";
156 if (/^\s*(\S+)\s*=\s*'?(.*?)'?\s*(#.*$|$)/) {
157 if (grep(/$1/,@ValidConfVars)) {
158 $$Config{$1} = $2 if $2 ne '';
160 warn "$0: W: $1 is not a valid configuration variable (reading from $$File)\n";
166 ################################## readconfig ##################################
167 # Takes a filename, a reference to an array, which will hold hashes with
168 # the data from $File, and - optionally - the name of the (single) FAQ to post
171 my ($File, $Config, $Faq) = @_;
172 my ($LastEntry, $Error, $i) = ('','',0);
174 print "Reading configuration from $$File.\n" if($Options{'v'});
176 open FH, "<$$File" or die "$0: E: Can't open $$File: $!";
178 next if (defined($$Faq) && !/^\s*=====\s*$/ && defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} ne $$Faq );
179 if (/^(\s*(\S+)\s*=\s*'?(.*?)'?\s*(#.*$|$)|^(.*?)'?\s*(#.*$|$))/ && not /^\s*$/) {
180 $LastEntry = lc($2) if $2;
181 $$Config[$i]{$LastEntry} .= $3 if $3;
182 $$Config[$i]{$LastEntry} .= "\n$5" if $5 && $5;
184 if (/^\s*=====\s*$/) {
192 next if (defined($$Faq) && defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} ne $$Faq );
193 unless(defined($$Config[$i]{'name'}) && $$Config[$i]{'name'} =~ /^\S+$/) {
194 $Error .= "E: The name of your project \"$$Config[$i]{'name'}\" is not defined or contains whitespaces.\n"
196 unless(defined($$Config[$i]{'file'}) && -f $$Config[$i]{'file'}) {
197 $Error .= "E: The file to post for your project \"$$Config[$i]{'name'}\" is not defined or does not exist.\n"
199 unless(defined($$Config[$i]{'from'}) && $$Config[$i]{'from'} =~ /\S+\@(\S+\.)?\S{2,}\.\S{2,}/) {
200 $Error .= "E: The From header for your project \"$$Config[$i]{'name'}\" seems to be incorrect.\n"
202 unless(defined($$Config[$i]{'ngs'}) && $$Config[$i]{'ngs'} =~ /^\S+$/) {
203 $Error .= "E: The Newsgroups header for your project \"$$Config[$i]{'name'}\" is not defined or contains whitespaces.\n"
205 unless(defined($$Config[$i]{'subject'})) {
206 $Error .= "E: The Subject header for your project \"$$Config[$i]{'name'}\" is not defined.\n"
208 unless(!$$Config[$i]{'fup2'} || $$Config[$i]{'fup2'} =~ /^\S+$/) {
209 $Error .= "E: The Followup-To header for your project \"$$Config[$i]{'name'}\" contains whitespaces.\n"
211 unless(defined($$Config[$i]{'posting-frequency'}) && $$Config[$i]{'posting-frequency'} =~ /^\s*\d+\s*[dwmy]\s*$/) {
212 $Error .= "E: The Posting-frequency for your project \"$$Config[$i]{'name'}\" is invalid.\n"
214 unless(!$$Config[$i]{'expires'} || $$Config[$i]{'expires'} =~ /^\s*\d+\s*[dwmy]\s*$/) {
215 warn "$0: W: The Expires for your project \"$$Config[$i]{'name'}\" is invalid - set to 3 month.\n";
216 $$Config[$i]{'expires'} = '3m'; # set default (3 month) if expires is unset or invalid
218 unless(!$$Config[$i]{'mid-format'} || $$Config[$i]{'mid-format'} =~ /^<\S+\@\S{2,}\.\S{2,}>$/) {
219 warn "$0: W: The Message-ID format for your project \"$$Config[$i]{'name'}\" seems to be invalid - set to default.\n";
220 $$Config[$i]{'mid-format'} = '<%n-%d.%m.%y@'.hostfqdn.'>'; # set default if mid-format is invalid
223 $Error .= "-" x 25 . 'program terminated' . "-" x 25 . "\n" if $Error;
224 die $Error if $Error;
227 ################################# calcdelta #################################
228 # Takes a date (year, month and day) and a time period (1d, 1w, 1m, 1y, ...)
229 # and adds the latter to the former
232 my ($Year, $Month, $Day, $Period) = @_;
233 my ($NYear, $NMonth, $NDay);
235 if ($Period =~ /(\d+)\s*([dw])/) { # Is counted in days or weeks: Use Add_Delta_Days.
236 ($NYear, $NMonth, $NDay) = Add_Delta_Days($Year, $Month, $Day, (($2 eq "w")?$1 * 7: $1 * 1));
237 } elsif ($Period =~ /(\d+)\s*([my])/) { #Is counted in months or years: Use Add_Delta_YM
238 ($NYear, $NMonth, $NDay) = Add_Delta_YM($Year, $Month, $Day, (($2 eq "m")?(0,$1):($1,0)));
240 return ($NYear, $NMonth, $NDay);
243 ################################ updatestatus ###############################
244 # Takes a MID and a status file name
245 # and writes status information to disk
248 my ($ActName, $File, $date, $MID) = @_;
250 print "$$ActName: Save status information.\n" if($Options{'v'});
252 open (FH, ">$$File.cfg") or die "$0: E: Can't open $$File.cfg: $!";
253 print FH "##;; Lastpost: $date\n";
254 print FH "##;; LastMID: $MID\n";
258 ################################## postfaq ##################################
259 # Takes a filename and many other vars.
261 # It reads the data-file $File and then posts the article.
264 my ($ActName,$File,$From,$Subject,$NG,$Fup2,$MIDF,$ExtraHeaders,$Sender,$TDY,$TDM,$TDD,$ReplyTo,$Supersedes,$Expire) = @_;
265 my (@Header,@Body,$MID,$InRealBody,$LastModified);
267 print "$$ActName: Preparing to post.\n" if($Options{'v'});
270 $$TDM = ($$TDM < 10 && $$TDM !~ /^0/) ? "0" . $$TDM : $$TDM;
271 $$TDD = ($$TDD < 10 && $$TDD !~ /^0/) ? "0" . $$TDD : $$TDD;
274 $MID = '<%n-%d.%m.%y@'.hostfqdn.'>' if !defined($MID); # set to default if unset
275 $MID =~ s/\%n/$$ActName/g;
276 $MID =~ s/\%d/$$TDD/g;
277 $MID =~ s/\%m/$$TDM/g;
278 $MID =~ s/\%y/$$TDY/g;
281 open (FH, "<$$File");
284 push (@Body, $_), next if $InRealBody;
285 $InRealBody++ if /^$/;
286 $LastModified = $1 if /^Last-modified: (\S+)$/i;
290 push @Body, "\n" if ($Body[-1] ne "\n");
292 #Create Date- and Expires-Header:
293 my @time = localtime;
294 my $ss = ($time[0]<10) ? "0" . $time[0] : $time[0];
295 my $mm = ($time[1]<10) ? "0" . $time[1] : $time[1];
296 my $hh = ($time[2]<10) ? "0" . $time[2] : $time[2];
298 my $month = ($time[4]+1<10) ? "0" . ($time[4]+1) : $time[4]+1;
299 my $monthN = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$time[4]];
300 my $wday = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")[$time[6]];
301 my $year = (1900 + $time[5]);
302 my $tz = $time[8] ? " +0200" : " +0100";
304 $$Expire = '3m' if !$$Expire; # set default if unset: 3 month
306 my ($expY,$expM,$expD) = calcdelta ($year,$month,$day,$$Expire);
307 my $expmonthN = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$expM-1];
309 my $date = "$day $monthN $year " . $hh . ":" . $mm . ":" . $ss . $tz;
310 my $expdate = "$expD $expmonthN $expY $hh:$mm:$ss$tz";
312 #Replace %LM by the content of the news.answer-pseudo-header Last-modified:
314 $$Subject =~ s/\%LM/$LastModified/;
318 if($Options{'t'} and $Options{'t'} !~ /console/i) {
319 $$NG = $Options{'t'};
322 #Now create the complete Header:
323 push @Header, "From: $$From\n";
324 push @Header, "Newsgroups: $$NG\n";
325 push @Header, "Followup-To: $$Fup2\n" if $$Fup2;
326 push @Header, "Subject: $$Subject\n";
327 push @Header, "Message-ID: $MID\n";
328 push @Header, "Supersedes: $$Supersedes\n" if $$Supersedes;
329 push @Header, "Date: $date\n";
330 push @Header, "Expires: $expdate\n";
331 push @Header, "Sender: $$Sender\n" if $$Sender;
332 push @Header, "Mime-Version: 1.0\n";
333 push @Header, "Reply-To: $$ReplyTo\n" if $$ReplyTo;
334 push @Header, "Content-Type: text/plain; charset=ISO-8859-15\n";
335 push @Header, "Content-Transfer-Encoding: 8bit\n";
336 push @Header, "User-Agent: yapfaq/$Version\n";
337 if ($$ExtraHeaders) {
338 push @Header, "$_\n" for (split /\n/, $$ExtraHeaders);
341 # sign article if $UsePGP is true
342 my @Article = ($Config{'UsePGP'})?@{signpgp(\@Header, \@Body)}:(@Header, "\n", @Body);
345 print "$$ActName: Posting article ...\n" if($Options{'v'});
346 my $failure = post(\@Article);
349 print "$$ActName: Posting failed, ERROR.dat may have more information.\n" if($Options{'v'} && (!defined($Options{'t'}) || $Options{'t'} !~ /console/i));
351 updatestatus($ActName, $File, "$day.$month.$year", $MID) if !defined($Options{'t'});
355 ################################## post ##################################
356 # Takes a complete article (Header and Body).
358 # It opens a connection to $NNTPServer and posts the message.
364 # test mode - print article to console
365 if(defined($Options{'t'}) and $Options{'t'} =~ /console/i) {
366 print "-----BEGIN--------------------------------------------------\n";
368 print "------END---------------------------------------------------\n";
369 # pipe article to script
370 } elsif(defined($Options{'s'})) {
371 open (POST, "| $Options{'s'}") or die "$0: E: Cannot fork $Options{'s'}: $!\n";
372 print POST @$ArticleR;
377 warn "$0: W: $Options{'s'} exited with status ", ($? >> 8), "\n";
382 my $NewsConnection = Net::NNTP->new($Config{'NNTPServer'}, Reader => 1) or die "$0: E: Can't connect to news server '$Config{'NNTPServer'}'!\n";
383 $NewsConnection->authinfo ($Config{'NNTPUser'}, $Config{'NNTPPass'}) if (defined($Config{'NNTPUser'}));
384 $NewsConnection->post();
385 $NewsConnection->datasend (@$ArticleR);
386 $NewsConnection->dataend();
388 if ($NewsConnection->ok()) {
390 # Posting failed? Save to ERROR.dat
392 warn "$0: W: Posting failed!\n";
393 open FH, ">>ERROR.dat";
394 print FH "\nPosting failed! Saving to ERROR.dat. Response from news server:\n";
395 print FH $NewsConnection->code();
396 print FH $NewsConnection->message();
399 print FH "-" x 80, "\n";
402 $NewsConnection->quit();
407 #-------- sub getpgpcommand
408 # getpgpcommand generates the command to sign the message and returns it.
411 # - $PGPVersion: A scalar holding the PGPVersion
413 my ($PGPVersion) = @_;
416 if ($PGPVersion eq '2') {
417 if ($Config{'PathtoPGPPass'} && !$Config{'PGPPass'}) {
418 open (PGPPW, $Config{'PathtoPGPPass'}) or die "$0: E: Can't open $Config{'PathtoPGPPass'}: $!";
419 Config{'$PGPPass'} = <PGPPW>;
423 if (Config{'$PGPPass'}) {
424 $PGPCommand = "PGPPASS=\"".$Config{'PGPPass'}."\" ".$Config{'pgp'}." -u \"".$Config{'PGPSigner'}."\" +verbose=0 language='en' -saft <".$Config{'pgptmpf'}.".txt >".$Config{'pgptmpf'}.".txt.asc";
426 die "$0: E: PGP-Passphrase is unknown!\n";
428 } elsif ($PGPVersion eq '5') {
429 if ($Config{'PathtoPGPPass'}) {
430 $PGPCommand = "PGPPASSFD=2 ".$Config{'pgp'}."s -u \"".$Config{'PGPSigner'}."\" -t --armor -o ".$Config{'pgptmpf'}.".txt.asc -z -f < ".$Config{'pgptmpf'}.".txt 2<".$Config{'PathtoPGPPass'};
432 die "$0: E: PGP-Passphrase is unknown!\n";
434 } elsif ($PGPVersion =~ m/GPG/io) {
435 if (Config{'$PathtoPGPPass'}) {
436 $PGPCommand = $Config{'pgp'}." --digest-algo MD5 -a -u \"".$Config{'PGPSigner'}."\" -o ".$Config{'pgptmpf'}.".txt.asc --no-tty --batch --passphrase-fd 2 2<".$Config{'PathtoPGPPass'}." --clearsign ".$Config{'pgptmpf'}.".txt";
438 die "$0: E: Passphrase is unknown!\n";
441 die "$0: E: Unknown PGP-Version $PGPVersion!";
447 #-------- sub signarticle
448 # signarticle signs an articel and returns a reference to an array
449 # containing the whole signed Message.
452 # - $HeaderAR: A reference to a array containing the articles headers.
453 # - $BodyR: A reference to an array containing the body.
456 # - $MessageRef: A reference to an array containing the whole message.
458 my ($HeaderAR, $BodyR) = @_;
459 my (@pgphead, @pgpbody, $pgphead, $pgpbody, $header, $signheaders, @signheaders, $currentheader, $HeaderR, $line);
461 foreach my $line (@$HeaderAR) {
462 if ($line =~ /^(\S+):\s+(.*)$/s) {
464 $$HeaderR{lc($currentheader)} = "$1: $2";
466 $$HeaderR{lc($currentheader)} .= $line;
470 foreach (@PGPSignHeaders) {
471 if (defined($$HeaderR{lc($_)}) && $$HeaderR{lc($_)} =~ m/^[^\s:]+: .+/o) {
472 push @signheaders, $_;
476 $pgpbody = join ("", @$BodyR);
478 # Delete and create the temporary pgp-Files
479 unlink "$Config{'pgptmpf'}.txt";
480 unlink "$Config{'pgptmpf'}.txt.asc";
481 $signheaders = join(",", @signheaders);
483 $pgphead = "X-Signed-Headers: $signheaders\n";
484 foreach $header (@signheaders) {
485 if ($$HeaderR{lc($header)} =~ m/^[^\s:]+: (.+?)\n?$/so) {
486 $pgphead .= $header.": ".$1."\n";
490 open(FH, ">" . $Config{'pgptmpf'} . ".txt") or die "$0: E: can't open $Config{'pgptmpf'}: $!\n";
491 print FH $pgphead, "\n", $pgpbody;
492 print FH "\n" if ($Config{'PGPVersion'} =~ m/GPG/io); # workaround a pgp/gpg incompatibility - should IMHO be fixed in pgpverify
493 close(FH) or warn "$0: W: Couldn't close TMP: $!\n";
495 # Start PGP, then read the signature;
496 my $PGPCommand = getpgpcommand($Config{'PGPVersion'});
499 open (FH, "<" . $Config{'pgptmpf'} . ".txt.asc") or die "$0: E: can't open ".$Config{'pgptmpf'}.".txt.asc: $!\n";
500 $/ = "$Config{'pgpbegin'}\n";
502 unless (m/\Q$Config{'pgpbegin'}\E$/o) {
503 # unlink $Config{'pgptmpf'} . ".txt";
504 # unlink $Config{'pgptmpf'} . ".txt.asc";
505 die "$0: E: $Config{'pgpbegin'} not found in ".$Config{'pgptmpf'}.".txt.asc\n"
507 unlink($Config{'pgptmpf'} . ".txt") or warn "$0: W: Couldn't unlink $Config{'pgptmpf'}.txt: $!\n";
511 unless (m/^Version: (\S+)(?:\s(\S+))?/o) {
512 unlink $Config{'pgptmpf'} . ".txt";
513 unlink $Config{'pgptmpf'} . ".txt.asc";
514 die "$0: E: didn't find PGP Version line where expected.\n";
518 $$HeaderR{$Config{'pgpheader'}} = $1."-".$2." ".$signheaders;
520 $$HeaderR{$Config{'pgpheader'}} = $1." ".$signheaders;
523 do { # skip other pgp headers like
524 $_ = <FH>; # "charset:"||"comment:" until empty line
529 last if /^\Q$Config{'pgpend'}\E$/;
530 $$HeaderR{$Config{'pgpheader'}} .= "\n\t$_";
533 $$HeaderR{$Config{'pgpheader'}} .= "\n" unless ($$HeaderR{$Config{'pgpheader'}} =~ /\n$/s);
537 unlink $Config{'pgptmpf'} . ".txt";
538 unlink $Config{'pgptmpf'} . ".txt.asc";
539 die "$0: E: unexpected data following $Config{'pgpend'}\n";
542 unlink "$Config{'pgptmpf'}.txt.asc";
544 my $tmppgpheader = $Config{'pgpheader'} . ": " . $$HeaderR{$Config{'pgpheader'}};
545 delete $$HeaderR{$Config{'pgpheader'}};
548 foreach $header (@PGPorderheaders) {
549 if ($$HeaderR{$header} && $$HeaderR{$header} ne "\n") {
550 push(@pgphead, "$$HeaderR{$header}");
551 delete $$HeaderR{$header};
555 foreach $header (keys %$HeaderR) {
556 if ($$HeaderR{$header} && $$HeaderR{$header} ne "\n") {
557 push(@pgphead, "$$HeaderR{$header}");
558 delete $$HeaderR{$header};
562 push @pgphead, ("X-PGP-Key: " . $Config{'PGPSigner'} . "\n"), $tmppgpheader;
565 @pgpbody = split /$/m, $pgpbody;
566 my @pgpmessage = (@pgphead, "\n", @pgpbody);
572 ################################ Documentation #################################
576 yapfaq - Post Usenet FAQs I<(yet another postfaq)>
580 B<yapfaq> [B<-Vhvpd>] [B<-t> I<newsgroups> | CONSOLE] [B<-f> I<project name>] [B<-s> I<program>] [B<-c> I<.rc file>]
604 Furthermore you need access to a news server to actually post FAQs.
608 B<yapfaq> posts (one or more) FAQs to Usenet with a certain posting
609 frequency (every n days, weeks, months or years), adding all necessary
610 headers as defined in its config file (by default F<yapfaq.cfg>).
614 F<yapfaq.cfg> consists of one or more blocks, separated by C<=====> on
615 a single line, each containing the configuration for one FAQ as a set
616 of definitions in the form of I<param = value>. Everything after a "#"
617 sign is ignored so you may comment your configuration file.
621 =item B<Name> = I<project name>
623 A name referring to your FAQ, also used for generation of a Message-ID.
625 This value must be set.
627 =item B<File> = I<file name>
629 A file containing the message body of your FAQ and all pseudo headers
630 (subheaders in the news.answers style).
632 This value must be set.
634 =item B<Posting-frequency> = I<time period>
636 The posting frequency defines how often your FAQ will be posted.
637 B<yapfaq> will only post your FAQ if this period of time has passed
638 since the last posting.
640 You can declare that time period either in I<B<d>ays> or I<B<w>weeks>
641 or I<B<m>onths> or I<B<y>ears>.
643 This value must be set.
645 =item B<Expires> = I<time period> (optional)
647 The period of time after which your message will expire. An Expires
648 header will be calculated adding this time period to today's date.
650 You can declare this time period either in I<B<d>ays> or I<B<w>weeks>
651 or I<B<m>onths> or I<B<y>ears>.
653 This setting is optional; the default is 3 months.
655 =item B<From> = I<author>
657 The author of your FAQ as it will appear in the From header of the
660 This value must be set.
662 =item B<Subject> = I<subject>
664 The title of your FAQ as it will appear in the Subject header of the
667 You may use the special string C<%LM> which will be replaced with
668 the contents of the Last-Modified subheader in your I<File>.
670 This value must be set.
672 =item B<NGs> = I<newsgroups>
674 A comma-separated list of newsgroup(s) to post your FAQ to as it will
675 appear in the Newsgroups header of the message.
677 This value must be set.
679 =item B<Fup2> = I<newsgroup | poster> (optional)
681 A comma-separated list of newsgroup(s) or the special string I<poster>
682 as it will appear in the Followup-To header of the message.
684 This setting is optional.
686 =item B<MID-Format> = I<pattern> (optional)
688 A pattern from which the message ID is generated as it will appear in
689 the Message-ID header of the message.
691 You may use the special strings C<%n> for the I<Name> of your project,
692 C<%d> for the date the message is posted, C<%m> for the month and
693 C<%y> for the year, respectively.
695 This setting is optional; the default is '<%n-%d.%m.%y@I<YOURHOST>>'
696 where I<YOURHOST> is the fully qualified domain name (FQDN) of the
697 host B<yapfaq> is running on. Obviously that will only work if you
698 have defined a reasonable hostname that the hostfqdn() function of
699 Net::Domain can return.
701 =item B<Supersede> = I<yes> (optional)
703 Add Supersedes header to the message containing the Message-ID header
706 This setting is optional; you should set it to yes or leave it out.
708 =item B<ExtraHeader> = I<additional headers> (optional)
710 The contents of I<ExtraHeader> is added verbatim to the headers of
711 your message so you can add custom headers like Approved.
713 This setting is optional.
717 =head3 Example configuration file
719 # name of your project
722 # file to post (complete body and pseudo-headers)
723 # ($File.cfg contains data on last posting and last MID)
726 # how often your project should be posted
727 # use (d)ay OR (w)eek OR (m)onth OR (y)ear
728 Posting-frequency = '1d'
730 # time period after which the posting should expire
731 # use (d)ay OR (w)eek OR (m)onth OR (y)ear
735 From = 'test@domain.invalid'
738 # (may contain "%LM" which will be replaced by the contents of the
739 # Last-Modified pseudo header).
740 Subject = 'test noreply ignore'
742 # comma-separated list of newsgroup(s) to post to
743 # (header "Newsgroups:")
746 # header "Followup-To:"
749 # Message-ID ("%n" is $Name)
750 # MID-Format = '<%n-%d.%m.%y@domain.invalid>'
752 # Supersede last posting?
755 # extra headers (appended verbatim)
756 # use this for custom headers like "Approved:"
757 ExtraHeader = 'Approved: moderator@domain.invalid
760 # other projects may follow separated with "====="
765 Posting-frequency = '2m'
766 From = 'My Name <my.name@domain.invalid>'
767 Subject = 'Test of yapfag <%LM>'
768 NGs = 'de.test,de.alt.test'
770 MID-Format = '<%n-%m.%y@domain.invalid>'
773 =head3 Status Information
775 Information about the last post and about how to form message IDs for
776 posts is stored in a file named F<I<project name>.cfg> which will be
777 generated if it does not exist. Each of those status files will
778 contain two lines, the first being the date of the last time the FAQ
779 was posted and the second being the message ID of that incarnation.
781 =head2 Runtime Configuration
783 Apart from configuring which FAQ(s) to post you may (re)set some
784 runtime configuration variables via the .rcfile (by default
785 F<.yapfaqrc>). F<.yapfaqrc> must contain one definition in the form of
786 I<param = value> on each line; everything after a "#" sign is ignored.
788 If you omit some settings they will be set to default values hardcoded
791 B<Please note that all parameter names are case-sensitive!>
795 =item B<NNTPServer> = I<NNTP server> (mandatory)
797 Host name of the NNTP server to post to. Must be set (or omitted; the
798 default is "localhost"); if set to en empty string, B<yapfaq> falls
799 back to Perl's build-in defaults (contents of environment variables
800 NNTPSERVER and NEWSHOST; if not set, default from Net::Config; if not
801 set, "news" is used).
803 =item B<NNTPUser> = I<user name> (optional)
805 User name used for authentication with the NNTP server (I<AUTHINFO
808 This setting is optional; if it is not set, I<NNTPPass> is ignored and
809 no authentication is tried.
811 =item B<NNTPPass> = I<password> (optional)
813 Password used for authentication with the NNTP server (I<AUTHINFO
816 This setting is optional; it must be set if I<NNTPUser> is present.
818 =item B<Sender> = I<Sender header> (optional)
820 The Sender header that will be added to every posted message.
822 This setting is optional.
824 =item B<ConfigFile> = I<configuration file> (mandatory)
826 The configuration file defining the FAQ(s) to post. Must be set (or
827 omitted; the default is "yapfaq.cfg").
829 =item B<UsePGP> = I<whether to add a digital signature> (optional)
831 Boolean value (0 or 1) controlling whether the FAQs will get digitally
832 signed via an X-PGP-Sig header.
834 This setting is optional; the default is 0.
836 If you have set I<UsePGP> to 1, you must also supply the necessary
837 information on your PGP oder GPG installation; please refer to the
838 sample F<.yapfaqrc> file (see below) for more information on this
843 =head3 Example runtime configuration file
845 NNTPServer = 'localhost'
849 ConfigFile = 'yapfaq.cfg'
852 ################################## PGP-Config #################################
853 pgp = '/usr/bin/pgp' # path to pgp
854 PGPVersion = '2' # Use 2 for 2.X 5 for PGP > 2.X and GPG for GPG
855 PGPSigner = '' # sign as who?
856 PGPPass = '' # pgp2 only
857 PathtoPGPPass = '' # pgp2 pgp5 and gpg
858 pgpbegin = '-----BEGIN PGP SIGNATURE-----' # Begin of PGP-Signature
859 pgpend = '-----END PGP SIGNATURE-----' # End of PGP-Signature
860 pgptmpf = 'pgptmp' # temporary file for PGP.
861 pgpheader = 'X-PGP-Sig'
863 =head3 Using more than one runtime configuration
865 You may use more than one runtime configuration file with the B<-c>
872 =item B<-V> (version)
874 Print out version and copyright information on B<yapfaq> and exit.
878 Print this man page and exit.
880 =item B<-v> (verbose)
882 Print out status information while running to STDOUT.
884 =item B<-p> (post unconditionally)
886 Post (all) FAQs unconditionally ignoring the posting frequency setting.
888 You may want to use this with the B<-f> option (see below).
890 =item B<-d> (dry run)
892 Start B<yapfaq> in simulation mode, i.e. don't post anything and don't
893 update any status information.
895 =item B<-t> I<newsgroup(s) | CONSOLE> (test)
897 Don't post to the newsgroups defined in F<yqpfaq.cfg>, but to the
898 newsgroups given after B<-t> as a comma-separated list or print the
899 FAQs to STDOUT separated by lines of dashes if the special string
900 C<CONSOLE> is given. This can be used to preview what B<yapfaq> would
901 do without embarassing yourself on Usenet. The status files are not
902 updated when this option is given.
904 You may want to use this with the B<-f> option (see below).
906 =item B<-f> I<project name>
908 Just deal with one FAQ only.
910 By default B<yapfaq> will work on all FAQs that are defined in
911 F<yapfaq.cfg>, check whether they are due for posting and - if they
912 are - post them. Consequently when the B<-p> option is set all FAQs
913 will be posted unconditionally. That may not be what you want to
914 achieve, so you can limit the operation of B<yapfaq> to the named FAQ
917 =item B<-s> I<program> (pipe to script)
919 Instead of posting the article(s) to Usenet pipe them to the external
920 I<program> on STDIN (which may post the article(s) then). A return
921 value of 0 will be considered success.
923 =item B<-c> I<.rc file>
925 Load another runtime configuration file (.rc file) than F<.yaofaq.rc>.
927 You may for example define another usenet server to post your FAQ(s)
928 to or load another configuration file defining (an)other FAQ(s).
934 Post all FAQs that are due for posting:
938 Do a dry run, showing which FAQs would be posted:
942 Do a test run and print on STDOUT what the FAQ I<myfaq> would look
943 like when posted, regardless whether it is due for posting or not:
945 yapfaq -pt CONSOLE -f myfaq
947 Do a "real" test run and post the FAQ I<myfaq> to I<de.test>, but only
950 yapfaq -t de.test -f myfaq
952 Post all FAQs (that are due for posting) using inews from INN:
956 Do a dry run using a runtime configuration from .alternaterc, showing
957 which FAQs would be posted:
959 yapfaq -dvc .alternaterc
967 The default NNTP server to post to, used by the Net::NNTP module. You
968 can also specify the server using the runtime configuration file (by
969 default F<.yapfaqrc>).
983 Runtime configuration file for B<yapfaq>.
987 Configuration file for B<yapfaq>.
993 The status files will be created on successful posting if they don't
994 already exist. The first line of the file will be the date of the last
995 time the FAQ was posted and the second line will be the message ID of
996 the last post of that FAQ.
1006 L<http://th-h.de/download/scripts.php> will have the current
1007 version of this program.
1011 Thomas Hochstein <thh@inter.net>
1013 Original author (up to version 0.5b, dating from 2003):
1014 Marc Brockschmidt <marc@marcbrockschmidt.de>
1016 =head1 COPYRIGHT AND LICENSE
1018 Copyright (c) 2003 Marc Brockschmidt <marc@marcbrockschmidt.de>
1020 Copyright (c) 2010 Thomas Hochstein <thh@inter.net>
1022 This program is free software; you may redistribute it and/or modify it
1023 under the same terms as Perl itself.