<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# $Id: params-lib.pl,v 1.3 2005/04/16 14:30:21 jfranken Exp $
# * Functions for editing parameters common to many kinds of directive
#
# File modified 2005-04-15 by Johannes Franken &lt;jfranken@jfranken.de&gt;:
# * Added support for the client-update option of dhcpd 3.

# display_params(&amp;config, type)
sub display_params
{
print &amp;ui_hidden("params_type", $_[1]);

print &amp;opt_input($text{'plib_deflt'}, "default-lease-time",
		 $_[0], $text{'default'}, 8, $text{'secs'});
print "&lt;/tr&gt;\n";

print "&lt;tr&gt;\n";
print &amp;opt_input($text{'plib_bfname'}, "filename", $_[0], $text{'none'}, 20);
print &amp;opt_input($text{'plib_maxlt'}, "max-lease-time",
		 $_[0], $text{'default'}, 8, $text{'secs'});
print "&lt;/tr&gt;\n";

print "&lt;tr&gt;\n";
print &amp;opt_input($text{'plib_bfserv'}, "next-server", $_[0], $text{'plib_thisserv'}, 15);
print &amp;opt_input($text{'plib_servname'}, "server-name", $_[0], $text{'default'}, 15);
print "&lt;/tr&gt;\n";

print "&lt;tr&gt;\n";
print &amp;opt_input($text{'plib_llbc'}, "dynamic-bootp-lease-length",
		 $_[0], $text{'plib_forever'}, 8, $text{'secs'});
print &amp;opt_input($text{'plib_lebc'}, "dynamic-bootp-lease-cutoff",
		 $_[0], $text{'plib_never'}, 21);
print "&lt;/tr&gt;\n";

if ($config{'dhcpd_version'} &gt;= 3) {
	# Inputs for DDNS
	print "&lt;tr&gt;\n";
	print &amp;choice_input($text{'plib_ddnsup'}, "ddns-updates", $_[0], $text{'yes'}, 'on', $text{'no'}, 'off', $text{'default'}, '');
	print &amp;opt_input($text{'plib_ddnsdom'}, "ddns-domainname", $_[0], $text{'default'}, 15);
	print "&lt;/tr&gt;\n";

	print "&lt;tr&gt;\n";
	print &amp;opt_input($text{'plib_ddnsrevdom'}, "ddns-rev-domainname", $_[0], $text{'default'}, 15);
	print &amp;opt_input($text{'plib_ddnshost'}, "ddns-hostname", $_[0], $text{'plib_ddnshost_def'}, 15);
	print "&lt;/tr&gt;\n";

	if ($_[1] eq 'global') {
		print "&lt;tr&gt;\n";
		print &amp;wide_choice_input($text{'plib_ddnsupstyle'}, "ddns-update-style", $_[0], $text{'plib_adhoc'}, 'ad-hoc', $text{'plib_interim'}, 'interim', $text{'plib_none'}, 'none', $text{'default'}, '');
		print "&lt;/tr&gt;\n";
		}

	# Inputs for allow/deny clients
	local @adi = ( &amp;find("allow", $_[0]), &amp;find("deny", $_[0]),
		       &amp;find("ignore", $_[0]) );
	local ($a, %vals);
	foreach $a (@adi) {
		$vals{$a-&gt;{'values'}-&gt;[0]} = $a;
		}
	local $uc = $vals{'unknown-clients'}-&gt;{'name'};
	print "&lt;tr&gt;&lt;td&gt;&lt;b&gt;$text{'plib_unclients'}&lt;/b&gt;&lt;/td&gt;&lt;td colspan=3&gt;\n";
    print &amp;ui_radio("unclients", $uc,
                          [ [ "allow", $text{'plib_allow'} ],
                            [ "deny", $text{'plib_deny'} ],
                            [ "ignore", $text{'plib_ignore'} ],
                            [ "", $text{'default'} ] ]);
	print "&lt;/td&gt;&lt;/tr&gt;\n";


######## START CLIENT-UPDATES #####
	# Inputs for allow/deny client-updates
	if ($config{'dhcpd_version'} &gt;= 3) {
		local @adi = ( &amp;find("allow", $_[0]), &amp;find("deny", $_[0]),
				   &amp;find("ignore", $_[0]) );
		local ($a, %vals);
		foreach $a (@adi) {
			$vals{$a-&gt;{'values'}-&gt;[0]} = $a;
			}
		local $cu = $vals{'client-updates'}-&gt;{'name'};
		print "&lt;tr&gt;&lt;td valign=middle&gt;&lt;b&gt;$text{'plib_clientupdates'}&lt;/b&gt;&lt;/td&gt;&lt;td valign=middle colspan=3&gt;\n";
        print &amp;ui_radio("clientupdates", $cu,
                          [ [ "allow", $text{'plib_allow'} ],
                            [ "deny", $text{'plib_deny'} ],
                            [ "ignore", $text{'plib_ignore'} ],
                            [ "", $text{'default'} ] ]);

		print "&lt;/td&gt; &lt;/tr&gt;\n";

	}
######## END CLIENT-UPDATES #####

	if ($_[1] eq 'subnet' || $_[1] eq 'shared-network' ||
	    $_[1] eq 'global') {
		# Inputs for authoratative
		my $auth = &amp;find("authoritative", $_[0]);
		print "&lt;tr&gt;&lt;td&gt;&lt;b&gt;",$text{'plib_auth_'.$_[1]},"&lt;/b&gt;&lt;/td&gt;\n";
        print "&lt;td&gt;";
        print &amp;ui_yesno_radio("auth", ( $auth ? 1: 0 ), 1, 0);
		print "&lt;/td&gt;&lt;/tr&gt;\n";
		}
	}

}

# parse_params(&amp;parent, [&amp;indent])
sub parse_params
{
# Check for expressions
local $type = $in{'params_type'};
local $c;
foreach $c (@{$_[0]-&gt;{'members'}}) {
	if ($c-&gt;{'values'}-&gt;[0] eq "=") {
		&amp;error(&amp;text('plib_eexpr', "&lt;tt&gt;$c-&gt;{'name'}&lt;/tt&gt;"));
		}
	}

&amp;save_opt("default-lease-time", \&amp;check_lease, $_[0], $_[1]);
&amp;save_opt("filename", undef, $_[0], $_[1], 1);
&amp;save_opt("max-lease-time", \&amp;check_lease, $_[0], $_[1]);
&amp;save_opt("next-server", \&amp;check_server, $_[0], $_[1]);
&amp;save_opt("server-name", \&amp;check_server, $_[0], $_[1], 1);
&amp;save_opt("dynamic-bootp-lease-length", \&amp;check_lease, $_[0], $_[1]);
&amp;save_opt("dynamic-bootp-lease-cutoff", \&amp;check_ldate, $_[0], $_[1], 1);
if ($config{'dhcpd_version'} &gt;= 3) {
	&amp;save_opt("ddns-domainname", \&amp;check_domain, $_[0], $_[1], 1);
	&amp;save_opt("ddns-rev-domainname", \&amp;check_domain, $_[0], $_[1], 1);
	&amp;save_opt("ddns-hostname", \&amp;check_server, $_[0], $_[1], 1);
	&amp;save_choice("ddns-updates", $_[0], $_[1]);
	if (defined($in{'ddns-update-style'})) {
		&amp;save_choice("ddns-update-style", $_[0], $_[1]);
		}
	local $pm = $_[0]-&gt;{'members'};
	local @adi = ( &amp;find("allow", $pm), &amp;find("deny", $pm),
		       &amp;find("ignore", $pm) );
	local ($a, %vals);
	foreach $a (@adi) {
		$vals{$a-&gt;{'values'}-&gt;[0]} = $a;
		}
	&amp;save_directive($_[0],
		$vals{'unknown-clients'} ? [ $vals{'unknown-clients'} ] : [ ],
		$in{'unclients'} ? [ { 'name' =&gt; $in{'unclients'},
				       'values' =&gt; [ 'unknown-clients' ] } ]
				 : [ ], $_[1], 1);
	&amp;save_directive($_[0],
		$vals{'client-updates'} ? [ $vals{'client-updates'} ] : [ ],
		$in{'clientupdates'} ? [ { 'name' =&gt; $in{'clientupdates'},
				       'values' =&gt; [ 'client-updates' ] } ]
				 : [ ], $_[1], 1);
	if (defined($in{'auth'})) {
		if ($in{'auth'}) {
			&amp;save_directive($_[0], "authoritative",
					[ { 'name' =&gt; 'authoritative' } ],
					$_[1], 1);
			}
		else {
			&amp;save_directive($_[0], "authoritative", [ ], $_[1]);
			}
		}
	}
}

sub check_lease
{
return $_[0] =~ /^\d+$/ ? undef : "'$_[0]' $text{'plib_invalidlt'}";
}

sub check_server
{
return $_[0] =~ /^\S+$/ ? undef : "'$_[0]' $text{'plib_invalidsn'}";
}

sub check_ldate
{
return $_[0] =~ /^(\d) (\d\d\d\d)\/(\d\d)\/(\d\d) (\d\d):(\d\d):(\d\d)$/ ?
	undef : $text{'plib_leformat'};
}

sub check_domain
{
return $_[0] =~ /^[A-Za-z0-9\.\-]+$/ ? undef : &amp;text('plib_invaliddom', $_[0]);
}

1;

</pre></body></html>