forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_subnet.cgi
executable file
·215 lines (196 loc) · 6.64 KB
/
edit_subnet.cgi
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/local/bin/perl
# edit_subnet.cgi
# Edit or create a subnet
require './dhcpd-lib.pl';
require './params-lib.pl';
&ReadParse();
$conf = &get_config();
($par, $sub) = &get_branch('sub');
$mems = $par->{'members'};
$sconf = $sub->{'members'};
# check acls
%access = &get_module_acl();
&error_setup($text{'eacl_aviol'});
if ($in{'new'}) {
&error("$text{'eacl_np'} $text{'eacl_pis'}")
unless &can('c', \%access, $sub) && &can('rw', \%access, $par);
}
else {
&error("$text{'eacl_np'} $text{'eacl_pss'}")
if !&can('r', \%access, $sub);
}
# display
if ($in{'sidx'} ne "") {
local $s = $conf->[$in{'sidx'}];
$desc = &text('ehost_shared', $s->{'values'}->[0]);
}
&ui_print_header($desc, $in{'new'} ? $text{'esub_crheader'} : $text{'esub_edheader'}, "");
foreach $s (&find("shared-network", $conf)) {
if ($in{'sidx'} eq $s->{'index'}) {
$s_parent = $s;
}
}
print "<form action=save_subnet.cgi method=post>\n";
print "<input name=ret value=\"$in{'ret'}\" type=hidden>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'esub_tabhdr'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print "<tr> <td><b>$text{'esub_desc'}</b></td>\n";
printf "<td colspan=3><input name=desc size=60 value='%s'></td> </tr>\n",
$sub ? &html_escape($sub->{'comment'}) : "";
print "<tr> <td><b>$text{'esub_naddr'}</b></td>\n";
printf "<td><input name=network size=25 value=\"%s\"></td>\n",
$sub ? $sub->{'values'}->[0] : "";
print "<td><b>$text{'esub_nmask'}</b></td>\n";
printf "<td><input name=netmask size=15 value=\"%s\"></td> </tr>\n",
$sub ? $sub->{'values'}->[2] : "";
@range = $sub ? &find("range", $sub->{'members'}) : ();
print "<tr> <td valign=top><b>$text{'esub_arange'}</b></td> <td colspan=3>\n";
for($i=0; $i<=@range; $i++) {
$r = $range[$i];
local $dyn = ($r->{'values'}->[0] eq "dynamic-bootp");
printf "<input name=range_low_$i size=15 value=\"%s\"> - \n",
$r->{'values'}->[$dyn];
printf "<input name=range_hi_$i size=15 value=\"%s\"> \n",
$r->{'values'}->[$dyn+1];
printf "<input type=checkbox name=range_dyn_$i value=1 %s>\n",
$dyn ? "checked" : "";
print "$text{'esub_dbooptpq'}<br>\n";
}
print "</td> </tr>\n";
if (!defined($in{'ret'})) {
print "<tr> <td><b>$text{'esub_shnet'}</b></td>\n";
print "<td><select name=parent>\n";
printf "<option value=\"\" '%s'><%s>\n",
$s_parent ? "" : "checked", $text{'esub_none'};
foreach $s (&find("shared-network", $conf)) {
printf "<option value=\"%s\" %s>%s\n",
$s->{'index'},
$s eq $s_parent ? "selected" : "",
$s->{'values'}->[0]
if &can('rw', \%access, $s);
}
print "</select></td>\n";
}
else {
print "<input name=parent type=hidden value=$s_parent->{'index'}>\n";
print "<tr> <td> </td> <td> </td>\n";
}
&display_params($sconf, "subnet");
foreach $h (&find("host", $mems)) {
push(@host, $h);
# if &can('r', \%access, $h);
}
foreach $g (&find("group", $mems)) {
push(@group, $g);
# if &can('r', \%access, $g);
}
foreach $s (&find("subnet", $mems)) {
foreach $h (&find("host", $s->{'members'})) {
push(@host, $h);
# if &can('r', \%access, $h);
$insubn{$h} = $s->{'index'};
}
foreach $g (&find("group", $s->{'members'})) {
push(@group, $g);
# if &can('r', \%access, $g);
$insubn{$g} = $s->{'index'};
}
}
@host = sort { $a->{'values'}->[0] cmp $b->{'values'}->[0] } @host;
# @group = sort { @{$a->{'members'}} <=> @{$b->{'members'}} } @group;
print "<tr> <td valign=top><b>$text{'esub_hosts'}</b></td>\n";
print "<td><select name=hosts size=3 multiple>\n";
foreach $h (@host) {
next if !&can('r', \%access, $h);
printf "<option value=\"%s,%s\" %s>%s\n",
$h->{'index'}, $insubn{$h},
(!$in{'new'}) && $insubn{$h} eq $sub->{'index'} ? "selected" : "",
$h->{'values'}->[0];
}
print "</select></td>\n";
print "<td valign=top><b>$text{'esub_groups'}</b></td>\n";
print "<td><select name=groups size=3 multiple>\n";
foreach $g (@group) {
local $gm = 0;
next if !&can('r', \%access, $g);
foreach $h (@{$g->{'members'}}) {
if ($h->{'name'} eq "host") { $gm++; }
}
printf "<option value=\"%s,%s\" %s>%s\n",
$g->{'index'}, $insubn{$g},
(!$in{'new'}) && $insubn{$g} eq $sub->{'index'} ? "selected" : "",
&group_name($gm, $g);
}
print "</select></td>\n";
if (!$in{'new'}) {
# inaccessible hosts in this subnet
foreach $h (@host) {
if (!&can('r', \%access, $h) && $insubn{$h} eq $sub->{'index'}) {
print "<input name=hosts value=\"$h->{'index'},$sub->{'index'}\" type=hidden>\n";
}
}
# inaccessible groups in this subnet
foreach $g (@group) {
if (!&can('r', \%access, $g) && $insubn{$g} eq $sub->{'index'}) {
print "<input name=groups value=\"$g->{'index'},$sub->{'index'}\" type=hidden>\n";
}
}
}
print "</table></td></tr></table>\n";
print "<input type=hidden name=sidx value=\"$in{'sidx'}\">\n";
if (!$in{'new'}) {
# Show buttons for existing subnet
print "<input type=hidden name=idx value=\"$in{'idx'}\">\n";
print "<table width=100%><tr>\n";
print "<td><input type=submit value=\"$text{'save'}\"></td>\n"
if &can('rw', \%access, $sub);
print "<td align=center><input type=submit name=options value=\"",
&can('rw', \%access, $sub) ? $text{'butt_eco'} : $text{'butt_vco'},
"\"></td>\n";
if ($access{'r_leases'}) {
print "<td align=center><input type=submit name=leases ",
"value=\"$text{'butt_leases'}\"></td>\n";
}
print "<td align=right><input type=submit name=delete ",
"value=\"$text{'delete'}\"></td>\n" if &can('rw', \%access, $sub, 1);
print "</tr></table>\n";
print "<a href=\"edit_host.cgi?new=1&sidx=$in{'sidx'}&uidx=$in{'idx'}"
."&ret=subnet\">$text{'index_addhst'}</a> \n"
if &can('rw', \%access, $sub);
print "<a href=\"edit_group.cgi?new=1&sidx=$in{'sidx'}&uidx=$in{'idx'}"
."&ret=subnet\">$text{'index_addhstg'}</a><p>\n"
if &can('rw', \%access, $sub);
}
else {
# Show create button for new subnet
print "<input type=hidden name=new value=1>\n";
print "<input type=submit value=\"$text{'create'}\">\n";
}
if ($config{'dhcpd_version'} >= 3 && !$in{'new'}) {
# Display address pools
print &ui_hr();
print &ui_subheading($text{'esub_pools'});
local $pn = 1;
foreach $p (&find('pool', $sconf)) {
push(@links, "edit_pool.cgi?uidx=$in{'idx'}&sidx=$in{'sidx'}&idx=$p->{'index'}");
push(@titles, &text('esub_pool', $pn));
push(@icons, "images/pool.gif");
$pn++;
}
if ($pn == 1) {
print "$text{'esub_poolnone'}<p>\n";
}
else {
&icons_table(\@links, \@titles, \@icons, 5);
}
print "<a href='edit_pool.cgi?uidx=$in{'idx'}&sidx=$in{'sidx'}&new=1'>",
"$text{'esub_pooladd'}</a><br>\n";
}
print "</form>\n";
if ($in{'ret'} eq "shared") {
&ui_print_footer("edit_shared.cgi?idx=$in{'sidx'}", $text{'esub_retshar'});
}
else {
&ui_print_footer("", $text{'esub_return'});
}