369a5cb1f97846982cb7386b6f385a7e09746c59
[ipfire-2.x.git] / html / cgi-bin / proxy.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 #                                                                             #
4 # IPFire.org - A linux based firewall                                         #
5 # Copyright (C) 2007-2013  IPFire Team  <info@ipfire.org>                     #
6 #                                                                             #
7 # This program is free software: you can redistribute it and/or modify        #
8 # it under the terms of the GNU General Public License as published by        #
9 # the Free Software Foundation, either version 3 of the License, or           #
10 # (at your option) any later version.                                         #
11 #                                                                             #
12 # This program is distributed in the hope that it will be useful,             #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
15 # GNU General Public License for more details.                                #
16 #                                                                             #
17 # You should have received a copy of the GNU General Public License           #
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
19 #                                                                             #
20 ###############################################################################
21 #
22 # (c) 2004-2009 marco.s - http://www.advproxy.net
23 #
24 # This code is distributed under the terms of the GPL
25 #
26 # $Id: advproxy.cgi,v 3.0.2 2009/02/04 00:00:00 marco.s Exp $
27 #
28
29 use strict;
30 use Apache::Htpasswd;
31
32 # enable only the following on debugging purpose
33 #use warnings;
34 #use CGI::Carp 'fatalsToBrowser';
35
36 require '/var/ipfire/general-functions.pl';
37 require "${General::swroot}/lang.pl";
38 require "${General::swroot}/header.pl";
39
40 my @squidversion = `/usr/sbin/squid -v`;
41 my $http_port='81';
42 my $https_port='444';
43
44 my %color = ();
45 my %mainsettings = ();
46 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
47 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
48
49 my %proxysettings=();
50 my %netsettings=();
51 my %filtersettings=();
52 my %xlratorsettings=();
53 my %stdproxysettings=();
54 my %mainsettings=();
55
56 my %checked=();
57 my %selected=();
58
59 my @throttle_limits=(64,128,256,512,1024,1536,2048,3072,4096,5120,6144,7168,8192,10240,16384,20480,51200,102400);
60
61 my $def_ports_safe="80 # http\n21 # ftp\n443 # https\n563 # snews\n70 # gopher\n210 # wais\n1025-65535 # unregistered ports\n280 # http-mgmt\n488 # gss-http\n591 # filemaker\n777 # multiling http\n800 # Squids port (for icons)\n";
62 my $def_ports_ssl="443 # https\n563 # snews\n";
63
64 my $hintcolour='#FFFFCC';
65 my $ncsa_buttontext='';
66 my $language='';
67 my $i=0;
68 my $n=0;
69 my $id=0;
70 my $line='';
71 my $user='';
72 my @userlist=();
73 my @grouplist=();
74 my @temp=();
75 my @templist=();
76
77 my $cachemem=0;
78 my $proxy1='';
79 my $proxy2='';
80 my $browser_regexp='';
81 my $needhup = 0;
82 my $errormessage='';
83
84 my $acldir   = "${General::swroot}/proxy/advanced/acls";
85 my $ncsadir  = "${General::swroot}/proxy/advanced/ncsa";
86 my $raddir   = "${General::swroot}/proxy/advanced/radius";
87 my $identdir = "${General::swroot}/proxy/advanced/ident";
88 my $credir   = "${General::swroot}/proxy/advanced/cre";
89
90 my $userdb = "$ncsadir/passwd";
91 my $stdgrp = "$ncsadir/standard.grp";
92 my $extgrp = "$ncsadir/extended.grp";
93 my $disgrp = "$ncsadir/disabled.grp";
94
95 my $mimetypes = "${General::swroot}/proxy/advanced/mimetypes";
96 my $throttled_urls = "${General::swroot}/proxy/advanced/throttle";
97
98 my $cre_enabled = "${General::swroot}/proxy/advanced/cre/enable";
99 my $cre_groups  = "${General::swroot}/proxy/advanced/cre/classrooms";
100 my $cre_svhosts = "${General::swroot}/proxy/advanced/cre/supervisors";
101
102 my $identhosts = "$identdir/hosts";
103
104 my $authdir  = "/usr/lib/squid";
105 my $errordir = "/usr/lib/squid/errors";
106
107 my $acl_src_subnets = "$acldir/src_subnets.acl";
108 my $acl_src_banned_ip  = "$acldir/src_banned_ip.acl";
109 my $acl_src_banned_mac = "$acldir/src_banned_mac.acl";
110 my $acl_src_unrestricted_ip  = "$acldir/src_unrestricted_ip.acl";
111 my $acl_src_unrestricted_mac = "$acldir/src_unrestricted_mac.acl";
112 my $acl_src_noaccess_ip  = "$acldir/src_noaccess_ip.acl";
113 my $acl_src_noaccess_mac = "$acldir/src_noaccess_mac.acl";
114 my $acl_dst_noauth   = "$acldir/dst_noauth.acl";
115 my $acl_dst_noauth_dom = "$acldir/dst_noauth_dom.acl";
116 my $acl_dst_noauth_net = "$acldir/dst_noauth_net.acl";
117 my $acl_dst_noauth_url = "$acldir/dst_noauth_url.acl";
118 my $acl_dst_nocache  = "$acldir/dst_nocache.acl";
119 my $acl_dst_nocache_dom = "$acldir/dst_nocache_dom.acl";
120 my $acl_dst_nocache_net = "$acldir/dst_nocache_net.acl";
121 my $acl_dst_nocache_url = "$acldir/dst_nocache_url.acl";
122 my $acl_dst_throttle = "$acldir/dst_throttle.acl";
123 my $acl_ports_safe = "$acldir/ports_safe.acl";
124 my $acl_ports_ssl  = "$acldir/ports_ssl.acl";
125 my $acl_include = "$acldir/include.acl";
126
127 my $acl_dst_noproxy_url = "$acldir/dst_noproxy_url.acl";
128 my $acl_dst_noproxy_ip = "$acldir/dst_noproxy_ip.acl";
129
130 my $updaccelversion  = 'n/a';
131 my $urlfilterversion = 'n/a';
132
133 unless (-d "$acldir")   { mkdir("$acldir"); }
134 unless (-d "$ncsadir")  { mkdir("$ncsadir"); }
135 unless (-d "$raddir")   { mkdir("$raddir"); }
136 unless (-d "$identdir") { mkdir("$identdir"); }
137 unless (-d "$credir")   { mkdir("$credir"); }
138
139 unless (-e $cre_groups)  { system("touch $cre_groups"); }
140 unless (-e $cre_svhosts) { system("touch $cre_svhosts"); }
141
142 unless (-e $userdb) { system("touch $userdb"); }
143 unless (-e $stdgrp) { system("touch $stdgrp"); }
144 unless (-e $extgrp) { system("touch $extgrp"); }
145 unless (-e $disgrp) { system("touch $disgrp"); }
146
147 unless (-e $acl_src_subnets)    { system("touch $acl_src_subnets"); }
148 unless (-e $acl_src_banned_ip)  { system("touch $acl_src_banned_ip"); }
149 unless (-e $acl_src_banned_mac) { system("touch $acl_src_banned_mac"); }
150 unless (-e $acl_src_unrestricted_ip)  { system("touch $acl_src_unrestricted_ip"); }
151 unless (-e $acl_src_unrestricted_mac) { system("touch $acl_src_unrestricted_mac"); }
152 unless (-e $acl_src_noaccess_ip)  { system("touch $acl_src_noaccess_ip"); }
153 unless (-e $acl_src_noaccess_mac) { system("touch $acl_src_noaccess_mac"); }
154 unless (-e $acl_dst_noauth)     { system("touch $acl_dst_noauth"); }
155 unless (-e $acl_dst_noauth_dom) { system("touch $acl_dst_noauth_dom"); }
156 unless (-e $acl_dst_noauth_net) { system("touch $acl_dst_noauth_net"); }
157 unless (-e $acl_dst_noauth_url) { system("touch $acl_dst_noauth_url"); }
158 unless (-e $acl_dst_nocache)     { system("touch $acl_dst_nocache"); }
159 unless (-e $acl_dst_nocache_dom) { system("touch $acl_dst_nocache_dom"); }
160 unless (-e $acl_dst_nocache_net) { system("touch $acl_dst_nocache_net"); }
161 unless (-e $acl_dst_nocache_url) { system("touch $acl_dst_nocache_url"); }
162 unless (-e $acl_dst_throttle)  { system("touch $acl_dst_throttle"); }
163 unless (-e $acl_ports_safe) { system("touch $acl_ports_safe"); }
164 unless (-e $acl_ports_ssl)  { system("touch $acl_ports_ssl"); }
165 unless (-e $acl_include) { system("touch $acl_include"); }
166
167 unless (-e $mimetypes) { system("touch $mimetypes"); }
168
169 my $HAVE_NTLM_AUTH = (-e "/usr/bin/ntlm_auth");
170
171 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
172 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
173
174 my $green_cidr = &General::ipcidr("$netsettings{'GREEN_NETADDRESS'}\/$netsettings{'GREEN_NETMASK'}");
175 my $blue_cidr = "";
176 if (&Header::blue_used() && $netsettings{'BLUE_DEV'}) {
177         $blue_cidr = &General::ipcidr("$netsettings{'BLUE_NETADDRESS'}\/$netsettings{'BLUE_NETMASK'}");
178 }
179
180 &Header::showhttpheaders();
181
182 $proxysettings{'ACTION'} = '';
183 $proxysettings{'VALID'} = '';
184
185 $proxysettings{'ENABLE'} = 'off';
186 $proxysettings{'ENABLE_BLUE'} = 'off';
187 $proxysettings{'TRANSPARENT'} = 'off';
188 $proxysettings{'TRANSPARENT_BLUE'} = 'off';
189 $proxysettings{'PROXY_PORT'} = '800';
190 $proxysettings{'TRANSPARENT_PORT'} = '3128';
191 $proxysettings{'VISIBLE_HOSTNAME'} = '';
192 $proxysettings{'ADMIN_MAIL_ADDRESS'} = '';
193 $proxysettings{'ADMIN_PASSWORD'} = '';
194 $proxysettings{'ERR_LANGUAGE'} = 'en';
195 $proxysettings{'ERR_DESIGN'} = 'ipfire';
196 $proxysettings{'SUPPRESS_VERSION'} = 'off';
197 $proxysettings{'FORWARD_VIA'} = 'off';
198 $proxysettings{'FORWARD_IPADDRESS'} = 'off';
199 $proxysettings{'FORWARD_USERNAME'} = 'off';
200 $proxysettings{'NO_CONNECTION_AUTH'} = 'off';
201 $proxysettings{'UPSTREAM_PROXY'} = '';
202 $proxysettings{'UPSTREAM_USER'} = '';
203 $proxysettings{'UPSTREAM_PASSWORD'} = '';
204 $proxysettings{'LOGGING'} = 'off';
205 $proxysettings{'CACHEMGR'} = 'off';
206 $proxysettings{'LOGQUERY'} = 'off';
207 $proxysettings{'LOGUSERAGENT'} = 'off';
208 $proxysettings{'FILEDESCRIPTORS'} = '16384';
209 $proxysettings{'CACHE_MEM'} = '128';
210 $proxysettings{'CACHE_SIZE'} = '0';
211 $proxysettings{'MAX_SIZE'} = '4096';
212 $proxysettings{'MIN_SIZE'} = '0';
213 $proxysettings{'MEM_POLICY'} = 'LRU';
214 $proxysettings{'CACHE_POLICY'} = 'LRU';
215 $proxysettings{'L1_DIRS'} = '16';
216 $proxysettings{'OFFLINE_MODE'} = 'off';
217 $proxysettings{'CACHE_DIGESTS'} = 'off';
218 $proxysettings{'CLASSROOM_EXT'} = 'off';
219 $proxysettings{'SUPERVISOR_PASSWORD'} = '';
220 $proxysettings{'NO_PROXY_LOCAL'} = 'off';
221 $proxysettings{'NO_PROXY_LOCAL_BLUE'} = 'off';
222 $proxysettings{'TIME_ACCESS_MODE'} = 'allow';
223 $proxysettings{'TIME_FROM_HOUR'} = '00';
224 $proxysettings{'TIME_FROM_MINUTE'} = '00';
225 $proxysettings{'TIME_TO_HOUR'} = '24';
226 $proxysettings{'TIME_TO_MINUTE'} = '00';
227 $proxysettings{'MAX_OUTGOING_SIZE'} = '0';
228 $proxysettings{'MAX_INCOMING_SIZE'} = '0';
229 $proxysettings{'THROTTLING_GREEN_TOTAL'} = 'unlimited';
230 $proxysettings{'THROTTLING_GREEN_HOST'} = 'unlimited';
231 $proxysettings{'THROTTLING_BLUE_TOTAL'} = 'unlimited';
232 $proxysettings{'THROTTLING_BLUE_HOST'} = 'unlimited';
233 $proxysettings{'ENABLE_MIME_FILTER'} = 'off';
234 $proxysettings{'FAKE_USERAGENT'} = '';
235 $proxysettings{'FAKE_REFERER'} = '';
236 $proxysettings{'AUTH_METHOD'} = 'none';
237 $proxysettings{'AUTH_REALM'} = '';
238 $proxysettings{'AUTH_MAX_USERIP'} = '';
239 $proxysettings{'AUTH_CACHE_TTL'} = '60';
240 $proxysettings{'AUTH_CHILDREN'} = '5';
241 $proxysettings{'NCSA_MIN_PASS_LEN'} = '6';
242 $proxysettings{'NCSA_BYPASS_REDIR'} = 'off';
243 $proxysettings{'NCSA_USERNAME'} = '';
244 $proxysettings{'NCSA_GROUP'} = '';
245 $proxysettings{'NCSA_PASS'} = '';
246 $proxysettings{'NCSA_PASS_CONFIRM'} = '';
247 $proxysettings{'LDAP_BASEDN'} = '';
248 $proxysettings{'LDAP_TYPE'} = 'ADS';
249 $proxysettings{'LDAP_SERVER'} = '';
250 $proxysettings{'LDAP_PORT'} = '389';
251 $proxysettings{'LDAP_BINDDN_USER'} = '';
252 $proxysettings{'LDAP_BINDDN_PASS'} = '';
253 $proxysettings{'LDAP_GROUP'} = '';
254 $proxysettings{'NTLM_AUTH_GROUP'} = '';
255 $proxysettings{'NTLM_AUTH_BASIC'} = 'off';
256 $proxysettings{'NTLM_DOMAIN'} = '';
257 $proxysettings{'NTLM_PDC'} = '';
258 $proxysettings{'NTLM_BDC'} = '';
259 $proxysettings{'NTLM_ENABLE_ACL'} = 'off';
260 $proxysettings{'NTLM_USER_ACL'} = 'positive';
261 $proxysettings{'RADIUS_SERVER'} = '';
262 $proxysettings{'RADIUS_PORT'} = '1812';
263 $proxysettings{'RADIUS_IDENTIFIER'} = '';
264 $proxysettings{'RADIUS_SECRET'} = '';
265 $proxysettings{'RADIUS_ENABLE_ACL'} = 'off';
266 $proxysettings{'RADIUS_USER_ACL'} = 'positive';
267 $proxysettings{'IDENT_REQUIRED'} = 'off';
268 $proxysettings{'IDENT_TIMEOUT'} = '10';
269 $proxysettings{'IDENT_ENABLE_ACL'} = 'off';
270 $proxysettings{'IDENT_USER_ACL'} = 'positive';
271 $proxysettings{'ENABLE_FILTER'} = 'off';
272 $proxysettings{'ENABLE_UPDXLRATOR'} = 'off';
273 $proxysettings{'ENABLE_CLAMAV'} = 'off';
274
275 $ncsa_buttontext = $Lang::tr{'advproxy NCSA create user'};
276
277 &Header::getcgihash(\%proxysettings);
278
279 if ($proxysettings{'THROTTLING_GREEN_TOTAL'} eq 0) {$proxysettings{'THROTTLING_GREEN_TOTAL'} = 'unlimited';}
280 if ($proxysettings{'THROTTLING_GREEN_HOST'}  eq 0) {$proxysettings{'THROTTLING_GREEN_HOST'}  = 'unlimited';}
281 if ($proxysettings{'THROTTLING_BLUE_TOTAL'}  eq 0) {$proxysettings{'THROTTLING_BLUE_TOTAL'}  = 'unlimited';}
282 if ($proxysettings{'THROTTLING_BLUE_HOST'}   eq 0) {$proxysettings{'THROTTLING_BLUE_HOST'}   = 'unlimited';}
283
284 if ($proxysettings{'ACTION'} eq $Lang::tr{'advproxy NCSA user management'})
285 {
286         $proxysettings{'NCSA_EDIT_MODE'} = 'yes';
287 }
288
289 if ($proxysettings{'ACTION'} eq $Lang::tr{'add'})
290 {
291         $proxysettings{'NCSA_EDIT_MODE'} = 'yes';
292         if (length($proxysettings{'NCSA_PASS'}) < $proxysettings{'NCSA_MIN_PASS_LEN'}) {
293                 $errormessage = $Lang::tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$Lang::tr{'advproxy errmsg password length 2'};
294         }
295         if (!($proxysettings{'NCSA_PASS'} eq $proxysettings{'NCSA_PASS_CONFIRM'})) {
296                 $errormessage = $Lang::tr{'advproxy errmsg passwords different'};
297         }
298         if ($proxysettings{'NCSA_USERNAME'} eq '') {
299                 $errormessage = $Lang::tr{'advproxy errmsg no username'};
300         }
301         if (!$errormessage) {
302                 $proxysettings{'NCSA_USERNAME'} =~ tr/A-Z/a-z/;
303                 &adduser($proxysettings{'NCSA_USERNAME'}, $proxysettings{'NCSA_PASS'}, $proxysettings{'NCSA_GROUP'});
304         }
305         $proxysettings{'NCSA_USERNAME'} = '';
306         $proxysettings{'NCSA_GROUP'} = '';
307         $proxysettings{'NCSA_PASS'} = '';
308         $proxysettings{'NCSA_PASS_CONFIRM'} = '';
309 }
310
311 if ($proxysettings{'ACTION'} eq $Lang::tr{'remove'})
312 {
313         $proxysettings{'NCSA_EDIT_MODE'} = 'yes';
314         &deluser($proxysettings{'ID'});
315 }
316
317 $checked{'ENABLE_UPDXLRATOR'}{'off'} = '';
318 $checked{'ENABLE_UPDXLRATOR'}{'on'} = '';
319 $checked{'ENABLE_UPDXLRATOR'}{$proxysettings{'ENABLE_UPDXLRATOR'}} = "checked='checked'";
320
321 if ($proxysettings{'ACTION'} eq $Lang::tr{'edit'})
322 {
323         $proxysettings{'NCSA_EDIT_MODE'} = 'yes';
324         $ncsa_buttontext = $Lang::tr{'advproxy NCSA update user'};
325         @temp = split(/:/,$proxysettings{'ID'});
326         $proxysettings{'NCSA_USERNAME'} = $temp[0];
327         $proxysettings{'NCSA_GROUP'} = $temp[1];
328         $proxysettings{'NCSA_PASS'} = "lEaVeAlOnE";
329         $proxysettings{'NCSA_PASS_CONFIRM'} = $proxysettings{'NCSA_PASS'};
330 }
331
332 if (($proxysettings{'ACTION'} eq $Lang::tr{'save'}) || ($proxysettings{'ACTION'} eq $Lang::tr{'advproxy save and restart'}) || ($proxysettings{'ACTION'} eq $Lang::tr{'proxy reconfigure'}))
333 {
334         if ($proxysettings{'ENABLE'} !~ /^(on|off)$/ ||
335             $proxysettings{'TRANSPARENT'} !~ /^(on|off)$/ ||
336             $proxysettings{'ENABLE_BLUE'} !~ /^(on|off)$/ ||
337             $proxysettings{'TRANSPARENT_BLUE'} !~ /^(on|off)$/ ) {
338                 $errormessage = $Lang::tr{'invalid input'};
339                 goto ERROR;
340         }
341         if($proxysettings{'CACHE_MEM'} > $proxysettings{'CACHE_SIZE'} && $proxysettings{'CACHE_SIZE'} > 0){
342                 $errormessage = $Lang::tr{'advproxy errmsg cache'}." ".$proxysettings{'CACHE_MEM'}." > ".$proxysettings{'CACHE_SIZE'};
343                 goto ERROR;
344         }
345
346         if (!(&General::validport($proxysettings{'PROXY_PORT'})))
347         {
348                 $errormessage = $Lang::tr{'advproxy errmsg invalid proxy port'};
349                 goto ERROR;
350         }
351         if (!(&General::validport($proxysettings{'TRANSPARENT_PORT'})))
352         {
353                 $errormessage = $Lang::tr{'advproxy errmsg invalid proxy port'};
354                 goto ERROR;
355         }
356         if ($proxysettings{'PROXY_PORT'} eq $proxysettings{'TRANSPARENT_PORT'}) {
357                 $errormessage = $Lang::tr{'advproxy errmsg proxy ports equal'};
358                 goto ERROR;
359         }
360         if (!($proxysettings{'UPSTREAM_PROXY'} eq ''))
361         {
362                 my @temp = split(/:/,$proxysettings{'UPSTREAM_PROXY'});
363                 if (!(&General::validip($temp[0])))
364                 {
365                         if (!(&General::validdomainname($temp[0])))
366                         {
367                                 $errormessage = $Lang::tr{'advproxy errmsg invalid upstream proxy'};
368                                 goto ERROR;
369                         }
370                 }
371         }
372         if (!($proxysettings{'CACHE_SIZE'} =~ /^\d+/) ||
373                 ($proxysettings{'CACHE_SIZE'} < 10))
374         {
375                 if (!($proxysettings{'CACHE_SIZE'} eq '0'))
376                 {
377                         $errormessage = $Lang::tr{'advproxy errmsg hdd cache size'};
378                         goto ERROR;
379                 }
380         }
381         if (!($proxysettings{'FILEDESCRIPTORS'} =~ /^\d+/) ||
382                 ($proxysettings{'FILEDESCRIPTORS'} < 1) || ($proxysettings{'FILEDESCRIPTORS'} > 1048576))
383         {
384                 $errormessage = $Lang::tr{'proxy errmsg filedescriptors'};
385                 goto ERROR;
386         }
387         if (!($proxysettings{'CACHE_MEM'} =~ /^\d+/))
388         {
389                 $errormessage = $Lang::tr{'advproxy errmsg mem cache size'};
390                 goto ERROR;
391         }
392         my @free = `/usr/bin/free`;
393         $free[1] =~ m/(\d+)/;
394         $cachemem = int $1 / 2048;
395         if ($proxysettings{'CACHE_MEM'} > $cachemem) {
396                 $proxysettings{'CACHE_MEM'} = $cachemem;
397         }
398         if (!($proxysettings{'MAX_SIZE'} =~ /^\d+/))
399         {
400                 $errormessage = $Lang::tr{'invalid maximum object size'};
401                 goto ERROR;
402         }
403         if (!($proxysettings{'MIN_SIZE'} =~ /^\d+/))
404         {
405                 $errormessage = $Lang::tr{'invalid minimum object size'};
406                 goto ERROR;
407         }
408         if (!($proxysettings{'MAX_OUTGOING_SIZE'} =~ /^\d+/))
409         {
410                 $errormessage = $Lang::tr{'invalid maximum outgoing size'};
411                 goto ERROR;
412         }
413         if (!($proxysettings{'TIME_TO_HOUR'}.$proxysettings{'TIME_TO_MINUTE'} gt $proxysettings{'TIME_FROM_HOUR'}.$proxysettings{'TIME_FROM_MINUTE'}))
414         {
415                 $errormessage = $Lang::tr{'advproxy errmsg time restriction'};
416                 goto ERROR;
417         }
418         if (!($proxysettings{'MAX_INCOMING_SIZE'} =~ /^\d+/))
419         {
420                 $errormessage = $Lang::tr{'invalid maximum incoming size'};
421                 goto ERROR;
422         }
423         if (!($proxysettings{'AUTH_METHOD'} eq 'none'))
424         {
425                 unless (($proxysettings{'AUTH_METHOD'} eq 'ident') &&
426                         ($proxysettings{'IDENT_REQUIRED'} eq 'off') &&
427                         ($proxysettings{'IDENT_ENABLE_ACL'} eq 'off'))
428                 {
429                         if ($netsettings{'BLUE_DEV'})
430                         {
431                                 if ((($proxysettings{'ENABLE'} eq 'off') || ($proxysettings{'TRANSPARENT'} eq 'on')) &&
432                                         (($proxysettings{'ENABLE_BLUE'} eq 'off') || ($proxysettings{'TRANSPARENT_BLUE'} eq 'on')))
433                                 {
434                                         $errormessage = $Lang::tr{'advproxy errmsg non-transparent proxy required'};
435                                         goto ERROR;
436                                 }
437                         } else {
438                                 if (($proxysettings{'ENABLE'} eq 'off') || ($proxysettings{'TRANSPARENT'} eq 'on'))
439                                 {
440                                         $errormessage = $Lang::tr{'advproxy errmsg non-transparent proxy required'};
441                                         goto ERROR;
442                                 }
443                         }
444                 }
445                 if (!($proxysettings{'AUTH_CACHE_TTL'} =~ /^\d+/))
446                 {
447                         $errormessage = $Lang::tr{'advproxy errmsg auth cache ttl'};
448                         goto ERROR;
449                 }
450                 if ((!($proxysettings{'AUTH_MAX_USERIP'} eq '')) &&
451                         ((!($proxysettings{'AUTH_MAX_USERIP'} =~ /^\d+/)) || ($proxysettings{'AUTH_MAX_USERIP'} < 1) || ($proxysettings{'AUTH_MAX_USERIP'} > 255)))
452                 {
453                         $errormessage = $Lang::tr{'advproxy errmsg max userip'};
454                         goto ERROR;
455                 }
456                 if (!($proxysettings{'AUTH_MAX_USERIP'} eq ''))
457                 {
458                         $errormessage = $Lang::tr{'advproxy errmsg auth ipcache may not be null'};
459                         goto ERROR;
460                 }
461                 if ((!($proxysettings{'AUTH_CHILDREN'} =~ /^\d+/)) || ($proxysettings{'AUTH_CHILDREN'} < 1) || ($proxysettings{'AUTH_CHILDREN'} > 255))
462                 {
463                         $errormessage = $Lang::tr{'advproxy errmsg auth children'};
464                         goto ERROR;
465                 }
466         }
467         if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
468         {
469                 if ((!($proxysettings{'NCSA_MIN_PASS_LEN'} =~ /^\d+/)) || ($proxysettings{'NCSA_MIN_PASS_LEN'} < 1) || ($proxysettings{'NCSA_MIN_PASS_LEN'} > 255))
470                 {
471                         $errormessage = $Lang::tr{'advproxy errmsg password length'};
472                         goto ERROR;
473                 }
474         }
475         if ($proxysettings{'AUTH_METHOD'} eq 'ident')
476         {
477                 if ((!($proxysettings{'IDENT_TIMEOUT'} =~ /^\d+/)) || ($proxysettings{'IDENT_TIMEOUT'} < 1))
478                 {
479                         $errormessage = $Lang::tr{'advproxy errmsg ident timeout'};
480                         goto ERROR;
481                 }
482         }
483         if ($proxysettings{'AUTH_METHOD'} eq 'ldap')
484         {
485                 if ($proxysettings{'LDAP_BASEDN'} eq '')
486                 {
487                         $errormessage = $Lang::tr{'advproxy errmsg ldap base dn'};
488                         goto ERROR;
489                 }
490                 if (!&General::validip($proxysettings{'LDAP_SERVER'}))
491                 {
492                         if (!&General::validdomainname($proxysettings{'LDAP_SERVER'}))
493                         {
494                                 $errormessage = $Lang::tr{'advproxy errmsg ldap server'};
495                                 goto ERROR;
496                         }
497                 }
498                 if (!&General::validport($proxysettings{'LDAP_PORT'}))
499                 {
500                         $errormessage = $Lang::tr{'advproxy errmsg ldap port'};
501                         goto ERROR;
502                 }
503                 if (($proxysettings{'LDAP_TYPE'} eq 'ADS') || ($proxysettings{'LDAP_TYPE'} eq 'NDS'))
504                 {
505                         if (($proxysettings{'LDAP_BINDDN_USER'} eq '') || ($proxysettings{'LDAP_BINDDN_PASS'} eq ''))
506                         {
507                                 $errormessage = $Lang::tr{'advproxy errmsg ldap bind dn'};
508                                 goto ERROR;
509                         }
510                 }
511         }
512         if ($proxysettings{'AUTH_METHOD'} eq 'radius')
513         {
514                 if (!&General::validip($proxysettings{'RADIUS_SERVER'}))
515                 {
516                         $errormessage = $Lang::tr{'advproxy errmsg radius server'};
517                         goto ERROR;
518                 }
519                 if (!&General::validport($proxysettings{'RADIUS_PORT'}))
520                 {
521                         $errormessage = $Lang::tr{'advproxy errmsg radius port'};
522                         goto ERROR;
523                 }
524                 if ($proxysettings{'RADIUS_SECRET'} eq '')
525                 {
526                         $errormessage = $Lang::tr{'advproxy errmsg radius secret'};
527                         goto ERROR;
528                 }
529         }
530
531         # Quick parent proxy error checking of username and password info. If username password don't both exist give an error.
532         $proxy1 = 'YES';
533         $proxy2 = 'YES';
534         if (($proxysettings{'UPSTREAM_USER'} eq '')) {$proxy1 = '';}
535         if (($proxysettings{'UPSTREAM_PASSWORD'} eq '')) {$proxy2 = '';}
536         if ($proxysettings{'UPSTREAM_USER'} eq 'PASS')  {$proxy1=$proxy2='PASS'; $proxysettings{'UPSTREAM_PASSWORD'} = '';}
537         if (($proxy1 ne $proxy2))
538         {
539                 $errormessage = $Lang::tr{'advproxy errmsg invalid upstream proxy username or password setting'};
540                 goto ERROR;
541         }
542
543 ERROR:
544         &check_acls;
545
546         if ($errormessage) {
547                 $proxysettings{'VALID'} = 'no'; }
548         else {
549                 $proxysettings{'VALID'} = 'yes'; }
550
551         if ($proxysettings{'VALID'} eq 'yes')
552         {
553                 &write_acls;
554
555                 delete $proxysettings{'SRC_SUBNETS'};
556                 delete $proxysettings{'SRC_BANNED_IP'};
557                 delete $proxysettings{'SRC_BANNED_MAC'};
558                 delete $proxysettings{'SRC_UNRESTRICTED_IP'};
559                 delete $proxysettings{'SRC_UNRESTRICTED_MAC'};
560                 delete $proxysettings{'DST_NOCACHE'};
561                 delete $proxysettings{'DST_NOAUTH'};
562                 delete $proxysettings{'PORTS_SAFE'};
563                 delete $proxysettings{'PORTS_SSL'};
564                 delete $proxysettings{'MIME_TYPES'};
565                 delete $proxysettings{'NTLM_ALLOW_USERS'};
566                 delete $proxysettings{'NTLM_DENY_USERS'};
567                 delete $proxysettings{'RADIUS_ALLOW_USERS'};
568                 delete $proxysettings{'RADIUS_DENY_USERS'};
569                 delete $proxysettings{'IDENT_HOSTS'};
570                 delete $proxysettings{'IDENT_ALLOW_USERS'};
571                 delete $proxysettings{'IDENT_DENY_USERS'};
572
573                 delete $proxysettings{'CRE_GROUPS'};
574                 delete $proxysettings{'CRE_SVHOSTS'};
575
576                 delete $proxysettings{'NCSA_USERNAME'};
577                 delete $proxysettings{'NCSA_GROUP'};
578                 delete $proxysettings{'NCSA_PASS'};
579                 delete $proxysettings{'NCSA_PASS_CONFIRM'};
580
581                 $proxysettings{'TIME_MON'} = 'off' unless exists $proxysettings{'TIME_MON'};
582                 $proxysettings{'TIME_TUE'} = 'off' unless exists $proxysettings{'TIME_TUE'};
583                 $proxysettings{'TIME_WED'} = 'off' unless exists $proxysettings{'TIME_WED'};
584                 $proxysettings{'TIME_THU'} = 'off' unless exists $proxysettings{'TIME_THU'};
585                 $proxysettings{'TIME_FRI'} = 'off' unless exists $proxysettings{'TIME_FRI'};
586                 $proxysettings{'TIME_SAT'} = 'off' unless exists $proxysettings{'TIME_SAT'};
587                 $proxysettings{'TIME_SUN'} = 'off' unless exists $proxysettings{'TIME_SUN'};
588
589                 $proxysettings{'AUTH_ALWAYS_REQUIRED'} = 'off' unless exists $proxysettings{'AUTH_ALWAYS_REQUIRED'};
590                 $proxysettings{'NTLM_ENABLE_INT_AUTH'} = 'off' unless exists $proxysettings{'NTLM_ENABLE_INT_AUTH'};
591
592                 &General::writehash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
593
594                 if (-e "${General::swroot}/proxy/settings") { &General::readhash("${General::swroot}/proxy/settings", \%stdproxysettings); }
595                 $stdproxysettings{'PROXY_PORT'} = $proxysettings{'PROXY_PORT'};
596                 $stdproxysettings{'UPSTREAM_PROXY'}    = $proxysettings{'UPSTREAM_PROXY'};
597                 $stdproxysettings{'UPSTREAM_USER'}     = $proxysettings{'UPSTREAM_USER'};
598                 $stdproxysettings{'UPSTREAM_PASSWORD'} = $proxysettings{'UPSTREAM_PASSWORD'};
599                 $stdproxysettings{'ENABLE_FILTER'} = $proxysettings{'ENABLE_FILTER'};
600                 $stdproxysettings{'ENABLE_UPDXLRATOR'} = $proxysettings{'ENABLE_UPDXLRATOR'};
601                 $stdproxysettings{'ENABLE_CLAMAV'} = $proxysettings{'ENABLE_CLAMAV'};
602                 &General::writehash("${General::swroot}/proxy/settings", \%stdproxysettings);
603
604                 &writeconfig;
605                 &writepacfile;
606
607                 if ($proxysettings{'CACHEMGR'} eq 'on'){&writecachemgr;}
608
609                 system ('/usr/local/bin/squidctrl', 'disable');
610                 unlink "${General::swroot}/proxy/enable";
611                 unlink "${General::swroot}/proxy/transparent";
612                 unlink "${General::swroot}/proxy/enable_blue";
613                 unlink "${General::swroot}/proxy/transparent_blue";
614
615                 if ($proxysettings{'ENABLE'} eq 'on') {
616                         system ('/usr/bin/touch', "${General::swroot}/proxy/enable");
617                         system ('/usr/local/bin/squidctrl', 'enable'); }
618                 if ($proxysettings{'TRANSPARENT'} eq 'on' && $proxysettings{'ENABLE'} eq 'on') {
619                         system ('/usr/bin/touch', "${General::swroot}/proxy/transparent"); }
620                 if ($proxysettings{'ENABLE_BLUE'} eq 'on') {
621                         system ('/usr/bin/touch', "${General::swroot}/proxy/enable_blue");
622                         system ('/usr/local/bin/squidctrl', 'enable'); }
623                 if ($proxysettings{'TRANSPARENT_BLUE'} eq 'on' && $proxysettings{'ENABLE_BLUE'} eq 'on') {
624                         system ('/usr/bin/touch', "${General::swroot}/proxy/transparent_blue"); }
625
626                 if ($proxysettings{'ACTION'} eq $Lang::tr{'advproxy save and restart'}) { system('/usr/local/bin/squidctrl restart >/dev/null 2>&1'); }
627                 if ($proxysettings{'ACTION'} eq $Lang::tr{'proxy reconfigure'}) { system('/usr/local/bin/squidctrl reconfigure >/dev/null 2>&1'); }
628   }
629 }
630
631 if ($proxysettings{'ACTION'} eq $Lang::tr{'advproxy clear cache'})
632 {
633         system('/usr/local/bin/squidctrl flush >/dev/null 2>&1');
634 }
635
636 if (!$errormessage)
637 {
638         if (-e "${General::swroot}/proxy/advanced/settings") {
639                 &General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
640         } elsif (-e "${General::swroot}/proxy/settings") {
641                 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
642         }
643         &read_acls;
644 }
645
646 # ------------------------------------------------------------------
647
648 # Hook to regenerate the configuration files, if cgi got called from command line.
649 if ($ENV{"REMOTE_ADDR"} eq "") {
650         writeconfig();
651         exit(0);
652 }
653
654 # -------------------------------------------------------------------
655
656 $checked{'ENABLE'}{'off'} = '';
657 $checked{'ENABLE'}{'on'} = '';
658 $checked{'ENABLE'}{$proxysettings{'ENABLE'}} = "checked='checked'";
659
660 $checked{'TRANSPARENT'}{'off'} = '';
661 $checked{'TRANSPARENT'}{'on'} = '';
662 $checked{'TRANSPARENT'}{$proxysettings{'TRANSPARENT'}} = "checked='checked'";
663
664 $checked{'ENABLE_BLUE'}{'off'} = '';
665 $checked{'ENABLE_BLUE'}{'on'} = '';
666 $checked{'ENABLE_BLUE'}{$proxysettings{'ENABLE_BLUE'}} = "checked='checked'";
667
668 $checked{'TRANSPARENT_BLUE'}{'off'} = '';
669 $checked{'TRANSPARENT_BLUE'}{'on'} = '';
670 $checked{'TRANSPARENT_BLUE'}{$proxysettings{'TRANSPARENT_BLUE'}} = "checked='checked'";
671
672 $checked{'SUPPRESS_VERSION'}{'off'} = '';
673 $checked{'SUPPRESS_VERSION'}{'on'} = '';
674 $checked{'SUPPRESS_VERSION'}{$proxysettings{'SUPPRESS_VERSION'}} = "checked='checked'";
675
676 $checked{'FORWARD_IPADDRESS'}{'off'} = '';
677 $checked{'FORWARD_IPADDRESS'}{'on'} = '';
678 $checked{'FORWARD_IPADDRESS'}{$proxysettings{'FORWARD_IPADDRESS'}} = "checked='checked'";
679 $checked{'FORWARD_USERNAME'}{'off'} = '';
680 $checked{'FORWARD_USERNAME'}{'on'} = '';
681 $checked{'FORWARD_USERNAME'}{$proxysettings{'FORWARD_USERNAME'}} = "checked='checked'";
682 $checked{'FORWARD_VIA'}{'off'} = '';
683 $checked{'FORWARD_VIA'}{'on'} = '';
684 $checked{'FORWARD_VIA'}{$proxysettings{'FORWARD_VIA'}} = "checked='checked'";
685 $checked{'NO_CONNECTION_AUTH'}{'off'} = '';
686 $checked{'NO_CONNECTION_AUTH'}{'on'} = '';
687 $checked{'NO_CONNECTION_AUTH'}{$proxysettings{'NO_CONNECTION_AUTH'}} = "checked='checked'";
688
689 $selected{'MEM_POLICY'}{$proxysettings{'MEM_POLICY'}} = "selected='selected'";
690 $selected{'CACHE_POLICY'}{$proxysettings{'CACHE_POLICY'}} = "selected='selected'";
691 $selected{'L1_DIRS'}{$proxysettings{'L1_DIRS'}} = "selected='selected'";
692 $checked{'OFFLINE_MODE'}{'off'} = '';
693 $checked{'OFFLINE_MODE'}{'on'} = '';
694 $checked{'OFFLINE_MODE'}{$proxysettings{'OFFLINE_MODE'}} = "checked='checked'";
695 $checked{'CACHE_DIGESTS'}{'off'} = '';
696 $checked{'CACHE_DIGESTS'}{'on'} = '';
697 $checked{'CACHE_DIGESTS'}{$proxysettings{'CACHE_DIGESTS'}} = "checked='checked'";
698
699 $checked{'LOGGING'}{'off'} = '';
700 $checked{'LOGGING'}{'on'} = '';
701 $checked{'LOGGING'}{$proxysettings{'LOGGING'}} = "checked='checked'";
702 $checked{'CACHEMGR'}{'off'} = '';
703 $checked{'CACHEMGR'}{'on'} = '';
704 $checked{'CACHEMGR'}{$proxysettings{'CACHEMGR'}} = "checked='checked'";
705 $checked{'LOGQUERY'}{'off'} = '';
706 $checked{'LOGQUERY'}{'on'} = '';
707 $checked{'LOGQUERY'}{$proxysettings{'LOGQUERY'}} = "checked='checked'";
708 $checked{'LOGUSERAGENT'}{'off'} = '';
709 $checked{'LOGUSERAGENT'}{'on'} = '';
710 $checked{'LOGUSERAGENT'}{$proxysettings{'LOGUSERAGENT'}} = "checked='checked'";
711
712 $selected{'ERR_LANGUAGE'}{$proxysettings{'ERR_LANGUAGE'}} = "selected='selected'";
713 $selected{'ERR_DESIGN'}{$proxysettings{'ERR_DESIGN'}} = "selected='selected'";
714
715 $checked{'NO_PROXY_LOCAL'}{'off'} = '';
716 $checked{'NO_PROXY_LOCAL'}{'on'} = '';
717 $checked{'NO_PROXY_LOCAL'}{$proxysettings{'NO_PROXY_LOCAL'}} = "checked='checked'";
718 $checked{'NO_PROXY_LOCAL_BLUE'}{'off'} = '';
719 $checked{'NO_PROXY_LOCAL_BLUE'}{'on'} = '';
720 $checked{'NO_PROXY_LOCAL_BLUE'}{$proxysettings{'NO_PROXY_LOCAL_BLUE'}} = "checked='checked'";
721
722 $checked{'CLASSROOM_EXT'}{'off'} = '';
723 $checked{'CLASSROOM_EXT'}{'on'} = '';
724 $checked{'CLASSROOM_EXT'}{$proxysettings{'CLASSROOM_EXT'}} = "checked='checked'";
725
726 $selected{'TIME_ACCESS_MODE'}{$proxysettings{'TIME_ACCESS_MODE'}} = "selected='selected'";
727 $selected{'TIME_FROM_HOUR'}{$proxysettings{'TIME_FROM_HOUR'}} = "selected='selected'";
728 $selected{'TIME_FROM_MINUTE'}{$proxysettings{'TIME_FROM_MINUTE'}} = "selected='selected'";
729 $selected{'TIME_TO_HOUR'}{$proxysettings{'TIME_TO_HOUR'}} = "selected='selected'";
730 $selected{'TIME_TO_MINUTE'}{$proxysettings{'TIME_TO_MINUTE'}} = "selected='selected'";
731
732 $proxysettings{'TIME_MON'} = 'on' unless exists $proxysettings{'TIME_MON'};
733 $proxysettings{'TIME_TUE'} = 'on' unless exists $proxysettings{'TIME_TUE'};
734 $proxysettings{'TIME_WED'} = 'on' unless exists $proxysettings{'TIME_WED'};
735 $proxysettings{'TIME_THU'} = 'on' unless exists $proxysettings{'TIME_THU'};
736 $proxysettings{'TIME_FRI'} = 'on' unless exists $proxysettings{'TIME_FRI'};
737 $proxysettings{'TIME_SAT'} = 'on' unless exists $proxysettings{'TIME_SAT'};
738 $proxysettings{'TIME_SUN'} = 'on' unless exists $proxysettings{'TIME_SUN'};
739
740 $checked{'TIME_MON'}{'off'} = '';
741 $checked{'TIME_MON'}{'on'} = '';
742 $checked{'TIME_MON'}{$proxysettings{'TIME_MON'}} = "checked='checked'";
743 $checked{'TIME_TUE'}{'off'} = '';
744 $checked{'TIME_TUE'}{'on'} = '';
745 $checked{'TIME_TUE'}{$proxysettings{'TIME_TUE'}} = "checked='checked'";
746 $checked{'TIME_WED'}{'off'} = '';
747 $checked{'TIME_WED'}{'on'} = '';
748 $checked{'TIME_WED'}{$proxysettings{'TIME_WED'}} = "checked='checked'";
749 $checked{'TIME_THU'}{'off'} = '';
750 $checked{'TIME_THU'}{'on'} = '';
751 $checked{'TIME_THU'}{$proxysettings{'TIME_THU'}} = "checked='checked'";
752 $checked{'TIME_FRI'}{'off'} = '';
753 $checked{'TIME_FRI'}{'on'} = '';
754 $checked{'TIME_FRI'}{$proxysettings{'TIME_FRI'}} = "checked='checked'";
755 $checked{'TIME_SAT'}{'off'} = '';
756 $checked{'TIME_SAT'}{'on'} = '';
757 $checked{'TIME_SAT'}{$proxysettings{'TIME_SAT'}} = "checked='checked'";
758 $checked{'TIME_SUN'}{'off'} = '';
759 $checked{'TIME_SUN'}{'on'} = '';
760 $checked{'TIME_SUN'}{$proxysettings{'TIME_SUN'}} = "checked='checked'";
761
762 $selected{'THROTTLING_GREEN_TOTAL'}{$proxysettings{'THROTTLING_GREEN_TOTAL'}} = "selected='selected'";
763 $selected{'THROTTLING_GREEN_HOST'}{$proxysettings{'THROTTLING_GREEN_HOST'}} = "selected='selected'";
764 $selected{'THROTTLING_BLUE_TOTAL'}{$proxysettings{'THROTTLING_BLUE_TOTAL'}} = "selected='selected'";
765 $selected{'THROTTLING_BLUE_HOST'}{$proxysettings{'THROTTLING_BLUE_HOST'}} = "selected='selected'";
766
767 $checked{'ENABLE_MIME_FILTER'}{'off'} = '';
768 $checked{'ENABLE_MIME_FILTER'}{'on'} = '';
769 $checked{'ENABLE_MIME_FILTER'}{$proxysettings{'ENABLE_MIME_FILTER'}} = "checked='checked'";
770
771 $checked{'AUTH_METHOD'}{'none'} = '';
772 $checked{'AUTH_METHOD'}{'ncsa'} = '';
773 $checked{'AUTH_METHOD'}{'ident'} = '';
774 $checked{'AUTH_METHOD'}{'ldap'} = '';
775 $checked{'AUTH_METHOD'}{'ntlm-auth'} = '';
776 $checked{'AUTH_METHOD'}{'radius'} = '';
777 $checked{'AUTH_METHOD'}{$proxysettings{'AUTH_METHOD'}} = "checked='checked'";
778
779 $proxysettings{'AUTH_ALWAYS_REQUIRED'} = 'on' unless exists $proxysettings{'AUTH_ALWAYS_REQUIRED'};
780
781 $checked{'AUTH_ALWAYS_REQUIRED'}{'off'} = '';
782 $checked{'AUTH_ALWAYS_REQUIRED'}{'on'} = '';
783 $checked{'AUTH_ALWAYS_REQUIRED'}{$proxysettings{'AUTH_ALWAYS_REQUIRED'}} = "checked='checked'";
784
785 $checked{'NCSA_BYPASS_REDIR'}{'off'} = '';
786 $checked{'NCSA_BYPASS_REDIR'}{'on'} = '';
787 $checked{'NCSA_BYPASS_REDIR'}{$proxysettings{'NCSA_BYPASS_REDIR'}} = "checked='checked'";
788
789 $selected{'NCSA_GROUP'}{$proxysettings{'NCSA_GROUP'}} = "selected='selected'";
790
791 $selected{'LDAP_TYPE'}{$proxysettings{'LDAP_TYPE'}} = "selected='selected'";
792
793 $proxysettings{'NTLM_ENABLE_INT_AUTH'} = 'on' unless exists $proxysettings{'NTLM_ENABLE_INT_AUTH'};
794
795 $checked{'NTLM_ENABLE_INT_AUTH'}{'off'} = '';
796 $checked{'NTLM_ENABLE_INT_AUTH'}{'on'} = '';
797 $checked{'NTLM_ENABLE_INT_AUTH'}{$proxysettings{'NTLM_ENABLE_INT_AUTH'}} = "checked='checked'";
798
799 $checked{'NTLM_ENABLE_ACL'}{'off'} = '';
800 $checked{'NTLM_ENABLE_ACL'}{'on'} = '';
801 $checked{'NTLM_ENABLE_ACL'}{$proxysettings{'NTLM_ENABLE_ACL'}} = "checked='checked'";
802
803 $checked{'NTLM_USER_ACL'}{'positive'} = '';
804 $checked{'NTLM_USER_ACL'}{'negative'} = '';
805 $checked{'NTLM_USER_ACL'}{$proxysettings{'NTLM_USER_ACL'}} = "checked='checked'";
806
807 $checked{'NTLM_AUTH_BASIC'}{'on'} = '';
808 $checked{'NTLM_AUTH_BASIC'}{'off'} = '';
809 $checked{'NTLM_AUTH_BASIC'}{$proxysettings{'NTLM_AUTH_BASIC'}} = "checked='checked'";
810
811 $checked{'RADIUS_ENABLE_ACL'}{'off'} = '';
812 $checked{'RADIUS_ENABLE_ACL'}{'on'} = '';
813 $checked{'RADIUS_ENABLE_ACL'}{$proxysettings{'RADIUS_ENABLE_ACL'}} = "checked='checked'";
814
815 $checked{'RADIUS_USER_ACL'}{'positive'} = '';
816 $checked{'RADIUS_USER_ACL'}{'negative'} = '';
817 $checked{'RADIUS_USER_ACL'}{$proxysettings{'RADIUS_USER_ACL'}} = "checked='checked'";
818
819 $checked{'IDENT_REQUIRED'}{'off'} = '';
820 $checked{'IDENT_REQUIRED'}{'on'} = '';
821 $checked{'IDENT_REQUIRED'}{$proxysettings{'IDENT_REQUIRED'}} = "checked='checked'";
822
823 $checked{'IDENT_ENABLE_ACL'}{'off'} = '';
824 $checked{'IDENT_ENABLE_ACL'}{'on'} = '';
825 $checked{'IDENT_ENABLE_ACL'}{$proxysettings{'IDENT_ENABLE_ACL'}} = "checked='checked'";
826
827 $checked{'IDENT_USER_ACL'}{'positive'} = '';
828 $checked{'IDENT_USER_ACL'}{'negative'} = '';
829 $checked{'IDENT_USER_ACL'}{$proxysettings{'IDENT_USER_ACL'}} = "checked='checked'";
830
831 $checked{'ENABLE_FILTER'}{'off'} = '';
832 $checked{'ENABLE_FILTER'}{'on'} = '';
833 $checked{'ENABLE_FILTER'}{$proxysettings{'ENABLE_FILTER'}} = "checked='checked'";
834
835 $checked{'ENABLE_UPDXLRATOR'}{'off'} = '';
836 $checked{'ENABLE_UPDXLRATOR'}{'on'} = '';
837 $checked{'ENABLE_UPDXLRATOR'}{$proxysettings{'ENABLE_UPDXLRATOR'}} = "checked='checked'";
838
839 $checked{'ENABLE_CLAMAV'}{'off'} = '';
840 $checked{'ENABLE_CLAMAV'}{'on'} = '';
841 $checked{'ENABLE_CLAMAV'}{$proxysettings{'ENABLE_CLAMAV'}} = "checked='checked'";
842
843 &Header::openpage($Lang::tr{'advproxy advanced web proxy configuration'}, 1, '');
844
845 &Header::openbigbox('100%', 'left', '', $errormessage);
846
847 if ($errormessage) {
848         &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
849         print "<font class='base'>$errormessage&nbsp;</font>\n";
850         &Header::closebox();
851 }
852
853 if ($squidversion[0] =~ /^Squid\sCache:\sVersion\s/i)
854 {
855         $squidversion[0] =~ s/^Squid\sCache:\sVersion//i;
856         $squidversion[0] =~ s/^\s+//g;
857         $squidversion[0] =~ s/\s+$//g;
858 } else {
859         $squidversion[0] = $Lang::tr{'advproxy unknown'};
860 }
861
862 # ===================================================================
863 #  Main settings
864 # ===================================================================
865
866 unless ($proxysettings{'NCSA_EDIT_MODE'} eq 'yes') {
867
868 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
869
870 &Header::openbox('100%', 'left', "$Lang::tr{'advproxy advanced web proxy'}");
871
872 print <<END
873 <table width='100%'>
874 <tr>
875         <td colspan='4' class='base'><b>$Lang::tr{'advproxy common settings'}</b></td>
876 </tr>
877 <tr>
878         <td width='25%' class='base'>$Lang::tr{'advproxy enabled on'} <font color="$Header::colourgreen">Green</font>:</td>
879         <td width='20%'><input type='checkbox' name='ENABLE' $checked{'ENABLE'}{'on'} /></td>
880         <td width='25%' class='base'>$Lang::tr{'advproxy proxy port'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
881         <td width='30%'><input type='text' name='PROXY_PORT' value='$proxysettings{'PROXY_PORT'}' size='5' /></td>
882 </tr>
883 <tr>
884         <td class='base'>$Lang::tr{'advproxy transparent on'} <font color="$Header::colourgreen">Green</font>:</td>
885         <td><input type='checkbox' name='TRANSPARENT' $checked{'TRANSPARENT'}{'on'} /></td>
886         <td width='25%' class='base'>$Lang::tr{'advproxy proxy port transparent'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
887         <td width='30%'><input type='text' name='TRANSPARENT_PORT' value='$proxysettings{'TRANSPARENT_PORT'}' size='5' /></td>
888 </tr>
889 <tr>
890 END
891 ;
892 if ($netsettings{'BLUE_DEV'}) {
893         print "<td class='base'>$Lang::tr{'advproxy enabled on'} <font color='$Header::colourblue'>Blue</font>:</td>";
894         print "<td><input type='checkbox' name='ENABLE_BLUE' $checked{'ENABLE_BLUE'}{'on'} /></td>";
895 } else {
896         print "<td colspan='2'>&nbsp;</td>";
897 }
898 print <<END
899         <td class='base'>$Lang::tr{'advproxy visible hostname'}:</td>
900         <td><input type='text' name='VISIBLE_HOSTNAME' value='$proxysettings{'VISIBLE_HOSTNAME'}' /></td>
901 </tr>
902 <tr>
903 END
904 ;
905 if ($netsettings{'BLUE_DEV'}) {
906         print "<td class='base'>$Lang::tr{'advproxy transparent on'} <font color='$Header::colourblue'>Blue</font>:</td>";
907         print "<td><input type='checkbox' name='TRANSPARENT_BLUE' $checked{'TRANSPARENT_BLUE'}{'on'} /></td>";
908 } else {
909         print "<td colspan='2'>&nbsp;</td>";
910 }
911 print <<END
912         <td class='base'>$Lang::tr{'advproxy error language'}:</td>
913         <td class='base'>
914         <select name='ERR_LANGUAGE'>
915 END
916 ;
917         foreach (<$errordir/*>) {
918                 if (-d) {
919                         $language = substr($_,rindex($_,"/")+1);
920                         print "<option value='$language' $selected{'ERR_LANGUAGE'}{$language}>$language</option>\n";
921                 }
922         }
923 print <<END
924         </select>
925         </td>
926 </tr>
927 <tr>
928         <td class='base'>$Lang::tr{'advproxy suppress version'}:</td>
929         <td><input type='checkbox' name='SUPPRESS_VERSION' $checked{'SUPPRESS_VERSION'}{'on'} /></td>
930         <td class='base'>$Lang::tr{'advproxy error design'}:</td>
931         <td class='base'><select name='ERR_DESIGN'>
932                 <option value='ipfire' $selected{'ERR_DESIGN'}{'ipfire'}>IPFire</option>
933                 <option value='squid' $selected{'ERR_DESIGN'}{'squid'}>$Lang::tr{'advproxy standard'}</option>
934         </select></td>
935 </tr>
936 <tr>
937         <td class='base'>$Lang::tr{'advproxy squid version'}:</td>
938         <td class='base'>&nbsp;[<font color='$Header::colourred'> $squidversion[0] </font>]</td>
939         <td>&nbsp;</td>
940         <td>&nbsp;</td>
941 </tr>
942 </table>
943 <hr size='1'>
944 <table width='100%'>
945 END
946 ;
947 if ( -e "/usr/bin/squidclamav" ) {
948         print "<td class='base'><b>".$Lang::tr{'advproxy squidclamav'}."</b><br />";
949         if ( ! -e "/var/run/clamav/clamd.pid" ){
950                 print "<font color='red'>clamav not running</font><br /><br />";
951                 $proxysettings{'ENABLE_CLAMAV'} = 'off';
952                 }
953         else {
954                 print $Lang::tr{'advproxy enabled'}."<input type='checkbox' name='ENABLE_CLAMAV' ".$checked{'ENABLE_CLAMAV'}{'on'}." /><br />";
955 }
956         print "</td>";
957 } else {
958         print "<td></td>";
959 }
960 print "<td class='base'><a href='/cgi-bin/urlfilter.cgi'><b>".$Lang::tr{'advproxy url filter'}."</a></b><br />";
961 print $Lang::tr{'advproxy enabled'}."<input type='checkbox' name='ENABLE_FILTER' ".$checked{'ENABLE_FILTER'}{'on'}." /><br />";
962 print "</td>";
963 print "<td class='base'><a href='/cgi-bin/updatexlrator.cgi'><b>".$Lang::tr{'advproxy update accelerator'}."</a></b><br />";
964 print $Lang::tr{'advproxy enabled'}."<input type='checkbox' name='ENABLE_UPDXLRATOR' ".$checked{'ENABLE_UPDXLRATOR'}{'on'}." /><br />";
965 print "</td></tr>";
966 print <<END
967 </table>
968 <hr size='1'>
969 <table width='100%'>
970 <tr>
971         <td colspan='4' class='base'><b>$Lang::tr{'advproxy upstream proxy'}</b></td>
972 </tr>
973 <tr>
974         <td width='25%' class='base'>$Lang::tr{'advproxy via forwarding'}:</td>
975         <td width='20%'><input type='checkbox' name='FORWARD_VIA' $checked{'FORWARD_VIA'}{'on'} /></td>
976         <td width='25%' class='base'>$Lang::tr{'advproxy upstream proxy host:port'}:</td>
977         <td width='30%'><input type='text' name='UPSTREAM_PROXY' value='$proxysettings{'UPSTREAM_PROXY'}' /></td>
978 </tr>
979 <tr>
980         <td class='base'>$Lang::tr{'advproxy client IP forwarding'}:</td>
981         <td><input type='checkbox' name='FORWARD_IPADDRESS' $checked{'FORWARD_IPADDRESS'}{'on'} /></td>
982         <td class='base'>$Lang::tr{'advproxy upstream username'}:</td>
983         <td><input type='text' name='UPSTREAM_USER' value='$proxysettings{'UPSTREAM_USER'}' /></td>
984 </tr>
985 <tr>
986         <td class='base'>$Lang::tr{'advproxy username forwarding'}:</td>
987         <td><input type='checkbox' name='FORWARD_USERNAME' $checked{'FORWARD_USERNAME'}{'on'} /></td>
988         <td class='base'>$Lang::tr{'advproxy upstream password'}:</td>
989         <td><input type='password' name='UPSTREAM_PASSWORD' value='$proxysettings{'UPSTREAM_PASSWORD'}' /></td>
990 </tr>
991 <tr>
992         <td class='base'>$Lang::tr{'advproxy no connection auth'}:</td>
993         <td><input type='checkbox' name='NO_CONNECTION_AUTH' $checked{'NO_CONNECTION_AUTH'}{'on'} /></td>
994         <td>&nbsp;</td>
995         <td>&nbsp;</td>
996 </tr>
997 </table>
998 <hr size='1'>
999 <table width='100%'>
1000 <tr>
1001         <td colspan='4' class='base'><b>$Lang::tr{'advproxy log settings'}</b></td>
1002 </tr>
1003 <tr>
1004         <td width='25%' class='base'>$Lang::tr{'advproxy log enabled'}:</td>
1005         <td width='20%'><input type='checkbox' name='LOGGING' $checked{'LOGGING'}{'on'} /></td>
1006         <td width='25%'class='base'>$Lang::tr{'advproxy log query'}:</td>
1007         <td width='30%'><input type='checkbox' name='LOGQUERY' $checked{'LOGQUERY'}{'on'} /></td>
1008 </tr>
1009 <tr>
1010         <td>&nbsp;</td>
1011         <td>&nbsp;</td>
1012         <td class='base'>$Lang::tr{'advproxy log useragent'}:</td>
1013         <td><input type='checkbox' name='LOGUSERAGENT' $checked{'LOGUSERAGENT'}{'on'} /></td>
1014 </tr>
1015 </table>
1016 <hr size='1'>
1017 <table width='100%'>
1018 <tr>
1019         <td colspan='4'><b>$Lang::tr{'advproxy cache management'}</b></td>
1020 </tr>
1021 <tr>
1022         <td class='base'><a href='/cgi-bin/cachemgr.cgi' target='_blank'>$Lang::tr{'proxy cachemgr'}:</td>
1023         <td><input type='checkbox' name='CACHEMGR' $checked{'CACHEMGR'}{'on'} /></td>
1024         <td class='base'>$Lang::tr{'advproxy admin mail'}:</td>
1025         <td><input type='text' name='ADMIN_MAIL_ADDRESS' value='$proxysettings{'ADMIN_MAIL_ADDRESS'}' /></td>
1026 </tr>
1027 <tr>
1028         <td class='base'>$Lang::tr{'proxy filedescriptors'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1029         <td><input type='text' name='FILEDESCRIPTORS' value='$proxysettings{'FILEDESCRIPTORS'}' size='5' /></td>
1030         <td class='base'>$Lang::tr{'proxy admin password'}:</td>
1031         <td><input type='text' name='ADMIN_PASSWORD' value='$proxysettings{'ADMIN_PASSWORD'}' /></td>
1032 </tr>
1033 <tr>
1034         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1035 </tr>
1036 <tr>
1037         <td class='base'>$Lang::tr{'advproxy ram cache size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1038         <td><input type='text' name='CACHE_MEM' value='$proxysettings{'CACHE_MEM'}' size='5' /></td>
1039         <td class='base'>$Lang::tr{'advproxy hdd cache size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1040         <td><input type='text' name='CACHE_SIZE' value='$proxysettings{'CACHE_SIZE'}' size='5' /></td>
1041 </tr>
1042 <tr>
1043         <td class='base'>$Lang::tr{'advproxy min size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1044         <td><input type='text' name='MIN_SIZE' value='$proxysettings{'MIN_SIZE'}' size='5' /></td>
1045         <td class='base'>$Lang::tr{'advproxy max size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1046         <td><input type='text' name='MAX_SIZE' value='$proxysettings{'MAX_SIZE'}' size='5' /></td>
1047 </tr>
1048 <tr>
1049         <td class='base'>$Lang::tr{'advproxy number of L1 dirs'}:</td>
1050         <td class='base'><select name='L1_DIRS'>
1051                 <option value='16'  $selected{'L1_DIRS'}{'16'}>16</option>
1052                 <option value='32'  $selected{'L1_DIRS'}{'32'}>32</option>
1053                 <option value='64'  $selected{'L1_DIRS'}{'64'}>64</option>
1054                 <option value='128' $selected{'L1_DIRS'}{'128'}>128</option>
1055                 <option value='256' $selected{'L1_DIRS'}{'256'}>256</option>
1056         </select></td>
1057         <td colspan='2' rowspan= '5' valign='top' class='base'>
1058                 <table cellspacing='0' cellpadding='0'>
1059                         <tr>
1060                                 <!-- intentionally left empty -->
1061                         </tr>
1062                         <tr>
1063                         <td>$Lang::tr{'advproxy no cache sites'}:</td>
1064                         </tr>
1065                         <tr>
1066                                 <!-- intentionally left empty -->
1067                         </tr>
1068                         <tr>
1069                                 <!-- intentionally left empty -->
1070                         </tr>
1071                         <tr>
1072                         <td><textarea name='DST_NOCACHE' cols='32' rows='6' wrap='off'>
1073 END
1074 ;
1075
1076 print $proxysettings{'DST_NOCACHE'};
1077
1078 print <<END
1079 </textarea></td>
1080                 </tr>
1081                 </table>
1082         </td>
1083 </tr>
1084 <tr>
1085         <td class='base'>$Lang::tr{'advproxy memory replacement policy'}:</td>
1086         <td class='base'><select name='MEM_POLICY'>
1087                 <option value='LRU' $selected{'MEM_POLICY'}{'LRU'}>LRU</option>
1088                 <option value='heap LFUDA' $selected{'MEM_POLICY'}{'heap LFUDA'}>heap LFUDA</option>
1089                 <option value='heap GDSF' $selected{'MEM_POLICY'}{'heap GDSF'}>heap GDSF</option>
1090                 <option value='heap LRU' $selected{'MEM_POLICY'}{'heap LRU'}>heap LRU</option>
1091         </select></td>
1092 </tr>
1093 <tr>
1094         <td class='base'>$Lang::tr{'advproxy cache replacement policy'}:</td>
1095         <td class='base'><select name='CACHE_POLICY'>
1096                 <option value='LRU' $selected{'CACHE_POLICY'}{'LRU'}>LRU</option>
1097                 <option value='heap LFUDA' $selected{'CACHE_POLICY'}{'heap LFUDA'}>heap LFUDA</option>
1098                 <option value='heap GDSF' $selected{'CACHE_POLICY'}{'heap GDSF'}>heap GDSF</option>
1099                 <option value='heap LRU' $selected{'CACHE_POLICY'}{'heap LRU'}>heap LRU</option>
1100         </select></td>
1101 </tr>
1102 <tr>
1103         <td colspan='2'>&nbsp;</td>
1104 </tr>
1105 <tr>
1106         <td class='base'>$Lang::tr{'advproxy offline mode'}:</td>
1107         <td><input type='checkbox' name='OFFLINE_MODE' $checked{'OFFLINE_MODE'}{'on'} /></td>
1108 </tr>
1109 <tr>
1110         <td class='base'>$Lang::tr{'advproxy cache-digest'}:</td>
1111         <td><input type='checkbox' name='CACHE_DIGESTS' $checked{'CACHE_DIGESTS'}{'on'} /></td>
1112 </tr>
1113 </table>
1114 <hr size='1'>
1115 <table width='100%'>
1116 <tr>
1117         <td colspan='4'><b>$Lang::tr{'advproxy destination ports'}</b></td>
1118 </tr>
1119 <tr>
1120         <td width='25%' align='center'></td> <td width='20%' align='center'></td><td width='25%' align='center'></td><td width='30%' align='center'></td>
1121 </tr>
1122 <tr>
1123         <td colspan='2' class='base'>$Lang::tr{'advproxy standard ports'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1124         <td colspan='2' class='base'>$Lang::tr{'advproxy ssl ports'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1125 </tr>
1126 <tr>
1127         <td colspan='2'><textarea name='PORTS_SAFE' cols='32' rows='6' wrap='off'>
1128 END
1129 ;
1130         if (!$proxysettings{'PORTS_SAFE'}) { print $def_ports_safe; } else { print $proxysettings{'PORTS_SAFE'}; }
1131
1132 print <<END
1133 </textarea></td>
1134         <td colspan='2'><textarea name='PORTS_SSL' cols='32' rows='6' wrap='off'>
1135 END
1136 ;
1137         if (!$proxysettings{'PORTS_SSL'}) { print $def_ports_ssl; } else { print $proxysettings{'PORTS_SSL'}; }
1138
1139 print <<END
1140 </textarea></td>
1141 </tr>
1142 </table>
1143 <hr size='1'>
1144 <table width='100%'>
1145 <tr>
1146         <td colspan='4'><b>$Lang::tr{'advproxy network based access'}</b></td>
1147 </tr>
1148 <tr>
1149         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1150 </tr>
1151 <tr>
1152         <td colspan='4' class='base'>$Lang::tr{'advproxy allowed subnets'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1153 </tr>
1154 <tr>
1155         <td colspan='2' rowspan='4'><textarea name='SRC_SUBNETS' cols='32' rows='3' wrap='off'>
1156 END
1157 ;
1158
1159 if (!$proxysettings{'SRC_SUBNETS'})
1160 {
1161         print "$green_cidr\n";
1162         if ($netsettings{'BLUE_DEV'})
1163         {
1164                 print "$blue_cidr\n";
1165         }
1166 } else { print $proxysettings{'SRC_SUBNETS'}; }
1167
1168 print <<END
1169 </textarea></td>
1170 END
1171 ;
1172
1173 $line = $Lang::tr{'advproxy no internal proxy on green'};
1174 $line =~ s/Green/<font color="$Header::colourgreen">Green<\/font>/i;
1175 print "<td class='base'>$line:</td>\n";
1176 print <<END
1177         <td><input type='checkbox' name='NO_PROXY_LOCAL' $checked{'NO_PROXY_LOCAL'}{'on'} /></td>
1178 </tr>
1179 END
1180 ;
1181 if ($netsettings{'BLUE_DEV'}) {
1182         $line = $Lang::tr{'advproxy no internal proxy on blue'};
1183         $line =~ s/Blue/<font color="$Header::colourblue">Blue<\/font>/i;
1184         print "<tr>\n";
1185         print "<td class='base'>$line:</td>\n";
1186         print <<END
1187         <td><input type='checkbox' name='NO_PROXY_LOCAL_BLUE' $checked{'NO_PROXY_LOCAL_BLUE'}{'on'} /></td>
1188 </tr>
1189 END
1190 ;
1191 }
1192 print <<END
1193 <tr>
1194         <td colspan='2'>&nbsp;</td>
1195 </tr>
1196 <tr>
1197         <td colspan='2'>&nbsp;</td>
1198 </tr>
1199 </table>
1200 <table width='100%'>
1201 <tr>
1202         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1203 </tr>
1204 <tr>
1205         <td colspan='2' class='base'>$Lang::tr{'advproxy unrestricted ip clients'}:</td>
1206         <td colspan='2' class='base'>$Lang::tr{'advproxy unrestricted mac clients'}:</td>
1207 </tr>
1208 <tr>
1209         <td colspan='2'><textarea name='SRC_UNRESTRICTED_IP' cols='32' rows='3' wrap='off'>
1210 END
1211 ;
1212
1213         print $proxysettings{'SRC_UNRESTRICTED_IP'};
1214
1215 print <<END
1216 </textarea></td>
1217         <td colspan='2'><textarea name='SRC_UNRESTRICTED_MAC' cols='32' rows='3' wrap='off'>
1218 END
1219 ;
1220
1221 print $proxysettings{'SRC_UNRESTRICTED_MAC'};
1222
1223 print <<END
1224 </textarea></td>
1225 </tr>
1226 </table>
1227 <table width='100%'>
1228 <tr>
1229         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1230 </tr>
1231 <tr>
1232         <td colspan='2' class='base'>$Lang::tr{'advproxy banned ip clients'}:</td>
1233         <td colspan='2' class='base'>$Lang::tr{'advproxy banned mac clients'}:</td>
1234 </tr>
1235 <tr>
1236         <td colspan='2'><textarea name='SRC_BANNED_IP' cols='32' rows='3' wrap='off'>
1237 END
1238 ;
1239
1240         print $proxysettings{'SRC_BANNED_IP'};
1241
1242 print <<END
1243 </textarea></td>
1244         <td colspan='2'><textarea name='SRC_BANNED_MAC' cols='32' rows='3' wrap='off'>
1245 END
1246 ;
1247
1248 print $proxysettings{'SRC_BANNED_MAC'};
1249
1250 print <<END
1251 </textarea></td>
1252 </tr>
1253 </table>
1254
1255 <hr size='1'>
1256
1257 END
1258 ;
1259 # -------------------------------------------------------------------
1260 #  CRE GUI - optional
1261 # -------------------------------------------------------------------
1262
1263 if (-e $cre_enabled) { print <<END
1264 <table width='100%'>
1265
1266 <tr>
1267         <td colspan='4'><b>$Lang::tr{'advproxy classroom extensions'}</b> $Lang::tr{'advproxy enabled'}:<input type='checkbox' name='CLASSROOM_EXT' $checked{'CLASSROOM_EXT'}{'on'} /></td>
1268 </tr>
1269 <tr>
1270         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1271 </tr>
1272 <tr>
1273
1274 END
1275 ;
1276 if ($proxysettings{'CLASSROOM_EXT'} eq 'on'){
1277 print <<END
1278         <td class='base'>$Lang::tr{'advproxy supervisor password'}:</td>
1279         <td><input type='password' name='SUPERVISOR_PASSWORD' value='$proxysettings{'SUPERVISOR_PASSWORD'}' size='12' /></td>
1280 </tr>
1281 <tr>
1282         <td colspan='2' class='base'>$Lang::tr{'advproxy cre group definitions'}:</td>
1283         <td colspan='2' class='base'>$Lang::tr{'advproxy cre supervisors'}:</td>
1284 END
1285 ;
1286 }
1287 print "</tr>";
1288 if ($proxysettings{'CLASSROOM_EXT'} eq 'on'){
1289 print <<END
1290 <tr>
1291         <td colspan='2'><textarea name='CRE_GROUPS' cols='32' rows='6' wrap='off'>
1292 END
1293 ;
1294
1295         print $proxysettings{'CRE_GROUPS'};
1296
1297 print <<END
1298 </textarea></td>
1299         <td colspan='2'><textarea name='CRE_SVHOSTS' cols='32' rows='6' wrap='off'>
1300 END
1301 ;
1302         print $proxysettings{'CRE_SVHOSTS'};
1303
1304 print <<END
1305 </textarea></td>
1306 </tr>
1307 END
1308 ;
1309 }
1310 print "</table><hr size='1'>";
1311
1312 } else {
1313         print <<END
1314         <input type='hidden' name='SUPERVISOR_PASSWORD' value='$proxysettings{'SUPERVISOR_PASSWORD'}' />
1315         <input type='hidden' name='CRE_GROUPS'          value='$proxysettings{'CRE_GROUPS'}' />
1316         <input type='hidden' name='CRE_SVHOSTS'         value='$proxysettings{'CRE_SVHOSTS'}' />
1317 END
1318 ;
1319 }
1320
1321 # -------------------------------------------------------------------
1322
1323 print <<END
1324
1325 <table width='100%'>
1326 <tr>
1327         <td colspan='4'><b>$Lang::tr{'advproxy time restrictions'}</b></td>
1328 </tr>
1329 <table width='100%'>
1330 <tr>
1331         <td width='2%'>$Lang::tr{'advproxy access'}</td>
1332         <td width='1%'>&nbsp;</td>
1333         <td width='2%' align='center'>$Lang::tr{'advproxy monday'}</td>
1334         <td width='2%' align='center'>$Lang::tr{'advproxy tuesday'}</td>
1335         <td width='2%' align='center'>$Lang::tr{'advproxy wednesday'}</td>
1336         <td width='2%' align='center'>$Lang::tr{'advproxy thursday'}</td>
1337         <td width='2%' align='center'>$Lang::tr{'advproxy friday'}</td>
1338         <td width='2%' align='center'>$Lang::tr{'advproxy saturday'}</td>
1339         <td width='2%' align='center'>$Lang::tr{'advproxy sunday'}</td>
1340         <td width='1%'>&nbsp;&nbsp;</td>
1341         <td width='7%' colspan=3>$Lang::tr{'advproxy from'}</td>
1342         <td width='1%'>&nbsp;</td>
1343         <td width='7%' colspan=3>$Lang::tr{'advproxy to'}</td>
1344         <td>&nbsp;</td>
1345 </tr>
1346 <tr>
1347         <td class='base'>
1348         <select name='TIME_ACCESS_MODE'>
1349         <option value='allow' $selected{'TIME_ACCESS_MODE'}{'allow'}>$Lang::tr{'advproxy mode allow'}</option>
1350         <option value='deny'  $selected{'TIME_ACCESS_MODE'}{'deny'}>$Lang::tr{'advproxy mode deny'}</option>
1351         </select>
1352         </td>
1353         <td>&nbsp;</td>
1354         <td class='base'><input type='checkbox' name='TIME_MON' $checked{'TIME_MON'}{'on'} /></td>
1355         <td class='base'><input type='checkbox' name='TIME_TUE' $checked{'TIME_TUE'}{'on'} /></td>
1356         <td class='base'><input type='checkbox' name='TIME_WED' $checked{'TIME_WED'}{'on'} /></td>
1357         <td class='base'><input type='checkbox' name='TIME_THU' $checked{'TIME_THU'}{'on'} /></td>
1358         <td class='base'><input type='checkbox' name='TIME_FRI' $checked{'TIME_FRI'}{'on'} /></td>
1359         <td class='base'><input type='checkbox' name='TIME_SAT' $checked{'TIME_SAT'}{'on'} /></td>
1360         <td class='base'><input type='checkbox' name='TIME_SUN' $checked{'TIME_SUN'}{'on'} /></td>
1361         <td>&nbsp;</td>
1362         <td class='base'>
1363         <select name='TIME_FROM_HOUR'>
1364 END
1365 ;
1366 for ($i=0;$i<=24;$i++) {
1367         $_ = sprintf("%02s",$i);
1368         print "<option $selected{'TIME_FROM_HOUR'}{$_}>$_</option>\n";
1369 }
1370 print <<END
1371         </select>
1372         </td>
1373         <td>:</td>
1374         <td class='base'>
1375         <select name='TIME_FROM_MINUTE'>
1376 END
1377 ;
1378 for ($i=0;$i<=45;$i+=15) {
1379         $_ = sprintf("%02s",$i);
1380         print "<option $selected{'TIME_FROM_MINUTE'}{$_}>$_</option>\n";
1381 }
1382 print <<END
1383         </select>
1384         <td> - </td>
1385         </td>
1386         <td class='base'>
1387         <select name='TIME_TO_HOUR'>
1388 END
1389 ;
1390 for ($i=0;$i<=24;$i++) {
1391         $_ = sprintf("%02s",$i);
1392         print "<option $selected{'TIME_TO_HOUR'}{$_}>$_</option>\n";
1393 }
1394 print <<END
1395         </select>
1396         </td>
1397         <td>:</td>
1398         <td class='base'>
1399         <select name='TIME_TO_MINUTE'>
1400 END
1401 ;
1402 for ($i=0;$i<=45;$i+=15) {
1403         $_ = sprintf("%02s",$i);
1404         print "<option $selected{'TIME_TO_MINUTE'}{$_}>$_</option>\n";
1405 }
1406 print <<END
1407         </select>
1408         </td>
1409 </tr>
1410 </table>
1411 <hr size='1'>
1412 <table width='100%'>
1413 <tr>
1414         <td colspan='4'><b>$Lang::tr{'advproxy transfer limits'}</b></td>
1415 </tr>
1416 <tr>
1417         <td width='25%' class='base'>$Lang::tr{'advproxy max download size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1418         <td width='20%'><input type='text' name='MAX_INCOMING_SIZE' value='$proxysettings{'MAX_INCOMING_SIZE'}' size='5' /></td>
1419         <td width='25%' class='base'>$Lang::tr{'advproxy max upload size'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
1420         <td width='30%'><input type='text' name='MAX_OUTGOING_SIZE' value='$proxysettings{'MAX_OUTGOING_SIZE'}' size='5' /></td>
1421 </tr>
1422 </table>
1423 <hr size='1'>
1424 <table width='100%'>
1425 <tr>
1426         <td colspan='4'><b>$Lang::tr{'advproxy download throttling'}</b></td>
1427 </tr>
1428 <tr>
1429         <td width='25%' class='base'>$Lang::tr{'advproxy throttling total on'} <font color="$Header::colourgreen">Green</font>:</td>
1430         <td width='20%' class='base'>
1431         <select name='THROTTLING_GREEN_TOTAL'>
1432 END
1433 ;
1434
1435 foreach (@throttle_limits) {
1436         my $val = $_;
1437         my $unit = "kbit/s";
1438
1439         if ($val >= 1024) {
1440                 $unit = "Mbit/s";
1441                 $val /= 1024;
1442         }
1443
1444         print "\t<option value='$_' $selected{'THROTTLING_GREEN_TOTAL'}{$_}>$val $unit</option>\n";
1445 }
1446
1447 print <<END
1448         <option value='0' $selected{'THROTTLING_GREEN_TOTAL'}{'unlimited'}>$Lang::tr{'advproxy throttling unlimited'}</option>\n";
1449         </select>
1450         </td>
1451         <td width='25%' class='base'>$Lang::tr{'advproxy throttling per host on'} <font color="$Header::colourgreen">Green</font>:</td>
1452         <td width='30%' class='base'>
1453         <select name='THROTTLING_GREEN_HOST'>
1454 END
1455 ;
1456
1457 foreach (@throttle_limits) {
1458         print "\t<option value='$_' $selected{'THROTTLING_GREEN_HOST'}{$_}>$_ kbit/s</option>\n";
1459 }
1460
1461 print <<END
1462         <option value='0' $selected{'THROTTLING_GREEN_HOST'}{'unlimited'}>$Lang::tr{'advproxy throttling unlimited'}</option>\n";
1463         </select>
1464         </td>
1465 </tr>
1466 END
1467 ;
1468
1469 if ($netsettings{'BLUE_DEV'}) {
1470         print <<END
1471 <tr>
1472         <td class='base'>$Lang::tr{'advproxy throttling total on'} <font color="$Header::colourblue">Blue</font>:</td>
1473         <td class='base'>
1474         <select name='THROTTLING_BLUE_TOTAL'>
1475 END
1476 ;
1477
1478 foreach (@throttle_limits) {
1479         print "\t<option value='$_' $selected{'THROTTLING_BLUE_TOTAL'}{$_}>$_ kbit/s</option>\n";
1480 }
1481
1482 print <<END
1483         <option value='0' $selected{'THROTTLING_BLUE_TOTAL'}{'unlimited'}>$Lang::tr{'advproxy throttling unlimited'}</option>\n";
1484         </select>
1485         </td>
1486         <td class='base'>$Lang::tr{'advproxy throttling per host on'} <font color="$Header::colourblue">Blue</font>:</td>
1487         <td class='base'>
1488         <select name='THROTTLING_BLUE_HOST'>
1489 END
1490 ;
1491
1492 foreach (@throttle_limits) {
1493         print "\t<option value='$_' $selected{'THROTTLING_BLUE_HOST'}{$_}>$_ kbit/s</option>\n";
1494 }
1495
1496 print <<END
1497         <option value='0' $selected{'THROTTLING_BLUE_HOST'}{'unlimited'}>$Lang::tr{'advproxy throttling unlimited'}</option>\n";
1498         </select>
1499         </td>
1500 </tr>
1501 END
1502 ;
1503 }
1504
1505 print <<END
1506 </table>
1507 <hr size='1'>
1508 <table width='100%'>
1509 <tr>
1510         <td colspan='4'><b>$Lang::tr{'advproxy MIME filter'}</b> $Lang::tr{'advproxy enabled'}:<input type='checkbox' name='ENABLE_MIME_FILTER' $checked{'ENABLE_MIME_FILTER'}{'on'} /></td>
1511 </tr>
1512 END
1513 ;
1514 if ( $proxysettings{'ENABLE_MIME_FILTER'} eq 'on' ){
1515 print <<END
1516 <tr>
1517         <td  colspan='2' class='base'>$Lang::tr{'advproxy MIME block types'}:</td>
1518         <td>&nbsp;</td>
1519         <td>&nbsp;</td>
1520 </tr>
1521 <tr>
1522         <td colspan='2'><textarea name='MIME_TYPES' cols='32' rows='6' wrap='off'>
1523 END
1524 ;
1525
1526 print $proxysettings{'MIME_TYPES'};
1527
1528 print <<END
1529 </textarea></td>
1530         <td>&nbsp;</td>
1531         <td>&nbsp;</td>
1532 </tr>
1533 END
1534 ;
1535 }
1536 print <<END
1537 </table>
1538
1539 <hr size='1'>
1540
1541 <table width='100%'>
1542 <tr>
1543         <td><b>$Lang::tr{'advproxy privacy'}</b></td>
1544 </tr>
1545 <tr>
1546         <td class='base'>$Lang::tr{'advproxy fake useragent'}:</td>
1547         <td class='base'>$Lang::tr{'advproxy fake referer'}:</td>
1548 </tr>
1549 <tr>
1550         <td><input type='text' name='FAKE_USERAGENT' value='$proxysettings{'FAKE_USERAGENT'}' size='40%' /></td>
1551         <td><input type='text' name='FAKE_REFERER' value='$proxysettings{'FAKE_REFERER'}' size='40%' /></td>
1552 </tr>
1553 </table>
1554 <hr size='1'>
1555 END
1556 ;
1557
1558 my $auth_columns = 5;
1559 if ($HAVE_NTLM_AUTH) {
1560         $auth_columns++;
1561 }
1562 my $auth_column_width = 100 / $auth_columns;
1563
1564 print <<END;
1565 <table width='100%'>
1566 <tr>
1567         <td colspan='$auth_columns'><b>$Lang::tr{'advproxy AUTH method'}</b></td>
1568 </tr>
1569 <tr>
1570         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='none' $checked{'AUTH_METHOD'}{'none'} />$Lang::tr{'advproxy AUTH method none'}</td>
1571         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='ncsa' $checked{'AUTH_METHOD'}{'ncsa'} />$Lang::tr{'advproxy AUTH method ncsa'}</td>
1572         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='ident' $checked{'AUTH_METHOD'}{'ident'} />$Lang::tr{'advproxy AUTH method ident'}</td>
1573         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='ldap' $checked{'AUTH_METHOD'}{'ldap'} />$Lang::tr{'advproxy AUTH method ldap'}</td>
1574 END
1575
1576 if ($HAVE_NTLM_AUTH) {
1577         print <<END;
1578         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='ntlm-auth' $checked{'AUTH_METHOD'}{'ntlm-auth'} />$Lang::tr{'advproxy AUTH method ntlm auth'}</td>
1579 END
1580 }
1581
1582 print <<END
1583         <td width='$auth_column_width%' class='base'><input type='radio' name='AUTH_METHOD' value='radius' $checked{'AUTH_METHOD'}{'radius'} />$Lang::tr{'advproxy AUTH method radius'}</td>
1584 </tr>
1585 </table>
1586 END
1587 ;
1588
1589 if (!($proxysettings{'AUTH_METHOD'} eq 'none')) { if (!($proxysettings{'AUTH_METHOD'} eq 'ident')) { print <<END
1590 <hr size='1'>
1591 <table width='100%'>
1592 <tr>
1593         <td colspan='4'><b>$Lang::tr{'advproxy AUTH global settings'}</b></td>
1594 </tr>
1595 <tr>
1596         <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
1597 </tr>
1598 <tr>
1599         <td class='base'>$Lang::tr{'advproxy AUTH number of auth processes'}:</td>
1600         <td><input type='text' name='AUTH_CHILDREN' value='$proxysettings{'AUTH_CHILDREN'}' size='5' /></td>
1601         <td colspan='2' rowspan= '6' valign='top' class='base'>
1602                 <table cellpadding='0' cellspacing='0'>
1603                         <tr>
1604                         <td class='base'>$Lang::tr{'advproxy AUTH realm'}:</td>
1605                         </tr>
1606                         <tr>
1607                                 <!-- intentionally left empty -->
1608                         </tr>
1609                         <tr>
1610                                 <!-- intentionally left empty -->
1611                         </tr>
1612                         <tr>
1613                         <td><input type='text' name='AUTH_REALM' value='$proxysettings{'AUTH_REALM'}' size='40' /></td>
1614                         </tr>
1615                         <tr>
1616                                 <!-- intentionally left empty -->
1617                         </tr>
1618                         <tr>
1619                                 <!-- intentionally left empty -->
1620                         </tr>
1621                         <tr>
1622                         <td>$Lang::tr{'advproxy AUTH no auth'}:</td>
1623                         </tr>
1624                         <tr>
1625                                 <!-- intentionally left empty -->
1626                         </tr>
1627                         <tr>
1628                                 <!-- intentionally left empty -->
1629                         </tr>
1630                         <tr>
1631                         <td><textarea name='DST_NOAUTH' cols='32' rows='6' wrap='off'>
1632 END
1633 ;
1634
1635 print $proxysettings{'DST_NOAUTH'};
1636
1637 print <<END
1638 </textarea></td>
1639                 </tr>
1640                 </table>
1641         </td>
1642 </tr>
1643 <tr>
1644         <td class='base'>$Lang::tr{'advproxy AUTH auth cache TTL'}:</td>
1645         <td><input type='text' name='AUTH_CACHE_TTL' value='$proxysettings{'AUTH_CACHE_TTL'}' size='5' /></td>
1646 </tr>
1647 <tr>
1648         <td class='base'>$Lang::tr{'advproxy AUTH limit of IP addresses'}:</td>
1649         <td><input type='text' name='AUTH_MAX_USERIP' value='$proxysettings{'AUTH_MAX_USERIP'}' size='5' /></td>
1650 </tr>
1651 <tr>
1652         <td class='base'>$Lang::tr{'advproxy AUTH always required'}:</td>
1653         <td><input type='checkbox' name='AUTH_ALWAYS_REQUIRED' $checked{'AUTH_ALWAYS_REQUIRED'}{'on'} /></td>
1654 </tr>
1655 <tr>
1656         <td colspan='2'>&nbsp;</td>
1657 </tr>
1658 </table>
1659 END
1660 ;
1661 }
1662
1663 # ===================================================================
1664 #  NCSA auth settings
1665 # ===================================================================
1666
1667 if ($proxysettings{'AUTH_METHOD'} eq 'ncsa') {
1668 print <<END
1669 <hr size='1'>
1670 <table width='100%'>
1671 <tr>
1672         <td colspan='4'><b>$Lang::tr{'advproxy NCSA auth'}</b></td>
1673 </tr>
1674 <tr>
1675         <td width='25%' class='base'>$Lang::tr{'advproxy NCSA min password length'}:</td>
1676         <td width='20%'><input type='text' name='NCSA_MIN_PASS_LEN' value='$proxysettings{'NCSA_MIN_PASS_LEN'}' size='5' /></td>
1677         <td width='25%' class='base'>$Lang::tr{'advproxy NCSA redirector bypass'} \'$Lang::tr{'advproxy NCSA grp extended'}\':</td>
1678         <td width='20%'><input type='checkbox' name='NCSA_BYPASS_REDIR' $checked{'NCSA_BYPASS_REDIR'}{'on'} /></td>
1679 </tr>
1680 <tr>
1681         <td colspan='2'><br>&nbsp;<input type='submit' name='ACTION' value='$Lang::tr{'advproxy NCSA user management'}'></td>
1682         <td>&nbsp;</td>
1683         <td>&nbsp;</td>
1684 </tr>
1685 </table>
1686 END
1687 ; }
1688
1689 # ===================================================================
1690 #  IDENTD auth settings
1691 # ===================================================================
1692
1693 if ($proxysettings{'AUTH_METHOD'} eq 'ident') {
1694 print <<END
1695 <hr size ='1'>
1696 <table width='100%'>
1697 <tr>
1698         <td colspan='4'><b>$Lang::tr{'advproxy IDENT identd settings'}</b></td>
1699 </tr>
1700 <tr>
1701         <td width='25%' class='base'>$Lang::tr{'advproxy IDENT required'}:</td>
1702         <td width='20%'><input type='checkbox' name='IDENT_REQUIRED' $checked{'IDENT_REQUIRED'}{'on'} /></td>
1703         <td width='25%' class='base'>$Lang::tr{'advproxy AUTH always required'}:</td>
1704         <td width='30%'><input type='checkbox' name='AUTH_ALWAYS_REQUIRED' $checked{'AUTH_ALWAYS_REQUIRED'}{'on'} /></td>
1705 </tr>
1706 <tr>
1707         <td class='base'>$Lang::tr{'advproxy IDENT timeout'}:</td>
1708         <td><input type='text' name='IDENT_TIMEOUT' value='$proxysettings{'IDENT_TIMEOUT'}' size='5' /></td>
1709         <td>&nbsp;</td>
1710         <td>&nbsp;</td>
1711 </tr>
1712 <tr>
1713         <td colspan='2' class='base'>$Lang::tr{'advproxy IDENT aware hosts'}:</td>
1714         <td colspan='2' class='base'>$Lang::tr{'advproxy AUTH no auth'}:</td>
1715 </tr>
1716 <tr>
1717         <td colspan='2'><textarea name='IDENT_HOSTS' cols='32' rows='6' wrap='off'>
1718 END
1719 ;
1720 if (!$proxysettings{'IDENT_HOSTS'}) {
1721         print "$green_cidr\n";
1722         if ($netsettings{'BLUE_DEV'}) {
1723                 print "$blue_cidr\n";
1724         }
1725 } else {
1726         print $proxysettings{'IDENT_HOSTS'};
1727 }
1728
1729 print <<END
1730 </textarea></td>
1731                         <td colspan='2'><textarea name='DST_NOAUTH' cols='32' rows='6' wrap='off'>
1732 END
1733 ;
1734
1735 print $proxysettings{'DST_NOAUTH'};
1736
1737 print <<END
1738 </textarea></td>
1739 </tr>
1740 </table>
1741 <hr size ='1'>
1742 <table width='100%'>
1743 <tr>
1744         <td colspan='4'><b>$Lang::tr{'advproxy IDENT user based access restrictions'}</b></td>
1745 </tr>
1746 <tr>
1747         <td width='25%' class='base'>$Lang::tr{'advproxy enabled'}:</td>
1748         <td width='20%'><input type='checkbox' name='IDENT_ENABLE_ACL' $checked{'IDENT_ENABLE_ACL'}{'on'} /></td>
1749         <td width='25%'>&nbsp;</td>
1750         <td width='30%'>&nbsp;</td>
1751 </tr>
1752 <tr>
1753         <td colspan='2'><input type='radio' name='IDENT_USER_ACL' value='positive' $checked{'IDENT_USER_ACL'}{'positive'} />
1754         $Lang::tr{'advproxy IDENT use positive access list'}:</td>
1755         <td colspan='2'><input type='radio' name='IDENT_USER_ACL' value='negative' $checked{'IDENT_USER_ACL'}{'negative'} />
1756         $Lang::tr{'advproxy IDENT use negative access list'}:</td>
1757 </tr>
1758 <tr>
1759         <td colspan='2'>$Lang::tr{'advproxy IDENT authorized users'}</td>
1760         <td colspan='2'>$Lang::tr{'advproxy IDENT unauthorized users'}</td>
1761 </tr>
1762 <tr>
1763         <td colspan='2'><textarea name='IDENT_ALLOW_USERS' cols='32' rows='6' wrap='off'>
1764 END
1765 ; }
1766
1767 if ($proxysettings{'AUTH_METHOD'} eq 'ident') { print $proxysettings{'IDENT_ALLOW_USERS'}; }
1768
1769 if ($proxysettings{'AUTH_METHOD'} eq 'ident') { print <<END
1770 </textarea></td>
1771         <td colspan='2'><textarea name='IDENT_DENY_USERS' cols='32' rows='6' wrap='off'>
1772 END
1773 ; }
1774
1775 if ($proxysettings{'AUTH_METHOD'} eq 'ident') { print $proxysettings{'IDENT_DENY_USERS'}; }
1776
1777 if ($proxysettings{'AUTH_METHOD'} eq 'ident') { print <<END
1778 </textarea></td>
1779 </tr>
1780 </table>
1781 END
1782 ; }
1783
1784 # ===================================================================
1785 #  NTLM-AUTH settings
1786 # ===================================================================
1787
1788 if ($proxysettings{'AUTH_METHOD'} eq 'ntlm-auth') {
1789         print <<END;
1790                 <hr size ='1'>
1791                 <table width='100%'>
1792                         <td width='20%' class='base'>$Lang::tr{'advproxy basic authentication'}:</td>
1793                         <td width='40%'><input type='checkbox' name='NTLM_AUTH_BASIC' $checked{'NTLM_AUTH_BASIC'}{'on'} /></td>
1794                         <td colspan='2'>&nbsp;</td>
1795                 </table>
1796
1797                 <hr size='1' />
1798
1799                 <table width='100%'>
1800                         <tr>
1801                                 <td colspan='4'><b>$Lang::tr{'advproxy group access control'}</b></td>
1802                         </tr>
1803                         <tr>
1804                                 <td width='20%' class='base'>$Lang::tr{'advproxy group required'}:</td>
1805                                 <td width='40%'><input type='text' name='NTLM_AUTH_GROUP' value='$proxysettings{'NTLM_AUTH_GROUP'}' size='37' /></td>
1806                                 <td>&nbsp;</td>
1807                                 <td>&nbsp;</td>
1808                         </tr>
1809         </table>
1810 END
1811 }
1812
1813 # ===================================================================
1814 #  LDAP auth settings
1815 # ===================================================================
1816
1817 if ($proxysettings{'AUTH_METHOD'} eq 'ldap') {
1818 print <<END
1819 <hr size='1'>
1820 <table width='100%'>
1821 <tr>
1822         <td colspan='4'><b>$Lang::tr{'advproxy LDAP common settings'}</b></td>
1823 </tr>
1824 <tr>
1825         <td class='base'>$Lang::tr{'advproxy LDAP basedn'}:</td>
1826         <td><input type='text' name='LDAP_BASEDN' value='$proxysettings{'LDAP_BASEDN'}' size='37' /></td>
1827         <td class='base'>$Lang::tr{'advproxy LDAP type'}:</td>
1828         <td class='base'><select name='LDAP_TYPE'>
1829                 <option value='ADS' $selected{'LDAP_TYPE'}{'ADS'}>$Lang::tr{'advproxy LDAP ADS'}</option>
1830                 <option value='NDS' $selected{'LDAP_TYPE'}{'NDS'}>$Lang::tr{'advproxy LDAP NDS'}</option>
1831                 <option value='V2' $selected{'LDAP_TYPE'}{'V2'}>$Lang::tr{'advproxy LDAP V2'}</option>
1832                 <option value='V3' $selected{'LDAP_TYPE'}{'V3'}>$Lang::tr{'advproxy LDAP V3'}</option>
1833         </select></td>
1834 </tr>
1835 <tr>
1836         <td width='20%' class='base'>$Lang::tr{'advproxy LDAP server'}:</td>
1837         <td width='40%'><input type='text' name='LDAP_SERVER' value='$proxysettings{'LDAP_SERVER'}' size='14' /></td>
1838         <td width='20%' class='base'>$Lang::tr{'advproxy LDAP port'}:</td>
1839         <td><input type='text' name='LDAP_PORT' value='$proxysettings{'LDAP_PORT'}' size='3' /></td>
1840 </tr>
1841 </table>
1842 <hr size ='1'>
1843 <table width='100%'>
1844 <tr>
1845         <td colspan='4'><b>$Lang::tr{'advproxy LDAP binddn settings'}</b></td>
1846 </tr>
1847 <tr>
1848         <td width='20%' class='base'>$Lang::tr{'advproxy LDAP binddn username'}:</td>
1849         <td width='40%'><input type='text' name='LDAP_BINDDN_USER' value='$proxysettings{'LDAP_BINDDN_USER'}' size='37' /></td>
1850         <td width='20%' class='base'>$Lang::tr{'advproxy LDAP binddn password'}:</td>
1851         <td><input type='password' name='LDAP_BINDDN_PASS' value='$proxysettings{'LDAP_BINDDN_PASS'}' size='14' /></td>
1852 </tr>
1853 </table>
1854 <hr size ='1'>
1855 <table width='100%'>
1856 <tr>
1857         <td colspan='4'><b>$Lang::tr{'advproxy LDAP group access control'}</b></td>
1858 </tr>
1859 <tr>
1860         <td width='20%' class='base'>$Lang::tr{'advproxy LDAP group required'}:</td>
1861         <td width='40%'><input type='text' name='LDAP_GROUP' value='$proxysettings{'LDAP_GROUP'}' size='37' /></td>
1862         <td>&nbsp;</td>
1863         <td>&nbsp;</td>
1864 </tr>
1865 </table>
1866 END
1867 ; }
1868
1869 # ===================================================================
1870 #  RADIUS auth settings
1871 # ===================================================================
1872
1873 if ($proxysettings{'AUTH_METHOD'} eq 'radius') {
1874 print <<END
1875 <hr size='1'>
1876 <table width='100%'>
1877 <tr>
1878         <td colspan='4'><b>$Lang::tr{'advproxy RADIUS radius settings'}</b></td>
1879 </tr>
1880 <tr>
1881         <td width='25%' class='base'>$Lang::tr{'advproxy RADIUS server'}:</td>
1882         <td width='20%'><input type='text' name='RADIUS_SERVER' value='$proxysettings{'RADIUS_SERVER'}' size='14' /></td>
1883         <td width='25%' class='base'>$Lang::tr{'advproxy RADIUS port'}:</td>
1884         <td width='30%'><input type='text' name='RADIUS_PORT' value='$proxysettings{'RADIUS_PORT'}' size='3' /></td>
1885 </tr>
1886 <tr>
1887         <td class='base'>$Lang::tr{'advproxy RADIUS identifier'}:</td>
1888         <td><input type='text' name='RADIUS_IDENTIFIER' value='$proxysettings{'RADIUS_IDENTIFIER'}' size='14' /></td>
1889         <td class='base'>$Lang::tr{'advproxy RADIUS secret'}:</td>
1890         <td><input type='password' name='RADIUS_SECRET' value='$proxysettings{'RADIUS_SECRET'}' size='14' /></td>
1891 </tr>
1892 </table>
1893 <hr size ='1'>
1894 <table width='100%'>
1895 <tr>
1896         <td colspan='4'><b>$Lang::tr{'advproxy RADIUS user based access restrictions'}</b></td>
1897 </tr>
1898 <tr>
1899         <td width='25%' class='base'>$Lang::tr{'advproxy enabled'}:</td>
1900         <td width='20%'><input type='checkbox' name='RADIUS_ENABLE_ACL' $checked{'RADIUS_ENABLE_ACL'}{'on'} /></td>
1901         <td width='25%'>&nbsp;</td>
1902         <td width='30%'>&nbsp;</td>
1903 </tr>
1904 <tr>
1905         <td colspan='2'><input type='radio' name='RADIUS_USER_ACL' value='positive' $checked{'RADIUS_USER_ACL'}{'positive'} />
1906         $Lang::tr{'advproxy RADIUS use positive access list'}:</td>
1907         <td colspan='2'><input type='radio' name='RADIUS_USER_ACL' value='negative' $checked{'RADIUS_USER_ACL'}{'negative'} />
1908         $Lang::tr{'advproxy RADIUS use negative access list'}:</td>
1909 </tr>
1910 <tr>
1911         <td colspan='2'>$Lang::tr{'advproxy RADIUS authorized users'}</td>
1912         <td colspan='2'>$Lang::tr{'advproxy RADIUS unauthorized users'}</td>
1913 </tr>
1914 <tr>
1915         <td colspan='2'><textarea name='RADIUS_ALLOW_USERS' cols='32' rows='6' wrap='off'>
1916 END
1917 ; }
1918
1919 if ($proxysettings{'AUTH_METHOD'} eq 'radius') { print $proxysettings{'RADIUS_ALLOW_USERS'}; }
1920
1921 if ($proxysettings{'AUTH_METHOD'} eq 'radius') { print <<END
1922 </textarea></td>
1923         <td colspan='2'><textarea name='RADIUS_DENY_USERS' cols='32' rows='6' wrap='off'>
1924 END
1925 ; }
1926
1927 if ($proxysettings{'AUTH_METHOD'} eq 'radius') { print $proxysettings{'RADIUS_DENY_USERS'}; }
1928
1929 if ($proxysettings{'AUTH_METHOD'} eq 'radius') { print <<END
1930 </textarea></td>
1931 </tr>
1932 </table>
1933 END
1934 ; }
1935
1936 # ===================================================================
1937
1938 }
1939
1940 print "<table>\n";
1941
1942 if ($proxysettings{'AUTH_METHOD'} eq 'none') {
1943 print <<END
1944 <td><input type='hidden' name='AUTH_CHILDREN'        value='$proxysettings{'AUTH_CHILDREN'}'></td>
1945 <td><input type='hidden' name='AUTH_CACHE_TTL'       value='$proxysettings{'AUTH_CACHE_TTL'}' size='5' /></td>
1946 <td><input type='hidden' name='AUTH_MAX_USERIP'      value='$proxysettings{'AUTH_MAX_USERIP'}' size='5' /></td>
1947 <td><input type='hidden' name='AUTH_ALWAYS_REQUIRED' value='$proxysettings{'AUTH_ALWAYS_REQUIRED'}'></td>
1948 <td><input type='hidden' name='AUTH_REALM'           value='$proxysettings{'AUTH_REALM'}'></td>
1949 <td><input type='hidden' name='DST_NOAUTH'           value='$proxysettings{'DST_NOAUTH'}'></td>
1950 END
1951 ; }
1952
1953 if ($proxysettings{'AUTH_METHOD'} eq 'ident') {
1954 print <<END
1955 <td><input type='hidden' name='AUTH_CHILDREN'        value='$proxysettings{'AUTH_CHILDREN'}'></td>
1956 <td><input type='hidden' name='AUTH_CACHE_TTL'       value='$proxysettings{'AUTH_CACHE_TTL'}' size='5' /></td>
1957 <td><input type='hidden' name='AUTH_MAX_USERIP'      value='$proxysettings{'AUTH_MAX_USERIP'}' size='5' /></td>
1958 <td><input type='hidden' name='AUTH_REALM'           value='$proxysettings{'AUTH_REALM'}'></td>
1959 END
1960 ; }
1961
1962 if (!($proxysettings{'AUTH_METHOD'} eq 'ncsa')) {
1963 print <<END
1964 <td><input type='hidden' name='NCSA_MIN_PASS_LEN' value='$proxysettings{'NCSA_MIN_PASS_LEN'}'></td>
1965 <td><input type='hidden' name='NCSA_BYPASS_REDIR' value='$proxysettings{'NCSA_BYPASS_REDIR'}'></td>
1966 END
1967 ; }
1968
1969 if (!($proxysettings{'AUTH_METHOD'} eq 'ident')) {
1970 print <<END
1971 <td><input type='hidden' name='IDENT_REQUIRED'    value='$proxysettings{'IDENT_REQUIRED'}'></td>
1972 <td><input type='hidden' name='IDENT_TIMEOUT'     value='$proxysettings{'IDENT_TIMEOUT'}'></td>
1973 <td><input type='hidden' name='IDENT_HOSTS'       value='$proxysettings{'IDENT_HOSTS'}'></td>
1974 <td><input type='hidden' name='IDENT_ENABLE_ACL'  value='$proxysettings{'IDENT_ENABLE_ACL'}'></td>
1975 <td><input type='hidden' name='IDENT_USER_ACL'    value='$proxysettings{'IDENT_USER_ACL'}'></td>
1976 <td><input type='hidden' name='IDENT_ALLOW_USERS' value='$proxysettings{'IDENT_ALLOW_USERS'}'></td>
1977 <td><input type='hidden' name='IDENT_DENY_USERS'  value='$proxysettings{'IDENT_DENY_USERS'}'></td>
1978 END
1979 ; }
1980
1981 if (!($proxysettings{'AUTH_METHOD'} eq 'ldap')) {
1982 print <<END
1983 <td><input type='hidden' name='LDAP_BASEDN'      value='$proxysettings{'LDAP_BASEDN'}'></td>
1984 <td><input type='hidden' name='LDAP_TYPE'        value='$proxysettings{'LDAP_TYPE'}'></td>
1985 <td><input type='hidden' name='LDAP_SERVER'      value='$proxysettings{'LDAP_SERVER'}'></td>
1986 <td><input type='hidden' name='LDAP_PORT'        value='$proxysettings{'LDAP_PORT'}'></td>
1987 <td><input type='hidden' name='LDAP_BINDDN_USER' value='$proxysettings{'LDAP_BINDDN_USER'}'></td>
1988 <td><input type='hidden' name='LDAP_BINDDN_PASS' value='$proxysettings{'LDAP_BINDDN_PASS'}'></td>
1989 <td><input type='hidden' name='LDAP_GROUP'       value='$proxysettings{'LDAP_GROUP'}'></td>
1990 END
1991 ; }
1992
1993 if (!($proxysettings{'AUTH_METHOD'} eq 'radius')) {
1994 print <<END
1995 <td><input type='hidden' name='RADIUS_SERVER'      value='$proxysettings{'RADIUS_SERVER'}'></td>
1996 <td><input type='hidden' name='RADIUS_PORT'        value='$proxysettings{'RADIUS_PORT'}'></td>
1997 <td><input type='hidden' name='RADIUS_IDENTIFIER'  value='$proxysettings{'RADIUS_IDENTIFIER'}'></td>
1998 <td><input type='hidden' name='RADIUS_SECRET'      value='$proxysettings{'RADIUS_SECRET'}'></td>
1999 <td><input type='hidden' name='RADIUS_ENABLE_ACL'  value='$proxysettings{'RADIUS_ENABLE_ACL'}'></td>
2000 <td><input type='hidden' name='RADIUS_USER_ACL'    value='$proxysettings{'RADIUS_USER_ACL'}'></td>
2001 <td><input type='hidden' name='RADIUS_ALLOW_USERS' value='$proxysettings{'RADIUS_ALLOW_USERS'}'></td>
2002 <td><input type='hidden' name='RADIUS_DENY_USERS'  value='$proxysettings{'RADIUS_DENY_USERS'}'></td>
2003 END
2004 ; }
2005
2006 print "</table>\n";
2007
2008 print <<END
2009 <hr size='1'>
2010 END
2011 ;
2012
2013 print <<END
2014 <table width='100%'>
2015 <tr>
2016         <td>&nbsp;</td>
2017         <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
2018         <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'proxy reconfigure'}' /></td>
2019         <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'advproxy save and restart'}' /></td>
2020         <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'advproxy clear cache'}' /></td>
2021         <td>&nbsp;</td>
2022 </tr>
2023
2024 </table>
2025 <br />
2026 <table width='100%'>
2027 <tr>
2028         <td><img src='/blob.gif' align='top' alt='*' />&nbsp;<font class='base'>$Lang::tr{'required field'}</font></td>
2029         <td align='right'>&nbsp;</td>
2030 </tr>
2031 </table>
2032 </form>
2033 END
2034 ;
2035
2036 &Header::closebox();
2037
2038 } else {
2039
2040 # ===================================================================
2041 #  NCSA user management
2042 # ===================================================================
2043
2044 &Header::openbox('100%', 'left', "$Lang::tr{'advproxy NCSA auth'}");
2045 print <<END
2046 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2047 <table width='100%'>
2048 <tr>
2049         <td colspan='4'><b>$Lang::tr{'advproxy NCSA user management'}</b></td>
2050 </tr>
2051 <tr>
2052         <td width='25%' class='base'>$Lang::tr{'advproxy NCSA username'}:</td>
2053         <td width='25%'><input type='text' name='NCSA_USERNAME' value='$proxysettings{'NCSA_USERNAME'}' size='12'
2054 END
2055 ;
2056         if ($proxysettings{'ACTION'} eq $Lang::tr{'edit'}) { print " readonly='readonly' "; }
2057         print <<END
2058          /></td>
2059         <td width='25%' class='base'>$Lang::tr{'advproxy NCSA group'}:</td>
2060         <td class='base'>
2061                 <select name='NCSA_GROUP'>
2062                 <option value='standard' $selected{'NCSA_GROUP'}{'standard'}>$Lang::tr{'advproxy NCSA grp standard'}</option>
2063                 <option value='extended' $selected{'NCSA_GROUP'}{'extended'}>$Lang::tr{'advproxy NCSA grp extended'}</option>
2064                 <option value='disabled' $selected{'NCSA_GROUP'}{'disabled'}>$Lang::tr{'advproxy NCSA grp disabled'}</option>
2065                 </select>
2066         </td>
2067
2068 </tr>
2069 <tr>
2070         <td class='base'>$Lang::tr{'advproxy NCSA password'}:</td>
2071         <td><input type='password' name='NCSA_PASS' value='$proxysettings{'NCSA_PASS'}' size='14' /></td>
2072         <td class='base'>$Lang::tr{'advproxy NCSA password confirm'}:</td>
2073         <td><input type='password' name='NCSA_PASS_CONFIRM' value='$proxysettings{'NCSA_PASS_CONFIRM'}' size='14' /></td>
2074 </tr>
2075 </table>
2076 <br>
2077 <table>
2078 <tr>
2079         <td>&nbsp;</td>
2080         <td><input type='submit' name='SUBMIT' value='$ncsa_buttontext' /></td>
2081         <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
2082         <td><input type='hidden' name='NCSA_MIN_PASS_LEN' value='$proxysettings{'NCSA_MIN_PASS_LEN'}'></td>
2083 END
2084 ;
2085         if ($proxysettings{'ACTION'} eq $Lang::tr{'edit'}) {
2086                 print "<td><input type='reset' name='ACTION' value='$Lang::tr{'advproxy reset'}' /></td>\n";
2087         }
2088
2089 print <<END
2090         <td>&nbsp;</td>
2091         <td>&nbsp;</td>
2092         <td><input type='button' name='return2main' value='$Lang::tr{'advproxy back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
2093 </tr>
2094 </table>
2095 </form>
2096 <hr size='1'>
2097 <table width='100%'>
2098 <tr>
2099         <td><b>$Lang::tr{'advproxy NCSA user accounts'}:</b></td>
2100 </tr>
2101 </table>
2102 <table width='100%' align='center'>
2103 END
2104 ;
2105
2106 if (-e $extgrp)
2107 {
2108         open(FILE, $extgrp); @grouplist = <FILE>; close(FILE);
2109         foreach $user (@grouplist) { chomp($user); push(@userlist,$user.":extended"); }
2110 }
2111 if (-e $stdgrp)
2112 {
2113         open(FILE, $stdgrp); @grouplist = <FILE>; close(FILE);
2114         foreach $user (@grouplist) { chomp($user); push(@userlist,$user.":standard"); }
2115 }
2116 if (-e $disgrp)
2117 {
2118         open(FILE, $disgrp); @grouplist = <FILE>; close(FILE);
2119         foreach $user (@grouplist) { chomp($user); push(@userlist,$user.":disabled"); }
2120 }
2121
2122 @userlist = sort(@userlist);
2123
2124 # If the password file contains entries, print entries and action icons
2125
2126 if ( ! -z "$userdb" ) {
2127         print <<END
2128         <tr>
2129                 <td width='30%' class='boldbase' align='center'><b><i>$Lang::tr{'advproxy NCSA username'}</i></b></td>
2130                 <td width='30%' class='boldbase' align='center'><b><i>$Lang::tr{'advproxy NCSA group membership'}</i></b></td>
2131                 <td class='boldbase' colspan='2' align='center'>&nbsp;</td>
2132         </tr>
2133 END
2134 ;
2135         $id = 0;
2136         foreach $line (@userlist)
2137         {
2138                 $id++;
2139                 chomp($line);
2140                 @temp = split(/:/,$line);
2141                 if($proxysettings{'ACTION'} eq $Lang::tr{'edit'} && $proxysettings{'ID'} eq $line) {
2142                         print "<tr bgcolor='$Header::colouryellow'>\n"; }
2143                 elsif ($id % 2) {
2144                         print "<tr bgcolor='$color{'color20'}'>\n"; }
2145                 else {
2146                         print "<tr bgcolor='$color{'color22'}'>\n"; }
2147
2148                 print <<END
2149                 <td align='center'>$temp[0]</td>
2150                 <td align='center'>
2151 END
2152 ;
2153                 if ($temp[1] eq 'standard') {
2154                         print $Lang::tr{'advproxy NCSA grp standard'};
2155                 } elsif ($temp[1] eq 'extended') {
2156                         print $Lang::tr{'advproxy NCSA grp extended'};
2157                 } elsif ($temp[1] eq 'disabled') {
2158                         print $Lang::tr{'advproxy NCSA grp disabled'}; }
2159                 print <<END
2160                 </td>
2161                 <td width='8%' align='center'>
2162                 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
2163                 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
2164                 <input type='hidden' name='ID' value='$line' />
2165                 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
2166                 </form>
2167                 </td>
2168
2169                 <td width='8%' align='center'>
2170                 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
2171                 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
2172                 <input type='hidden' name='ID' value='$temp[0]' />
2173                 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
2174                 </form>
2175                 </td>
2176         </tr>
2177 END
2178 ;
2179         }
2180
2181 print <<END
2182 </table>
2183 <br>
2184 <table>
2185 <tr>
2186         <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
2187         <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
2188         <td class='base'>$Lang::tr{'edit'}</td>
2189         <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
2190         <td class='base'>$Lang::tr{'remove'}</td>
2191 </tr>
2192 END
2193 ;
2194 } else {
2195         print <<END
2196         <tr>
2197                 <td><i>$Lang::tr{'advproxy NCSA no accounts'}</i></td>
2198         </tr>
2199 END
2200 ;
2201 }
2202
2203 print <<END
2204 </table>
2205 END
2206 ;
2207
2208 &Header::closebox();
2209
2210 }
2211
2212 # ===================================================================
2213
2214 &Header::closebigbox();
2215
2216 &Header::closepage();
2217
2218 # -------------------------------------------------------------------
2219
2220 sub read_acls
2221 {
2222         if (-e "$acl_src_subnets") {
2223                 open(FILE,"$acl_src_subnets");
2224                 delete $proxysettings{'SRC_SUBNETS'};
2225                 while (<FILE>) { $proxysettings{'SRC_SUBNETS'} .= $_ };
2226                 close(FILE);
2227         }
2228         if (-e "$acl_src_banned_ip") {
2229                 open(FILE,"$acl_src_banned_ip");
2230                 delete $proxysettings{'SRC_BANNED_IP'};
2231                 while (<FILE>) { $proxysettings{'SRC_BANNED_IP'} .= $_ };
2232                 close(FILE);
2233         }
2234         if (-e "$acl_src_banned_mac") {
2235                 open(FILE,"$acl_src_banned_mac");
2236                 delete $proxysettings{'SRC_BANNED_MAC'};
2237                 while (<FILE>) { $proxysettings{'SRC_BANNED_MAC'} .= $_ };
2238                 close(FILE);
2239         }
2240         if (-e "$acl_src_unrestricted_ip") {
2241                 open(FILE,"$acl_src_unrestricted_ip");
2242                 delete $proxysettings{'SRC_UNRESTRICTED_IP'};
2243                 while (<FILE>) { $proxysettings{'SRC_UNRESTRICTED_IP'} .= $_ };
2244                 close(FILE);
2245         }
2246         if (-e "$acl_src_unrestricted_mac") {
2247                 open(FILE,"$acl_src_unrestricted_mac");
2248                 delete $proxysettings{'SRC_UNRESTRICTED_MAC'};
2249                 while (<FILE>) { $proxysettings{'SRC_UNRESTRICTED_MAC'} .= $_ };
2250                 close(FILE);
2251         }
2252         if (-e "$acl_dst_nocache") {
2253                 open(FILE,"$acl_dst_nocache");
2254                 delete $proxysettings{'DST_NOCACHE'};
2255                 while (<FILE>) { $proxysettings{'DST_NOCACHE'} .= $_ };
2256                 close(FILE);
2257         }
2258         if (-e "$acl_dst_noauth") {
2259                 open(FILE,"$acl_dst_noauth");
2260                 delete $proxysettings{'DST_NOAUTH'};
2261                 while (<FILE>) { $proxysettings{'DST_NOAUTH'} .= $_ };
2262                 close(FILE);
2263         }
2264         if (-e "$acl_ports_safe") {
2265                 open(FILE,"$acl_ports_safe");
2266                 delete $proxysettings{'PORTS_SAFE'};
2267                 while (<FILE>) { $proxysettings{'PORTS_SAFE'} .= $_ };
2268                 close(FILE);
2269         }
2270         if (-e "$acl_ports_ssl") {
2271                 open(FILE,"$acl_ports_ssl");
2272                 delete $proxysettings{'PORTS_SSL'};
2273                 while (<FILE>) { $proxysettings{'PORTS_SSL'} .= $_ };
2274                 close(FILE);
2275         }
2276         if (-e "$mimetypes") {
2277                 open(FILE,"$mimetypes");
2278                 delete $proxysettings{'MIME_TYPES'};
2279                 while (<FILE>) { $proxysettings{'MIME_TYPES'} .= $_ };
2280                 close(FILE);
2281         }
2282         if (-e "$raddir/radauth.allowusers") {
2283                 open(FILE,"$raddir/radauth.allowusers");
2284                 delete $proxysettings{'RADIUS_ALLOW_USERS'};
2285                 while (<FILE>) { $proxysettings{'RADIUS_ALLOW_USERS'} .= $_ };
2286                 close(FILE);
2287         }
2288         if (-e "$raddir/radauth.denyusers") {
2289                 open(FILE,"$raddir/radauth.denyusers");
2290                 delete $proxysettings{'RADIUS_DENY_USERS'};
2291                 while (<FILE>) { $proxysettings{'RADIUS_DENY_USERS'} .= $_ };
2292                 close(FILE);
2293         }
2294         if (-e "$identdir/identauth.allowusers") {
2295                 open(FILE,"$identdir/identauth.allowusers");
2296                 delete $proxysettings{'IDENT_ALLOW_USERS'};
2297                 while (<FILE>) { $proxysettings{'IDENT_ALLOW_USERS'} .= $_ };
2298                 close(FILE);
2299         }
2300         if (-e "$identdir/identauth.denyusers") {
2301                 open(FILE,"$identdir/identauth.denyusers");
2302                 delete $proxysettings{'IDENT_DENY_USERS'};
2303                 while (<FILE>) { $proxysettings{'IDENT_DENY_USERS'} .= $_ };
2304                 close(FILE);
2305         }
2306         if (-e "$identhosts") {
2307                 open(FILE,"$identhosts");
2308                 delete $proxysettings{'IDENT_HOSTS'};
2309                 while (<FILE>) { $proxysettings{'IDENT_HOSTS'} .= $_ };
2310                 close(FILE);
2311         }
2312         if (-e "$cre_groups") {
2313                 open(FILE,"$cre_groups");
2314                 delete $proxysettings{'CRE_GROUPS'};
2315                 while (<FILE>) { $proxysettings{'CRE_GROUPS'} .= $_ };
2316                 close(FILE);
2317         }
2318         if (-e "$cre_svhosts") {
2319                 open(FILE,"$cre_svhosts");
2320                 delete $proxysettings{'CRE_SVHOSTS'};
2321                 while (<FILE>) { $proxysettings{'CRE_SVHOSTS'} .= $_ };
2322                 close(FILE);
2323         }
2324 }
2325
2326 # -------------------------------------------------------------------
2327
2328 sub check_acls
2329 {
2330         @temp = split(/\n/,$proxysettings{'PORTS_SAFE'});
2331         undef $proxysettings{'PORTS_SAFE'};
2332         foreach (@temp)
2333         {
2334                 s/^\s+//g; s/\s+$//g;
2335                 if ($_)
2336                 {
2337                         $line = $_;
2338                         if (/^[^#]+\s+#\sSquids\sport/) { s/(^[^#]+)(\s+#\sSquids\sport)/$proxysettings{'PROXY_PORT'}\2/; $line=$_; }
2339                         s/#.*//g; s/\s+//g;
2340                         if (/.*-.*-.*/) { $errormessage = $Lang::tr{'advproxy errmsg invalid destination port'}; }
2341                         @templist = split(/-/);
2342                         foreach (@templist) { unless (&General::validport($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid destination port'}; } }
2343                         $proxysettings{'PORTS_SAFE'} .= $line."\n";
2344                 }
2345         }
2346
2347         @temp = split(/\n/,$proxysettings{'PORTS_SSL'});
2348         undef $proxysettings{'PORTS_SSL'};
2349         foreach (@temp)
2350         {
2351                 s/^\s+//g; s/\s+$//g;
2352                 if ($_)
2353                 {
2354                         $line = $_;
2355                         s/#.*//g; s/\s+//g;
2356                         if (/.*-.*-.*/) { $errormessage = $Lang::tr{'advproxy errmsg invalid destination port'}; }
2357                         @templist = split(/-/);
2358                         foreach (@templist) { unless (&General::validport($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid destination port'}; } }
2359                         $proxysettings{'PORTS_SSL'} .= $line."\n";
2360                 }
2361         }
2362
2363         @temp = split(/\n/,$proxysettings{'DST_NOCACHE'});
2364         undef $proxysettings{'DST_NOCACHE'};
2365         foreach (@temp)
2366         {
2367                 s/^\s+//g;
2368                 unless (/^#/) { s/\s+//g; }
2369                 if ($_)
2370                 {
2371                         if (/^\./) { $_ = '*'.$_; }
2372                         $proxysettings{'DST_NOCACHE'} .= $_."\n";
2373                 }
2374         }
2375
2376         @temp = split(/\n/,$proxysettings{'SRC_SUBNETS'});
2377         undef $proxysettings{'SRC_SUBNETS'};
2378         foreach (@temp)
2379         {
2380                 s/^\s+//g; s/\s+$//g;
2381                 if ($_)
2382                 {
2383                         unless (&General::validipandmask($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid ip or mask'}; }
2384                         $proxysettings{'SRC_SUBNETS'} .= $_."\n";
2385                 }
2386         }
2387
2388         @temp = split(/\n/,$proxysettings{'SRC_BANNED_IP'});
2389         undef $proxysettings{'SRC_BANNED_IP'};
2390         foreach (@temp)
2391         {
2392                 s/^\s+//g; s/\s+$//g;
2393                 if ($_)
2394                 {
2395                         unless (&General::validipormask($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid ip or mask'}; }
2396                         $proxysettings{'SRC_BANNED_IP'} .= $_."\n";
2397                 }
2398         }
2399
2400         @temp = split(/\n/,$proxysettings{'SRC_BANNED_MAC'});
2401         undef $proxysettings{'SRC_BANNED_MAC'};
2402         foreach (@temp)
2403         {
2404                 s/^\s+//g; s/\s+$//g; s/-/:/g;
2405                 if ($_)
2406                 {
2407                         unless (&General::validmac($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid mac'}; }
2408                         $proxysettings{'SRC_BANNED_MAC'} .= $_."\n";
2409                 }
2410         }
2411
2412         @temp = split(/\n/,$proxysettings{'SRC_UNRESTRICTED_IP'});
2413         undef $proxysettings{'SRC_UNRESTRICTED_IP'};
2414         foreach (@temp)
2415         {
2416                 s/^\s+//g; s/\s+$//g;
2417                 if ($_)
2418                 {
2419                         unless (&General::validipormask($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid ip or mask'}; }
2420                         $proxysettings{'SRC_UNRESTRICTED_IP'} .= $_."\n";
2421                 }
2422         }
2423
2424         @temp = split(/\n/,$proxysettings{'SRC_UNRESTRICTED_MAC'});
2425         undef $proxysettings{'SRC_UNRESTRICTED_MAC'};
2426         foreach (@temp)
2427         {
2428                 s/^\s+//g; s/\s+$//g; s/-/:/g;
2429                 if ($_)
2430                 {
2431                         unless (&General::validmac($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid mac'}; }
2432                         $proxysettings{'SRC_UNRESTRICTED_MAC'} .= $_."\n";
2433                 }
2434         }
2435
2436         @temp = split(/\n/,$proxysettings{'DST_NOAUTH'});
2437         undef $proxysettings{'DST_NOAUTH'};
2438         foreach (@temp)
2439         {
2440                 s/^\s+//g;
2441                 unless (/^#/) { s/\s+//g; }
2442                 if ($_)
2443                 {
2444                         if (/^\./) { $_ = '*'.$_; }
2445                         $proxysettings{'DST_NOAUTH'} .= $_."\n";
2446                 }
2447         }
2448
2449         if (($proxysettings{'NTLM_ENABLE_ACL'} eq 'on') && ($proxysettings{'NTLM_USER_ACL'} eq 'positive'))
2450         {
2451                 @temp = split(/\n/,$proxysettings{'NTLM_ALLOW_USERS'});
2452                 undef $proxysettings{'NTLM_ALLOW_USERS'};
2453                 foreach (@temp)
2454                 {
2455                         s/^\s+//g; s/\s+$//g;
2456                         if ($_) { $proxysettings{'NTLM_ALLOW_USERS'} .= $_."\n"; }
2457                 }
2458                 if ($proxysettings{'NTLM_ALLOW_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2459         }
2460
2461         if (($proxysettings{'NTLM_ENABLE_ACL'} eq 'on') && ($proxysettings{'NTLM_USER_ACL'} eq 'negative'))
2462         {
2463                 @temp = split(/\n/,$proxysettings{'NTLM_DENY_USERS'});
2464                 undef $proxysettings{'NTLM_DENY_USERS'};
2465                 foreach (@temp)
2466                 {
2467                         s/^\s+//g; s/\s+$//g;
2468                         if ($_) { $proxysettings{'NTLM_DENY_USERS'} .= $_."\n"; }
2469                 }
2470                 if ($proxysettings{'NTLM_DENY_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2471         }
2472
2473         if (($proxysettings{'IDENT_ENABLE_ACL'} eq 'on') && ($proxysettings{'IDENT_USER_ACL'} eq 'positive'))
2474         {
2475                 @temp = split(/\n/,$proxysettings{'IDENT_ALLOW_USERS'});
2476                 undef $proxysettings{'IDENT_ALLOW_USERS'};
2477                 foreach (@temp)
2478                 {
2479                         s/^\s+//g; s/\s+$//g;
2480                         if ($_) { $proxysettings{'IDENT_ALLOW_USERS'} .= $_."\n"; }
2481                 }
2482                 if ($proxysettings{'IDENT_ALLOW_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2483         }
2484
2485         if (($proxysettings{'IDENT_ENABLE_ACL'} eq 'on') && ($proxysettings{'IDENT_USER_ACL'} eq 'negative'))
2486         {
2487                 @temp = split(/\n/,$proxysettings{'IDENT_DENY_USERS'});
2488                 undef $proxysettings{'IDENT_DENY_USERS'};
2489                 foreach (@temp)
2490                 {
2491                         s/^\s+//g; s/\s+$//g;
2492                         if ($_) { $proxysettings{'IDENT_DENY_USERS'} .= $_."\n"; }
2493                 }
2494                 if ($proxysettings{'IDENT_DENY_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2495         }
2496
2497         if (($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on') && ($proxysettings{'RADIUS_USER_ACL'} eq 'positive'))
2498         {
2499                 @temp = split(/\n/,$proxysettings{'RADIUS_ALLOW_USERS'});
2500                 undef $proxysettings{'RADIUS_ALLOW_USERS'};
2501                 foreach (@temp)
2502                 {
2503                         s/^\s+//g; s/\s+$//g;
2504                         if ($_) { $proxysettings{'RADIUS_ALLOW_USERS'} .= $_."\n"; }
2505                 }
2506                 if ($proxysettings{'RADIUS_ALLOW_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2507         }
2508
2509         if (($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on') && ($proxysettings{'RADIUS_USER_ACL'} eq 'negative'))
2510         {
2511                 @temp = split(/\n/,$proxysettings{'RADIUS_DENY_USERS'});
2512                 undef $proxysettings{'RADIUS_DENY_USERS'};
2513                 foreach (@temp)
2514                 {
2515                         s/^\s+//g; s/\s+$//g;
2516                         if ($_) { $proxysettings{'RADIUS_DENY_USERS'} .= $_."\n"; }
2517                 }
2518                 if ($proxysettings{'RADIUS_DENY_USERS'} eq '') { $errormessage = $Lang::tr{'advproxy errmsg acl cannot be empty'}; }
2519         }
2520
2521         @temp = split(/\n/,$proxysettings{'IDENT_HOSTS'});
2522         undef $proxysettings{'IDENT_HOSTS'};
2523         foreach (@temp)
2524         {
2525                 s/^\s+//g; s/\s+$//g;
2526                 if ($_)
2527                 {
2528                         unless (&General::validipormask($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid ip or mask'}; }
2529                         $proxysettings{'IDENT_HOSTS'} .= $_."\n";
2530                 }
2531         }
2532
2533         @temp = split(/\n/,$proxysettings{'CRE_SVHOSTS'});
2534         undef $proxysettings{'CRE_SVHOSTS'};
2535         foreach (@temp)
2536         {
2537                 s/^\s+//g; s/\s+$//g;
2538                 if ($_)
2539                 {
2540                         unless (&General::validipormask($_)) { $errormessage = $Lang::tr{'advproxy errmsg invalid ip or mask'}; }
2541                         $proxysettings{'CRE_SVHOSTS'} .= $_."\n";
2542                 }
2543         }
2544 }
2545
2546 # -------------------------------------------------------------------
2547
2548 sub write_acls
2549 {
2550         open(FILE, ">$acl_src_subnets");
2551         flock(FILE, 2);
2552         if (!$proxysettings{'SRC_SUBNETS'})
2553         {
2554                 print FILE "$green_cidr\n";
2555                 if ($netsettings{'BLUE_DEV'})
2556                 {
2557                         print FILE "$blue_cidr\n";
2558                 }
2559         } else { print FILE $proxysettings{'SRC_SUBNETS'}; }
2560         close(FILE);
2561
2562         open(FILE, ">$acl_src_banned_ip");
2563         flock(FILE, 2);
2564         print FILE $proxysettings{'SRC_BANNED_IP'};
2565         close(FILE);
2566
2567         open(FILE, ">$acl_src_banned_mac");
2568         flock(FILE, 2);
2569         print FILE $proxysettings{'SRC_BANNED_MAC'};
2570         close(FILE);
2571
2572         open(FILE, ">$acl_src_unrestricted_ip");
2573         flock(FILE, 2);
2574         print FILE $proxysettings{'SRC_UNRESTRICTED_IP'};
2575         close(FILE);
2576
2577         open(FILE, ">$acl_src_unrestricted_mac");
2578         flock(FILE, 2);
2579         print FILE $proxysettings{'SRC_UNRESTRICTED_MAC'};
2580         close(FILE);
2581
2582         open(FILE, ">$acl_dst_noauth");
2583         flock(FILE, 2);
2584         print FILE $proxysettings{'DST_NOAUTH'};
2585         close(FILE);
2586
2587         open(FILE, ">$acl_dst_noauth_net");
2588         close(FILE);
2589         open(FILE, ">$acl_dst_noauth_dom");
2590         close(FILE);
2591         open(FILE, ">$acl_dst_noauth_url");
2592         close(FILE);
2593
2594         @temp = split(/\n/,$proxysettings{'DST_NOAUTH'});
2595         foreach(@temp)
2596         {
2597                 unless (/^#/)
2598                 {
2599                         if (/^\*\.\w/)
2600                         {
2601                                 s/^\*//;
2602                                 open(FILE, ">>$acl_dst_noauth_dom");
2603                                 flock(FILE, 2);
2604                                 print FILE "$_\n";
2605                                 close(FILE);
2606                         }
2607                         elsif (&General::validipormask($_))
2608                         {
2609                                 open(FILE, ">>$acl_dst_noauth_net");
2610                                 flock(FILE, 2);
2611                                 print FILE "$_\n";
2612                                 close(FILE);
2613                         }
2614                         elsif (/\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?-\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?/)
2615                         {
2616                                 open(FILE, ">>$acl_dst_noauth_net");
2617                                 flock(FILE, 2);
2618                                 print FILE "$_\n";
2619                                 close(FILE);
2620                         }
2621                         else
2622                         {
2623                                 open(FILE, ">>$acl_dst_noauth_url");
2624                                 flock(FILE, 2);
2625                                 if (/^[fh]tt?ps?:\/\//) { print FILE "$_\n"; } else { print FILE "^[fh]tt?ps?://$_\n"; }
2626                                 close(FILE);
2627                         }
2628                 }
2629         }
2630
2631         open(FILE, ">$acl_dst_nocache");
2632         flock(FILE, 2);
2633         print FILE $proxysettings{'DST_NOCACHE'};
2634         close(FILE);
2635
2636         open(FILE, ">$acl_dst_nocache_net");
2637         close(FILE);
2638         open(FILE, ">$acl_dst_nocache_dom");
2639         close(FILE);
2640         open(FILE, ">$acl_dst_nocache_url");
2641         close(FILE);
2642
2643         @temp = split(/\n/,$proxysettings{'DST_NOCACHE'});
2644         foreach(@temp)
2645         {
2646                 unless (/^#/)
2647                 {
2648                         if (/^\*\.\w/)
2649                         {
2650                                 s/^\*//;
2651                                 open(FILE, ">>$acl_dst_nocache_dom");
2652                                 flock(FILE, 2);
2653                                 print FILE "$_\n";
2654                                 close(FILE);
2655                         }
2656                         elsif (&General::validipormask($_))
2657                         {
2658                                 open(FILE, ">>$acl_dst_nocache_net");
2659                                 flock(FILE, 2);
2660                                 print FILE "$_\n";
2661                                 close(FILE);
2662                         }
2663                         elsif (/\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?-\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?/)
2664                         {
2665                                 open(FILE, ">>$acl_dst_nocache_net");
2666                                 flock(FILE, 2);
2667                                 print FILE "$_\n";
2668                                 close(FILE);
2669                         }
2670                         else
2671                         {
2672                                 open(FILE, ">>$acl_dst_nocache_url");
2673                                 flock(FILE, 2);
2674                                 if (/^[fh]tt?ps?:\/\//) { print FILE "$_\n"; } else { print FILE "^[fh]tt?ps?://$_\n"; }
2675                                 close(FILE);
2676                         }
2677                 }
2678         }
2679
2680         open(FILE, ">$acl_ports_safe");
2681         flock(FILE, 2);
2682         if (!$proxysettings{'PORTS_SAFE'}) { print FILE $def_ports_safe; } else { print FILE $proxysettings{'PORTS_SAFE'}; }
2683         close(FILE);
2684
2685         open(FILE, ">$acl_ports_ssl");
2686         flock(FILE, 2);
2687         if (!$proxysettings{'PORTS_SSL'}) { print FILE $def_ports_ssl; } else { print FILE $proxysettings{'PORTS_SSL'}; }
2688         close(FILE);
2689
2690         if (-s $throttled_urls)
2691         {
2692                 open(URLFILE, $throttled_urls);
2693                 @temp = <URLFILE>;
2694                 close(URLFILE);
2695                 foreach (@temp) { print FILE; }
2696         }
2697         close(FILE);
2698
2699         open(FILE, ">$mimetypes");
2700         flock(FILE, 2);
2701         print FILE $proxysettings{'MIME_TYPES'};
2702         close(FILE);
2703
2704         open(FILE, ">$raddir/radauth.allowusers");
2705         flock(FILE, 2);
2706         print FILE $proxysettings{'RADIUS_ALLOW_USERS'};
2707         close(FILE);
2708
2709         open(FILE, ">$raddir/radauth.denyusers");
2710         flock(FILE, 2);
2711         print FILE $proxysettings{'RADIUS_DENY_USERS'};
2712         close(FILE);
2713
2714         open(FILE, ">$identdir/identauth.allowusers");
2715         flock(FILE, 2);
2716         print FILE $proxysettings{'IDENT_ALLOW_USERS'};
2717         close(FILE);
2718
2719         open(FILE, ">$identdir/identauth.denyusers");
2720         flock(FILE, 2);
2721         print FILE $proxysettings{'IDENT_DENY_USERS'};
2722         close(FILE);
2723
2724         open(FILE, ">$identhosts");
2725         flock(FILE, 2);
2726         print FILE $proxysettings{'IDENT_HOSTS'};
2727         close(FILE);
2728
2729         open(FILE, ">$cre_groups");
2730         flock(FILE, 2);
2731         print FILE $proxysettings{'CRE_GROUPS'};
2732         close(FILE);
2733
2734         open(FILE, ">$cre_svhosts");
2735         flock(FILE, 2);
2736         print FILE $proxysettings{'CRE_SVHOSTS'};
2737         close(FILE);
2738 }
2739
2740 # -------------------------------------------------------------------
2741
2742 sub writepacfile
2743 {
2744         open(FILE, ">/srv/web/ipfire/html/proxy.pac");
2745         flock(FILE, 2);
2746         print FILE "function FindProxyForURL(url, host)\n";
2747         print FILE "{\n";
2748         if (($proxysettings{'ENABLE'} eq 'on') || ($proxysettings{'ENABLE_BLUE'} eq 'on'))
2749         {
2750                 print FILE <<END
2751 if (
2752      (isPlainHostName(host)) ||
2753      (isInNet(host, "127.0.0.1", "255.0.0.0")) ||
2754 END
2755 ;
2756
2757         if ($netsettings{'GREEN_DEV'}) {
2758                 print FILE "     (isInNet(host, \"$netsettings{'GREEN_NETADDRESS'}\", \"$netsettings{'GREEN_NETMASK'}\")) ||\n";
2759         }
2760
2761         if (&Header::blue_used() && $netsettings{'BLUE_DEV'}) {
2762                 print FILE "     (isInNet(host, \"$netsettings{'BLUE_NETADDRESS'}\", \"$netsettings{'BLUE_NETMASK'}\")) ||\n";
2763         }
2764
2765         if (&Header::orange_used() && $netsettings{'ORANGE_DEV'}) {
2766                 print FILE "     (isInNet(host, \"$netsettings{'ORANGE_NETADDRESS'}\", \"$netsettings{'ORANGE_NETMASK'}\")) ||\n";
2767         }
2768
2769         # Additional exceptions for URLs
2770         # The file has to be created by the user and should contain one entry per line
2771         # Line-Format: <URL incl. wildcards>
2772         # e.g. *ipfire.org*
2773         if (-s "$acl_dst_noproxy_url") {
2774                 undef @templist;
2775
2776                 open(NOPROXY,"$acl_dst_noproxy_url");
2777                 @templist = <NOPROXY>;
2778                 close(NOPROXY);
2779                 chomp (@templist);
2780
2781                 foreach (@templist)
2782                 {
2783                         print FILE "     (shExpMatch(url, \"$_\")) ||\n";
2784                 }
2785         }
2786
2787         # Additional exceptions for Subnets
2788         # The file has to be created by the user and should contain one entry per line
2789         # Line-Format: "<IP>", "<SUBNET MASK>"
2790         # e.g. "192.168.0.0", "255.255.255.0"
2791         if (-s "$acl_dst_noproxy_ip") {
2792                 undef @templist;
2793
2794                 open(NOPROXY,"$acl_dst_noproxy_ip");
2795                 @templist = <NOPROXY>;
2796                 close(NOPROXY);
2797                 chomp (@templist);
2798
2799                 foreach (@templist)
2800                 {
2801                         print FILE "     (isInNet(host, $_)) ||\n";
2802                 }
2803         }
2804
2805         print FILE <<END
2806      (isInNet(host, "169.254.0.0", "255.255.0.0"))
2807    )
2808      return "DIRECT";
2809
2810  else
2811
2812 END
2813 ;
2814                 if ($proxysettings{'ENABLE'} eq 'on')
2815                 {
2816                         print FILE "if (\n";
2817                         print FILE "     (isInNet(myIpAddress(), \"$netsettings{'GREEN_NETADDRESS'}\", \"$netsettings{'GREEN_NETMASK'}\"))";
2818
2819                         undef @templist;
2820                         if (-e "$acl_src_subnets") {
2821                                 open(SUBNETS,"$acl_src_subnets");
2822                                 @templist = <SUBNETS>;
2823                                 close(SUBNETS);
2824                         }
2825
2826                         foreach (@templist)
2827                         {
2828                                 @temp = split(/\//);
2829                                 if (
2830                                         ($temp[0] ne $netsettings{'GREEN_NETADDRESS'}) && ($temp[1] ne $netsettings{'GREEN_NETMASK'}) &&
2831                                         ($temp[0] ne $netsettings{'BLUE_NETADDRESS'}) && ($temp[1] ne $netsettings{'BLUE_NETMASK'})
2832                                         )
2833                                 {
2834                                         chomp $temp[1];
2835                                         print FILE " ||\n     (isInNet(myIpAddress(), \"$temp[0]\", \"$temp[1]\"))";
2836                                 }
2837                         }
2838
2839                         print FILE "\n";
2840
2841                         print FILE <<END
2842    )
2843      return "PROXY $netsettings{'GREEN_ADDRESS'}:$proxysettings{'PROXY_PORT'}";
2844 END
2845 ;
2846                 }
2847                 if (($proxysettings{'ENABLE'} eq 'on') && ($proxysettings{'ENABLE_BLUE'} eq 'on') && ($netsettings{'BLUE_DEV'}))
2848                 {
2849                         print FILE "\n else\n\n";
2850                 }
2851                 if (($netsettings{'BLUE_DEV'}) && ($proxysettings{'ENABLE_BLUE'} eq 'on'))
2852                 {
2853                         print FILE <<END
2854 if (
2855      (isInNet(myIpAddress(), "$netsettings{'BLUE_NETADDRESS'}", "$netsettings{'BLUE_NETMASK'}"))
2856    )
2857      return "PROXY $netsettings{'BLUE_ADDRESS'}:$proxysettings{'PROXY_PORT'}";
2858 END
2859 ;
2860                 }
2861         }
2862         print FILE "}\n";
2863         close(FILE);
2864 }
2865
2866 # -------------------------------------------------------------------
2867
2868 sub writeconfig
2869 {
2870         my $authrealm;
2871         my $delaypools;
2872
2873         if ($proxysettings{'THROTTLING_GREEN_TOTAL'} +
2874             $proxysettings{'THROTTLING_GREEN_HOST'}  +
2875             $proxysettings{'THROTTLING_BLUE_TOTAL'}  +
2876             $proxysettings{'THROTTLING_BLUE_HOST'} gt 0)
2877         {
2878                 $delaypools = 1; } else { $delaypools = 0;
2879         }
2880
2881         if ($proxysettings{'AUTH_REALM'} eq '')
2882         {
2883                 $authrealm = "IPFire Advanced Proxy Server";
2884         } else {
2885                 $authrealm = $proxysettings{'AUTH_REALM'};
2886         }
2887
2888         $_ = $proxysettings{'UPSTREAM_PROXY'};
2889         my ($remotehost, $remoteport) = split(/:/,$_);
2890
2891         if ($remoteport eq '') { $remoteport = 80; }
2892
2893         open(FILE, ">${General::swroot}/proxy/squid.conf");
2894         flock(FILE, 2);
2895         print FILE <<END
2896 # Do not modify '${General::swroot}/proxy/squid.conf' directly since any changes
2897 # you make will be overwritten whenever you resave proxy settings using the
2898 # web interface!
2899 #
2900 # Instead, modify the file '$acl_include' and
2901 # then restart the proxy service using the web interface. Changes made to the
2902 # 'include.acl' file will propagate to the 'squid.conf' file at that time.
2903
2904 shutdown_lifetime 5 seconds
2905 icp_port 0
2906
2907 END
2908         ;
2909
2910         # Include file with user defined settings.
2911         if (-e "/etc/squid/squid.conf.pre.local") {
2912                 print FILE "include /etc/squid/squid.conf.pre.local\n\n";
2913         }
2914
2915         print FILE "http_port $netsettings{'GREEN_ADDRESS'}:$proxysettings{'PROXY_PORT'}";
2916         if ($proxysettings{'NO_CONNECTION_AUTH'} eq 'on') { print FILE " no-connection-auth" }
2917         print FILE "\n";
2918
2919         if ($proxysettings{'TRANSPARENT'} eq 'on') {
2920                 print FILE "http_port $netsettings{'GREEN_ADDRESS'}:$proxysettings{'TRANSPARENT_PORT'} intercept";
2921                 if ($proxysettings{'NO_CONNECTION_AUTH'} eq 'on') { print FILE " no-connection-auth" }
2922                 print FILE "\n";
2923         }
2924
2925         if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {
2926                 print FILE "http_port $netsettings{'BLUE_ADDRESS'}:$proxysettings{'PROXY_PORT'}";
2927                 if ($proxysettings{'NO_CONNECTION_AUTH'} eq 'on') { print FILE " no-connection-auth" }
2928                 print FILE "\n";
2929
2930                 if ($proxysettings{'TRANSPARENT_BLUE'} eq 'on') {
2931                         print FILE "http_port $netsettings{'BLUE_ADDRESS'}:$proxysettings{'TRANSPARENT_PORT'} intercept";
2932                         if ($proxysettings{'NO_CONNECTION_AUTH'} eq 'on') { print FILE " no-connection-auth" }
2933                         print FILE "\n";
2934                 }
2935         }
2936
2937         if (($proxysettings{'CACHE_SIZE'} > 0) || ($proxysettings{'CACHE_MEM'} > 0))
2938         {
2939                 print FILE "\n";
2940
2941                 if (!-z $acl_dst_nocache_dom) {
2942                         print FILE "acl no_cache_domains dstdomain \"$acl_dst_nocache_dom\"\n";
2943                         print FILE "cache deny no_cache_domains\n";
2944                 }
2945                 if (!-z $acl_dst_nocache_net) {
2946                         print FILE "acl no_cache_ipaddr dst \"$acl_dst_nocache_net\"\n";
2947                         print FILE "cache deny no_cache_ipaddr\n";
2948                 }
2949                 if (!-z $acl_dst_nocache_url) {
2950                         print FILE "acl no_cache_hosts url_regex -i \"$acl_dst_nocache_url\"\n";
2951                         print FILE "cache deny no_cache_hosts\n";
2952                 }
2953         }
2954
2955         print FILE <<END
2956
2957 cache_effective_user squid
2958 umask 022
2959
2960 pid_filename /var/run/squid.pid
2961
2962 cache_mem $proxysettings{'CACHE_MEM'} MB
2963 END
2964         ;
2965         print FILE "error_directory $errordir/$proxysettings{'ERR_LANGUAGE'}\n\n";
2966
2967         if ($proxysettings{'OFFLINE_MODE'} eq 'on') {  print FILE "offline_mode on\n\n"; }
2968         if ($proxysettings{'CACHE_DIGESTS'} eq 'on') {  print FILE "digest_generation on\n\n"; } else {  print FILE "digest_generation off\n\n"; }
2969
2970         if ((!($proxysettings{'MEM_POLICY'} eq 'LRU')) || (!($proxysettings{'CACHE_POLICY'} eq 'LRU')))
2971         {
2972                 if (!($proxysettings{'MEM_POLICY'} eq 'LRU'))
2973                 {
2974                         print FILE "memory_replacement_policy $proxysettings{'MEM_POLICY'}\n";
2975                 }
2976                 if (!($proxysettings{'CACHE_POLICY'} eq 'LRU'))
2977                 {
2978                         print FILE "cache_replacement_policy $proxysettings{'CACHE_POLICY'}\n";
2979                 }
2980                 print FILE "\n";
2981         }
2982
2983         open (PORTS,"$acl_ports_ssl");
2984         my @ssl_ports = <PORTS>;
2985         close PORTS;
2986
2987         if (@ssl_ports) {
2988                 foreach (@ssl_ports) {
2989                         print FILE "acl SSL_ports port $_";
2990                 }
2991         }
2992
2993         open (PORTS,"$acl_ports_safe");
2994         my @safe_ports = <PORTS>;
2995         close PORTS;
2996
2997         if (@safe_ports) {
2998                 foreach (@safe_ports) {
2999                         print FILE "acl Safe_ports port $_";
3000                 }
3001         }
3002
3003         print FILE <<END
3004
3005 acl IPFire_http  port $http_port
3006 acl IPFire_https port $https_port
3007 acl IPFire_ips              dst $netsettings{'GREEN_ADDRESS'}
3008 acl IPFire_networks         src "$acl_src_subnets"
3009 acl IPFire_servers          dst "$acl_src_subnets"
3010 acl IPFire_green_network    src $green_cidr
3011 acl IPFire_green_servers    dst $green_cidr
3012 END
3013         ;
3014         if ($netsettings{'BLUE_DEV'}) { print FILE "acl IPFire_blue_network     src $blue_cidr\n"; }
3015         if ($netsettings{'BLUE_DEV'}) { print FILE "acl IPFire_blue_servers     dst $blue_cidr\n"; }
3016         if (!-z $acl_src_banned_ip) { print FILE "acl IPFire_banned_ips       src \"$acl_src_banned_ip\"\n"; }
3017         if (!-z $acl_src_banned_mac) { print FILE "acl IPFire_banned_mac       arp \"$acl_src_banned_mac\"\n"; }
3018         if (!-z $acl_src_unrestricted_ip) { print FILE "acl IPFire_unrestricted_ips src \"$acl_src_unrestricted_ip\"\n"; }
3019         if (!-z $acl_src_unrestricted_mac) { print FILE "acl IPFire_unrestricted_mac arp \"$acl_src_unrestricted_mac\"\n"; }
3020         print FILE <<END
3021 acl CONNECT method CONNECT
3022 END
3023         ;
3024
3025         if ($proxysettings{'CACHE_SIZE'} > 0) {
3026                 print FILE <<END
3027 maximum_object_size $proxysettings{'MAX_SIZE'} KB
3028 minimum_object_size $proxysettings{'MIN_SIZE'} KB
3029
3030 cache_dir aufs /var/log/cache $proxysettings{'CACHE_SIZE'} $proxysettings{'L1_DIRS'} 256
3031 END
3032                 ;
3033         } else {
3034                 if ($proxysettings{'CACHE_MEM'} > 0) {
3035                         # always 2% of CACHE_MEM defined as max object size
3036                         print FILE "maximum_object_size_in_memory " . int($proxysettings{'CACHE_MEM'} * 1024 * 0.02) . " KB\n\n";
3037                 } else {
3038                         print FILE "cache deny all\n\n";
3039             }
3040         }
3041
3042         print FILE <<END
3043 request_body_max_size $proxysettings{'MAX_OUTGOING_SIZE'} KB
3044 END
3045         ;
3046
3047         if ($proxysettings{'MAX_INCOMING_SIZE'} > 0) {
3048                 if (!-z $acl_src_unrestricted_ip) { print FILE "reply_body_max_size none IPFire_unrestricted_ips\n"; }
3049                 if (!-z $acl_src_unrestricted_mac) { print FILE "reply_body_max_size none IPFire_unrestricted_mac\n"; }
3050                 if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3051                 {
3052                         if (!-z $extgrp) { print FILE "reply_body_max_size none for_extended_users\n"; }
3053                 }
3054         }
3055
3056         if ( $proxysettings{'MAX_INCOMING_SIZE'} != '0' )
3057         {
3058                 print FILE "reply_body_max_size $proxysettings{'MAX_INCOMING_SIZE'} KB all\n\n";
3059         }
3060
3061         if ($proxysettings{'LOGGING'} eq 'on')
3062         {
3063                 print FILE <<END
3064 access_log stdio:/var/log/squid/access.log
3065 cache_log /var/log/squid/cache.log
3066 cache_store_log none
3067 END
3068         ;
3069                 if ($proxysettings{'LOGUSERAGENT'} eq 'on') { print FILE "access_log stdio:\/var\/log\/squid\/user_agent.log useragent\n"; }
3070                 if ($proxysettings{'LOGQUERY'} eq 'on') { print FILE "\nstrip_query_terms off\n"; }
3071         } else {
3072                 print FILE <<END
3073 access_log /dev/null
3074 cache_log /dev/null
3075 cache_store_log none
3076 END
3077         ;}
3078         print FILE <<END
3079
3080 log_mime_hdrs off
3081 END
3082         ;
3083
3084         if ($proxysettings{'FORWARD_IPADDRESS'} eq 'on')
3085         {
3086                 print FILE "forwarded_for on\n";
3087         } else {
3088                 print FILE "forwarded_for off\n";
3089         }
3090         if ($proxysettings{'FORWARD_VIA'} eq 'on')
3091         {
3092                 print FILE "via on\n";
3093         } else {
3094                 print FILE "via off\n";
3095         }
3096         print FILE "\n";
3097
3098         # If we use authentication, users must always authenticate
3099         unless ($proxysettings{"AUTH_METHOD"} eq "") {
3100                 print FILE "authenticate_ip_ttl 0\n\n";
3101         }
3102
3103         if ((!($proxysettings{'AUTH_METHOD'} eq 'none')) && (!($proxysettings{'AUTH_METHOD'} eq 'ident')))
3104         {
3105                 if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3106                 {
3107                         print FILE "auth_param basic program $authdir/basic_ncsa_auth $userdb\n";
3108                         print FILE "auth_param basic children $proxysettings{'AUTH_CHILDREN'}\n";
3109                         print FILE "auth_param basic realm $authrealm\n";
3110                         print FILE "auth_param basic credentialsttl $proxysettings{'AUTH_CACHE_TTL'} minutes\n";
3111                 }
3112
3113                 if ($proxysettings{'AUTH_METHOD'} eq 'ldap')
3114                 {
3115                         print FILE "auth_param basic utf8 on\n";
3116                         print FILE "auth_param basic program $authdir/basic_ldap_auth -b \"$proxysettings{'LDAP_BASEDN'}\"";
3117                         if (!($proxysettings{'LDAP_BINDDN_USER'} eq '')) { print FILE " -D \"$proxysettings{'LDAP_BINDDN_USER'}\""; }
3118                         if (!($proxysettings{'LDAP_BINDDN_PASS'} eq '')) { print FILE " -w $proxysettings{'LDAP_BINDDN_PASS'}"; }
3119                         if ($proxysettings{'LDAP_TYPE'} eq 'ADS')
3120                         {
3121                                 if ($proxysettings{'LDAP_GROUP'} eq '')
3122                                 {
3123                                         print FILE " -f \"(\&(objectClass=person)(sAMAccountName=\%s))\"";
3124                                 } else {
3125                                         print FILE " -f \"(\&(\&(objectClass=person)(sAMAccountName=\%s))(memberOf=$proxysettings{'LDAP_GROUP'}))\"";
3126                                 }
3127                                 print FILE " -u sAMAccountName -P";
3128                         }
3129                         if ($proxysettings{'LDAP_TYPE'} eq 'NDS')
3130                         {
3131                                 if ($proxysettings{'LDAP_GROUP'} eq '')
3132                                 {
3133                                         print FILE " -f \"(\&(objectClass=person)(cn=\%s))\"";
3134                                 } else {
3135                                         print FILE " -f \"(\&(\&(objectClass=person)(cn=\%s))(groupMembership=$proxysettings{'LDAP_GROUP'}))\"";
3136                                 }
3137                                 print FILE " -u cn -P";
3138                         }
3139                         if (($proxysettings{'LDAP_TYPE'} eq 'V2') || ($proxysettings{'LDAP_TYPE'} eq 'V3'))
3140                         {
3141                                 if ($proxysettings{'LDAP_GROUP'} eq '')
3142                                 {
3143                                         print FILE " -f \"(\&(objectClass=person)(uid=\%s))\"";
3144                                 } else {
3145                                         print FILE " -f \"(\&(\&(objectClass=person)(uid=\%s))(memberOf=$proxysettings{'LDAP_GROUP'}))\"";
3146                                 }
3147                                 if ($proxysettings{'LDAP_TYPE'} eq 'V2') { print FILE " -v 2"; }
3148                                 if ($proxysettings{'LDAP_TYPE'} eq 'V3') { print FILE " -v 3"; }
3149                                 print FILE " -u uid -P";
3150                         }
3151                         print FILE " $proxysettings{'LDAP_SERVER'}:$proxysettings{'LDAP_PORT'}\n";
3152                         print FILE "auth_param basic children $proxysettings{'AUTH_CHILDREN'}\n";
3153                         print FILE "auth_param basic realm $authrealm\n";
3154                         print FILE "auth_param basic credentialsttl $proxysettings{'AUTH_CACHE_TTL'} minutes\n";
3155                 }
3156
3157                 if ($proxysettings{'AUTH_METHOD'} eq 'ntlm-auth')
3158                 {
3159                         print FILE "auth_param ntlm program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp";
3160                         if ($proxysettings{'NTLM_AUTH_GROUP'}) {
3161                                 my $ntlm_auth_group = $proxysettings{'NTLM_AUTH_GROUP'};
3162                                 $ntlm_auth_group =~ s/\\/\+/;
3163
3164                                 print FILE " --require-membership-of=$ntlm_auth_group";
3165                         }
3166                         print FILE "\n";
3167
3168                         print FILE "auth_param ntlm children $proxysettings{'AUTH_CHILDREN'}\n\n";
3169                         print FILE "auth_param ntlm credentialsttl $proxysettings{'AUTH_CACHE_TTL'} minutes\n\n";
3170
3171                         # BASIC authentication
3172                         if ($proxysettings{'NTLM_AUTH_BASIC'} eq "on") {
3173                                 print FILE "auth_param basic program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-basic";
3174                                 if ($proxysettings{'NTLM_AUTH_GROUP'}) {
3175                                         my $ntlm_auth_group = $proxysettings{'NTLM_AUTH_GROUP'};
3176                                         $ntlm_auth_group =~ s/\\/\+/;
3177
3178                                         print FILE " --require-membership-of=$ntlm_auth_group";
3179                                 }
3180                                 print FILE "\n";
3181                                 print FILE "auth_param basic children $proxysettings{'AUTH_CHILDREN'}\n";
3182                                 print FILE "auth_param basic realm $authrealm\n";
3183                                 print FILE "auth_param basic credentialsttl $proxysettings{'AUTH_CACHE_TTL'} minutes\n\n";
3184                         }
3185                 }
3186
3187                 if ($proxysettings{'AUTH_METHOD'} eq 'radius')
3188                 {
3189                         print FILE "auth_param basic program $authdir/basic_radius_auth -h $proxysettings{'RADIUS_SERVER'} -p $proxysettings{'RADIUS_PORT'} ";
3190                         if (!($proxysettings{'RADIUS_IDENTIFIER'} eq '')) { print FILE "-i $proxysettings{'RADIUS_IDENTIFIER'} "; }
3191                         print FILE "-w $proxysettings{'RADIUS_SECRET'}\n";
3192                         print FILE "auth_param basic children $proxysettings{'AUTH_CHILDREN'}\n";
3193                         print FILE "auth_param basic realm $authrealm\n";
3194                         print FILE "auth_param basic credentialsttl $proxysettings{'AUTH_CACHE_TTL'} minutes\n";
3195                 }
3196
3197                 print FILE "\n";
3198                 print FILE "acl for_inetusers proxy_auth REQUIRED\n";
3199                 if (($proxysettings{'AUTH_METHOD'} eq 'radius') && ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on'))
3200                 {
3201                         if ((!-z "$raddir/radauth.allowusers") && ($proxysettings{'RADIUS_USER_ACL'} eq 'positive'))
3202                         {
3203                                 print FILE "acl for_acl_users proxy_auth \"$raddir/radauth.allowusers\"\n";
3204                         }
3205                         if ((!-z "$raddir/radauth.denyusers") && ($proxysettings{'RADIUS_USER_ACL'} eq 'negative'))
3206                         {
3207                                 print FILE "acl for_acl_users proxy_auth \"$raddir/radauth.denyusers\"\n";
3208                         }
3209                 }
3210                 if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3211                 {
3212                         print FILE "\n";
3213                         if (!-z $extgrp) { print FILE "acl for_extended_users proxy_auth \"$extgrp\"\n"; }
3214                         if (!-z $disgrp) { print FILE "acl for_disabled_users proxy_auth \"$disgrp\"\n"; }
3215                 }
3216                 if (!($proxysettings{'AUTH_MAX_USERIP'} eq '')) { print FILE "\nacl concurrent max_user_ip -s $proxysettings{'AUTH_MAX_USERIP'}\n"; }
3217                 print FILE "\n";
3218
3219                 if (!-z $acl_dst_noauth_net) { print FILE "acl to_ipaddr_without_auth dst \"$acl_dst_noauth_net\"\n"; }
3220                 if (!-z $acl_dst_noauth_dom) { print FILE "acl to_domains_without_auth dstdomain \"$acl_dst_noauth_dom\"\n"; }
3221                 if (!-z $acl_dst_noauth_url) { print FILE "acl to_hosts_without_auth url_regex -i \"$acl_dst_noauth_url\"\n"; }
3222                 print FILE "\n";
3223
3224         }
3225
3226         if ($proxysettings{'AUTH_METHOD'} eq 'ident')
3227         {
3228                 if ($proxysettings{'IDENT_REQUIRED'} eq 'on')
3229                 {
3230                         print FILE "acl for_inetusers ident REQUIRED\n";
3231                 }
3232                 if ($proxysettings{'IDENT_ENABLE_ACL'} eq 'on')
3233                 {
3234                         if ((!-z "$identdir/identauth.allowusers") && ($proxysettings{'IDENT_USER_ACL'} eq 'positive'))
3235                         {
3236                                 print FILE "acl for_acl_users ident_regex -i \"$identdir/identauth.allowusers\"\n\n";
3237                         }
3238                         if ((!-z "$identdir/identauth.denyusers") && ($proxysettings{'IDENT_USER_ACL'} eq 'negative'))
3239                         {
3240                                 print FILE "acl for_acl_users ident_regex -i \"$identdir/identauth.denyusers\"\n\n";
3241                         }
3242                 }
3243                 if (!-z $acl_dst_noauth_net) { print FILE "acl to_ipaddr_without_auth dst \"$acl_dst_noauth_net\"\n"; }
3244                 if (!-z $acl_dst_noauth_dom) { print FILE "acl to_domains_without_auth dstdomain \"$acl_dst_noauth_dom\"\n"; }
3245                 if (!-z $acl_dst_noauth_url) { print FILE "acl to_hosts_without_auth url_regex -i \"$acl_dst_noauth_url\"\n"; }
3246                 print FILE "\n";
3247         }
3248
3249         if (($delaypools) && (!-z $acl_dst_throttle)) { print FILE "acl for_throttled_urls url_regex -i \"$acl_dst_throttle\"\n\n"; }
3250
3251         print FILE "acl within_timeframe time ";
3252         if ($proxysettings{'TIME_MON'} eq 'on') { print FILE "M"; }
3253         if ($proxysettings{'TIME_TUE'} eq 'on') { print FILE "T"; }
3254         if ($proxysettings{'TIME_WED'} eq 'on') { print FILE "W"; }
3255         if ($proxysettings{'TIME_THU'} eq 'on') { print FILE "H"; }
3256         if ($proxysettings{'TIME_FRI'} eq 'on') { print FILE "F"; }
3257         if ($proxysettings{'TIME_SAT'} eq 'on') { print FILE "A"; }
3258         if ($proxysettings{'TIME_SUN'} eq 'on') { print FILE "S"; }
3259         print FILE " $proxysettings{'TIME_FROM_HOUR'}:";
3260         print FILE "$proxysettings{'TIME_FROM_MINUTE'}-";
3261         print FILE "$proxysettings{'TIME_TO_HOUR'}:";
3262         print FILE "$proxysettings{'TIME_TO_MINUTE'}\n\n";
3263
3264         if ((!-z $mimetypes) && ($proxysettings{'ENABLE_MIME_FILTER'} eq 'on')) {
3265                 print FILE "acl blocked_mimetypes rep_mime_type \"$mimetypes\"\n\n";
3266         }
3267
3268         if ($proxysettings{'CLASSROOM_EXT'} eq 'on') {
3269                 print FILE <<END
3270
3271 #Classroom extensions
3272 acl IPFire_no_access_ips src "$acl_src_noaccess_ip"
3273 acl IPFire_no_access_mac arp "$acl_src_noaccess_mac"
3274 END
3275                 ;
3276                 print FILE "deny_info ";
3277                 if (($proxysettings{'ERR_DESIGN'} eq 'squid') && (-e "$errordir/$proxysettings{'ERR_LANGUAGE'}/ERR_ACCESS_DISABLED"))
3278                 {
3279                         print FILE "ERR_ACCESS_DISABLED";
3280                 } else {
3281                         print FILE "ERR_ACCESS_DENIED";
3282                 }
3283                 print FILE " IPFire_no_access_ips\n";
3284                 print FILE "deny_info ";
3285                 if (($proxysettings{'ERR_DESIGN'} eq 'squid') && (-e "$errordir/$proxysettings{'ERR_LANGUAGE'}/ERR_ACCESS_DISABLED"))
3286                 {
3287                         print FILE "ERR_ACCESS_DISABLED";
3288                 } else {
3289                         print FILE "ERR_ACCESS_DENIED";
3290                 }
3291                 print FILE " IPFire_no_access_mac\n";
3292
3293                 print FILE <<END
3294 http_access deny IPFire_no_access_ips
3295 http_access deny IPFire_no_access_mac
3296 END
3297         ;
3298         }
3299
3300         #Insert acl file and replace __VAR__ with correct values
3301         my $blue_net = ''; #BLUE empty by default
3302         my $blue_ip = '';
3303         if ($netsettings{'BLUE_DEV'} && $proxysettings{'ENABLE_BLUE'} eq 'on') {
3304                 $blue_net = "$blue_cidr";
3305                 $blue_ip  = "$netsettings{'BLUE_ADDRESS'}";
3306         }
3307         if (!-z $acl_include)
3308         {
3309                 open (ACL, "$acl_include");
3310                 print FILE "\n#Start of custom includes\n\n";
3311                 while (<ACL>) {
3312                         $_ =~ s/__GREEN_IP__/$netsettings{'GREEN_ADDRESS'}/;
3313                         $_ =~ s/__GREEN_NET__/$green_cidr/;
3314                         $_ =~ s/__BLUE_IP__/$blue_ip/;
3315                         $_ =~ s/__BLUE_NET__/$blue_net/;
3316                         $_ =~ s/__PROXY_PORT__/$proxysettings{'PROXY_PORT'}/;
3317                         print FILE $_;
3318                 }
3319                 print FILE "\n#End of custom includes\n";
3320                 close (ACL);
3321         }
3322         if ((!-z $extgrp) && ($proxysettings{'AUTH_METHOD'} eq 'ncsa') && ($proxysettings{'NCSA_BYPASS_REDIR'} eq 'on')) { print FILE "\nredirector_access deny for_extended_users\n"; }
3323
3324         # Check if squidclamav is enabled.
3325         if ($proxysettings{'ENABLE_CLAMAV'} eq 'on') {
3326                 print FILE "\n#Settings for squidclamav:\n";
3327                 print FILE "http_port 127.0.0.1:$proxysettings{'PROXY_PORT'}\n";
3328                 print FILE "acl purge method PURGE\n";
3329                 print FILE "http_access deny to_localhost\n";
3330                 print FILE "http_access allow localhost\n";
3331                 print FILE "http_access allow purge localhost\n";
3332                 print FILE "http_access deny purge\n";
3333                 print FILE "url_rewrite_access deny localhost\n";
3334         }
3335         print FILE <<END;
3336
3337 #Access to squid:
3338 #local machine, no restriction
3339 http_access allow         localhost
3340
3341 #GUI admin if local machine connects
3342 http_access allow         IPFire_ips IPFire_networks IPFire_http
3343 http_access allow CONNECT IPFire_ips IPFire_networks IPFire_https
3344
3345 #Deny not web services
3346 END
3347
3348 if (@safe_ports) {
3349         print FILE "http_access deny          !Safe_ports\n";
3350 }
3351
3352 if (@ssl_ports) {
3353         print FILE "http_access deny  CONNECT !SSL_ports\n";
3354 }
3355
3356 if ($proxysettings{'AUTH_METHOD'} eq 'ident')
3357 {
3358 print FILE "#Set ident ACLs\n";
3359 if (!-z $identhosts)
3360         {
3361                 print FILE "acl on_ident_aware_hosts src \"$identhosts\"\n";
3362                 print FILE "ident_lookup_access allow on_ident_aware_hosts\n";
3363                 print FILE "ident_lookup_access deny all\n";
3364         } else {
3365                 print FILE "ident_lookup_access allow all\n";
3366         }
3367         print FILE "ident_timeout $proxysettings{'IDENT_TIMEOUT'} seconds\n\n";
3368 }
3369
3370 if ($delaypools) {
3371         print FILE "#Set download throttling\n";
3372
3373         if ($netsettings{'BLUE_DEV'})
3374         {
3375                 print FILE "delay_pools 2\n";
3376         } else {
3377                 print FILE "delay_pools 1\n";
3378         }
3379
3380         print FILE "delay_class 1 3\n";
3381         if ($netsettings{'BLUE_DEV'}) { print FILE "delay_class 2 3\n"; }
3382
3383         print FILE "delay_parameters 1 ";
3384         if ($proxysettings{'THROTTLING_GREEN_TOTAL'} eq 'unlimited')
3385         {
3386                 print FILE "-1/-1";
3387         } else {
3388                 print FILE $proxysettings{'THROTTLING_GREEN_TOTAL'} * 125;
3389                 print FILE "/";
3390                 print FILE $proxysettings{'THROTTLING_GREEN_TOTAL'} * 250;
3391         }
3392
3393         print FILE " -1/-1 ";
3394         if ($proxysettings{'THROTTLING_GREEN_HOST'} eq 'unlimited')
3395         {
3396                 print FILE "-1/-1";
3397         } else {
3398                 print FILE $proxysettings{'THROTTLING_GREEN_HOST'} * 125;
3399                 print FILE "/";
3400                 print FILE $proxysettings{'THROTTLING_GREEN_HOST'} * 250;
3401         }
3402         print FILE "\n";
3403
3404         if ($netsettings{'BLUE_DEV'})
3405         {
3406                 print FILE "delay_parameters 2 ";
3407                 if ($proxysettings{'THROTTLING_BLUE_TOTAL'} eq 'unlimited')
3408                 {
3409                         print FILE "-1/-1";
3410                 } else {
3411                         print FILE $proxysettings{'THROTTLING_BLUE_TOTAL'} * 125;
3412                         print FILE "/";
3413                         print FILE $proxysettings{'THROTTLING_BLUE_TOTAL'} * 250;
3414                 }
3415                 print FILE " -1/-1 ";
3416                 if ($proxysettings{'THROTTLING_BLUE_HOST'} eq 'unlimited')
3417                 {
3418                         print FILE "-1/-1";
3419                 } else {
3420                         print FILE $proxysettings{'THROTTLING_BLUE_HOST'} * 125;
3421                         print FILE "/";
3422                         print FILE $proxysettings{'THROTTLING_BLUE_HOST'} * 250;
3423                 }
3424                 print FILE "\n";
3425         }
3426
3427         print FILE "delay_access 1 deny  IPFire_ips\n";
3428         if (!-z $acl_src_unrestricted_ip)  { print FILE "delay_access 1 deny  IPFire_unrestricted_ips\n"; }
3429         if (!-z $acl_src_unrestricted_mac) { print FILE "delay_access 1 deny  IPFire_unrestricted_mac\n"; }
3430         if (($proxysettings{'AUTH_METHOD'} eq 'ncsa') && (!-z $extgrp)) { print FILE "delay_access 1 deny  for_extended_users\n"; }
3431
3432         if ($netsettings{'BLUE_DEV'})
3433         {
3434                 print FILE "delay_access 1 allow IPFire_green_network";
3435                 if (!-z $acl_dst_throttle) { print FILE " for_throttled_urls"; }
3436                 print FILE "\n";
3437                 print FILE "delay_access 1 deny  all\n";
3438         } else {
3439                 print FILE "delay_access 1 allow all";
3440                 if (!-z $acl_dst_throttle) { print FILE " for_throttled_urls"; }
3441                 print FILE "\n";
3442         }
3443
3444         if ($netsettings{'BLUE_DEV'})
3445         {
3446                 print FILE "delay_access 2 deny  IPFire_ips\n";
3447                 if (!-z $acl_src_unrestricted_ip)  { print FILE "delay_access 2 deny  IPFire_unrestricted_ips\n"; }
3448                 if (!-z $acl_src_unrestricted_mac) { print FILE "delay_access 2 deny  IPFire_unrestricted_mac\n"; }
3449                 if (($proxysettings{'AUTH_METHOD'} eq 'ncsa') && (!-z $extgrp)) { print FILE "delay_access 2 deny  for_extended_users\n"; }
3450                 print FILE "delay_access 2 allow IPFire_blue_network";
3451                 if (!-z $acl_dst_throttle) { print FILE " for_throttled_urls"; }
3452                 print FILE "\n";
3453                 print FILE "delay_access 2 deny  all\n";
3454         }
3455
3456         print FILE "delay_initial_bucket_level 100\n";
3457         print FILE "\n";
3458 }
3459
3460 if ($proxysettings{'NO_PROXY_LOCAL'} eq 'on')
3461 {
3462         print FILE "#Prevent internal proxy access to Green except IPFire itself\n";
3463         print FILE "http_access deny IPFire_green_servers !IPFire_ips !IPFire_green_network\n\n";
3464 }
3465
3466 if ($proxysettings{'NO_PROXY_LOCAL_BLUE'} eq 'on')
3467 {
3468         print FILE "#Prevent internal proxy access from Blue except IPFire itself\n";
3469         print FILE "http_access allow IPFire_blue_network IPFire_blue_servers\n";
3470         print FILE "http_access deny  IPFire_blue_network !IPFire_ips IPFire_servers\n\n";
3471 }
3472
3473         print FILE <<END
3474 #Set custom configured ACLs
3475 END
3476         ;
3477         if (!-z $acl_src_banned_ip) { print FILE "http_access deny  IPFire_banned_ips\n"; }
3478         if (!-z $acl_src_banned_mac) { print FILE "http_access deny  IPFire_banned_mac\n"; }
3479
3480         if ((!-z $acl_dst_noauth) && (!($proxysettings{'AUTH_METHOD'} eq 'none')))
3481         {
3482                 if (!-z $acl_src_unrestricted_ip)
3483                 {
3484                         if (!-z $acl_dst_noauth_net) { print FILE "http_access allow IPFire_unrestricted_ips to_ipaddr_without_auth\n"; }
3485                         if (!-z $acl_dst_noauth_dom) { print FILE "http_access allow IPFire_unrestricted_ips to_domains_without_auth\n"; }
3486                         if (!-z $acl_dst_noauth_url) { print FILE "http_access allow IPFire_unrestricted_ips to_hosts_without_auth\n"; }
3487                 }
3488                 if (!-z $acl_src_unrestricted_mac)
3489                 {
3490                         if (!-z $acl_dst_noauth_net) { print FILE "http_access allow IPFire_unrestricted_mac to_ipaddr_without_auth\n"; }
3491                         if (!-z $acl_dst_noauth_dom) { print FILE "http_access allow IPFire_unrestricted_mac to_domains_without_auth\n"; }
3492                         if (!-z $acl_dst_noauth_url) { print FILE "http_access allow IPFire_unrestricted_mac to_hosts_without_auth\n"; }
3493                 }
3494                 if (!-z $acl_dst_noauth_net)
3495                 {
3496                         print FILE "http_access allow IPFire_networks";
3497                         if ($proxysettings{'TIME_ACCESS_MODE'} eq 'deny') {
3498                                 print FILE " !within_timeframe";
3499                         } else {
3500                                 print FILE " within_timeframe"; }
3501                         print FILE " to_ipaddr_without_auth\n";
3502                 }
3503                 if (!-z $acl_dst_noauth_dom)
3504                 {
3505                         print FILE "http_access allow IPFire_networks";
3506                         if ($proxysettings{'TIME_ACCESS_MODE'} eq 'deny') {
3507                                 print FILE " !within_timeframe";
3508                         } else {
3509                                 print FILE " within_timeframe"; }
3510                         print FILE " to_domains_without_auth\n";
3511                 }
3512                 if (!-z $acl_dst_noauth_url)
3513                 {
3514                         print FILE "http_access allow IPFire_networks";
3515                         if ($proxysettings{'TIME_ACCESS_MODE'} eq 'deny') {
3516                                 print FILE " !within_timeframe";
3517                         } else {
3518                                 print FILE " within_timeframe"; }
3519                         print FILE " to_hosts_without_auth\n";
3520                 }
3521         }
3522
3523         if (($proxysettings{'AUTH_METHOD'} eq 'ident') && ($proxysettings{'IDENT_REQUIRED'} eq 'on') && ($proxysettings{'AUTH_ALWAYS_REQUIRED'} eq 'on'))
3524         {
3525                 print FILE "http_access deny  !for_inetusers";
3526                 if (!-z $identhosts) { print FILE " on_ident_aware_hosts"; }
3527                 print FILE "\n";
3528         }
3529
3530         if (
3531              ($proxysettings{'AUTH_METHOD'} eq 'ident') &&
3532              ($proxysettings{'AUTH_ALWAYS_REQUIRED'} eq 'on') &&
3533              ($proxysettings{'IDENT_ENABLE_ACL'} eq 'on') &&
3534              ($proxysettings{'IDENT_USER_ACL'} eq 'negative') &&
3535              (!-z "$identdir/identauth.denyusers")
3536            )
3537         {
3538                 print FILE "http_access deny  for_acl_users";
3539                 if (($proxysettings{'AUTH_METHOD'} eq 'ident') && (!-z "$identdir/hosts")) { print FILE " on_ident_aware_hosts"; }
3540                 print FILE "\n";
3541         }
3542
3543         if (!-z $acl_src_unrestricted_ip)
3544         {
3545                 print FILE "http_access allow IPFire_unrestricted_ips";
3546                 if ($proxysettings{'AUTH_ALWAYS_REQUIRED'} eq 'on')
3547                 {
3548                         if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3549                         {
3550                                 if (!-z $disgrp) { print FILE " !for_disabled_users"; } else { print FILE " for_inetusers"; }
3551                         }
3552                         if (($proxysettings{'AUTH_METHOD'} eq 'ldap') || ($proxysettings{'AUTH_METHOD'} eq 'radius'))
3553                         {
3554                                 print FILE " for_inetusers";
3555                         }
3556                         if (($proxysettings{'AUTH_METHOD'} eq 'radius') && ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on'))
3557                         {
3558                                 if ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on')
3559                                 {
3560                                         if (($proxysettings{'RADIUS_USER_ACL'} eq 'positive') && (!-z "$raddir/radauth.allowusers"))
3561                                         {
3562                                                 print FILE " for_acl_users";
3563                                         }
3564                                         if (($proxysettings{'RADIUS_USER_ACL'} eq 'negative') && (!-z "$raddir/radauth.denyusers"))
3565                                         {
3566                                                 print FILE " !for_acl_users";
3567                                         }
3568                                 } else { print FILE " for_inetusers"; }
3569                         }
3570                 }
3571                 print FILE "\n";
3572         }
3573
3574         if (!-z $acl_src_unrestricted_mac)
3575         {
3576                 print FILE "http_access allow IPFire_unrestricted_mac";
3577                 if ($proxysettings{'AUTH_ALWAYS_REQUIRED'} eq 'on')
3578                 {
3579                         if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3580                         {
3581                                 if (!-z $disgrp) { print FILE " !for_disabled_users"; } else { print FILE " for_inetusers"; }
3582                         }
3583                         if (($proxysettings{'AUTH_METHOD'} eq 'ldap') || ($proxysettings{'AUTH_METHOD'} eq 'radius'))
3584                         {
3585                                 print FILE " for_inetusers";
3586                         }
3587                         if (($proxysettings{'AUTH_METHOD'} eq 'radius') && ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on'))
3588                         {
3589                                 if ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on')
3590                                 {
3591                                         if (($proxysettings{'RADIUS_USER_ACL'} eq 'positive') && (!-z "$raddir/radauth.allowusers"))
3592                                         {
3593                                                 print FILE " for_acl_users";
3594                                         }
3595                                         if (($proxysettings{'RADIUS_USER_ACL'} eq 'negative') && (!-z "$raddir/radauth.denyusers"))
3596                                         {
3597                                                 print FILE " !for_acl_users";
3598                                         }
3599                                 } else { print FILE " for_inetusers"; }
3600                         }
3601                 }
3602                 print FILE "\n";
3603         }
3604
3605         if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3606         {
3607                 if (!-z $disgrp) { print FILE "http_access deny  for_disabled_users\n"; }
3608                 if (!-z $extgrp) { print FILE "http_access allow IPFire_networks for_extended_users\n"; }
3609         }
3610
3611         if (
3612             (
3613              ($proxysettings{'AUTH_METHOD'} eq 'radius') &&
3614              ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on') &&
3615              ($proxysettings{'RADIUS_USER_ACL'} eq 'negative') &&
3616              (!-z "$raddir/radauth.denyusers")
3617             )
3618                 ||
3619             (
3620              ($proxysettings{'AUTH_METHOD'} eq 'ident') &&
3621              ($proxysettings{'AUTH_ALWAYS_REQUIRED'} eq 'off') &&
3622              ($proxysettings{'IDENT_ENABLE_ACL'} eq 'on') &&
3623              ($proxysettings{'IDENT_USER_ACL'} eq 'negative') &&
3624              (!-z "$identdir/identauth.denyusers")
3625             )
3626            )
3627         {
3628                 print FILE "http_access deny  for_acl_users";
3629                 if (($proxysettings{'AUTH_METHOD'} eq 'ident') && (!-z "$identdir/hosts")) { print FILE " on_ident_aware_hosts"; }
3630                 print FILE "\n";
3631         }
3632
3633         if (($proxysettings{'AUTH_METHOD'} eq 'ident') && ($proxysettings{'IDENT_REQUIRED'} eq 'on') && (!-z "$identhosts"))
3634         {
3635                 print FILE "http_access allow";
3636                 if ($proxysettings{'TIME_ACCESS_MODE'} eq 'deny') {
3637                         print FILE " !within_timeframe";
3638                 } else {
3639                         print FILE " within_timeframe"; }
3640                 print FILE " !on_ident_aware_hosts\n";
3641         }
3642
3643         print FILE "http_access allow IPFire_networks";
3644         if (
3645             (
3646              ($proxysettings{'AUTH_METHOD'} eq 'radius') &&
3647              ($proxysettings{'RADIUS_ENABLE_ACL'} eq 'on') &&
3648              ($proxysettings{'RADIUS_USER_ACL'} eq 'positive') &&
3649              (!-z "$raddir/radauth.allowusers")
3650             )
3651                 ||
3652             (
3653              ($proxysettings{'AUTH_METHOD'} eq 'ident') &&
3654              ($proxysettings{'IDENT_REQUIRED'} eq 'on') &&
3655              ($proxysettings{'IDENT_ENABLE_ACL'} eq 'on') &&
3656              ($proxysettings{'IDENT_USER_ACL'} eq 'positive') &&
3657              (!-z "$identdir/identauth.allowusers")
3658             )
3659            )
3660         {
3661                 print FILE " for_acl_users";
3662         } elsif (((!($proxysettings{'AUTH_METHOD'} eq 'none')) && (!($proxysettings{'AUTH_METHOD'} eq 'ident'))) ||
3663                 (($proxysettings{'AUTH_METHOD'} eq 'ident') && ($proxysettings{'IDENT_REQUIRED'} eq 'on'))) {
3664                 print FILE " for_inetusers";
3665         }
3666         if ((!($proxysettings{'AUTH_MAX_USERIP'} eq '')) && (!($proxysettings{'AUTH_METHOD'} eq 'none')) && (!($proxysettings{'AUTH_METHOD'} eq 'ident')))
3667         {
3668                 print FILE " !concurrent";
3669         }
3670         if ($proxysettings{'TIME_ACCESS_MODE'} eq 'deny') {
3671                 print FILE " !within_timeframe";
3672         } else {
3673                 print FILE " within_timeframe"; }
3674         print FILE "\n";
3675
3676         print FILE "http_access deny  all\n\n";
3677
3678         if (($proxysettings{'FORWARD_IPADDRESS'} eq 'off') || ($proxysettings{'FORWARD_VIA'} eq 'off') ||
3679                 (!($proxysettings{'FAKE_USERAGENT'} eq '')) || (!($proxysettings{'FAKE_REFERER'} eq '')))
3680         {
3681                 print FILE "#Strip HTTP Header\n";
3682
3683                 if ($proxysettings{'FORWARD_IPADDRESS'} eq 'off')
3684                 {
3685                         print FILE "request_header_access X-Forwarded-For deny all\n";
3686                         print FILE "reply_header_access X-Forwarded-For deny all\n";
3687                 }
3688                 if ($proxysettings{'FORWARD_VIA'} eq 'off')
3689                 {
3690                         print FILE "request_header_access Via deny all\n";
3691                         print FILE "reply_header_access Via deny all\n";
3692                 }
3693                 if (!($proxysettings{'FAKE_USERAGENT'} eq ''))
3694                 {
3695                         print FILE "request_header_access User-Agent deny all\n";
3696                         print FILE "reply_header_access User-Agent deny all\n";
3697                 }
3698                 if (!($proxysettings{'FAKE_REFERER'} eq ''))
3699                 {
3700                         print FILE "request_header_access Referer deny all\n";
3701                         print FILE "reply_header_access Referer deny all\n";
3702                 }
3703
3704                 print FILE "\n";
3705
3706                 if ((!($proxysettings{'FAKE_USERAGENT'} eq '')) || (!($proxysettings{'FAKE_REFERER'} eq '')))
3707                 {
3708                         if (!($proxysettings{'FAKE_USERAGENT'} eq ''))
3709                         {
3710                                 print FILE "header_replace User-Agent $proxysettings{'FAKE_USERAGENT'}\n";
3711                         }
3712                         if (!($proxysettings{'FAKE_REFERER'} eq ''))
3713                         {
3714                                 print FILE "header_replace Referer $proxysettings{'FAKE_REFERER'}\n";
3715                         }
3716                         print FILE "\n";
3717                 }
3718         }
3719
3720         if ($proxysettings{'SUPPRESS_VERSION'} eq 'on') { print FILE "httpd_suppress_version_string on\n\n" }
3721
3722         if ((!-z $mimetypes) && ($proxysettings{'ENABLE_MIME_FILTER'} eq 'on')) {
3723                 if (!-z $acl_src_unrestricted_ip)  { print FILE "http_reply_access allow IPFire_unrestricted_ips\n"; }
3724                 if (!-z $acl_src_unrestricted_mac) { print FILE "http_reply_access allow IPFire_unrestricted_mac\n"; }
3725                 if ($proxysettings{'AUTH_METHOD'} eq 'ncsa')
3726                 {
3727                         if (!-z $extgrp) { print FILE "http_reply_access allow for_extended_users\n"; }
3728                 }
3729                 print FILE "http_reply_access deny  blocked_mimetypes\n";
3730                 print FILE "http_reply_access allow all\n\n";
3731         }
3732
3733         print FILE "visible_hostname";
3734         if ($proxysettings{'VISIBLE_HOSTNAME'} eq '')
3735         {
3736                 print FILE " $mainsettings{'HOSTNAME'}.$mainsettings{'DOMAINNAME'}\n\n";
3737         } else {
3738                 print FILE " $proxysettings{'VISIBLE_HOSTNAME'}\n\n";
3739         }
3740
3741         if (!($proxysettings{'ADMIN_MAIL_ADDRESS'} eq '')) { print FILE "cache_mgr $proxysettings{'ADMIN_MAIL_ADDRESS'}\n"; }
3742         if (!($proxysettings{'ADMIN_PASSWORD'} eq '')) { print FILE "cachemgr_passwd $proxysettings{'ADMIN_PASSWORD'} all\n"; }
3743         print FILE "\n";
3744
3745         print FILE "max_filedescriptors $proxysettings{'FILEDESCRIPTORS'}\n\n";
3746
3747         # Write the parent proxy info, if needed.
3748         if ($remotehost ne '')
3749         {
3750                 print FILE "cache_peer $remotehost parent $remoteport 3130 default no-query";
3751
3752                 # Enter authentication for the parent cache. Option format is
3753                 # login=user:password   ($proxy1='YES')
3754                 # login=PASS            ($proxy1='PASS')
3755                 # login=*:password      ($proxysettings{'FORWARD_USERNAME'} eq 'on')
3756                 if (($proxy1 eq 'YES') || ($proxy1 eq 'PASS'))
3757                 {
3758                         print FILE " login=$proxysettings{'UPSTREAM_USER'}";
3759                         if ($proxy1 eq 'YES') { print FILE ":$proxysettings{'UPSTREAM_PASSWORD'}"; }
3760                 }
3761                 elsif ($proxysettings{'FORWARD_USERNAME'} eq 'on') { print FILE " login=*:password"; }
3762
3763                 print FILE "\nalways_direct allow IPFire_ips\n";
3764                 print FILE "never_direct  allow all\n\n";
3765         }
3766         if (($proxysettings{'ENABLE_FILTER'} eq 'on') || ($proxysettings{'ENABLE_UPDXLRATOR'} eq 'on') || ($proxysettings{'ENABLE_CLAMAV'} eq 'on'))
3767         {
3768                 print FILE "url_rewrite_program /usr/sbin/redirect_wrapper\n";
3769                 print FILE "url_rewrite_children ", &General::number_cpu_cores();
3770                 print FILE " startup=", &General::number_cpu_cores();
3771                 print FILE " idle=", &General::number_cpu_cores();
3772                 print FILE " queue-size=", &General::number_cpu_cores() * 32, "\n\n";
3773         }
3774
3775         # Include file with user defined settings.
3776         if (-e "/etc/squid/squid.conf.local") {
3777                 print FILE "include /etc/squid/squid.conf.local\n";
3778         }
3779         close FILE;
3780
3781         # Proxy settings for squidclamav - if installed.
3782         #
3783         # Check if squidclamav is enabled.
3784         if ($proxysettings{'ENABLE_CLAMAV'} eq 'on') {
3785
3786                 my $configfile='/etc/squidclamav.conf';
3787
3788                 my $data = &General::read_file_utf8($configfile);
3789                 $data =~ s/squid_port [0-9]+/squid_port $proxysettings{'PROXY_PORT'}/g;
3790                 &General::write_file_utf8($configfile, $data);
3791         }
3792 }
3793
3794 # -------------------------------------------------------------------
3795
3796 sub adduser
3797 {
3798         my ($str_user, $str_pass, $str_group) = @_;
3799         my @groupmembers=();
3800
3801         if ($str_pass eq 'lEaVeAlOnE')
3802         {
3803                 open(FILE, "$userdb");
3804                 @groupmembers = <FILE>;
3805                 close(FILE);
3806                 foreach $line (@groupmembers) { if ($line =~ /^$str_user:/i) { $str_pass = substr($line,index($line,":")); } }
3807                 &deluser($str_user);
3808                 open(FILE, ">>$userdb");
3809                 flock FILE,2;
3810                 print FILE "$str_user$str_pass";
3811                 close(FILE);
3812         } else {
3813                 &deluser($str_user);