Handle hostnames with upper-case letters
[webmin.git] / dhcpd / params-lib.pl
1 #!/usr/bin/perl
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
4 #
5 # File modified 2005-04-15 by Johannes Franken <jfranken@jfranken.de>:
6 # * Added support for the client-update option of dhcpd 3.
7
8 # display_params(&config, type)
9 sub display_params
10 {
11 print &ui_hidden("params_type", $_[1]);
12
13 print &opt_input($text{'plib_deflt'}, "default-lease-time",
14                  $_[0], $text{'default'}, 8, $text{'secs'});
15 print "</tr>\n";
16
17 print "<tr>\n";
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'});
21 print "</tr>\n";
22
23 print "<tr>\n";
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);
26 print "</tr>\n";
27
28 print "<tr>\n";
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);
33 print "</tr>\n";
34
35 if ($config{'dhcpd_version'} >= 3) {
36         # Inputs for DDNS
37         print "<tr>\n";
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);
40         print "</tr>\n";
41
42         print "<tr>\n";
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);
45         print "</tr>\n";
46
47         if ($_[1] eq 'global') {
48                 print "<tr>\n";
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'}, '');
50                 print "</tr>\n";
51                 }
52
53         # Inputs for allow/deny clients
54         local @adi = ( &find("allow", $_[0]), &find("deny", $_[0]),
55                        &find("ignore", $_[0]) );
56         local ($a, %vals);
57         foreach $a (@adi) {
58                 $vals{$a->{'values'}->[0]} = $a;
59                 }
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";
71
72
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]) );
78                 local ($a, %vals);
79                 foreach $a (@adi) {
80                         $vals{$a->{'values'}->[0]} = $a;
81                         }
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";
93
94         }
95 ######## END CLIENT-UPDATES #####
96
97         if ($_[1] eq 'subnet' || $_[1] eq 'shared-network' ||
98             $_[1] eq 'global') {
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'};
106
107                 print "</tr>\n";
108                 }
109         }
110
111 }
112
113 # parse_params(&parent, [&indent])
114 sub parse_params
115 {
116 # Check for expressions
117 local $type = $in{'params_type'};
118 local $c;
119 foreach $c (@{$_[0]->{'members'}}) {
120         if ($c->{'values'}->[0] eq "=") {
121                 &error(&text('plib_eexpr', "<tt>$c->{'name'}</tt>"));
122                 }
123         }
124
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]);
139                 }
140         local $pm = $_[0]->{'members'};
141         local @adi = ( &find("allow", $pm), &find("deny", $pm),
142                        &find("ignore", $pm) );
143         local ($a, %vals);
144         foreach $a (@adi) {
145                 $vals{$a->{'values'}->[0]} = $a;
146                 }
147         &save_directive($_[0],
148                 $vals{'unknown-clients'} ? [ $vals{'unknown-clients'} ] : [ ],
149                 $in{'unclients'} ? [ { 'name' => $in{'unclients'},
150                                        'values' => [ 'unknown-clients' ] } ]
151                                  : [ ], $_[1], 1);
152         &save_directive($_[0],
153                 $vals{'client-updates'} ? [ $vals{'client-updates'} ] : [ ],
154                 $in{'clientupdates'} ? [ { 'name' => $in{'clientupdates'},
155                                        'values' => [ 'client-updates' ] } ]
156                                  : [ ], $_[1], 1);
157         if (defined($in{'auth'})) {
158                 if ($in{'auth'}) {
159                         &save_directive($_[0], "authoritative",
160                                         [ { 'name' => 'authoritative' } ],
161                                         $_[1], 1);
162                         }
163                 else {
164                         &save_directive($_[0], "authoritative", [ ], $_[1]);
165                         }
166                 }
167         }
168 }
169
170 sub check_lease
171 {
172 return $_[0] =~ /^\d+$/ ? undef : "'$_[0]' $text{'plib_invalidlt'}";
173 }
174
175 sub check_server
176 {
177 return $_[0] =~ /^\S+$/ ? undef : "'$_[0]' $text{'plib_invalidsn'}";
178 }
179
180 sub check_ldate
181 {
182 return $_[0] =~ /^(\d) (\d\d\d\d)\/(\d\d)\/(\d\d) (\d\d):(\d\d):(\d\d)$/ ?
183         undef : $text{'plib_leformat'};
184 }
185
186 sub check_domain
187 {
188 return $_[0] =~ /^[A-Za-z0-9\.\-]+$/ ? undef : &text('plib_invaliddom', $_[0]);
189 }
190
191 1;
192