Handle hostnames with upper-case letters
[webmin.git] / squid / edit_ports.cgi
1 #!/usr/local/bin/perl
2 # edit_ports.cgi
3 # A form for editing ports and other networking options
4
5 require './squid-lib.pl';
6 $access{'portsnets'} || &error($text{'eports_ecannot'});
7 &ui_print_header(undef, $text{'eports_header'}, "", "edit_ports", 0, 0, 0, &restart_button());
8 $conf = &get_config();
9
10 print "<form action=save_ports.cgi>\n";
11 print "<table border width=100%>\n";
12 print "<tr $tb> <td><b>$text{'eports_pano'}</b></td> </tr>\n";
13 print "<tr $cb> <td><table width=100%>\n";
14
15 print "<tr>\n";
16 if ($squid_version >= 2.3) {
17         # Display table of normal ports
18         print "<td valign=top><b>$text{'eports_paap'}</b></td><td colspan=3>\n";
19         &ports_table("http_port");
20         print "</table></td></tr>\n";
21
22         if ($squid_version >= 2.5) {
23                 # Display table of SSL ports
24                 print "<tr> <td valign=top><b>$text{'eports_ssl'}</b></td><td colspan=3>\n";
25                 &ports_table("https_port");
26                 print "</table></td></tr>\n";
27                 }
28         print "<tr>\n";
29         print &opt_input($text{'eports_ip'}, "icp_port", 
30                                 $conf, $text{'default'}, 6);
31         }
32 else {
33         # Just show single-port inputs
34         print &opt_input($text{'eports_pp'}, "http_port", 
35                                 $conf, $text{'default'}, 6);
36         print &opt_input($text{'eports_ip'}, "icp_port", 
37                                 $conf, $text{'default'}, 6);
38         print "</tr>\n";
39
40         print "<tr>\n";
41         print &opt_input($text{'eports_ita'}, "tcp_incoming_address",
42                          $conf, $text{'eports_a'}, 15);
43         }
44
45 print &opt_input($text{'eports_ota'}, "tcp_outgoing_address",
46                  $conf, $text{'eports_a'}, 15);
47 print "</tr>\n";
48
49 print "<tr>\n";
50 print &opt_input($text{'eports_oua'}, "udp_outgoing_address",
51                  $conf, $text{'eports_a'}, 15);
52 print &opt_input($text{'eports_iua'}, "udp_incoming_address",
53                  $conf, $text{'eports_a'}, 15);
54 print "</tr>\n";
55
56 print "<tr>\n";
57 print &address_input($text{'eports_mg'}, "mcast_groups", $conf, 0);
58 print &opt_input($text{'eports_trb'}, "tcp_recv_bufsize", $conf,
59                  $text{'eports_od'}, 6);
60 print "</tr>\n";
61
62 if ($squid_version >= 2.6) {
63         print "<tr>\n";
64         print &choice_input($text{'eports_checkhost'}, "check_hostnames",
65                             $conf, "on", $text{'yes'}, "on", $text{'no'},"off");
66         print &choice_input($text{'eports_underscore'}, "allow_underscore",
67                             $conf, "on", $text{'yes'}, "on", $text{'no'},"off");
68         print "</tr>\n";
69         }
70
71 if ($squid_version >= 2.5) {
72         print "<tr>\n";
73         print &choice_input($text{'eports_unc'}, "ssl_unclean_shutdown",
74                             $conf, "off", $text{'on'},"on", $text{'off'},"off");
75         print "</tr>\n";
76         }
77
78 print "</table></td></tr></table>\n";
79 print "<input type=submit value=$text{'buttsave'}></form>\n";
80
81 &ui_print_footer("", $text{'eports_return'});
82
83 # ports_table(name)
84 sub ports_table
85 {
86 local ($p, $i, @ports, @opts);
87 foreach $p (&find_config($_[0], $conf)) {
88         foreach $v (@{$p->{'values'}}) {
89                 if ($v =~ /^(\S+):\d+$/ || $v =~ /^\d+$/) {
90                         push(@ports, $v);
91                         }
92                 else {
93                         push(@{$opts[$#ports]}, $v);
94                         }
95                 }
96         }
97 printf "<input type=radio name=$_[0]_ports_def value=1 %s> %s\n",
98         @ports ? "" : "checked", $text{'eports_def'};
99 printf "<input type=radio name=$_[0]_ports_def value=0 %s> %s<br>\n",
100         @ports ? "checked" : "", $text{'eports_sel'};
101 print "<table border>\n";
102 print "<tr $tb> <td><b>$text{'eports_p'}</b></td>\n",
103       "<td><b>$text{'eports_hia'}</b></td> ",
104       ($squid_version >= 2.5 ? "<td><b>$text{'eports_opts'}</b></td> "
105                              : ""),"</tr>\n";
106 $i = 0;
107 foreach $p (@ports, '') {
108         print "<tr $cb>\n";
109         printf "<td><input name=$_[0]_port_$i size=6 value='%s'></td> <td>\n",
110                 $p =~ /(\d+)$/ ? $1 : '';
111         printf "<input type=radio name=$_[0]_addr_def_$i value=1 %s> All\n",
112                 $p =~ /:/ ? '' : 'checked';
113         printf "<input type=radio name=$_[0]_addr_def_$i value=0 %s>\n",
114                 $p =~ /:/ ? 'checked' : '';
115         printf "<input name=$_[0]_addr_$i size=20 value='%s'></td>\n",
116                 $p =~ /^\[(\S+)\]:/ || $p =~ /^(\S+):/ ? $1 : '';
117         if ($squid_version >= 2.5) {
118                 # Show port options
119                 printf "<td><input name=$_[0]_opts_$i size=40 value='%s'></td>\n",
120                         join(" ", @{$opts[$i]});
121                 }
122         print "</tr>\n";
123         $i++;
124         }
125 }
126