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