head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	perseant-exfatfs-base-20250801:1.1.1.1
	netbsd-11:1.1.1.1.0.18
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	perseant-exfatfs-base-20240630:1.1.1.1
	perseant-exfatfs:1.1.1.1.0.16
	perseant-exfatfs-base:1.1.1.1
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.14
	netbsd-10-base:1.1.1.1
	netbsd-9-3-RELEASE:1.1.1.1
	DHCP4_4_3:1.1.1.1
	cjep_sun2x-base1:1.1.1.1
	cjep_sun2x:1.1.1.1.0.12
	cjep_sun2x-base:1.1.1.1
	cjep_staticlib_x-base1:1.1.1.1
	DHCP4_4_2_P1:1.1.1.1
	netbsd-9-2-RELEASE:1.1.1.1
	cjep_staticlib_x:1.1.1.1.0.10
	cjep_staticlib_x-base:1.1.1.1
	netbsd-9-1-RELEASE:1.1.1.1
	DHCP4_4_2:1.1.1.1
	phil-wifi-20200421:1.1.1.1
	phil-wifi-20200411:1.1.1.1
	is-mlppp:1.1.1.1.0.8
	is-mlppp-base:1.1.1.1
	phil-wifi-20200406:1.1.1.1
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	phil-wifi-20191119:1.1.1.1
	netbsd-9:1.1.1.1.0.6
	netbsd-9-base:1.1.1.1
	phil-wifi-20190609:1.1.1.1
	pgoyette-compat-merge-20190127:1.1.1.1.2.2
	pgoyette-compat-20190127:1.1.1.1
	pgoyette-compat-20190118:1.1.1.1
	pgoyette-compat-1226:1.1.1.1
	pgoyette-compat-1126:1.1.1.1
	pgoyette-compat-1020:1.1.1.1
	pgoyette-compat-0930:1.1.1.1
	pgoyette-compat-0906:1.1.1.1
	pgoyette-compat-0728:1.1.1.1
	phil-wifi:1.1.1.1.0.4
	phil-wifi-base:1.1.1.1
	pgoyette-compat-0625:1.1.1.1
	pgoyette-compat-0521:1.1.1.1
	pgoyette-compat-0502:1.1.1.1
	pgoyette-compat-0422:1.1.1.1
	pgoyette-compat:1.1.1.1.0.2
	pgoyette-compat-0415:1.1.1.1
	DHCP4_4_1:1.1.1.1
	ISC:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2018.04.07.22.34.26;	author christos;	state Exp;
branches
	1.1.1.1;
next	;
commitid	ZVMAguZtny6GRyxA;

1.1.1.1
date	2018.04.07.22.34.26;	author christos;	state Exp;
branches
	1.1.1.1.2.1;
next	;
commitid	ZVMAguZtny6GRyxA;

1.1.1.1.2.1
date	2018.04.07.22.34.26;	author pgoyette;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	qk3nktk0szmTIByA;

1.1.1.1.2.2
date	2018.04.16.01.59.46;	author pgoyette;	state Exp;
branches;
next	;
commitid	qk3nktk0szmTIByA;


desc
@@


1.1
log
@Initial revision
@
text
@#!/usr/bin/perl
#
# Start Date:   Mon, 26 Mar 2001 14:24:09 +0200
# Time-stamp:   <Monday, 26 March 2001 16:09:44 by brister>
# File:         leaseconvertor.pl
# RCSId:        Id: 3.0b1-lease-convert,v 1.1 2001/04/18 19:17:34 mellon Exp 
#
# Description:  Convert 3.0b1 to 3.0b2/final lease file format
#

require 5.004;

my $rcsID =<<'EOM';
Id: 3.0b1-lease-convert,v 1.1 2001/04/18 19:17:34 mellon Exp 
EOM

use strict;

my $revstatement =<<'EOS';
	  switch (ns-update (delete (1, 12, ddns-rev-name, null))) {
	    case 0:
	      unset ddns-rev-name;
	      break;
	  }
EOS

my $fwdstatement =<<'EOS';
	  switch (ns-update (delete (1, 1, ddns-fwd-name, leased-address))) {
	    case 0:
	      unset ddns-fwd-name;
	      break;
	  }
EOS


if (@@ARGV && $ARGV[0] =~ m!^-!) {
    usage();
}



# read stdin and write stdout.
while (<>) {
    if (! /^lease\s/) {
	print;
    } else {
	my $lease = $_;
	while (<>) {
	    $lease .= $_;
	    # in a b1 file we should only see a left curly brace on a lease
	    # lines. Seening it anywhere else means the user is probably
	    # running a b2 or later file through this.
	    # Ditto for a 'set' statement.
	    if (m!\{! || m!^\s*set\s!) {
		warn "this doesn't look like a 3.0b1 file. Ignoring rest.\n";
		print $lease;
		dumpRestAndExit();
	    }

	    last if m!^\}\s*$!;
	}

	# $lease contains all the lines for the lease entry.
	$lease = makeNewLease($lease);
	print $lease;
    }
}



sub usage {
    my $prog = $0;
    $prog =~ s!.*/!!;

    print STDERR <<EOM;
usage: $prog [ file ]

Reads from the lease file listed on the command line (or stdin if not filename
given) and writes to stdout.  Converts a 3.0b1-style leases file to a 3.0b2
style (for ad-hoc ddns updates).
EOM

    exit (0);
}



# takes a string that's the lines of a lease entry and converts it, if
# necessary to a b2 style lease entry. Returns the new lease in printable form.
sub makeNewLease {
    my ($lease) = @@_;

    my $convertedfwd;
    my $convertedrev;
    my $newlease = "";
    foreach (split "\n", $lease) {
	if (m!^(\s+)(ddns-fwd-name|ddns-rev-name)\s+(\"[^\"]+\"\s*;)!) {
	    $newlease .= $1 . "set " . $2 . " = " . $3 . "\n";

	    # If there's one of them, then it will always be the -fwd-. There
	    # may not always be a -rev-.
	    $convertedfwd++;
	    $convertedrev++ if ($2 eq "ddns-rev-name");
	} elsif (m!^\s*\}!) {
	    if ($convertedfwd) {
		$newlease .= "\ton expiry or release {\n";
		$newlease .= $revstatement if $convertedrev;
		$newlease .= $fwdstatement;
		$newlease .= "\t  on expiry or release;\n\t}\n";
	    }
	    $newlease .= "}\n";
	} else {
	    $newlease .= $_ . "\n";
	}
    }

    return $newlease;
}


sub dumpRestAndExit {
    while (<>) {
	print;
    }
    exit (0);
}
@


1.1.1.1
log
@import dhcp-4.4.1
@
text
@@


1.1.1.1.2.1
log
@file 3.0b1-lease-convert was added on branch pgoyette-compat on 2018-04-16 01:59:46 +0000
@
text
@d1 126
@


1.1.1.1.2.2
log
@Sync with HEAD, resolve some conflicts
@
text
@a0 126
#!/usr/bin/perl
#
# Start Date:   Mon, 26 Mar 2001 14:24:09 +0200
# Time-stamp:   <Monday, 26 March 2001 16:09:44 by brister>
# File:         leaseconvertor.pl
# RCSId:        Id: 3.0b1-lease-convert,v 1.1 2001/04/18 19:17:34 mellon Exp 
#
# Description:  Convert 3.0b1 to 3.0b2/final lease file format
#

require 5.004;

my $rcsID =<<'EOM';
Id: 3.0b1-lease-convert,v 1.1 2001/04/18 19:17:34 mellon Exp 
EOM

use strict;

my $revstatement =<<'EOS';
	  switch (ns-update (delete (1, 12, ddns-rev-name, null))) {
	    case 0:
	      unset ddns-rev-name;
	      break;
	  }
EOS

my $fwdstatement =<<'EOS';
	  switch (ns-update (delete (1, 1, ddns-fwd-name, leased-address))) {
	    case 0:
	      unset ddns-fwd-name;
	      break;
	  }
EOS


if (@@ARGV && $ARGV[0] =~ m!^-!) {
    usage();
}



# read stdin and write stdout.
while (<>) {
    if (! /^lease\s/) {
	print;
    } else {
	my $lease = $_;
	while (<>) {
	    $lease .= $_;
	    # in a b1 file we should only see a left curly brace on a lease
	    # lines. Seening it anywhere else means the user is probably
	    # running a b2 or later file through this.
	    # Ditto for a 'set' statement.
	    if (m!\{! || m!^\s*set\s!) {
		warn "this doesn't look like a 3.0b1 file. Ignoring rest.\n";
		print $lease;
		dumpRestAndExit();
	    }

	    last if m!^\}\s*$!;
	}

	# $lease contains all the lines for the lease entry.
	$lease = makeNewLease($lease);
	print $lease;
    }
}



sub usage {
    my $prog = $0;
    $prog =~ s!.*/!!;

    print STDERR <<EOM;
usage: $prog [ file ]

Reads from the lease file listed on the command line (or stdin if not filename
given) and writes to stdout.  Converts a 3.0b1-style leases file to a 3.0b2
style (for ad-hoc ddns updates).
EOM

    exit (0);
}



# takes a string that's the lines of a lease entry and converts it, if
# necessary to a b2 style lease entry. Returns the new lease in printable form.
sub makeNewLease {
    my ($lease) = @@_;

    my $convertedfwd;
    my $convertedrev;
    my $newlease = "";
    foreach (split "\n", $lease) {
	if (m!^(\s+)(ddns-fwd-name|ddns-rev-name)\s+(\"[^\"]+\"\s*;)!) {
	    $newlease .= $1 . "set " . $2 . " = " . $3 . "\n";

	    # If there's one of them, then it will always be the -fwd-. There
	    # may not always be a -rev-.
	    $convertedfwd++;
	    $convertedrev++ if ($2 eq "ddns-rev-name");
	} elsif (m!^\s*\}!) {
	    if ($convertedfwd) {
		$newlease .= "\ton expiry or release {\n";
		$newlease .= $revstatement if $convertedrev;
		$newlease .= $fwdstatement;
		$newlease .= "\t  on expiry or release;\n\t}\n";
	    }
	    $newlease .= "}\n";
	} else {
	    $newlease .= $_ . "\n";
	}
    }

    return $newlease;
}


sub dumpRestAndExit {
    while (<>) {
	print;
    }
    exit (0);
}
@


