Handle hostnames with upper-case letters
[webmin.git] / net / list_ifcs.cgi
1 #!/usr/local/bin/perl
2 # list_ifcs.cgi
3 # List active and boot-time interfaces
4
5 require './net-lib.pl';
6 &ReadParse();
7 $access{'ifcs'} || &error($text{'ifcs_ecannot'});
8 $allow_add = &can_create_iface() && !$noos_support_add_ifcs;
9 &ui_print_header(undef, $text{'ifcs_title'}, "");
10
11 # Start tabs for active/boot time interfaces
12 @tabs = ( [ "active", $text{'ifcs_now'}, "list_ifcs.cgi?mode=active" ] );
13 $defmode = "active";
14 if (!$access{'bootonly'}) {
15         push(@tabs, [ "boot", $text{'ifcs_boot'}, "list_ifcs.cgi?mode=boot" ] );
16         $defmode = "boot";
17         }
18 print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || $defmode, 1);
19
20 # Show interfaces that are currently active
21 @act = &active_interfaces(1);
22 if (!$access{'bootonly'}) {
23         # Table heading and links
24         print &ui_tabs_start_tab("mode", "active");
25         print $text{'ifcs_activedesc'},"<p>\n";
26         local @tds;
27         @links = ( );
28         if ($access{'ifcs'} >= 2) {
29                 print &ui_form_start("delete_aifcs.cgi", "post");
30                 push(@links, &select_all_link("d"),
31                              &select_invert_link("d") );
32                 push(@tds, "width=5 valign=top");
33                 }
34         push(@tds, "width=20% valign=top", "width=20% valign=top",
35                    "width=20% valign=top", "width=20% valign=top");
36         push(@tds, "width=20% valign=top") if (&supports_address6());
37         push(@tds, "width=5% valign=top");
38         if ($allow_add) {
39                 push(@links,
40                      "<a href='edit_aifc.cgi?new=1'>$text{'ifcs_add'}</a>");
41                 }
42         print &ui_links_row(\@links);
43         print &ui_columns_start([ $access{'ifcs'} >= 2 ? ( "" ) : ( ),
44                                   $text{'ifcs_name'},
45                                   $text{'ifcs_type'},
46                                   $text{'ifcs_ip'},
47                                   $text{'ifcs_mask'},
48                                   &supports_address6() ?
49                                         ( $text{'ifcs_ip6'} ) : ( ),
50                                   $text{'ifcs_status'} ], 100, 0, \@tds);
51
52         # Show table of interfaces
53         @act = sort iface_sort @act;
54         foreach $a (@act) {
55                 next if ($access{'hide'} &&     # skip hidden
56                          (!$a->{'edit'} || !&can_iface($a)));
57                 local $mod = &module_for_interface($a);
58                 local %minfo = $mod ? &get_module_info($mod->{'module'}) : ( );
59                 local @cols;
60                 if ($a->{'edit'} && &can_iface($a) && $a->{'address'}) {
61                         push(@cols,
62                             "<a href=\"edit_aifc.cgi?idx=$a->{'index'}\">".
63                             &html_escape($a->{'fullname'})."</a>");
64                         }
65                 elsif (!$a->{'edit'} && $mod) {
66                         push(@cols,
67                            "<a href=\"mod_aifc.cgi?idx=$a->{'index'}\">".
68                            &html_escape($a->{'fullname'})."</a>");
69                         }
70                 else {
71                         push(@cols, &html_escape($a->{'fullname'}));
72                         }
73                 if ($a->{'virtual'} ne "") {
74                         $cols[0] = "&nbsp;&nbsp;".$cols[0];
75                         }
76                 if (%minfo && $minfo{'dir'} eq 'virtual-server') {
77                         # Shorten name
78                         $minfo{'desc'} = $text{'index_vmin'};
79                         }
80                 push(@cols, &iface_type($a->{'name'}).
81                       ($a->{'virtual'} eq "" ||
82                        $mod ? "" : " ($text{'ifcs_virtual'})").
83                       (%minfo ? " ($minfo{'desc'})" : "").
84                       ($a->{'speed'} ? " ".$a->{'speed'} : ""));
85                 push(@cols, &html_escape($a->{'address'}) ||
86                             $text{'ifcs_noaddress'});
87                 push(@cols, &html_escape($a->{'netmask'}) ||
88                             $text{'ifcs_nonetmask'});
89                 if (&supports_address6()) {
90                         push(@cols, join("<br>\n", map { &html_escape($_) }
91                                                     @{$a->{'address6'}}));
92                         }
93                 push(@cols, $a->{'up'} ? $text{'ifcs_up'} :
94                         "<font color=#ff0000>$text{'ifcs_down'}</font>");
95                 if ($a->{'edit'} && &can_iface($a)) {
96                         print &ui_checked_columns_row(\@cols, \@tds, "d",
97                                                       $a->{'fullname'});
98                         }
99                 else {
100                         print &ui_columns_row([ "", @cols ], \@tds);
101                         }
102                 }
103         print &ui_columns_end();
104         print &ui_links_row(\@links);
105         if ($access{'ifcs'} >= 2) {
106                 print &ui_form_end([ [ "delete", $text{'index_delete1'} ] ]);
107                 }
108         print &ui_tabs_end_tab();
109         }
110
111 # Show interfaces that get activated at boot
112 print &ui_tabs_start_tab("mode", "boot");
113 print $text{'ifcs_bootdesc'},"<p>\n";
114 print &ui_form_start("delete_bifcs.cgi", "post");
115 @links = ( &select_all_link("b", 1),
116            &select_invert_link("b", 1) );
117 if ($allow_add) {
118         push(@links, "<a href='edit_bifc.cgi?new=1'>$text{'ifcs_add'}</a>");
119         if (defined(&supports_bonding) && &supports_bonding()) {
120                 push(@links, "<a href='edit_bifc.cgi?new=1&bond=1'>".
121                              "$text{'bonding_add'}</a>");
122         }
123         if (defined(&supports_vlans) && &supports_vlans()) {
124                 push(@links, "<a href='edit_bifc.cgi?new=1&vlan=1'>".
125                              "$text{'vlan_add'}</a>");
126         }
127         }
128 if ($allow_add && defined(&supports_bridges) && &supports_bridges()) {
129         push(@links, "<a href='edit_bifc.cgi?new=1&bridge=1'>".
130                      "$text{'ifcs_badd'}</a>");
131         }
132 if ($allow_add && defined(&supports_ranges) && &supports_ranges()) {
133         push(@links, "<a href='edit_range.cgi?new=1'>$text{'ifcs_radd'}</a>");
134         }
135 print &ui_links_row(\@links);
136 @tds = ( "width=5 valign=top", "width=20% valign=top", "width=20% valign=top",
137          "width=20% valign=top", "width=20% valign=top" );
138 push(@tds, "width=20% valign=top xxx") if (&supports_address6());
139 push(@tds, "width=5% valign=top");
140 print &ui_columns_start([ "",
141                           $text{'ifcs_name'},
142                           $text{'ifcs_type'},
143                           $text{'ifcs_ip'},
144                           $text{'ifcs_mask'},
145                           &supports_address6() ? ( $text{'ifcs_ip6'} ) : ( ),
146                           $text{'ifcs_act'} ], 100, 0, \@tds);
147
148 @boot = &boot_interfaces();
149 @boot = sort iface_sort @boot;
150 foreach $a (@boot) {
151         local $can = $a->{'edit'} && &can_iface($a);
152         next if ($access{'hide'} && !$can);     # skip hidden
153         local @cols;
154         local @mytds = @tds;
155         if ($a->{'range'} ne "") {
156                 # A range of addresses
157                 local $rng = &text('ifcs_range', $a->{'range'});
158                 if ($can && ($gconfig{'os_type'} eq 'debian-linux') && &has_command("")) {
159                         $link = "edit_bifc.cgi?idx=$a->{'index'}";
160                         if(&iface_type($a->{'name'}) eq 'Bonded'){
161                                 $link = $link . "&bond=1";
162                         } elsif (&iface_type($a->{'name'}) =~ /^(.*) (VLAN)$/) {
163                                 $link = $link . "&vlan=1";
164                         }
165                         push(@cols, "<a href='$link'" . &html_escape($a->{'fullname'})."</a>");
166                         }
167                 elsif($can) {
168                         $link = "edit_bifc.cgi?idx=$a->{'index'}";
169                         push(@cols, "<a href='$link'" . &html_escape($a->{'fullname'})."</a>");
170                 }
171                 else {
172                         push(@cols, &html_escape($rng));
173                         }
174                 push(@cols, &iface_type($a->{'name'}));
175                 push(@cols, "$a->{'start'} - $a->{'end'}");
176                 if (&supports_address6()) {
177                         # IPv6 not possible for ranges
178                         push(@cols, "");
179                         }
180                 splice(@mytds, 3, 2, "colspan=2 width=40% valign=top");
181                 }
182         else {
183                 # A normal single interface
184                 local $mod = &module_for_interface($a);
185                 local %minfo = $mod ? &get_module_info($mod->{'module'}) : ( );
186                 if ($can) {
187                         $link = "edit_bifc.cgi?idx=$a->{'index'}";
188                         if(&iface_type($a->{'name'}) eq 'Bonded'){
189                                 $link = $link . "&bond=1";
190                         } elsif (&iface_type($a->{'name'}) =~ /^(.*) (VLAN)$/) {
191                                 $link = $link . "&vlan=1";
192                         }
193                         push(@cols, "<a href='$link'>"
194                                     .&html_escape($a->{'fullname'})."</a>");
195                         }
196                 else {
197                         push(@cols, &html_escape($a->{'fullname'}));
198                         }
199                 if ($a->{'virtual'} ne "") {
200                         $cols[0] = "&nbsp;&nbsp;".$cols[0];
201                         }
202                 if (%minfo && $minfo{'dir'} eq 'virtual-server') {
203                         # Shorten name
204                         $minfo{'desc'} = $text{'index_vmin'};
205                         }
206                 push(@cols, &iface_type($a->{'name'}).
207                      ($a->{'virtual'} eq "" ||
208                       $mod ? "" : " ($text{'ifcs_virtual'})").
209                      (%minfo ? " ($minfo{'desc'})" : ""));
210                 push(@cols, $a->{'bootp'} ? $text{'ifcs_bootp'} :
211                             $a->{'dhcp'} ? $text{'ifcs_dhcp'} :
212                             $a->{'address'} ? &html_escape($a->{'address'}) :
213                                                $text{'ifcs_noaddress'});
214                 push(@cols, $a->{'bootp'} ? $text{'ifcs_bootp'} :
215                             $a->{'dhcp'} ? $text{'ifcs_dhcp'} :
216                             $a->{'netmask'} ? &html_escape($a->{'netmask'}) :
217                                               $text{'ifcs_nonetmask'});
218                 if (&supports_address6()) {
219                         push(@cols, $a->{'auto6'} ? $text{'ifcs_auto6'} :
220                                       join("<br>\n", map { &html_escape($_) }
221                                                     @{$a->{'address6'}}));
222                         }
223                 }
224         push(@cols, $a->{'up'} ? $text{'yes'} : $text{'no'});
225         if ($can) {
226                 print &ui_checked_columns_row(\@cols, \@mytds, "b",
227                                               $a->{'fullname'});
228                 }
229         else {
230                 print &ui_columns_row([ "", @cols ], \@tds);
231                 }
232         }
233 print &ui_columns_end();
234 print &ui_links_row(\@links);
235 print &ui_form_end([ [ "delete", $text{'index_delete2'} ],
236                      [ "deleteapply", $text{'index_delete3'} ],
237                      undef,
238                      [ "apply", $text{'index_apply2'} ] ]);
239 print &ui_tabs_end_tab();
240
241 print &ui_tabs_end(1);
242
243 &ui_print_footer("", $text{'index_return'});
244
245 sub iface_sort
246 {
247 return $a->{'name'} cmp $b->{'name'} if ($a->{'name'} cmp $b->{'name'});
248 return $a->{'virtual'} eq '' ? -1 :
249        $b->{'virtual'} eq '' ? 1 : $a->{'virtual'} <=> $b->{'virtual'};
250 }
251