Debian Codegraph @

misc/contrib/areafix-0.5.07/areafix.pl

raw
1 #!/usr/bin/perl
2 use Sys::Syslog;
3
4 # run syslogd with -r if you want it to work.
5 # locate Syslog.pm and if it doesn't exist, read the manpage for h2ph.
6 #
7 # bug: crashes in line ~300 if system does not appear in newsfeeds
8 # but has areafix password.
9 #
10 # bug: run this as root, or it will zero your newsfeeds file.
11
12 #
13 # Revision 1.3 1998/08/01 18:03:41 fnet
14 # Fixed for perl5. James Vahn 1:346/3 <[email protected]>
15 #
16 # Revision 1.2 1997/04/19 13:23:31 fnet
17 # gup3w-compatible locking added
18 #
19 # Revision 1.1 1997/04/09 13:52:10 fnet
20 # Initial revision
21 #
22
23
24 # $VERSION = "0.5.07-jv12";
25
26 ## Type _full_ path below
27
28 $CONFIGFILE="/usr/lib/ifmail/areafix/config";
29 $CONFIGFILE=$ARGV[0] if defined($ARGV[0]);
30
31 ## main program :)
32
33 &areafix();
34
35 sub areafix
36 {
37 &startup();
38
39 unless (&shlock($SEMAPHORE,1))
40 {
41 if (time-(stat($SEMAPHORE))[9] > 86400)
42 {
43 die &log('alert',"Possibly hung areafix (PID=$oldpid)",0);
44 }
45 else
46 {
47 &log('warning',"Overlapping with areafix[$oldpid] - exiting",1); }
48 return;
49 }
50
51 if ($NEWSLOCK && !&shlock("$NEWSLOCK/LOCK.newsfeeds",5))
52 {
53 return;
54 }
55
56 &read_control_files();
57
58 &process_queue();
59
60 &finish();
61
62 &shunlock("$NEWSLOCK/LOCK.newsfeeds") if $NEWSLOCK;
63 &shunlock($SEMAPHORE);
64 }
65
66 sub process_queue
67 {
68 local(@file,$file,$rc);
69
70 @file=<$QUEUE/*>;
71
72 foreach $file (@file)
73 {
74 if ( -f $file )
75 {
76 open(IN,$file) || (&log('err',"Cannot open queue file $file",0), next);
77 $rc=&process_message();
78 close(IN);
79 if ($rc)
80 {
81 unlink($file) || &log('err',"Cannot unlink queue file $file",0);
82 }
83 else
84 {
85 &log('warning',"Bad message header in message ".&basename($file)." - moving to $QUEUE/bad",1);
86 mkdir("$QUEUE/bad",0777) || (&log('err',"Cannot make directory $QUEUE/bad",0), next) unless ( -d "$QUEUE/bad" );
87 rename($file,"$QUEUE/bad/".&basename($file)) || &log('err',"Cannot move $file to $QUEUE/bad",0);
88 }
89 }
90 }
91 }
92
93 sub process_message
94 {
95 &parse_header() || return 0;
96 open(OUT,$MAILCOMMAND) || die &log('err',"Bad mailing command $MAILCOMMAND",0);
97 &log('info',"Processing message from $USERADDR",1);
98 print OUT "From: $ROBOT_NAME \<$ROBOT_NAME\@$ADDRESS\>\n";
99 print OUT "To: Sysop \<".(defined($REPLYTO)?$REPLYTO:$USERADDR)."\>\n";
100 print OUT "Subject: Reply from Area Manager\n\n";
101
102 if ( &newsfeeds_check($USERHOST) )
103 {
104 if ( &passwd_check($USERHOST,$SUBJECT) )
105 {
106 $SITE=$feeds{$USERHOST};
107 $IS_FTN_LINK=$SITE=~/^(p\d+\.)?f\d+\.n\d+$/ && !$NO_FIDO;
108 $WIDE=!$IS_FTN_LINK;
109 &process_message_body();
110 }
111 else
112 {
113 &write_password_flame();
114 }
115 }
116 else
117 {
118 &write_address_flame();
119 }
120 close(OUT);
121 return 1;
122 }
123
124 sub startup
125
126 {
127 &read_config($CONFIGFILE) || die "Bad configuration file";
128 &openlog('areafix','cons,pid',$LOG_FACILITY);
129 ##&log('info','Starting areafix',3);
130 }
131
132 sub finish
133 {
134 if($NEWSFEEDSCHANGED)
135 {
136 if ( -e $OUTNEWSFEEDS)
137 {
138 if ( -e $OUTNEWSFEEDS.".bak")
139 {
140 unlink($OUTNEWSFEEDS.".bak") || die &log('err',"Can not unlink file $OUTNEWSFEEDS.bak",0);
141 }
142 rename($OUTNEWSFEEDS,$OUTNEWSFEEDS.".bak") || die &log('err',"Can not rename file $OUTNEWSFEEDS to $OUTNEWSFEEDS.bak",0);
143 }
144 &write_newsfeeds($OUTNEWSFEEDS,$PASSIVE_NEWSFEEDS) || &log('err',"Cannot write newsfeeds",0);
145
146 system("$RELOADCOMMAND");
147 &log('debug',"Newsfeeds reloaded",4);
148 }
149 close(IN);
150 close(FORWARD) if ($DOING_FORWARD);
151 ##&log('info','stopping areafix');
152 &closelog();
153 }
154
155 ##--------- top-level functions
156 sub passwd_check
157 {
158 return (defined $passwds{$_[0]}) && (&to_upper_case($_[1]) eq &to_upper_case($passwds{$_[0]}));
159 }
160
161 sub newsfeeds_check
162 {
163 return (defined $feeds{$_[0]});
164 }
165
166 sub to_upper_case
167 {
168 $_[0]=~tr/[a-z]/[A-Z]/;
169 return $_[0];
170 }
171
172 sub quote_meta
173 {
174 local($c);
175 foreach $c (('\.','\+','\$','\?','\/','\{','\}','\(','\)','\<','\>'))
176 {
177 $_[0]=~s/$c/$c/g;
178 }
179 return $_[0];
180 }
181
182 sub wildmat_to_regexp
183 {
184 $_[0]=~s/\*/\\S\*/go;
185 $_[0]="^".&quote_meta($_[0])."\$";
186 }
187
188 sub basename
189 {
190 local($s)=@_;
191 return $1 if ($s=~m|.*/([^/]+)$|);
192 return $s;
193 }
194
195 sub log
196 {
197 local($prio,$message,$level)=@_;
198 $message=~s/%/%%/go;
199 &syslog($prio,$message) if ($level<=$LOG_LEVEL);
200 return($_[1]."\n");
201 }
202
203 sub write_password_flame
204 {
205 print OUT "Your areafix password can't be found and the request\n";
206 print OUT "has been refused. Perhaps you didn't use the correct\n";
207 print OUT "password, please try again.\n";
208 &log('notice',"Remote $USERADDR gave incorrect password $SUBJECT",1);
209 }
210
211 sub write_restricted_flame
212 {
213 print OUT "$_[1]$_[0] -- '$_[0]' is restricted. You cannot change its status.\n";
214 &log('notice',"Remote $USERADDR attempted to \'$_[1]\' restricted echo (newsgroup) $_[0]",1);
215 }
216
217 sub write_address_flame
218 {
219 print OUT "Your site isn't configured for areafix here and\n";
220 print OUT "the request has been refused.\n";
221 &log('notice',"Site $USERHOST was not found in passwords/newsfeeds",1);
222 }
223
224 sub process_message_body
225 {
226 &build_hashes();
227 while (<IN>)
228 {
229 last if (/^---/o);
230 next if (/^\s*$/o);
231 s/^\s*(.*)\s*$/$1/;
232 if (defined($XCOM_TABLE{$_}))
233 {
234 &log('debug',"Read command: $_",3);
235 &log('debug',"Translating $_ to ".$XCOM_TABLE{$_},3);
236 $_=$XCOM_TABLE{$_};
237 }
238 &log('info',"Executing command: $_",2);
239 next if (/^\s*\%NOP\s*$/io);
240 &print_help(), next if (/^%HELP$/io);
241 &print_list(), next if (/^%LIST$/io);
242 &do_wide(), next if (/^%WIDE$/io);
243 &print_query(), next if (/^%QUERY$/io);
244 &make_passive(), next if (/^%PASSIVE$/io);
245 &make_active(), next if (/^%ACTIVE$/io);
246 &print_unlinked(), next if (/^%UNLINKED$/io);
247 &subscribe_to_ngroup($1), next if (/^%\+(\S+)/o);
248 &unsubscribe_from_ngroup($1), next if (/^%-(\S+)/o);
249 $NO_FIDO?&unsubscribe_from_ngroup($1):&unsubscribe($1), next if (/^\-(\S+)/o);
250 $NO_FIDO?&subscribe_to_ngroup($1):&subscribe($1), next if (/^\+(\S+)/o);
251 &print_invalid($_);
252 }
253 $patterns{$SITE}=join(",",sort(keys(%patt_hash)));
254 }
255
256 ## top-level commands processing
257
258 sub make_passive
259 {
260 &log('debug',"Processing %PASSIVE operation",4);
261 if ($passive{$SITE}==1)
262 {
263 print OUT "-----------------------------------------------------\n";
264 print OUT "%PASSIVE - your newsfeeds already have passive status\n";
265 print OUT "-----------------------------------------------------\n";
266 }
267 else
268 {
269 $passive{$SITE}=1;
270 $NEWSFEEDSCHANGED=1;
271 print OUT "-------------------------------------------------\n";
272 print OUT "%PASSIVE - your newsfeeds have passive status now\n";
273 print OUT "-------------------------------------------------\n";
274 }
275 }
276
277 sub make_active
278 {
279 &log('debug',"Processing %ACTIVE operation",4);
280 if ($passive{$SITE}==0)
281 {
282 print OUT "----------------------------------------------------\n";
283 print OUT "%ACTIVE - your news feeds already have active status\n";
284 print OUT "----------------------------------------------------\n";
285 }
286 else
287 {
288 $passive{$SITE}=0;
289 $NEWSFEEDSCHANGED=1;
290 print OUT "------------------------------------------------\n";
291 print OUT "%ACTIVE - your news feeds have active status now\n";
292 print OUT "------------------------------------------------\n";
293 }
294 }
295
296 sub build_hashes
297 {
298 local($group);
299 undef %patt_hash;
300 undef %active_hash;
301 foreach $group (split(",",$patterns{$SITE}))
302 {
303 $patt_hash{$group}=1;
304 }
305 foreach $group (@active)
306 {
307 $active_hash{$group}=1;
308 }
309 }
310
311 sub subscribe
312 {
313 local($echo,@echoes,$curecho,@tmp,$curgroup);
314 $echo=$_[0];
315 $echo=~tr/a-z/A-Z/;
316 &log('debug',"Processing subscribe operation",4);
317 &wildmat_to_regexp($echo);
318 @tmp=grep(/$echo/,keys(%echo2ng));
319 foreach $curecho (@tmp)
320 {
321 push(@echoes,$curecho) if defined($active_hash{$echo2ng{$curecho}});
322 }
323
324 if (defined(@echoes))
325 {
326 foreach $curecho (@echoes)
327 {
328 $curgroup=$echo2ng{$curecho};
329
330 if (&findinrestricted($curgroup) || &findinrestricted($curecho))
331 {
332 &write_restricted_flame($curecho,"+");
333 }
334 elsif (!defined($patt_hash{$curgroup}))
335 {
336 $patt_hash{$curgroup}=1;
337 $NEWSFEEDSCHANGED=1;
338 print OUT "+$curecho -- Subscribed to $curecho\n";
339 &log('debug',"Remote subsribed to $curecho",5);
340 }
341 else
342 {
343 print OUT "+$curecho -- Already subscribed to $curecho\n";
344 &log('debug',"Remote already subscribed to $curecho",5);
345 }
346 }
347 }
348 else
349 {
350 print OUT "+$_[0] -- No such echo(es) here.";
351 &log('notice',"Can not subscribe to $_[0] - no such echo",1);
352 if ($FORWARD)
353 {
354 print OUT "Your request will be forwarded to our uplink. Try later.\n";
355 &log('notice',"This request will be forwarded to our uplink",1);
356 &forward($_[0]);
357 }
358 else
359 {
360 print OUT "\n";
361 }
362 }
363 }
364
365 sub subscribe_to_ngroup
366 {
367 local($group,@groups,$curgroup,@tmp);
368 $group=$_[0];
369 $group=~tr/A-Z/a-z/;
370 &log('debug',"Processing subscribe operation to newsgroup",4);
371 &wildmat_to_regexp($group);
372 if ($IS_FTN_LINK)
373 {
374 @tmp=grep(/$group/,keys(%ng2echo));
375 foreach $curgroup (@tmp)
376 {
377 push(@groups,$curgroup) if defined($active_hash{$curgroup});
378 }
379 }
380 else
381 {
382 @groups=grep(/$group/,@active);
383 }
384 if (defined(@groups))
385 {
386 foreach $curgroup (@groups)
387 {
388 if (&findinrestricted($curgroup) || &findinrestricted($ng2echo{$curgroup}))
389 {
390 &write_restricted_flame($curgroup,"%+");
391 }
392 elsif (!defined($patt_hash{$curgroup}))
393 {
394 $patt_hash{$curgroup}=1;
395 $NEWSFEEDSCHANGED=1;
396 print OUT "%+$curgroup -- Subscribed to $curgroup\n";
397 &log('debug',"Remote subsribed to $curgroup",5);
398 }
399 else
400 {
401 print OUT "%+$curgroup -- Already subscribed to $curgroup\n";
402 &log('debug',"Remote already subscribed to $curgroup",5);
403 }
404 }
405 }
406 else
407 {
408 print OUT "%+$_[0] -- No such group(s) here.\n";
409 &log('notice',"Can not subscribe to newsgroup $_[0]",1);
410 }
411 }
412
413 sub torealname
414 {
415 local($tmp)=$_[0];
416 $tmp=~tr/[_ \.]/ /;
417 return $tmp;
418 }
419
420 sub findinrestricted
421 {
422 local($fgroup,$fcurgroup);
423 $fgroup=$_[0];
424 foreach $fcurgroup (keys(%restricted))
425 {
426 return 1 if ($fgroup=~/$fcurgroup/i && $USERHOST=~/$restricted{$fcurgroup}/);
427 }
428 return 0;
429 }
430
431 sub forward
432 {
433 unless ($DOING_FORWARD)
434 {
435 open(FORWARD,$MAILCOMMAND) || (&log('err',"Bad mailing command $MAILCOMMAND",0),return);
436 $SYSOP_NAME=~tr/[_ ]/./;
437 print FORWARD "From: $SYSOP_NAME \<$SYSOP_NAME\@$ADDRESS\>\n";
438 print FORWARD "To: $UPLINK_ROBOT_NAME \<$UPLINK_ROBOT_NAME\@$UPLINK_ADDRESS\>\n";
439 print FORWARD "Subject: $UPLINK_PASSWORD\n\n";
440 $DOING_FORWARD=1;
441 }
442 print FORWARD "+$_[0]\n";
443 }
444
445 sub unsubscribe
446 {
447 local($echo,$curecho,$curgroup,$unsubscribed);
448 $echo=$_[0];
449 $echo=~tr/a-z/A-Z/;
450 &log('debug',"Processing unsubscribe operation",4);
451
452 &wildmat_to_regexp($echo);
453
454 foreach $curgroup (keys(%patt_hash))
455 {
456 $curecho=$ng2echo{$curgroup};
457 if ($curecho=~/$echo/)
458 {
459 if (&findinrestricted($curecho) || &findinrestricted($curgroup))
460 {
461 &write_restricted_flame($curecho,"-");
462 }
463 else
464 {
465 delete $patt_hash{$curgroup};
466 print OUT "-$curecho -- Unsubscribed\n";
467 &log('debug',"Remote unsubsribed from $curecho",5);
468 }
469 $unsubscribed=1;
470 }
471 }
472
473 unless ($unsubscribed)
474 {
475 print OUT "-$_[0] -- No match in your subscription list.\n";
476 &log('debug',"Remote is not subscribed to $_[0]",5);
477 }
478 else
479 {
480 $NEWSFEEDSCHANGED=1;
481 }
482 }
483
484 sub unsubscribe_from_ngroup
485 {
486 local($group,$curgroup,$unsubscribed);
487 $group=$_[0];
488 $group=~tr/A-Z/a-z/;
489 &log('debug',"Processing unsubscribe operation from newsgroup",4);
490
491 &wildmat_to_regexp($group);
492
493 foreach $curgroup (keys(%patt_hash))
494 {
495 if ($curgroup=~/$group/)
496 {
497 if (&findinrestricted($curgroup) || &findinrestricted($ng2echo{$curgroup}))
498 {
499 &write_restricted_flame($curgroup,"%-");
500 }
501 else
502 {
503 delete $patt_hash{$curgroup};
504 print OUT "%-$curgroup -- Unsubscribed\n";
505 &log('debug',"Remote unsubsribed from $curgroup",5);
506 }
507 $unsubscribed=1;
508 }
509 }
510
511 unless ($unsubscribed)
512 {
513 print OUT "%-$_[0] -- No match in your subscription list\n";
514 &log('debug',"Remote is not subsribed to $_[0]",5);
515 }
516 else
517 {
518 $NEWSFEEDSCHANGED=1;
519 }
520 }
521
522 sub print_list
523 {
524 local($echo,$group,$descr,$oldfh);
525 &log('debug',"Processing %LIST operation",4);
526 print OUT "--------------------------------------------------------\n";
527 print OUT "These are the echos currently available on this node.\n";
528 print OUT "To get a complete list please send a file request for\n";
529 print OUT "'backbone.na'. New requests will be forwarded.\n";
530 print OUT "--------------------------------------------------------\n";
531 $oldfh=select(OUT);
532 $~=$NO_FIDO?NO_FIDO:($WIDE?OUTWIDE:OUT);
533 foreach $group (sort($IS_FTN_LINK?values(%echo2ng):@active))
534 {
535 if (defined($active_hash{$group}))
536 {
537 $echo=$ng2echo{$group};
538 $descr=defined($description{$group})?$description{$group}:$DESCRMISSING;
539 write;
540 }
541 }
542 select($oldfh);
543 }
544
545 sub do_wide
546 {
547 $WIDE=1;
548 print OUT "%WIDE -- OK\n";
549 }
550
551 sub print_invalid
552 {
553 print OUT "$_[0] -- invalid command\n";
554 }
555
556 sub print_help
557 {
558 print OUT "--------------------------------------\n";
559 print OUT "In response to your request for %HELP\n";
560 print OUT "--------------------------------------\n";
561 print OUT "$HELP\n";
562 }
563
564 format OUTWIDE=
565 @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
566 $echo, $group, $descr
567 .
568 ;
569 format OUT=
570 @<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
571 $echo, $descr
572 .
573 format NO_FIDO=
574 @<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
575 $group, $descr
576 .
577
578 sub print_query
579 {
580 local($echo,$group,$descr,$oldfh);
581 &log('debug',"Processing %QUERY operation",4);
582 print OUT "---------------------------\n";
583 print OUT "In response to your %QUERY \n";
584 print OUT "---------------------------\n";
585 $oldfh=select(OUT);
586 $~=$NO_FIDO?NO_FIDO:($WIDE?OUTWIDE:OUT);
587 foreach $group (sort(keys(%patt_hash)))
588 {
589 ##$echo=defined ($ng2echo{$group}) ? $ng2echo{$group}: "UNTRANSLATED";
590 #$echo=defined ($ng2echo{$group}) ? $ng2echo{$group}: " ----??----";
591 #$descr=defined( $description{$group}) ? $description{$group}:$DESCRMISSING;
592 #if ($echo ne " ----??----") { write ; }
593
594 $echo=$ng2echo{$group};
595 $descr=defined( $description{$group}) ? $description{$group}:$DESCRMISSING;
596 if ($echo) { write ; }
597 }
598 select($oldfh);
599 }
600
601 sub print_unlinked
602 {
603 local($echo,$group,$descr,$oldfh);
604 &log('debug',"Processing %UNLINKED operation",4);
605 print OUT "-------------------------------------------\n";
606 print OUT "You are %UNLINKED from the following echos:\n";
607 print OUT "-------------------------------------------\n";
608 $oldfh=select(OUT);
609 $~=$NO_FIDO?NO_FIDO:($WIDE?OUTWIDE:OUT);
610
611 foreach $echo (sort(keys(%echo2ng)))
612 {
613 $group=$echo2ng{$echo};
614 unless (defined($patt_hash{$group}))
615 {
616 $descr=defined($description{$group})?$description{$group}:$DESCRMISSING;
617 write ;
618 }
619 }
620 select($oldfh);
621 }
622
623 # ---- RFC822-header parsing
624 # $USERADDR - full address (user@host)
625 # $USERNAME - username part
626 # $USERHOST - host part ( $USERADDR eq "$USERNAME\@$USERHOST")
627 # $SUBJECT - letter's subject
628 # $FROM - From field
629 # inputs from IN filehandle
630
631 sub parse_addr
632 {
633 local($line)=@_;
634 return $1 if ($line=~/^[^<]*<(\S+@\S+)>/o);
635 return $1 if ($line=~/^(\S+@\S+)/o);
636 }
637
638 sub parse_header
639 {
640 undef $REPLYTO;
641 undef $USERADDR;
642 undef $SUBJECT;
643 while(<IN>)
644 {
645 last if (/^\s*$/o); ## empty string -- break
646 next unless (($headline,$value)=/([^:]+):\s*(.*)\s*$/o);
647 $SUBJECT=$value if ($headline=~/^Subject$/io);
648 $USERADDR=&parse_addr($value) if ($headline=~/^From$/io);
649 $REPLYTO=&parse_addr($value) if ($headline=~/^Reply-To$/io);
650 }
651 return 0 unless (defined($USERADDR) && defined($SUBJECT));
652 $USERNAME="";
653 ($USERNAME,$USERHOST)=split("@",$USERADDR);
654 return 1;
655 }
656
657 ## ------- NEWSFEEDS MANIPULATION SUBS
658
659 sub write_newsfeeds
660 {
661 local ($site,$groupstr,$outfile,$passive_outfile);
662 $outfile=$_[0];
663 $passive_outfile=$_[1];
664 open(OutHandle,">".$outfile) || return 0;
665 open(passive_OutHandle,">".$passive_outfile) || return 0;
666 foreach $site (@sites)
667 {
668 $patterns{$site}="!*" if ($patterns{$site} eq "");
669 if ($passive{$site}==0)
670 {
671 print OutHandle $comments{$site};
672 print OutHandle $site;
673 print OutHandle "/".$exclude{$site} unless($exclude{$site}eq"");
674 print OutHandle "\\\n";
675 $groupstr=$patterns{$site};
676 $groupstr=~s|,|,\\\n\t|go;
677 print OutHandle "\t:$groupstr\\\n";
678 print OutHandle ("\t/".$distribs{$site}."\\\n") unless($distribs{$site} eq "");
679 print OutHandle "\t:";
680 print OutHandle ($flags{$site}) unless ($flags{$site} eq "");
681 print OutHandle ":";
682 print OutHandle $params{$site} unless ($params{$site}eq "");
683 print OutHandle "\n";
684 }
685 else
686 {
687 print passive_OutHandle $comments{$site};
688 print OutHandle $comments{$site};
689 print passive_OutHandle $site;
690 print OutHandle $site;
691 print passive_OutHandle "/".$exclude{$site} unless($exclude{$site}eq"");
692 print OutHandle "/".$exclude{$site} unless($exclude{$site}eq"");
693 print passive_OutHandle "\\\n";
694 print OutHandle "\\\n";
695 $groupstr=$patterns{$site};
696 $groupstr=~s|,|,\\\n\t|go;
697 print passive_OutHandle "\t:$groupstr\\\n";
698 print OutHandle "\t:!*\\\n";
699 print passive_OutHandle ("\t/".$distribs{$site}."\\\n") unless($distribs{$site} eq "");
700 print passive_OutHandle "\t:";
701 print OutHandle "\t:";
702 print passive_OutHandle ($flags{$site}) unless ($flags{$site} eq "");
703 print passive_OutHandle ":";
704 print passive_OutHandle $params{$site} unless ($params{$site}eq "");
705 print passive_OutHandle "\n";
706 print OutHandle ($flags{$site}) unless ($flags{$site} eq "");
707 print OutHandle ":";
708 print OutHandle $params{$site} unless ($params{$site}eq "");
709 print OutHandle "\n";
710 }
711 }
712 print OutHandle $last_comment;
713 close(OutHandle);
714 close(passive_OutHandle);
715 return 1;
716 }
717
718 ## ---------------- reading of config files
719
720 sub read_control_files
721 {
722 &read_active($ACTIVE) || die &log('err',"Bad active file",0);
723 &read_areas($ECHO2NEWS) || die &log('err',"Bad Areas file",0) unless $NO_FIDO;
724 &read_help($HELPFILE) || die &log('err',"Bad help file",0);
725 &read_newsgroups($NEWSGROUPS) || die &log('err',"Bad newsgroups file",0);
726 &read_newsfeeds($NEWSFEEDS) || die &log('err',"Bad newsfeeds file",0);
727 &read_passive_newsfeeds($PASSIVE_NEWSFEEDS) || die &log('err',"Bad passive newsfeeds file",0);
728 &read_passwd($PASSWDFILE) || die &log('err',"Bad passwords file",0);
729 &read_restricted($RESTFILE) || die &log('err',"Bad restricted file",0);
730 $NEWSFEEDSCHANGED=0;
731 $WIDE=0;
732 }
733
734 sub read_passwd {
735 local($pwd_file,$host,$feed,$passwd);
736 $pwd_file=$_[0];
737 open(pwd_Handle,$pwd_file) || die &log('err',"Cannot open $pwd_file",0);
738
739 while(<pwd_Handle>) {
740 chop;
741 next if (/\s+#/o);
742 next unless(($host,$feed,$passwd)=/([^:]+):([^:]+):([^:]+)/o);
743 $passwds{$host}=$passwd;
744 $feeds{$host}=$feed;
745 }
746 close(pwd_Handle);
747 return 1;
748 }
749
750 sub read_newsgroups
751 {
752 local($ng_file);
753 $ng_file=$_[0];
754 open(ng_Handle,$ng_file) || die &log('err',"Cannot open $ng_file",0);
755
756 while(<ng_Handle>){
757 next if(/^\s*#/o);
758 next unless(($group,$descr)=/^(\S+)\s+(.*)\s*$/o);
759 $description{$group}=$descr;
760 }
761 close(ng_Handle);
762 return 1;
763 }
764
765 sub read_newsfeeds
766 {
767 local($current_line,$temp_line,$commentstr,@newsfeeds);
768 local($index,$nf_file,$site,$sitetmp);
769 local($excl,$pats,$patstmp,$distr,$flgs,$param);
770 $nf_file=$_[0];
771 $index=0;
772 $commentstr="";
773 open(Handle,$nf_file) || die &log('err',"Cannot open $nf_file",0);
774 push(@newsfeeds,$_) while <Handle>;
775 close(Handle);
776
777 input:
778 while($_=shift(@newsfeeds))
779 {
780 next input if /^$/o;
781
782 $current_line=$_;
783 if($current_line=~m/^\s*#/o)
784 {
785 $commentstr.=$current_line;
786 next input;
787 }
788
789 chop($current_line); ##MSDOS
790
791 while ($current_line=~/\\$/o )
792 {
793 chop($current_line);
794 chop($temp_line=shift(@newsfeeds));
795 $temp_line=~s/^\s*//o;
796 $current_line .= $temp_line;
797 }
798 $sitestr=$current_line;
799
800 ($sitetmp,$patstmp, $flgs, $param)=split(/:/,$sitestr);
801 $site=$sitetmp;
802 $pats=$patstmp;
803 $excl="";
804
805 if ($sitetmp=~m|([^/]+)/([^/]+)|o)
806 {
807 $site=$1;
808 $excl=$2;
809 }
810
811 $distr="";
812
813 if($patstmp=~m|([^/]+)/([^/]+)|o)
814 {
815 $pats=$1;
816 $distr=$2;
817 }
818
819 $pats="" if ($pats eq "!*");
820
821 $sites[$index]=$site;
822 $passive{$site}=0;
823 $exclude{$site}=$excl;
824 $patterns{$site}=$pats;
825 $distribs{$site}=$distr;
826 $flags{$site}=$flgs;
827 $params{$site}=$param;
828 $comments{$site}=$commentstr;
829 $index++;
830 $commentstr="";
831 }
832 $last_comment=$commentstr;
833 return 1;
834 }
835
836 sub read_passive_newsfeeds
837 {
838 $counter="";
839 local($current_line,$temp_line,$commentstr);
840 local($nf_file,$site,$sitetmp,$index);
841 local($excl,$pats,$patstmp,$distr,$flgs,$param,$counter);
842 $nf_file=$_[0];
843 $commentstr="";
844 open(Handle,$nf_file) || die &log('err',"Cannot open $nf_file",0);
845 input:
846 while(<Handle>)
847 {
848 next input if /^$/o;
849 $current_line=$_;
850 if($current_line=~m/^\s*#/o)
851 {
852 $commentstr.=$current_line;
853 next input;
854 }
855 chop($current_line); ##MSDOS
856 while ($current_line=~/\\$/o)
857 {
858 chop($current_line);
859 chop($temp_line=<Handle>);
860 $temp_line=~s/^\s*//o;
861
862 $current_line.=$temp_line;
863 }
864 $sitestr=$current_line;
865 ($sitetmp,$patstmp, $flgs, $param)=split(/:/,$sitestr);
866 $site=$sitetmp;
867 $pats=$patstmp;
868 $excl="";
869 if ($sitetmp=~m|([^/]+)/([^/]+)|o)
870 {
871 $site=$1;
872 $excl=$2;
873 }
874 $distr="";
875 if($patstmp=~m|([^/]+)/([^/]+)|o)
876 {
877 $pats=$1;
878 $distr=$2;
879 }
880 $pats="" if ($pats eq "!*");
881
882 $passive{$site}=1;
883 $exclude{$site}=$excl;
884 $patterns{$site}=$pats;
885 $distribs{$site}=$distr;
886 $flags{$site}=$flgs;
887 $params{$site}=$param;
888 $comments{$site}=$commentstr;
889 $commentstr="";
890 }
891 close(Handle);
892 return 1;
893 }
894
895 sub read_help
896 {
897 local($helpf);
898 $helpf=$_[0];
899 open(HH,$helpf) || die &log('err',"Cannot open $helpf",0);
900 $HELP="";
901 $HELP.=$_ while(<HH>);
902 close(HH);
903 return 1;
904 }
905
906 sub read_areas
907 {
908 local($areas_file,$echo,$ngroup);
909 $areas_file=$_[0];
910 open(areas_Handle,$areas_file) || die &log('err',"Cannot open $areas_file",0);
911
912 while(<areas_Handle>)
913 {
914 next if (/^\s*#/o);
915 next unless(($echo,$ngroup)=/(\S+)\s+(\S+)/o);
916 next if ($echo=~/\*/o);
917 $ngroup=~tr/A-Z/a-z/;
918 $echo=~tr/a-z/A-Z/;
919 $echo2ng{$echo}=$ngroup;
920 $ng2echo{$ngroup}=$echo;
921 }
922 close(areas_Handle);
923 return 1;
924 }
925
926 sub findinactive
927 {
928 local($tmp)=$_[0];
929 &quote_meta($tmp);
930 return grep(/^$tmp$/,@active);
931 }
932
933 sub read_active
934 {
935 local($active_file,$ngroup);
936 $active_file=$_[0];
937 open(active_Handle,$active_file) || die &log('err',"Cannot open $active_file",0);
938 while(<active_Handle>)
939 {
940 next if (/^\s*#/o);
941 next unless(($ngroup)=/^(\S+)/o);
942 push(@active,$ngroup);
943 }
944 close(active_Handle);
945 return 1;
946 }
947
948 sub read_restricted
949 {
950 local($echo,$addrpatt);
951 open(Handle,$_[0]) || die &log('err',"Cannot open $_[0]",0);
952 while(<Handle>)
953 {
954 next if (/^\s*#/o);
955 if (/^(\S+)\s+(\S+)/o)
956 {
957 $echo=$1;
958 $addrpatt=$2;
959 }
960 elsif (/^(\S+)/o)
961 {
962 $echo=$1;
963 $addrpatt='*';
964 }
965 else
966 {
967 next;
968 }
969 &wildmat_to_regexp($echo);
970 &wildmat_to_regexp($addrpatt);
971 $restricted{$echo}=$addrpatt;
972 }
973 close(Handle);
974 return 1;
975 }
976
977 sub read_config
978 {
979 local($config_file);
980 $config_file=$_[0];
981 open(Handle,$config_file) || die "Cannot open $config_file";
982 while(<Handle>)
983 {
984 next if (/^\s*#/o);
985 next unless(($keyword,$val)=/^(\S+)\s+(.*)\s*$/o);
986 $NO_FIDO=($val!~/^FTN$/io) if ($keyword=~/^Afix_Mode$/io);
987 $ROBOT_NAME=$val if ($keyword=~/^Robot$/io);
988 $HELPFILE=$val if ($keyword=~/^HelpFile$/io);
989 $NEWSFEEDS=$val if ($keyword=~/^NewsFeeds$/io);
990 $PASSIVE_NEWSFEEDS=$val if ($keyword=~/^Passive_NewsFeeds$/io);
991 $NEWSGROUPS=$val if ($keyword=~/^NewsGroups$/io);
992 $ECHO2NEWS=$val if ($keyword=~/^Echo2News$/io);
993 $ACTIVE=$val if ($keyword=~/^Active$/io);
994 $RESTFILE=$val if ($keyword=~/^RestEcho$/io);
995 $PASSWDFILE=$val if ($keyword=~/^PasswdFile$/io);
996 $OUTNEWSFEEDS=$val if ($keyword=~/^OutNewsFeeds$/io);
997 $MAILCOMMAND=$val if ($keyword=~/^MailCommand$/io);
998 $DESCRMISSING=$val if ($keyword=~/^DescrMissing$/io);
999 $RELOADCOMMAND=$val if ($keyword=~/^ReloadCommand$/io);
1000 $SYSOP_NAME=$val if ($keyword=~/^SysOp$/io);
1001 $ADDRESS=$val if ($keyword=~/^Address$/io);
1002 $UPLINK_ADDRESS=$val if ($keyword=~/^UpLink_Address$/io);
1003 $UPLINK_ROBOT_NAME=$val if ($keyword=~/^UpLink_Robot$/io);
1004 $UPLINK_PASSWORD=$val if ($keyword=~/^UpLink_Password$/io);
1005 $FORWARD=($val=~/^Yes$/io)?1:0 if ($keyword=~/^Forward$/io);
1006 $QUEUE=$val if ($keyword=~/^Queue$/io);
1007 $SEMAPHORE=$val if ($keyword=~/^Semaphore$/io);
1008 $NEWSLOCK=$val if ($keyword=~/^NewsLockDir$/io);
1009 $LOG_FACILITY=$val if ($keyword=~/^LogFacility$/io);
1010 $LOG_LEVEL=$val if ($keyword=~/^LogLevel$/io);
1011 $val=~/(\S+)\s*(\S+)/o,$XCOM_TABLE{$1}=$2 if ($keyword=~/^XlateCommand$/io);
1012 }
1013 $DESCRMISSING="Description missing" unless (defined($DESCRMISSING));
1014 return (defined($ACTIVE)
1015 && ((defined($ECHO2NEWS)
1016 && defined($UPLINK_ADDRESS)
1017 && defined($UPLINK_ROBOT_NAME)
1018 && defined($UPLINK_PASSWORD)) || $NO_FIDO)
1019 && defined($NEWSGROUPS)
1020 && defined($HELPFILE)
1021 && defined($PASSWDFILE)
1022 && defined($OUTNEWSFEEDS)
1023 && defined($MAILCOMMAND)
1024 && defined($RELOADCOMMAND)
1025 && defined($SYSOP_NAME)
1026 && defined($ADDRESS)
1027 && defined($PASSIVE_NEWSFEEDS)
1028 && defined($NEWSFEEDS)
1029 && defined($SEMAPHORE)
1030 && defined($LOG_FACILITY));
1031 }
1032
1033 sub shlock
1034 {
1035 local($file,$try)=@_;
1036 local($pid,$n,$rc);
1037
1038 open(F,">$file.$$") || die "Cannot open $file.$$\n$!";
1039 print F $$;
1040 close F;
1041
1042 $rc=1;
1043
1044 until (link("$file.$$",$file))
1045 {
1046 $rc=0, last if $try && $n++>=$try;
1047 open(F,$file) || die "Cannot open lock file: $!";
1048 $pid=<F>;
1049 close F;
1050 if ($pid && !kill(0,$pid))
1051 {
1052 unlink($file) || die "Cannot unlink stale lock: $!";
1053 next;
1054 }
1055 sleep(1);
1056 }
1057 unlink("$file.$$") || die "Cannot unlink temp lock file: $!";
1058 return $rc;
1059 }
1060
1061 sub shunlock
1062 {
1063 unlink($_[0]) || die "Cannot unlink lock file: $!";
1064 }
1065
1066 sub _POSIX_C_SOURCE {0;}