Handle hostnames with upper-case letters
[webmin.git] / squid / edit_icp.cgi
1 #!/usr/local/bin/perl
2 # edit_icp.cgi
3 # A form for editing options for communication with other caches
4
5 require './squid-lib.pl';
6 $access{'othercaches'} || &error($text{'eicp_ecannot'});
7 &ui_print_header(undef, $text{'eicp_header'}, "", "edit_icp", 0, 0, 0, &restart_button());
8 $conf = &get_config();
9 $cache_host = $squid_version >= 2 ? "cache_peer" : "cache_host";
10
11 @ch = &find_config($cache_host, $conf);
12 @links = ( &select_all_link("d"),
13            &select_invert_link("d"),
14            "<a href='edit_cache_host.cgi?new=1'>$text{'eicp_aac'}</a>" );
15 if (@ch) {
16         #print &ui_subheading($text{'eicp_opcs'});
17         $mid = int((@ch+1)/2);
18         print &ui_form_start("delete_icps.cgi", "post");
19         print &ui_links_row(\@links);
20         print "<table width=100%><tr> <td width=50% valign=top>\n";
21         &cache_table(0, $mid-1);
22         print "</td><td width=50% valign=top>\n";
23         if ($mid < @ch) { &cache_table($mid, $#ch); }
24         print "</td> </tr></table>\n";
25         print &ui_links_row(\@links);
26         print &ui_form_end([ [ "delete", $text{'eicp_delete'} ] ]);
27         }
28 else {
29         print "<b>$text{'eicp_nocd'}</b>.<p>\n";
30         print &ui_links_row([ $links[2] ]);
31         }
32
33 print &ui_hr();
34 print "<form action=save_icp.cgi>\n";
35 print "<table border width=100%>\n";
36 print "<tr $tb> <td><b>$text{'eicp_cso'}</b></td> </tr>\n";
37 print "<tr $cb> <td><table width=100%>\n";
38
39 if ($squid_version < 2) {
40         print "<tr>\n";
41         print &list_input($text{'eicp_fdfd'}, "local_domain", $conf);
42         print &address_input($text{'eicp_fdfi'}, "local_ip", $conf);
43         print "</tr>\n";
44
45         print "<tr>\n";
46         print &list_input($text{'eicp_dif'}, "inside_firewall", $conf);
47         print &address_input($text{'eicp_iif'}, "firewall_ip", $conf);
48         print "</tr>\n";
49         }
50
51 print "<tr>\n";
52 print &list_input($text{'eicp_dfuc'}, "hierarchy_stoplist",
53                   $conf, 1, $text{'default'});
54 print "</tr>\n";
55
56 if ($squid_version < 2) {
57         print "<tr>\n";
58         print &choice_input($text{'eicp_bpfsp'},
59                             "single_parent_bypass",
60                             $conf, "off", $text{'yes'}, "on", $text{'no'}, "off");
61         print &choice_input($text{'eicp_ssip'}, "source_ping", $conf, "off",
62                             $text{'yes'}, "on", $text{'no'}, "off");
63         print "</tr>\n";
64
65         print "<tr>\n";
66         print &opt_input($text{'eicp_crt'}, "neighbor_timeout", $conf,
67                          $text{'default'}, 4, $text{'eicp_secs'});
68         print "</tr>\n";
69         }
70 else {
71         print "<tr>\n";
72         print &opt_input($text{'eicp_iqt'}, "icp_query_timeout", $conf,
73                          $text{'default'}, 8, "ms");
74         print &opt_input($text{'eicp_mit'}, "mcast_icp_query_timeout",
75                          $conf, $text{'default'}, 8, "ms");
76         print "</tr>\n";
77
78         print "<tr>\n";
79         print &opt_input($text{'eicp_dpt'}, "dead_peer_timeout", $conf,
80                          $text{'default'}, 8, $text{'eicp_secs'});
81         print "</tr>\n";
82         }
83
84 if ($squid_version >= 2.3) {
85         # Display always/never_direct options
86         print "<tr> <td colspan=4><hr></td> </tr>\n";
87
88         print "<tr> <td colspan=2 valign=top width=50%>\n";
89         @always = &find_config("always_direct", $conf);
90         if (@always) {
91                 print "<b>$text{'eicp_always'}</b><p>\n";
92                 print "<table border>\n";
93                 print "<tr $tb><td width=10%><b>$text{'eacl_act'}</b></td>\n";
94                 print "<td><b>$text{'eacl_acls1'}</b></td>\n";
95                 print "<td width=10%><b>$text{'eacl_move'}</b></td> </tr>\n";
96                 $hc = 0;
97                 foreach $h (@always) {
98                         @v = @{$h->{'values'}};
99                         if ($v[0] eq "allow") {
100                                 $v[0] = $text{'eacl_allow'};
101                         } else {
102                                 $v[0] = $text{'eacl_deny'};
103                         }
104                         print "<tr $cb>\n";
105                         print "<td><a href=\"always.cgi?index=$h->{'index'}\">",
106                               "$v[0]</a></td>\n";
107                         print "<td>",&html_escape(join(' ', @v[1..$#v])),
108                               "</td>\n";
109                         print "<td>\n";
110                         if ($hc != @always-1) {
111                                 print "<a href=\"move_always.cgi?$hc+1\">",
112                                       "<img src=images/down.gif border=0></a>";
113                                 }
114                         else { print "<img src=images/gap.gif>"; }
115                         if ($hc != 0) {
116                                 print "<a href=\"move_always.cgi?$hc+-1\">",
117                                       "<img src=images/up.gif border=0></a>";
118                                 }
119                         print "</td></tr>\n";
120                         $hc++;
121                         }
122                 print "</table>\n";
123                 }
124         else {
125                 print "<b>$text{'eicp_noalways'}</b><p>\n";
126                 }
127         print "<a href=always.cgi?new=1>$text{'eicp_addalways'}</a>\n";
128
129         print "</td> <td colspan=2 valign=top width=50%>\n";
130         @never = &find_config("never_direct", $conf);
131         if (@never) {
132                 print "<b>$text{'eicp_never'}</b><p>\n";
133                 print "<table border>\n";
134                 print "<tr $tb><td width=10%><b>$text{'eacl_act'}</b></td>\n";
135                 print "<td><b>$text{'eacl_acls1'}</b></td>\n";
136                 print "<td width=10%><b>$text{'eacl_move'}</b></td> </tr>\n";
137                 $hc = 0;
138                 foreach $h (@never) {
139                         @v = @{$h->{'values'}};
140                         if ($v[0] eq "allow") {
141                                 $v[0] = $text{'eacl_allow'};
142                         } else {
143                                 $v[0] = $text{'eacl_deny'};
144                         }
145                         print "<tr $cb>\n";
146                         print "<td><a href=\"never.cgi?index=$h->{'index'}\">",
147                               "$v[0]</a></td>\n";
148                         print "<td>",&html_escape(join(' ', @v[1..$#v])),
149                               "</td>\n";
150                         print "<td>\n";
151                         if ($hc != @never-1) {
152                                 print "<a href=\"move_never.cgi?$hc+1\">",
153                                       "<img src=images/down.gif border=0></a>";
154                                 }
155                         else { print "<img src=images/gap.gif>"; }
156                         if ($hc != 0) {
157                                 print "<a href=\"move_never.cgi?$hc+-1\">",
158                                       "<img src=images/up.gif border=0></a>";
159                                 }
160                         print "</td></tr>\n";
161                         $hc++;
162                         }
163                 print "</table>\n";
164                 }
165         else {
166                 print "<b>$text{'eicp_nonever'}</b><p>\n";
167                 }
168         print "<a href=never.cgi?new=1>$text{'eicp_addnever'}</a>\n";
169         print "</td> </tr>\n";
170         }
171
172 print "</table></td></tr></table>\n";
173 print "<input type=submit value=$text{'buttsave'}></form>\n";
174
175 &ui_print_footer("", $text{'eicp_return'});
176
177 # cache_table(start, end)
178 sub cache_table
179 {
180 local @tds = ( "width=5" );
181 print &ui_columns_start([ "",
182                           $text{'eicp_thost'},
183                           $text{'eicp_ttype'},
184                           $text{'eicp_tpport'},
185                           $text{'eicp_tiport'} ], 100, 0, \@tds);
186 for($i=$_[0]; $i<=$_[1]; $i++) {
187         @chv = @{$ch[$i]->{'values'}};
188         print &ui_checked_columns_row([
189                 "<a href=\"edit_cache_host.cgi?num=$i\">".
190                 &html_escape($chv[0])."</a>",
191                 &html_escape($chv[1]),
192                 &html_escape($chv[2]),
193                 &html_escape($chv[3])
194                 ], \@tds, "d", $i);
195         }
196 print &ui_columns_end();
197 }
198