forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams-lib.pl
executable file
·192 lines (169 loc) · 6.45 KB
/
params-lib.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/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 <[email protected]>:
# * Added support for the client-update option of dhcpd 3.
# display_params(&config, type)
sub display_params
{
print &ui_hidden("params_type", $_[1]);
print &opt_input($text{'plib_deflt'}, "default-lease-time",
$_[0], $text{'default'}, 8, $text{'secs'});
print "</tr>\n";
print "<tr>\n";
print &opt_input($text{'plib_bfname'}, "filename", $_[0], $text{'none'}, 20);
print &opt_input($text{'plib_maxlt'}, "max-lease-time",
$_[0], $text{'default'}, 8, $text{'secs'});
print "</tr>\n";
print "<tr>\n";
print &opt_input($text{'plib_bfserv'}, "next-server", $_[0], $text{'plib_thisserv'}, 15);
print &opt_input($text{'plib_servname'}, "server-name", $_[0], $text{'default'}, 15);
print "</tr>\n";
print "<tr>\n";
print &opt_input($text{'plib_llbc'}, "dynamic-bootp-lease-length",
$_[0], $text{'plib_forever'}, 8, $text{'secs'});
print &opt_input($text{'plib_lebc'}, "dynamic-bootp-lease-cutoff",
$_[0], $text{'plib_never'}, 21);
print "</tr>\n";
if ($config{'dhcpd_version'} >= 3) {
# Inputs for DDNS
print "<tr>\n";
print &choice_input($text{'plib_ddnsup'}, "ddns-updates", $_[0], $text{'yes'}, 'on', $text{'no'}, 'off', $text{'default'}, '');
print &opt_input($text{'plib_ddnsdom'}, "ddns-domainname", $_[0], $text{'default'}, 15);
print "</tr>\n";
print "<tr>\n";
print &opt_input($text{'plib_ddnsrevdom'}, "ddns-rev-domainname", $_[0], $text{'default'}, 15);
print &opt_input($text{'plib_ddnshost'}, "ddns-hostname", $_[0], $text{'plib_ddnshost_def'}, 15);
print "</tr>\n";
if ($_[1] eq 'global') {
print "<tr>\n";
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'}, '');
print "</tr>\n";
}
# Inputs for allow/deny clients
local @adi = ( &find("allow", $_[0]), &find("deny", $_[0]),
&find("ignore", $_[0]) );
local ($a, %vals);
foreach $a (@adi) {
$vals{$a->{'values'}->[0]} = $a;
}
local $uc = $vals{'unknown-clients'}->{'name'};
print "<tr> <td><b>$text{'plib_unclients'}</b></td> <td colspan=3>\n";
printf "<input type=radio name=unclients value=allow %s> %s\n",
$uc eq 'allow' ? "checked" : "", $text{'plib_allow'};
printf "<input type=radio name=unclients value=deny %s> %s\n",
$uc eq 'deny' ? "checked" : "", $text{'plib_deny'};
printf "<input type=radio name=unclients value=ignore %s> %s\n",
$uc eq 'ignore' ? "checked" : "", $text{'plib_ignore'};
printf "<input type=radio name=unclients value='' %s> %s\n",
$uc ? "" : "checked", $text{'default'};
print "</td> </tr>\n";
######## START CLIENT-UPDATES #####
# Inputs for allow/deny client-updates
if ($config{'dhcpd_version'} >= 3) {
local @adi = ( &find("allow", $_[0]), &find("deny", $_[0]),
&find("ignore", $_[0]) );
local ($a, %vals);
foreach $a (@adi) {
$vals{$a->{'values'}->[0]} = $a;
}
local $cu = $vals{'client-updates'}->{'name'};
print "<tr> <td><b>$text{'plib_clientupdates'}</b></td> <td colspan=3>\n";
printf "<input type=radio name=clientupdates value=allow %s> %s\n",
$cu eq 'allow' ? "checked" : "", $text{'plib_allow'};
printf "<input type=radio name=clientupdates value=deny %s> %s\n",
$cu eq 'deny' ? "checked" : "", $text{'plib_deny'};
printf "<input type=radio name=clientupdates value=ignore %s> %s\n",
$cu eq 'ignore' ? "checked" : "", $text{'plib_ignore'};
printf "<input type=radio name=clientupdates value='' %s> %s\n",
$cu ? "" : "checked", $text{'default'};
print "</td> </tr>\n";
}
######## END CLIENT-UPDATES #####
if ($_[1] eq 'subnet' || $_[1] eq 'shared-network' ||
$_[1] eq 'global') {
# Inputs for authoratative
local $auth = &find("authoritative", $_[0]);
print "<tr> <td><b>",$text{'plib_auth_'.$_[1]},"</b></td>\n";
printf "<td><input type=radio name=auth value=1 %s> %s\n",
$auth ? "checked" : "", $text{'yes'};
printf "<input type=radio name=auth value=0 %s> %s (%s)</td>\n",
$auth ? "" : "checked", $text{'default'}, $text{'no'};
print "</tr>\n";
}
}
}
# parse_params(&parent, [&indent])
sub parse_params
{
# Check for expressions
local $type = $in{'params_type'};
local $c;
foreach $c (@{$_[0]->{'members'}}) {
if ($c->{'values'}->[0] eq "=") {
&error(&text('plib_eexpr', "<tt>$c->{'name'}</tt>"));
}
}
&save_opt("default-lease-time", \&check_lease, $_[0], $_[1]);
&save_opt("filename", undef, $_[0], $_[1], 1);
&save_opt("max-lease-time", \&check_lease, $_[0], $_[1]);
&save_opt("next-server", \&check_server, $_[0], $_[1]);
&save_opt("server-name", \&check_server, $_[0], $_[1], 1);
&save_opt("dynamic-bootp-lease-length", \&check_lease, $_[0], $_[1]);
&save_opt("dynamic-bootp-lease-cutoff", \&check_ldate, $_[0], $_[1], 1);
if ($config{'dhcpd_version'} >= 3) {
&save_opt("ddns-domainname", \&check_domain, $_[0], $_[1], 1);
&save_opt("ddns-rev-domainname", \&check_domain, $_[0], $_[1], 1);
&save_opt("ddns-hostname", \&check_server, $_[0], $_[1], 1);
&save_choice("ddns-updates", $_[0], $_[1]);
if (defined($in{'ddns-update-style'})) {
&save_choice("ddns-update-style", $_[0], $_[1]);
}
local $pm = $_[0]->{'members'};
local @adi = ( &find("allow", $pm), &find("deny", $pm),
&find("ignore", $pm) );
local ($a, %vals);
foreach $a (@adi) {
$vals{$a->{'values'}->[0]} = $a;
}
&save_directive($_[0],
$vals{'unknown-clients'} ? [ $vals{'unknown-clients'} ] : [ ],
$in{'unclients'} ? [ { 'name' => $in{'unclients'},
'values' => [ 'unknown-clients' ] } ]
: [ ], $_[1], 1);
&save_directive($_[0],
$vals{'client-updates'} ? [ $vals{'client-updates'} ] : [ ],
$in{'clientupdates'} ? [ { 'name' => $in{'clientupdates'},
'values' => [ 'client-updates' ] } ]
: [ ], $_[1], 1);
if (defined($in{'auth'})) {
if ($in{'auth'}) {
&save_directive($_[0], "authoritative",
[ { 'name' => 'authoritative' } ],
$_[1], 1);
}
else {
&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 : &text('plib_invaliddom', $_[0]);
}
1;