3 # Start Date: Mon, 26 Mar 2001 14:24:09 +0200
4 # Time-stamp: <Monday, 26 March 2001 16:09:44 by brister>
5 # File: leaseconvertor.pl
6 # RCSId: $Id: 3.0b1-lease-convert,v 1.1.1.1 2005/12/07 10:50:32 sonic_amiga Exp $
8 # Description: Convert 3.0b1 to 3.0b2/final lease file format
14 $Id: 3.0b1-lease-convert,v 1.1.1.1 2005/12/07 10:50:32 sonic_amiga Exp $
19 my $revstatement =<<'EOS';
20 switch (ns-update (delete (1, 12, ddns-rev-name, null))) {
27 my $fwdstatement =<<'EOS';
28 switch (ns-update (delete (1, 1, ddns-fwd-name, leased-address))) {
36 if (@ARGV && $ARGV[0] =~ m!^-!) {
42 # read stdin and write stdout.
50 # in a b1 file we should only see a left curly brace on a lease
51 # lines. Seening it anywhere else means the user is probably
52 # running a b2 or later file through this.
53 # Ditto for a 'set' statement.
54 if (m!\{! || m!^\s*set\s!) {
55 warn "this doesn't look like a 3.0b1 file. Ignoring rest.\n";
63 # $lease contains all the lines for the lease entry.
64 $lease = makeNewLease
($lease);
78 Reads from the lease file listed on the command line (or stdin if not filename
79 given) and writes to stdout. Converts a 3.0b1-style leases file to a 3.0b2
80 style (for ad-hoc ddns updates).
88 # takes a string that's the lines of a lease entry and converts it, if
89 # necessary to a b2 style lease entry. Returns the new lease in printable form.
96 foreach (split "\n", $lease) {
97 if (m!^(\s+)(ddns-fwd-name|ddns-rev-name)\s+(\"[^\"]+\"\s*;)!) {
98 $newlease .= $1 . "set " . $2 . " = " . $3 . "\n";
100 # If there's one of them, then it will always be the -fwd-. There
101 # may not always be a -rev-.
103 $convertedrev++ if ($2 eq "ddns-rev-name");
104 } elsif (m!^\s*\}!) {
106 $newlease .= "\ton expiry or release {\n";
107 $newlease .= $revstatement if $convertedrev;
108 $newlease .= $fwdstatement;
109 $newlease .= "\t on expiry or release;\n\t}\n";
113 $newlease .= $_ . "\n";
121 sub dumpRestAndExit
{