Handle hostnames with upper-case letters
[webmin.git] / squid / edit_cache_host.cgi
1 #!/usr/local/bin/perl
2 # edit_cache_host.cgi
3 # Display a form for editing or creating a cache_host line
4
5 require './squid-lib.pl';
6 $access{'othercaches'} || &error($text{'eicp_ecannot'});
7 &ReadParse();
8 $conf = &get_config();
9 $cache_host = $squid_version >= 2 ? "cache_peer" : "cache_host";
10 if ($in{'new'}) {
11         &ui_print_header(undef, $text{'ech_header'}, "", undef, 0, 0, 0, &restart_button());
12         }
13 else {
14         &ui_print_header(undef, $text{'ech_header1'}, "", undef, 0, 0, 0, &restart_button());
15         @chl = &find_config($cache_host, $conf);
16         @ch = @{$chl[$in{'num'}]->{'values'}};
17         for($i=4; $i<@ch; $i++) {
18                 if ($ch[$i] =~ /^(\S+)=(\S+)$/) { $opts{$1} = $2; }
19                 else { $opts{$ch[$i]} = 1; }
20                 }
21         }
22
23 print "<form action=save_cache_host.cgi>\n";
24 if ($in{'new'}) { print "<input type=hidden name=new value=1>\n"; }
25 else { print "<input type=hidden name=num value=$in{'num'}>\n"; }
26 print "<table border width=100%>\n";
27 print "<tr $tb> <td><b>$text{'ech_cho'}</b></td> </tr>\n";
28 print "<tr $cb> <td><table width=100%>\n";
29
30 print "<tr> <td><b>$text{'ech_h'}</b></td>\n";
31 print "<td><input name=host size=20 value=\"$ch[0]\"></td>\n";
32
33 %ts = ( "parent"=> $text{"ech_parent"},
34         "sibling"=>$text{"ech_sibling"},
35         "multicast"=>$text{"ech_multicast"} );
36 print "<td><b>$text{'ech_t'}</b></td>\n";
37 print "<td><select name=type>\n";
38 foreach $t (keys %ts) {
39         printf "<option value=$t %s>$ts{$t}\n", $t eq $ch[1] ? "selected" : "";
40         }
41 print "</select></td> </tr>\n";
42
43 print "<tr> <td><b>$text{'ech_pp'}</b></td>\n";
44 print "<td><input name=proxy size=6 value=\"$ch[2]\"></td>\n";
45
46 print "<td><b>$text{'ech_ip'}</b></td>\n";
47 print "<td><input name=icp size=6 value=\"$ch[3]\"></td> </tr>\n";
48
49 print "<tr> <td><b>$text{'ech_po'}</b></td>\n";
50 printf "<td><input type=radio name=proxy-only value=1 %s> $text{'ech_y'}\n",
51         $opts{'proxy-only'} ? "checked" : "";
52 printf "<input type=radio name=proxy-only value=0 %s> $text{'ech_n'}</td>\n",
53         $opts{'proxy-only'} ? "" : "checked";
54
55 print "<td><b>$text{'ech_siq'}</b></td>\n";
56 printf "<td><input type=radio name=no-query value=0 %s> $text{'ech_y'}\n",
57         $opts{'no-query'} ? "" : "checked";
58 printf "<input type=radio name=no-query value=1 %s> $text{'ech_n'}</td> </tr>\n",
59         $opts{'no-query'} ? "checked" : "";
60
61 print "<tr> <td><b>$text{'ech_dc'}</b></td>\n";
62 printf "<td><input type=radio name=default value=1 %s> $text{'ech_y'}\n",
63         $opts{'default'} ? "checked" : "";
64 printf "<input type=radio name=default value=0 %s> $text{'ech_n'}</td>\n",
65         $opts{'default'} ? "" : "checked";
66
67 print "<td><b>$text{'ech_rrc'}</b></td>\n";
68 printf "<td><input type=radio name=round-robin value=1 %s> $text{'ech_y'}\n",
69         $opts{'round-robin'} ? "checked" : "";
70 printf "<input type=radio name=round-robin value=0 %s> $text{'ech_n'}</td> </tr>\n",
71         $opts{'round-robin'} ? "" : "checked";
72
73 print "<tr> <td><b>$text{'ech_ittl'}</b></td>\n";
74 printf "<td><input type=radio name=ttl_def value=1 %s> $text{'ech_d'}\n",
75         $opts{'ttl'} ? "" : "checked";
76 printf "<input type=radio name=ttl_def value=0 %s>\n",
77         $opts{'ttl'} ? "checked" : "";
78 print "<input name=ttl size=6 value=\"$opts{'ttl'}\"></td>\n";
79
80 print "<td><b>$text{'ech_cw'}</b></td>\n";
81 printf "<td><input type=radio name=weight_def value=1 %s> $text{'ech_d'}\n",
82         $opts{'weight'} ? "" : "checked";
83 printf "<input type=radio name=weight_def value=0 %s>\n",
84         $opts{'weight'} ? "checked" : "";
85 print "<input name=weight size=6 value=\"$opts{'weight'}\"></td> </tr>\n";
86
87 if ($squid_version >= 2) {
88         print "<tr> <td><b>$text{'ech_co'}</b></td>\n";
89         printf "<td><input type=radio name=closest-only value=1 %s> $text{'ech_y'}\n",
90                 $opts{'closest-only'} ? "checked" : "";
91         printf "<input type=radio name=closest-only value=0 %s> $text{'ech_n'}</td>\n",
92                 $opts{'closest-only'} ? "" : "checked";
93
94         print "<td><b>$text{'ech_nd'}</b></td>\n";
95         printf "<td><input type=radio name=no-digest value=1 %s> $text{'ech_y'}\n",
96                 $opts{'no-digest'} ? "checked" : "";
97         printf "<input type=radio name=no-digest value=0 %s> $text{'ech_n'}</td> </tr>\n",
98                 $opts{'no-digest'} ? "" : "checked";
99
100         print "<tr> <td><b>$text{'ech_nne'}</b></td>\n";
101         printf "<td><input type=radio name=no-netdb-exchange value=1 %s> $text{'ech_y'}\n",
102                 $opts{'no-netdb-exchange'} ? "checked" : "";
103         printf "<input type=radio name=no-netdb-exchange value=0 %s> $text{'ech_n'}</td>\n",
104                 $opts{'no-netdb-exchange'} ? "" : "checked";
105
106         print "<td><b>$text{'ech_nd1'}</b></td>\n";
107         printf "<td><input type=radio name=no-delay value=1 %s> $text{'ech_y'}\n",
108                 $opts{'no-delay'} ? "checked" : "";
109         printf "<input type=radio name=no-delay value=0 %s> $text{'ech_n'}</td> </tr>\n",
110                 $opts{'no-delay'} ? "" : "checked";
111         }
112
113 if ($squid_version >= 2.1) {
114         local $mode = $opts{'login'} eq 'PASS' ? 2 :
115                       $opts{'login'} =~ /^\*:\S+$/ ? 3 :
116                       $opts{'login'} ? 1 : 0;
117         local @up = split(/:/, $opts{'login'});
118         print "<tr> <td valign=top><b>$text{'ech_ltp'}</b></td>\n";
119         print "<td colspan=3>\n";
120         printf "<input type=radio name=login value=0 %s> $text{'ech_nl'}<br>\n",
121                 $mode == 0 ? "checked" : "";
122         printf "<input type=radio name=login value=1 %s>\n",
123                 $mode == 1 ? "checked" : "";
124         printf "$text{'ech_u'} <input name=login_user size=15 value=\"%s\">\n", $mode == 1 ? $up[0] : "";
125                 
126         printf "$text{'ech_p'} <input name=login_pass size=15 value=\"%s\"><br>\n", $mode == 1 ? $up[1] : "";
127         if ($squid_version >= 2.5 || $mode > 1) {
128                 printf "<input type=radio name=login value=2 %s> %s<br>\n",
129                         $mode == 2 ? "checked" : "",
130                         $text{'ech_pass'};
131                 printf "<input type=radio name=login value=3 %s> %s\n",
132                         $mode == 3 ? "checked" : "",
133                         $text{'ech_upass'};
134                 printf "<input name=login_pass2 size=15 value=\"%s\">\n",
135                         $mode == 3 ? $up[1] : "";
136                 }
137         print "</td> </tr>\n";
138         }
139
140 if ($squid_version >= 2.6) {
141         print "<tr> <td><b>$text{'ech_timeo'}</b></td>\n";
142         printf "<td><input type=radio name=connect-timeout_def value=1 %s> $text{'ech_d'}\n",
143                 $opts{'connect-timeout'} ? "" : "checked";
144         printf "<input type=radio name=connect-timeout_def value=0 %s>\n",
145                 $opts{'connect-timeout'} ? "checked" : "";
146         print "<input name=connect-timeout size=6 value=\"$opts{'connect-timeout'}\"></td>\n";
147
148         print "<td><b>$text{'ech_digest'}</b></td>\n";
149         printf "<td><input type=radio name=digest-url_def value=1 %s> $text{'ech_d'}\n",
150                 $opts{'digest-url'} ? "" : "checked";
151         printf "<input type=radio name=digest-url_def value=0 %s>\n",
152                 $opts{'digest-url'} ? "checked" : "";
153         print "<input name=digest-url size=20 value=\"$opts{'digest-url'}\"></td> </tr>\n";
154
155         print "<tr> <td><b>$text{'ech_miss'}</b></td>\n";
156         printf "<td><input type=radio name=allow-miss value=1 %s> $text{'ech_y'}\n",
157                 $opts{'allow-miss'} ? "checked" : "";
158         printf "<input type=radio name=allow-miss value=0 %s> $text{'ech_n'}</td>\n",
159                 $opts{'allow-miss'} ? "" : "checked";
160
161         print "<td><b>$text{'ech_maxconn'}</b></td>\n";
162         printf "<td><input type=radio name=max-conn_def value=1 %s> $text{'ech_d'}\n",
163                 $opts{'max-conn'} ? "" : "checked";
164         printf "<input type=radio name=max-conn_def value=0 %s>\n",
165                 $opts{'max-conn'} ? "checked" : "";
166         print "<input name=max-conn size=6 value=\"$opts{'max-conn'}\"></td> </tr>\n";
167
168         print "<tr> <td><b>$text{'ech_htcp'}</b></td>\n";
169         printf "<td><input type=radio name=htcp value=1 %s> $text{'ech_y'}\n",
170                 $opts{'htcp'} ? "checked" : "";
171         printf "<input type=radio name=htcp value=0 %s> $text{'ech_n'}</td>\n",
172                 $opts{'htcp'} ? "" : "checked";
173
174         print "<td><b>$text{'ech_force'}</b></td>\n";
175         printf "<td><input type=radio name=forceddomain_def value=1 %s> %s\n",
176                 $opts{'forceddomain'} ? "" : "checked", $text{'ech_same'};
177         printf "<input type=radio name=forceddomain_def value=0 %s>\n",
178                 $opts{'forceddomain'} ? "checked" : "";
179         print "<input name=forceddomain size=20 value=\"$opts{'forceddomain'}\"></td> </tr>\n";
180
181         print "<tr> <td><b>$text{'ech_origin'}</b></td>\n";
182         printf "<td><input type=radio name=originserver value=1 %s> $text{'ech_y'}\n",
183                 $opts{'originserver'} ? "checked" : "";
184         printf "<input type=radio name=originserver value=0 %s> $text{'ech_n'}</td>\n",
185                 $opts{'originserver'} ? "" : "checked";
186
187         print "<td><b>$text{'ech_ssl'}</b></td>\n";
188         printf "<td><input type=radio name=ssl value=1 %s> $text{'ech_y'}\n",
189                 $opts{'ssl'} ? "checked" : "";
190         printf "<input type=radio name=ssl value=0 %s> $text{'ech_n'}</td> </tr>\n",
191                 $opts{'ssl'} ? "" : "checked";
192         }
193
194 print "<tr> <td><b>$text{'ech_mr'}</b></td>\n";
195 printf "<td><input type=radio name=multicast-responder value=1 %s> $text{'ech_y'}\n",
196         $opts{'multicast-responder'} ? "checked" : "";
197 printf "<input type=radio name=multicast-responder value=0 %s> $text{'ech_n'}</td>\n",
198         $opts{'multicast-responder'} ? "" : "checked";
199 print "</tr>\n";
200
201 if (!$in{'new'}) {
202         @chd = &find_config($cache_host."_domain", $conf);
203         foreach $chd (@chd) {
204                 @chdv = @{$chd->{'values'}};
205                 if ($chdv[0] eq $ch[0]) {
206                         # found a record for this host..
207                         for($i=1; $i<@chdv; $i++) {
208                                 if ($chdv[$i] =~ /^\!(\S+)$/) {
209                                         push(@dontq, $1);
210                                         }
211                                 else { push(@doq, $chdv[$i]); }
212                                 }
213                         }
214                 }
215         }
216 print "<tr> <td valign=top><b>$text{'ech_qhfd'}</b></td>\n";
217 print "<td><textarea name=doq rows=6 cols=25>",join("\n", @doq),
218       "</textarea></td>\n";
219 print "<td valign=top><b>$text{'ech_dqfd'}</b></td>\n";
220 print "<td><textarea name=dontq rows=6 cols=25>",join("\n", @dontq),
221       "</textarea></td> </tr>\n";
222
223 print "</table></td></tr></table>\n";
224 print "<table width=100%><tr>\n";
225 print "<td><input type=submit value=$text{'ech_buttsave'}></td> <td align=right>\n";
226 if (!$in{'new'}) { print "<input type=submit value=$text{'ech_buttdel'} name=delete>\n"; }
227 print "</td></tr></table>\n";
228 print "</form>\n";
229
230 &ui_print_footer("edit_icp.cgi", $text{'ech_return'},
231         "", $text{'index_return'});
232