forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_bifc.cgi
executable file
·339 lines (314 loc) · 9.58 KB
/
edit_bifc.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/local/bin/perl
# edit_bifc.cgi
# Edit or create a bootup interface
require './net-lib.pl';
&ReadParse();
!$in{'new'} || &can_create_iface() || &error($text{'ifcs_ecannot'});
@boot = &boot_interfaces();
# Show page title and get interface
if ($in{'new'} && $in{'bond'}) {
# New bonding interface
&ui_print_header(undef, $text{'bonding_create'}, "");
$bmax = -1;
foreach $b (@boot) {
if ($b->{'fullname'} =~ /^bond(\d+)$/) {
$bmax = $1;
}
}
}
elsif ($in{'new'} && $in{'vlan'}) {
# New VLAN
&ui_print_header(undef, $text{'vlan_create'}, "");
}
elsif ($in{'new'} && $in{'bridge'}) {
# New Bridge
&ui_print_header(undef, $text{'bridge_create'}, "");
$bmax = -1;
foreach $b (@boot) {
if ($b->{'fullname'} =~ /^br(\d+)$/) {
$bmax = $1;
}
}
}
elsif ($in{'new'}) {
# New real or virtual interface
&ui_print_header(undef, $text{'bifc_create'}, "");
if ($in{'virtual'}) {
# Pick a virtual number
$vmax = int($net::min_virtual_number);
foreach my $e (@boot) {
$vmax = $e->{'virtual'}
if ($e->{'name'} eq $in{'virtual'} &&
$e->{'virtual'} > $vmax);
}
}
}
else {
# Editing existing
$b = $boot[$in{'idx'}];
&can_iface($b) || &error($text{'ifcs_ecannot_this'});
&ui_print_header(undef, $text{'bifc_edit'}, "");
if (!$b->{'dhcp'} && !$b->{'bootp'} && !$b->{'broadcast'}) {
# Fill in broadcast if missing
$b->{'broadcast'} = &compute_broadcast(
$b->{'address'}, $b->{'netmask'});
}
}
# Start of the form
print &ui_form_start("save_bifc.cgi");
print &ui_hidden("new", $in{'new'});
print &ui_hidden("idx", $in{'idx'});
print &ui_hidden("vlan", $in{'vlan'});
print &ui_hidden("bond", $in{'bond'});
print &ui_hidden("bridge", $in{'bridge'});
print &ui_table_start($in{'virtual'} || $b && $b->{'virtual'} ne "" ?
$text{'bifc_desc2'} : $text{'bifc_desc1'}, undef, 2);
# Comment, if allowed
if (defined(&can_iface_desc) && &can_iface_desc($b)) {
print &ui_table_row($text{'ifcs_desc'},
&ui_textbox("desc", $b ? $b->{'desc'} : undef, 60), 3);
}
# Interface name
if ($in{'new'} && $in{'virtual'}) {
# New virtual interface
$namefield = $in{'virtual'}.":".
&ui_textbox("virtual", $vmax+1, 3).
&ui_hidden("name", $in{'virtual'});
}
elsif ($in{'new'}) {
# New real interface
if ($in{'vlan'} == 1) {
$namefield = "auto".&ui_hidden("name", "auto");
}
elsif ($in{'bridge'}) {
$namefield = "br ".&ui_textbox("name", ($bmax+1), 3);
}
elsif ($in{'bond'}) {
$namefield = "bond ".&ui_textbox("name", ($bmax+1), 3);
}
else {
$namefield = &ui_textbox("name", undef, 6);
}
}
else {
# Existing interface
$namefield = "<tt>$b->{'fullname'}</tt>";
}
print &ui_table_row($text{'ifcs_name'}, $namefield);
# Activate at boot?
if (&can_edit("up", $b) && $access{'up'}) {
$upfield = &ui_yesno_radio("up", !$b || $b->{'up'});
}
else {
$upfield = !$b ? $text{'yes'} :
$b->{'up'} ? $text{'yes'} : $text{'no'};
}
print &ui_table_row($text{'bifc_act'}, $upfield);
# IP address source. This can either be DHCP, BootP or a fixed IP,
# netmask and broadcast
$virtual = (!$b && $in{'virtual'}) || ($b && $b->{'virtual'} ne "");
$dhcp = &can_edit("dhcp") && !$virtual;
$bootp = &can_edit("bootp") && !$virtual;
if (defined(&supports_no_address) && &supports_no_address()) {
# Having no address is allowed
$canno = 1;
}
elsif ($b && !$b->{'address'} && !$b->{'dhcp'} && !$b->{'bootp'}) {
# Has no address
$canno = 1;
}
@opts = ( );
if ($canno) {
push(@opts, [ "none", $text{'ifcs_noaddress'} ]);
}
if ($dhcp) {
push(@opts, [ "dhcp", $text{'ifcs_dhcp'} ]);
}
if ($bootp) {
push(@opts, [ "bootp", $text{'ifcs_bootp'} ]);
}
if ($canno) {
}
@grid = ( $text{'ifcs_ip'},
&ui_textbox("address", $b ? $b->{'address'} : "", 15) );
if ($in{'virtual'} && $in{'new'} && $virtual_netmask) {
# Netmask is fixed
push(@grid, $text{'ifcs_mask'}, "<tt>$virtual_netmask</tt>");
}
elsif (&can_edit("netmask", $b) && $access{'netmask'}) {
# Can edit netmask
push(@grid, $text{'ifcs_mask'},
&ui_textbox("netmask", $b ? $b->{'netmask'}
: $config{'def_netmask'}, 15));
}
elsif ($b && $b->{'netmask'}) {
# Cannot edit
push(@grid, $text{'ifcs_mask'}, "<tt>$b->{'netmask'}</tt>");
}
if (&can_edit("broadcast", $b) && $access{'broadcast'}) {
# Can edit broadcast address
push(@grid, $text{'ifcs_broad'},
&ui_opt_textbox("broadcast",
$b ? $b->{'broadcast'} : $config{'def_broadcast'},
15, $text{'ifcs_auto'}));
}
elsif ($b && $b->{'broadcast'}) {
# Broadcast is fixed
push(@grid, $text{'ifcs_broad'}, "<tt>$b->{'broadcast'}</tt>");
}
push(@opts, [ "address", $text{'ifcs_static2'}, &ui_grid_table(\@grid, 2) ]);
# Show the IP field
if (@opts > 1) {
print &ui_table_row($text{'ifcs_mode'},
&ui_radio_table("mode", $b && $b->{'dhcp'} ? "dhcp" :
$b && $b->{'bootp'} ? "bootp" :
$b && !$b->{'address'} ? "none" :
"address",
\@opts), 3);
}
else {
print &ui_table_row($opts[0]->[1], $opts[0]->[2]);
}
# Show the IPv6 field
if (&supports_address6($b)) {
# Multiple IPs allowed
$table6 = &ui_columns_start([ $text{'ifcs_address6'},
$text{'ifcs_netmask6'} ], 50);
for($i=0; $i<=($b ? scalar(@{$b->{'address6'}}) : 0); $i++) {
$table6 .= &ui_columns_row([
&ui_textbox("address6_$i",
$b->{'address6'}->[$i], 40),
&ui_textbox("netmask6_$i",
$b->{'netmask6'}->[$i] || 64, 10) ]);
}
$table6 .= &ui_columns_end();
print &ui_table_row($text{'ifcs_mode6'},
&ui_radio_table("mode6",
!$b ? "none" :
$b->{'auto6'} ? "auto" :
@{$b->{'address6'}} ? "address" : "none",
[ [ "none", $text{'ifcs_none6'} ],
[ "auto", $text{'ifcs_auto6'} ],
[ "address", $text{'ifcs_static2'}, $table6 ] ]), 2);
}
# MTU
if (&can_edit("mtu", $b) && $access{'mtu'}) {
$mtufield = &ui_opt_textbox(
"mtu", $b ? $b->{'mtu'} : $config{'def_mtu'}, 8,
$text{'default'});
}
else {
$mtufield = $b && $b->{'mtu'} ? $b->{'mtu'} : undef;
}
if ($mtufield) {
print &ui_table_row($text{'ifcs_mtu'}, $mtufield);
}
# Virtual sub-interfaces
if ($b && $b->{'virtual'} eq "") {
$vcount = 0;
foreach $vb (@boot) {
if ($vb->{'virtual'} ne "" && $vb->{'name'} eq $b->{'name'}) {
$vcount++;
}
}
$vlink = "";
if ($access{'virt'} && !$noos_support_add_virtifcs) {
$vlink = "(<a href='edit_bifc.cgi?new=1&virtual=$b->{'name'}'>".
"$text{'ifcs_addvirt'}</a>)\n";
}
print &ui_table_row($text{'ifcs_virts'}, $vcount." ".$vlink);
}
# Special parameters for teaming
if ($in{'bond'} || &iface_type($b->{'name'}) eq 'Bonded') {
# Select bonding teampartner
print &ui_table_row($text{'bonding_teamparts'},
&ui_textbox("partner", $b->{'partner'}, 10)." ".$text{'bonding_teampartsdesc'});
# Select teaming mode
@mode = ("balance-rr", "activebackup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb");
print &ui_table_row($text{'bonding_teammode'},
&ui_select("bondmode", int($b->{'mode'}),
[ map { [ $_, $mode[$_] ] } (0 .. $#mode) ]));
# Select mii Monitoring Interval
print &ui_table_row($text{'bonding_miimon'},
&ui_textbox("miimon", $b->{'miimon'}, 5)." ms");
# Select updelay
print &ui_table_row($text{'bonding_updelay'},
&ui_textbox("updelay", $b->{'updelay'}, 5)." ms");
# Select downdelay
print &ui_table_row($text{'bonding_downdelay'},
&ui_textbox("downdelay", $b->{'downdelay'}, 5)." ms");
}
# Special Parameter for vlan tagging
if(($in{'vlan'}) or (&iface_type($b->{'name'}) =~ /^(.*) (VLAN)$/)) {
$b->{'name'} =~ /(\S+)\.(\d+)/;
$physical = $1;
$vlanid = $2;
# Phyical device
@phys = grep { (($_->{'virtual'} eq '') && ($_->{'vlanid'} eq '')) } &active_interfaces(1);
print &ui_table_row($text{'vlan_physical'},
$in{'new'} ? &ui_select("physical", $physical,
[ map { $_->{'fullname'} } @phys ])
: $physical.&ui_hidden("physical", $physical));
# VLAN ID
print &ui_table_row($text{'vlan_id'},
$in{'new'} ? &ui_textbox("vlanid", $vlanid, 10)
: $vlanid.&ui_hidden("vlanid", $vlanid));
}
# Hardware address, if non-virtual
if (($in{'new'} && $in{'virtual'} eq "" && !$in{'bridge'}) ||
(!$in{'new'} && $b->{'virtual'} eq "" &&
defined(&boot_iface_hardware) &&
&boot_iface_hardware($b->{'name'}))) {
$hardfield = &ui_opt_textbox("ether", $b->{'ether'}, 30,
$text{'aifc_default'});
print &ui_table_row($text{'aifc_hard'}, $hardfield);
}
# Real interface for bridge
if ($in{'bridge'} || $b && $b->{'bridge'}) {
@ethboot = sort { $a cmp $b }
map { $_->{'fullname'} }
grep { $_->{'fullname'} =~ /^(eth|vlan|bond)/ &&
$_->{'virtual'} eq '' } @boot;
print &ui_table_row($text{'bifc_bridgeto'},
&ui_select("bridgeto", $b->{'bridgeto'},
[ [ "", $text{'bifc_nobridge'} ],
@ethboot ],
1, 0, $in{'new'} ? 0 : 1));
}
print &ui_table_end();
# Generate and show buttons at end of the form
@buts = ( );
if ($access{'bootonly'}) {
# Can only save both boot-time and active
if ($in{'new'}) {
push(@buts, [ "activate", $text{'bifc_capply'} ]);
}
else {
push(@buts, [ "activate", $text{'bifc_apply'} ]);
if ($access{'delete'}) {
push(@buts, [ "unapply", $text{'bifc_dapply'} ]);
}
}
}
else {
# Show buttons to save both boot-time and/or active
if ($in{'new'}) {
push(@buts, [ undef, $text{'create'} ]);
push(@buts, [ "activate", $text{'bifc_capply'} ]);
}
else {
push(@buts, [ undef, $text{'save'} ])
unless $always_apply_ifcs;
if (!($b->{'bootp'} || $b->{'dhcp'}) ||
defined(&apply_interface)) {
push(@buts, [ "activate", $text{'bifc_apply'} ]);
}
if ($access{'delete'}) {
push(@buts, [ "unapply", $text{'bifc_dapply'} ]);
push(@buts, [ "delete", $text{'delete'} ])
unless $noos_support_delete_ifcs;
}
}
}
print &ui_form_end(\@buts);
&ui_print_footer("list_ifcs.cgi?mode=boot", $text{'ifcs_return'});