| 1 | #!/usr/bin/perl |
| 2 | # Copyright (C) 1999,2003 Ian Jackson |
| 3 | # |
| 4 | # This is free software; you can redistribute it and/or modify it |
| 5 | # under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation; either version 2 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, but |
| 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | # General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with userv-utils; if not, write to the Free Software |
| 16 | # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # $Id$ |
| 19 | |
| 20 | $minreaddays= 21; |
| 21 | $maxperuser= 250; |
| 22 | $fetchdir= "/var/lib/news/fetch"; |
| 23 | chdir("/etc/news") || die $!; |
| 24 | |
| 25 | open(CONF,"nntp-merge.conf") || die $!; |
| 26 | while(<CONF>) { |
| 27 | next if m/^\#/ || !m/^\S/; |
| 28 | next if m/^(myfqdn|xref|server|server-nosearch|fetch|read|post|permit|believe|minreaddays)\s/; |
| 29 | if (m/^maxperuser\s+(\d+)\s+$/) { |
| 30 | $maxperuser= $1; |
| 31 | } elsif (m/^extrarc\s+(\S+)\s+$/) { |
| 32 | push(@extrarc,$1); |
| 33 | } else { |
| 34 | die "$_ ?"; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | open IGN,"</etc/news/newsrc-ignoredusers" or die $!; |
| 39 | while (<IGN>) { |
| 40 | chomp; |
| 41 | next if m/^\#/; |
| 42 | s/\s*$//; |
| 43 | $ign{$_}= 1; |
| 44 | } |
| 45 | close IGN or die $!; |
| 46 | |
| 47 | open PASS,"</etc/userlist" or die $!; |
| 48 | while (<PASS>) { |
| 49 | chomp; |
| 50 | next if m/^\#/; |
| 51 | $user= $_; |
| 52 | next if $ign{$user}; |
| 53 | open GL,"userv -t 30 $user newsrc-listgroups |" or die $!; |
| 54 | scan("user $user",1); |
| 55 | close GL; $? and warn "getgroups: error getting groups for $user (code $?)"; |
| 56 | } |
| 57 | close PASS or die $!; |
| 58 | |
| 59 | for $f (@extrarc) { |
| 60 | open GL,"< $f" or die $!; |
| 61 | scan("file $f",0); |
| 62 | close GL or die $!; |
| 63 | } |
| 64 | |
| 65 | chdir($fetchdir) || die $!; |
| 66 | open(NG,">all-read-groups.new") || die $!; |
| 67 | print(NG join("\n",sort keys %yes)."\n") || die $!; |
| 68 | close(NG) || die $!; |
| 69 | rename("all-read-groups.new","all-read-groups") || die $!; |
| 70 | |
| 71 | printf "total %d groups\n",scalar(keys %yes); |
| 72 | exit(0); |
| 73 | |
| 74 | sub scan ($) { |
| 75 | my ($where,$toomanyenf) = @_; |
| 76 | @g= (); |
| 77 | while (<GL>) { |
| 78 | die "bad group in $where" unless m/^[-a-z0-9+]+\.[-a-z0-9+._]+$/i; |
| 79 | push @g, $&; |
| 80 | } |
| 81 | warn("too many from $where"), return if $toomanyenf && @g > $maxperuser; |
| 82 | map { $yes{$_}=1; } @g; |
| 83 | printf "%-20s - %4d groups\n",$where,scalar(@g); |
| 84 | } |