⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.0b1-lease-convert

📁 DHCP服务器源码
💻 0B1-LEASE-CONVERT
字号:
#!/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 $EOMuse strict;my $revstatement =<<'EOS';	  switch (ns-update (delete (1, 12, ddns-rev-name, null))) {	    case 0:	      unset ddns-rev-name;	      break;	  }EOSmy $fwdstatement =<<'EOS';	  switch (ns-update (delete (1, 1, ddns-fwd-name, leased-address))) {	    case 0:	      unset ddns-fwd-name;	      break;	  }EOSif (@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 filenamegiven) and writes to stdout.  Converts a 3.0b1-style leases file to a 3.0b2style (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);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -