2 # $Id: params-lib.pl,v 1.3 2005/04/16 14:30:21 jfranken Exp $
3 # * Functions for editing parameters common to many kinds of directive
5 # File modified 2005-04-15 by Johannes Franken <jfranken@jfranken.de>:
6 # * Added support for the client-update option of dhcpd 3.
8 # display_params(&config, type)
11 print &ui_hidden("params_type", $_[1]);
13 print &opt_input($text{'plib_deflt'}, "default-lease-time",
14 $_[0], $text{'default'}, 8, $text{'secs'});
18 print &opt_input($text{'plib_bfname'}, "filename", $_[0], $text{'none'}, 20);
19 print &opt_input($text{'plib_maxlt'}, "max-lease-time",
20 $_[0], $text{'default'}, 8, $text{'secs'});
24 print &opt_input($text{'plib_bfserv'}, "next-server", $_[0], $text{'plib_thisserv'}, 15);
25 print &opt_input($text{'plib_servname'}, "server-name", $_[0], $text{'default'}, 15);
29 print &opt_input($text{'plib_llbc'}, "dynamic-bootp-lease-length",
30 $_[0], $text{'plib_forever'}, 8, $text{'secs'});
31 print &opt_input($text{'plib_lebc'}, "dynamic-bootp-lease-cutoff",
32 $_[0], $text{'plib_never'}, 21);
35 if ($config{'dhcpd_version'} >= 3) {
38 print &choice_input($text{'plib_ddnsup'}, "ddns-updates", $_[0], $text{'yes'}, 'on', $text{'no'}, 'off', $text{'default'}, '');
39 print &opt_input($text{'plib_ddnsdom'}, "ddns-domainname", $_[0], $text{'default'}, 15);
43 print &opt_input($text{'plib_ddnsrevdom'}, "ddns-rev-domainname", $_[0], $text{'default'}, 15);
44 print &opt_input($text{'plib_ddnshost'}, "ddns-hostname", $_[0], $text{'plib_ddnshost_def'}, 15);
47 if ($_[1] eq 'global') {
49 print &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'}, '');
53 # Inputs for allow/deny clients
54 local @adi = ( &find("allow", $_[0]), &find("deny", $_[0]),
55 &find("ignore", $_[0]) );
58 $vals{$a->{'values'}->[0]} = $a;
60 local $uc = $vals{'unknown-clients'}->{'name'};
61 print "<tr> <td><b>$text{'plib_unclients'}</b></td> <td colspan=3>\n";
62 printf "<input type=radio name=unclients value=allow %s> %s\n",
63 $uc eq 'allow' ? "checked" : "", $text{'plib_allow'};
64 printf "<input type=radio name=unclients value=deny %s> %s\n",
65 $uc eq 'deny' ? "checked" : "", $text{'plib_deny'};
66 printf "<input type=radio name=unclients value=ignore %s> %s\n",
67 $uc eq 'ignore' ? "checked" : "", $text{'plib_ignore'};
68 printf "<input type=radio name=unclients value='' %s> %s\n",
69 $uc ? "" : "checked", $text{'default'};
70 print "</td> </tr>\n";
73 ######## START CLIENT-UPDATES #####
74 # Inputs for allow/deny client-updates
75 if ($config{'dhcpd_version'} >= 3) {
76 local @adi = ( &find("allow", $_[0]), &find("deny", $_[0]),
77 &find("ignore", $_[0]) );
80 $vals{$a->{'values'}->[0]} = $a;
82 local $cu = $vals{'client-updates'}->{'name'};
83 print "<tr> <td><b>$text{'plib_clientupdates'}</b></td> <td colspan=3>\n";
84 printf "<input type=radio name=clientupdates value=allow %s> %s\n",
85 $cu eq 'allow' ? "checked" : "", $text{'plib_allow'};
86 printf "<input type=radio name=clientupdates value=deny %s> %s\n",
87 $cu eq 'deny' ? "checked" : "", $text{'plib_deny'};
88 printf "<input type=radio name=clientupdates value=ignore %s> %s\n",
89 $cu eq 'ignore' ? "checked" : "", $text{'plib_ignore'};
90 printf "<input type=radio name=clientupdates value='' %s> %s\n",
91 $cu ? "" : "checked", $text{'default'};
92 print "</td> </tr>\n";
95 ######## END CLIENT-UPDATES #####
97 if ($_[1] eq 'subnet' || $_[1] eq 'shared-network' ||
99 # Inputs for authoratative
100 local $auth = &find("authoritative", $_[0]);
101 print "<tr> <td><b>",$text{'plib_auth_'.$_[1]},"</b></td>\n";
102 printf "<td><input type=radio name=auth value=1 %s> %s\n",
103 $auth ? "checked" : "", $text{'yes'};
104 printf "<input type=radio name=auth value=0 %s> %s (%s)</td>\n",
105 $auth ? "" : "checked", $text{'default'}, $text{'no'};
113 # parse_params(&parent, [&indent])
116 # Check for expressions
117 local $type = $in{'params_type'};
119 foreach $c (@{$_[0]->{'members'}}) {
120 if ($c->{'values'}->[0] eq "=") {
121 &error(&text('plib_eexpr', "<tt>$c->{'name'}</tt>"));
125 &save_opt("default-lease-time", \&check_lease, $_[0], $_[1]);
126 &save_opt("filename", undef, $_[0], $_[1], 1);
127 &save_opt("max-lease-time", \&check_lease, $_[0], $_[1]);
128 &save_opt("next-server", \&check_server, $_[0], $_[1]);
129 &save_opt("server-name", \&check_server, $_[0], $_[1], 1);
130 &save_opt("dynamic-bootp-lease-length", \&check_lease, $_[0], $_[1]);
131 &save_opt("dynamic-bootp-lease-cutoff", \&check_ldate, $_[0], $_[1], 1);
132 if ($config{'dhcpd_version'} >= 3) {
133 &save_opt("ddns-domainname", \&check_domain, $_[0], $_[1], 1);
134 &save_opt("ddns-rev-domainname", \&check_domain, $_[0], $_[1], 1);
135 &save_opt("ddns-hostname", \&check_server, $_[0], $_[1], 1);
136 &save_choice("ddns-updates", $_[0], $_[1]);
137 if (defined($in{'ddns-update-style'})) {
138 &save_choice("ddns-update-style", $_[0], $_[1]);
140 local $pm = $_[0]->{'members'};
141 local @adi = ( &find("allow", $pm), &find("deny", $pm),
142 &find("ignore", $pm) );
145 $vals{$a->{'values'}->[0]} = $a;
147 &save_directive($_[0],
148 $vals{'unknown-clients'} ? [ $vals{'unknown-clients'} ] : [ ],
149 $in{'unclients'} ? [ { 'name' => $in{'unclients'},
150 'values' => [ 'unknown-clients' ] } ]
152 &save_directive($_[0],
153 $vals{'client-updates'} ? [ $vals{'client-updates'} ] : [ ],
154 $in{'clientupdates'} ? [ { 'name' => $in{'clientupdates'},
155 'values' => [ 'client-updates' ] } ]
157 if (defined($in{'auth'})) {
159 &save_directive($_[0], "authoritative",
160 [ { 'name' => 'authoritative' } ],
164 &save_directive($_[0], "authoritative", [ ], $_[1]);
172 return $_[0] =~ /^\d+$/ ? undef : "'$_[0]' $text{'plib_invalidlt'}";
177 return $_[0] =~ /^\S+$/ ? undef : "'$_[0]' $text{'plib_invalidsn'}";
182 return $_[0] =~ /^(\d) (\d\d\d\d)\/(\d\d)\/(\d\d) (\d\d):(\d\d):(\d\d)$/ ?
183 undef : $text{'plib_leformat'};
188 return $_[0] =~ /^[A-Za-z0-9\.\-]+$/ ? undef : &text('plib_invaliddom', $_[0]);