Handle hostnames with upper-case letters
[webmin.git] / net / interface_chooser.cgi
1 #!/usr/local/bin/perl
2 # interface_chooser.cgi
3 #
4 # Based on user_chooser.cgi by Jamie Cameron
5 # (c) Tomas Pospisek <tpo_deb@sourcepole.ch>
6 # Licensed under the webmin license
7 #
8 # made possible by: 
9 #       Sourcepole          http://sourcepole.ch
10 # under contract from:
11 #       AO Media Services   http://www.ao-asif.ch/aoi/media/
12 # Thanks!
13
14 # TODO:
15 # replace active_interfaces by a merged list from active_* and boot_interfaces
16
17 # This CGI generated the HTML for choosing an interface or a list of interfaces.
18
19 require './net-lib.pl';
20 &init_config();
21 &ReadParse();
22 %access = &get_module_acl();
23
24 if ($in{'multi'}) {
25         # selecting multiple interfaces.
26         if ($in{'frame'} == 0) {
27                 # base frame
28                 &PrintHeader();
29                 print "<script>\n";
30                 @il = split(/\s+/, $in{'interface'});
31                 $len = @il;
32                 print "sel = new Array($len);\n";
33                 for($i=0; $i<$len; $i++) {
34                         print "sel[$i] = \"$il[$i]\";\n";
35                         }
36                 print "</script>\n";
37                 print "<title>$text{'interfaces_title1'}</title>\n";
38                 print "<frameset cols='50%,50%'>\n";
39                 print "<frame src=\"/net/interface_chooser.cgi?frame=1&multi=1\">\n";
40                 print "<frameset rows='*,50' frameborder=no>\n";
41                 print " <frame src=\"/net/interface_chooser.cgi?frame=2&multi=1\">\n";
42                 print " <frame src=\"/net/interface_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
43                 print "</frameset>\n";
44                 print "</frameset>\n";
45                 }
46         elsif ($in{'frame'} == 1) {
47                 # list of all interfaces to choose from
48                 &ui_print_header(undef, );
49                 print "<script>\n";
50                 print "function addinterface(i)\n";
51                 print "{\n";
52                 print "top.sel[top.sel.length] = i\n";
53                 print "top.frames[1].location = top.frames[1].location\n";
54                 print "return false;\n";
55                 print "}\n";
56                 print "</script>\n";
57                 print "<font size=+1>$text{'interfaces_all'}</font>\n";
58                 print "<table width=100%>\n";
59                 foreach $if (&active_interfaces()) {
60                         if ($in{'interface'} eq $if->{'fullname'}) { print "<tr $cb>\n"; }
61                         else { print "<tr>\n"; }
62                         print "<td width=20%><a href=\"\" onClick='return addinterface(\"$if->{'fullname'}\")'>$if->{'fullname'}</a></td>\n";
63                         }
64                 print "</table>\n";
65                 }
66         elsif ($in{'frame'} == 2) {
67                 # show chosen interfaces
68                 &ui_print_header(undef, );
69                 print "<font size=+1>$text{'interfaces_sel'}</font>\n";
70                 print <<'EOF';
71 <table width=100%>
72 <script>
73 function sub(j)
74 {
75   sel2 = new Array();
76   for(k=0,l=0; k<top.sel.length; k++) {
77         if (k != j) {
78                 sel2[l] = top.sel[k];
79                 l++;
80                 }
81         }
82   top.sel = sel2;
83   top.frames[1].location = top.frames[1].location;
84   return false;
85 }
86 for(i=0; i<top.sel.length; i++) {
87         document.write("<tr>\n");
88         document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
89         }
90 </script>
91 </table>
92 EOF
93                 }
94         elsif ($in{'frame'} == 3) {
95                 # output OK and Cancel buttons
96                 &ui_print_header(undef, );
97                 print "<form>\n";
98                 print "<input type=button value=\"$text{'interfaces_ok'}\" ",
99                       "onClick='top.ifield.value = top.sel.join(\" \"); ",
100                       "top.close()'>\n";
101                 print "<input type=button value=\"$text{'interfaces_cancel'}\" ",
102                       "onClick='top.close()'>\n";
103                 print "&nbsp;&nbsp;<input type=button value=\"$text{'interfaces_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
104                 print "</form>\n";
105                 }
106         }
107 else {
108         # selecting just one interface .. display a list of all interfaces to choose from
109         &ui_print_header(undef, );
110         print "<script>\n";
111         print "function select(f)\n";
112         print "{\n";
113         print "ifield.value = f;\n";
114         print "top.close();\n";
115         print "return false;\n";
116         print "}\n";
117         print "</script>\n";
118         print "<title>$text{'interfaces_title2'}</title>\n";
119         print "<table width=100%>\n";
120         foreach $if (&active_interfaces()) {
121                 if ($in{'interface'} eq $if->{'fullname'}) { print "<tr $cb>\n"; }
122                 else { print "<tr>\n"; }
123                 print "<td width=20%><a href=\"\" onClick='return select(\"$if->{'fullname'}\")'>$if->{'fullname'}</a></td></tr>\n";
124                 }
125         print "</table>\n";
126         }
127