INN commit: branches/2.4/control (4 files)

INN Commit Russ_Allbery at isc.org
Sun Apr 6 10:04:43 UTC 2008


    Date: Sunday, April 6, 2008 @ 03:04:43
  Author: iulius
Revision: 7743

docheckgroups now handles wireformat articles (for using it manually
from the spool) and warns when there are missing or obsolete descriptions.

Newgroup control messages for existing groups now change their description.
If a mail is sent to administrators, it reminds them to update their
newsgroups file.
Now pretty print the newsgroups file (from one to three tabulations between
the name of the group and its short description).
Refuse the creation of to. groups.

Checkgroups when there is nothing to change no longer result in sending
a blank mail to administrators.

Modified:
  branches/2.4/control/docheckgroups.in
  branches/2.4/control/modules/checkgroups.pl
  branches/2.4/control/modules/newgroup.pl
  branches/2.4/control/modules/rmgroup.pl

------------------------+
 docheckgroups.in       |   34 ++++++++++++-
 modules/checkgroups.pl |    8 ++-
 modules/newgroup.pl    |  118 ++++++++++++++++++++++++++++-------------------
 modules/rmgroup.pl     |    3 +
 4 files changed, 113 insertions(+), 50 deletions(-)

Modified: docheckgroups.in
===================================================================
--- docheckgroups.in	2008-04-06 10:00:59 UTC (rev 7742)
+++ docheckgroups.in	2008-04-06 10:04:43 UTC (rev 7743)
@@ -29,7 +29,7 @@
 comm -23 ${T}/$$active ${T}/$$newsgrps >${T}/$$remove
 
 ${EGREP} "${PATS}" ${ACTIVE} | ${EGREP} "${1:-.}" | ${SED} -n '/ m$/s/ .*//p' | sort >${T}/$$amod.all
-${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" |
+${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' |
 ${SED} -n '/(Moderated)$/s/[ 	].*//p' | sort >${T}/$$ng.mod
 
 comm -12 ${T}/$$missing ${T}/$$ng.mod >${T}/$$add.mod
@@ -41,6 +41,15 @@
 comm -23 ${T}/$$ng.mod ${T}/$$amod >${T}/$$nm.all
 comm -23 ${T}/$$nm.all ${T}/$$add >${T}/$$notmod
 
+${EGREP} "${PATS}" ${NEWSGROUPS} | ${EGREP} "${1:-.}" | ${SED} 's/[	]\+/	/' | sort >${T}/$$localdesc
+${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' |
+${SED} 's/[	]\+/	/' | sort >${T}/$$newdesc
+
+if ! (head -1 ${T}/$$newdesc | egrep " [[:digit:]]+ [[:digit:]]+ " > /dev/null) ; then
+  comm -13 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$missingdesc
+  comm -23 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$removedesc
+fi
+
 if [ -s ${T}/$$remove ] ; then
     (
 	echo "# The following newsgroups are non-standard."
@@ -97,6 +106,25 @@
     ) >>${T}/$$out
 fi
 
+if [ -s ${T}/$$removedesc ] ; then
+    (
+        echo "# The following newsgroups descriptions are obsolete."
+        ${SED} "s/^/#	/" ${T}/$$removedesc
+        echo "# You can remove them by editing ${NEWSGROUPS}."
+        echo ''
+    ) >>${T}/$$out
+fi
+
+if [ -s ${T}/$$missingdesc ] ; then
+    (
+        echo "# The following newsgroups descriptions were missing and should be added."
+        ${SED} "s/^/#	/" ${T}/$$missingdesc
+        echo "# You can add them by editing ${NEWSGROUPS}."
+        echo ''
+    ) >>${T}/$$out
+fi
+
+
 test -s ${T}/$$out && {
     cat ${T}/$$out
     echo 'exit # so you can feed this message into the shell'
@@ -108,12 +136,12 @@
     }
     test -s ${T}/$$ngadd && {
 	echo "# Add these lines:"
-	${SED} "s/^/#   /" ${T}/$$ngadd
+	${SED} "s/^/#	/" ${T}/$$ngadd
 	echo ''
     }
     test -s ${T}/$$ngchng && {
 	echo "# Change these lines:"
-	${SED} "s/^/#   /" ${T}/$$ngchng
+	${SED} "s/^/#	/" ${T}/$$ngchng
 	echo ''
     }
 }

Modified: modules/checkgroups.pl
===================================================================
--- modules/checkgroups.pl	2008-04-06 10:00:59 UTC (rev 7742)
+++ modules/checkgroups.pl	2008-04-06 10:04:43 UTC (rev 7743)
@@ -68,6 +68,7 @@
     my $st = system("$inn::pathbin/docheckgroups", $newsgrouppats);
     logdie('Cannot run docheckgroups: ' . $!) if $st == -1;
     logdie('docheckgroups returned status ' . ($st & 255)) if $st > 0;
+    close(STDIN);
     close(STDOUT);
     open(STDIN, '<&OLDIN') or die $!;
     open(STDOUT, '>&OLDOUT') or die $!;
@@ -75,7 +76,12 @@
     open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!");
     my @output = <TEMPFILE>;
     chop @output;
-    logger($log || 'mail', "checkgroups by $sender", \@output);
+    # There is no need to send an empty mail.
+    if ($#output > 0) {
+        logger($log || 'mail', "checkgroups by $sender", \@output);
+    } else {
+        logmsg("checkgroups by $sender processed (no change)");
+    }
     close TEMPFILE;
     unlink($tempfile, "$tempfile.art");
 }

Modified: modules/newgroup.pl
===================================================================
--- modules/newgroup.pl	2008-04-06 10:00:59 UTC (rev 7742)
+++ modules/newgroup.pl	2008-04-06 10:04:43 UTC (rev 7743)
@@ -29,9 +29,7 @@
     $errmsg= local_checkgroupname($groupname) if defined &local_checkgroupname;
     if ($errmsg) {
         $errmsg = checkgroupname($groupname) if $errmsg eq 'DONE';
-    }
 
-    if ($errmsg) {
         if ($log) {
             logger($log, "skipping newgroup ($errmsg)", $headers, $body);
         } else {
@@ -49,30 +47,73 @@
         last;
     }
     close ACTIVE;
+    
     my $status;
+    my $ngdesc = 'No description.';
+    my $olddesc = '';    
+    my $ngname = $groupname;
+
+    # If there is a tag line, search whether the description has changed.
+    my $found = 0;
+    my $ngline = '';
+    foreach (@$body) {
+        if ($found) {
+            # It is the line which contains the description.
+            $ngline = $_;
+            last;
+        }
+        $found = 1 if $_ =~ /^For your newsgroups file:\s*$/;
+    }
+    
+    if ($found) {
+      ($ngname, $ngdesc) = split(/\s+/, $ngline, 2);
+      if ($ngdesc) {
+          $ngdesc =~ s/\s+$//;
+          $ngdesc =~ s/\s+\(moderated\)\s*$//i;
+          $ngdesc .= ' (Moderated)' if $modflag eq 'moderated';
+      }
+      # Scan newsgroups to see the previous description, if any.
+      open(NEWSGROUPS, $inn::newsgroups)
+          or logdie("Cannot open $inn::newsgroups: $!");
+      while (<NEWSGROUPS>) {
+          if (/^\Q$groupname\E\s+(.*)/) {
+              $olddesc = $1;
+              last;
+          }
+      }
+      close NEWSGROUPS;
+    }
+
     if (@oldgroup) {
         if ($oldgroup[3] eq 'm' and $modflag ne 'moderated') {
-            $status = 'made unmoderated';
+            $status = 'be made unmoderated';
         } elsif ($oldgroup[3] ne 'm' and $modflag eq 'moderated') {
-            $status = 'made moderated';
+            $status = 'be made moderated';
         } else {
-            $status = 'no change';
+            if ($ngdesc eq $olddesc) {
+                $status = 'no change';
+            } else {
+                $status = 'have a new description';
+            }
         }
     } elsif (not $approved) {
         $status = 'unapproved';
     } else {
-        $status = 'created';
+        $status = 'be created';
     }
 
-    if ($action eq 'mail' and $status !~ /no change|unapproved/) {
+    if ($action eq 'mail' and $status !~ /(no change|unapproved)/) {
         my $mail = sendmail("newgroup $groupname $modcmd $sender");
         print $mail <<END;
 $sender asks for $groupname
-to be $status.
+to $status.
 
 If this is acceptable, type:
   $inn::newsbin/ctlinnd newgroup $groupname $modcmd $sender
 
+And do not forget to update the corresponding description in your
+newsgroups file.
+
 The control message follows:
 
 END
@@ -83,34 +124,21 @@
     } elsif ($action eq 'log') {
         if ($log) {
             logger($log, "skipping newgroup $groupname $modcmd"
-                . " $sender (would be $status)", $headers, $body);
+                . " $sender (would $status)", $headers, $body);
         } else {
             logmsg("skipping newgroup $groupname $modcmd $sender"
-                . " (would be $status)");
+                . " (would $status)");
         }
     } elsif ($action eq 'doit' and $status ne 'unapproved') {
-        ctlinnd('newgroup', $groupname, $modcmd, $sender)
-            if $status ne 'no change';
-
-        # If there is a tag line, update newsgroups too, even if the group
-        # did already exist.
-        my $found = 0;
-        my $ngline = '';
-        foreach (@$body) {
-            if ($found) {
-                $ngline = $_;
-                last;
-            }
-            $found = 1 if $_ eq 'For your newsgroups file:';
+        if ($status ne 'no change') {
+            # The status 'be made (un)moderated' prevails over
+            # 'have a new description' so it is executed.
+            ctlinnd('newgroup', $groupname, $modcmd, $sender)
+                if $status ne 'have a new description';
+            # We know the description has changed.
+            update_desc($ngname, $ngdesc) if $ngdesc and $ngname eq $groupname;
         }
-        my ($ngname, $ngdesc) = split(/\s+/, $ngline, 2);
-        if ($ngdesc) {
-            $ngdesc =~ s/\s+$//;
-            $ngdesc =~ s/\s+\(moderated\)\s*$//i;
-            $ngdesc .= ' (Moderated)' if $modflag eq 'moderated';
-        }
-        update_desc($ngname, $ngdesc) if $ngdesc and $ngname eq $groupname;
-
+        
         if ($log ne 'mail' or $status ne 'no change') {
             logger($log, "newgroup $groupname $modcmd $status $sender",
                    $headers, $body) if $log;
@@ -126,24 +154,22 @@
     open(NEWSGROUPS, $inn::newsgroups)
         or logdie("Cannot open $inn::newsgroups: $!");
     open(TEMPFILE, ">$tempfile") or logdie("Cannot open $tempfile: $!");
-    my $olddesc = '';
     while (<NEWSGROUPS>) {
-        if (/^\Q$name\E\s+(.*)/) {
-            $olddesc = $1;
-            next;
-        }
+        next if (/^\Q$name\E\s+(.*)/);
         print TEMPFILE $_;
     }
-    print TEMPFILE "$name\t$desc\n";
+    # We now write a pretty line for the description.
+    if (length $name < 8) {
+        print TEMPFILE "$name\t\t\t$desc\n";
+    } elsif (length $name < 16) {
+        print TEMPFILE "$name\t\t$desc\n";
+    } else {
+        print TEMPFILE "$name\t$desc\n";
+    }
     close TEMPFILE;
     close NEWSGROUPS;
-    # install the modified file only if the description has changed
-    if ($desc ne $olddesc) {
-        rename($tempfile, $inn::newsgroups)
-            or logdie("Cannot rename $tempfile: $!");
-    } else {
-        unlink($tempfile);
-    }
+    rename($tempfile, $inn::newsgroups)
+        or logdie("Cannot rename $tempfile: $!");
     unlink("$inn::locks/LOCK.newsgroups", $tempfile);
 }
 
@@ -156,11 +182,11 @@
     # whole-name checking
     return 'Empty group name' if /^$/;
     return 'Whitespace in group name' if /\s/;
-    return 'unsafe group name' if /[\`\/:;]/;
+    return 'Unsafe group name' if /[\`\/:;]/;
     return 'Bad dots in group name' if /^\./ or /\.$/ or /\.\./;
 #    return 'Group name does not begin/end with alphanumeric'
 #        if (/^[a-zA-Z0-9].+[a-zA-Z0-9]$/;
-    return 'Group name begins in control. or junk.' if /^(?:junk|control)\./;
+    return 'Group name begins in control., junk. or to.' if /^(?:control|junk|to)\./;
 #    return 'Group name too long' if length $_ > 128;
 
     my @components = split(/\./);

Modified: modules/rmgroup.pl
===================================================================
--- modules/rmgroup.pl	2008-04-06 10:00:59 UTC (rev 7742)
+++ modules/rmgroup.pl	2008-04-06 10:04:43 UTC (rev 7743)
@@ -49,6 +49,9 @@
 If this is acceptable, type:
   $inn::newsbin/ctlinnd rmgroup $groupname
 
+And do not forget to remove the corresponding description, if any,
+from your newsgroups file.
+
 The control message follows:
 
 END



More information about the inn-committers mailing list