[debian-edu-commits] r80355 - in branches/wheezy/debian-edu-config: debian share/debian-edu-config/tools

pere at alioth.debian.org pere at alioth.debian.org
Sat Jun 8 07:21:12 UTC 2013


Author: pere
Date: 2013-06-08 07:21:12 +0000 (Sat, 08 Jun 2013)
New Revision: 80355

Modified:
   branches/wheezy/debian-edu-config/debian/changelog
   branches/wheezy/debian-edu-config/share/debian-edu-config/tools/subnet-change
Log:
Made subnet-change complete, teach it how to update
/etc/munin/debian-edu-munin-node.conf and /etc/hosts.allow.

Modified: branches/wheezy/debian-edu-config/debian/changelog
===================================================================
--- branches/wheezy/debian-edu-config/debian/changelog	2013-06-08 05:58:47 UTC (rev 80354)
+++ branches/wheezy/debian-edu-config/debian/changelog	2013-06-08 07:21:12 UTC (rev 80355)
@@ -9,13 +9,13 @@
    - French, thanks to Guilhelm Panaget.
 
   [ Petter Reinholdtsen ]
-  * Made subnet-change more complete, teach it how to update
-    /etc/munin/debian-edu-munin-node.conf.
+  * Made subnet-change complete, teach it how to update
+    /etc/munin/debian-edu-munin-node.conf and /etc/hosts.allow.
   * Report the files that need a manual update at the end of the
     script run, to make the text easier to see.
   * Make internal password type debconf templates non-translatable
     to try to work around bug #711251.
- 
+
  -- Holger Levsen <holger at debian.org>  Thu, 30 May 2013 13:46:34 +0200
 
 debian-edu-config (1.705) unstable; urgency=low

Modified: branches/wheezy/debian-edu-config/share/debian-edu-config/tools/subnet-change
===================================================================
--- branches/wheezy/debian-edu-config/share/debian-edu-config/tools/subnet-change	2013-06-08 05:58:47 UTC (rev 80354)
+++ branches/wheezy/debian-edu-config/share/debian-edu-config/tools/subnet-change	2013-06-08 07:21:12 UTC (rev 80355)
@@ -104,11 +104,12 @@
 replace_ips("/etc/squid/squid.conf", $oldsubnet, $newsubnet);
 change_muninnode("/etc/munin/debian-edu-munin-node.conf", $oldsubnet,
                  $newsubnet);
+change_hostallow("/etc/hosts.allow", $oldsubnet, $newsubnet);
 
 # Not needed on main-server (but on all clients):
 # /etc/samba/smb-debian-edu-client.conf
 
-my @files = qw(/etc/hosts.allow);
+my @files = qw();
 
 # Make sure bind see all zones in LDAP, also when the zones change
 my $dnszoneupdate =
@@ -674,3 +675,54 @@
         print "error: Unable to read from file $filename or write to $filename.new\n";
     }
 }
+sub change_hostallow {
+    my ($filename, $oldsubnet, $newsubnet) = @_;
+    my $ibase = $newsubnet->{'IBASE'};
+    my $newbits = $newsubnet->bits();
+    my $size = $newsubnet->size();
+    my $fixedblocks = floor($newbits / 8);
+    my $movingbits = 8 - ($newsubnet->bits() - ($fixedblocks*8));
+    $movingbits = 0 if 8 == $movingbits;
+    my $blocks = 2 ** $movingbits;
+    my $blockstep = 256 ** (3-$fixedblocks);
+#    print "bits=$newbits size=$size blocks=$blocks fixedblocks=$fixedblocks movingbits=$movingbits blockstep=$blockstep\n";
+    if ($fixedblocks >= 3) {
+        $blocks = 1;
+        $fixedblocks = 2;
+    }
+    my @nets;
+    for (my $i = 0; $i < $blocks; $i++) {
+        push(@nets, join('.', unpack("C" . ($fixedblocks+1),
+                               pack('N',$ibase+$i*$blockstep)), ""));
+    }
+
+    if (open(my $in, "<", $filename) && open(my $out, ">", "$filename.new")) {
+        my $changed = 0;
+        while (my $line = <$in>) {
+            chomp $line;
+            # only handle "foo: 10."
+            if ($line =~ m/^([a-z]+): ([\d\.]+)\.$/) {
+                my ($prog, $subnet) = ($1, $2);
+                warn "not handling address $subnet. properly"
+                    unless "10" eq $subnet;
+                my $addr = "$subnet.0.0.0";
+                my $newaddr = join(" ", @nets);
+                if ($addr ne $newaddr) {
+                    $line = "$prog: $newaddr";
+                    $changed = 1;
+                }
+            }
+            print $out "$line\n";
+        }
+        close($out);
+        close($in);
+        if ($changed) {
+            print "info: changed $filename\n";
+            rename "$filename.new", $filename;
+        } else {
+            unlink "$filename.new";
+        }
+    } else {
+        print "error: Unable to read from file $filename or write to $filename.new\n";
+    }
+}




More information about the debian-edu-commits mailing list