Revision: 6153
          http://ipcop.svn.sourceforge.net/ipcop/?rev=6153&view=rev
Author:   dotzball
Date:     2011-12-05 15:36:36 +0000 (Mon, 05 Dec 2011)
Log Message:
-----------
Fix parent proxy auth, was not working as the (copied) code was using variables 
which are not
set in the makesquidconf script (in proxy.cgi they were set on validating 
before save).

Fix Perl warnings.

Modified Paths:
--------------
    ipcop/trunk/src/scripts/makesquidconf

Modified: ipcop/trunk/src/scripts/makesquidconf
===================================================================
--- ipcop/trunk/src/scripts/makesquidconf       2011-12-04 15:57:55 UTC (rev 
6152)
+++ ipcop/trunk/src/scripts/makesquidconf       2011-12-05 15:36:36 UTC (rev 
6153)
@@ -24,6 +24,7 @@
 
 use strict;
 use NetAddr::IP;
+#use warnings;
 
 require '/usr/lib/ipcop/general-functions.pl';
 
@@ -33,7 +34,6 @@
 my %mainsettings=();
 my %proxysettings=();
 my %netsettings=();
-my %redirectorsettings=();
 my %ovpnsettings=();
 my $ovpnactive = 0;
 
@@ -42,11 +42,8 @@
 
 my @temp=();
 
-my $proxy1='';
-my $proxy2='';
-my $replybodymaxsize=0;
+my $replybodymaxsize = '';
 my $browser_regexp='';
-my $redirectors=0;
 
 my $acldir   = "/var/ipcop/proxy/acls";
 my $ncsadir  = "/var/ipcop/proxy/ncsa";
@@ -130,7 +127,9 @@
 {
     chomp;
     @useragent = split(/,/);
-    if ($proxysettings{'UA_'.@useragent[0]} eq 'on') { $browser_regexp .= 
"@useragent[2]|"; }
+    if (defined($proxysettings{'UA_'.$useragent[0]}) && 
$proxysettings{'UA_'.$useragent[0]} eq 'on') {
+        $browser_regexp .= "$useragent[2]|";
+    }
 }
 chop($browser_regexp);
 
@@ -157,7 +156,7 @@
 
     foreach my $redirector (</var/ipcop/proxy/redirector/*>) {
         if (-e $redirector) {
-            %redirectorsettings=();
+            my %redirectorsettings=();
             &General::readhash($redirector, \%redirectorsettings);
 
             if (defined($redirectorsettings{'NAME'}) && 
($redirectorsettings{'ENABLED'} eq 'on')) {
@@ -286,25 +285,31 @@
     my $authrealm;
     my $delaypools;
 
-    if ($proxysettings{'THROTTLING_GREEN_TOTAL'} +
-        $proxysettings{'THROTTLING_GREEN_HOST'}  +
-        $proxysettings{'THROTTLING_BLUE_TOTAL'}  +
-        $proxysettings{'THROTTLING_BLUE_HOST'} gt 0)
+    if ($proxysettings{'THROTTLING_GREEN_TOTAL'} eq 'unlimited'
+        && $proxysettings{'THROTTLING_GREEN_HOST'} eq 'unlimited'
+        && $proxysettings{'THROTTLING_BLUE_TOTAL'} eq 'unlimited'
+        && $proxysettings{'THROTTLING_BLUE_HOST'} eq 'unlimited')
     {
-        $delaypools = 1; } else { $delaypools = 0;
+        $delaypools = 0;
     }
+    else {
+        $delaypools = 1;
+    }
 
     if ($proxysettings{'AUTH_REALM'} eq '')
     {
         $authrealm = "IPCop Proxy Server";
-    } else {
+    }
+    else {
         $authrealm = $proxysettings{'AUTH_REALM'};
     }
 
     $_ = $proxysettings{'UPSTREAM_PROXY'};
     my ($remotehost, $remoteport) = (/^(?:[a-zA-Z 
]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
 
-    if ($remoteport eq '') { $remoteport = 80; }
+    if ( (!defined($remoteport)) || $remoteport eq '') {
+        $remoteport = 80;
+    }
 
     open(FILE, ">/var/ipcop/proxy/squid.conf");
     flock(FILE, 2);
@@ -597,7 +602,9 @@
         print FILE "\n";
     }
 
-    if (($delaypools) && (!-z $acl_dst_throttle)) { print FILE "acl 
for_throttled_urls url_regex -i \"$acl_dst_throttle\"\n\n"; }
+    if (($delaypools) && (!-z $acl_dst_throttle)) {
+        print FILE "acl for_throttled_urls url_regex -i 
\"$acl_dst_throttle\"\n\n";
+    }
 
     if ($proxysettings{'ENABLE_BROWSER_CHECK'} eq 'on') { print FILE "acl 
with_allowed_useragents browser $browser_regexp\n\n"; }
 
@@ -753,21 +760,23 @@
 if ($delaypools) {
     print FILE "#Set download throttling\n";
 
-    if ($netsettings{'BLUE_COUNT'} >= 1)
-    {
+    if ($netsettings{'BLUE_COUNT'} >= 1) {
         print FILE "delay_pools 2\n";
-    } else {
+    }
+    else {
         print FILE "delay_pools 1\n";
     }
 
     print FILE "delay_class 1 3\n";
-    if ($netsettings{'BLUE_COUNT'} >= 1) {     print FILE "delay_class 2 3\n"; 
}
+    if ($netsettings{'BLUE_COUNT'} >= 1) {
+        print FILE "delay_class 2 3\n";
+    }
 
     print FILE "delay_parameters 1 ";
-    if ($proxysettings{'THROTTLING_GREEN_TOTAL'} eq 'unlimited')
-    {
+    if ($proxysettings{'THROTTLING_GREEN_TOTAL'} eq 'unlimited') {
         print FILE "-1/-1";
-    } else {
+    }
+    else {
         print FILE $proxysettings{'THROTTLING_GREEN_TOTAL'} * 125;
         print FILE "/";
         print FILE $proxysettings{'THROTTLING_GREEN_TOTAL'} * 250;
@@ -777,7 +786,8 @@
     if ($proxysettings{'THROTTLING_GREEN_HOST'} eq 'unlimited')
     {
         print FILE "-1/-1";
-    } else {
+    }
+    else {
         print FILE $proxysettings{'THROTTLING_GREEN_HOST'} * 125;
         print FILE "/";
         print FILE $proxysettings{'THROTTLING_GREEN_HOST'} * 250;
@@ -787,19 +797,23 @@
     if ($netsettings{'BLUE_COUNT'} >= 1)
     {
         print FILE "delay_parameters 2 ";
+
         if ($proxysettings{'THROTTLING_BLUE_TOTAL'} eq 'unlimited')
         {
             print FILE "-1/-1";
-        } else {
+        }
+        else {
             print FILE $proxysettings{'THROTTLING_BLUE_TOTAL'} * 125;
             print FILE "/";
             print FILE $proxysettings{'THROTTLING_BLUE_TOTAL'} * 250;
         }
+
         print FILE " -1/-1 ";
-        if ($proxysettings{'THROTTLING_BLUE_HOST'} eq 'unlimited')
-        {
+
+        if ($proxysettings{'THROTTLING_BLUE_HOST'} eq 'unlimited') {
             print FILE "-1/-1";
-        } else {
+        }
+        else {
             print FILE $proxysettings{'THROTTLING_BLUE_HOST'} * 125;
             print FILE "/";
             print FILE $proxysettings{'THROTTLING_BLUE_HOST'} * 250;
@@ -810,17 +824,24 @@
     print FILE "delay_access 1 deny  IPCop_ips\n";
     if (!-z $acl_src_unrestricted_ip)  { print FILE "delay_access 1 deny  
IPCop_unrestricted_ips\n"; }
     if (!-z $acl_src_unrestricted_mac) { print FILE "delay_access 1 deny  
IPCop_unrestricted_mac\n"; }
-    if (($proxysettings{'AUTH_METHOD'} eq 'ncsa') && (!-z $extgrp)) { print 
FILE "delay_access 1 deny  for_extended_users\n"; }
+    if (($proxysettings{'AUTH_METHOD'} eq 'ncsa') && (!-z $extgrp)) {
+        print FILE "delay_access 1 deny  for_extended_users\n";
+    }
 
     if ($netsettings{'BLUE_COUNT'} >= 1)
     {
         print FILE "delay_access 1 allow IPCop_green_network";
-        if (!-z $acl_dst_throttle) { print FILE " for_throttled_urls"; }
+        if (!-z $acl_dst_throttle) {
+            print FILE " for_throttled_urls";
+        }
         print FILE "\n";
         print FILE "delay_access 1 deny  all\n";
-    } else {
+    }
+    else {
         print FILE "delay_access 1 allow all";
-        if (!-z $acl_dst_throttle) { print FILE " for_throttled_urls"; }
+        if (!-z $acl_dst_throttle) {
+            print FILE " for_throttled_urls";
+        }
         print FILE "\n";
     }
 
@@ -1183,7 +1204,6 @@
 request_body_max_size $proxysettings{'MAX_OUTGOING_SIZE'} KB
 END
     ;
-    $replybodymaxsize = "$proxysettings{'MAX_INCOMING_SIZE'} KB";
     if ($proxysettings{'MAX_INCOMING_SIZE'} > 0) {
         if (!-z $acl_src_unrestricted_ip) { print FILE "reply_body_max_size 
none IPCop_unrestricted_ips\n"; }
         if (!-z $acl_src_unrestricted_mac) { print FILE "reply_body_max_size 
none IPCop_unrestricted_mac\n"; }
@@ -1192,7 +1212,13 @@
             if (!-z $extgrp) { print FILE "reply_body_max_size none 
for_extended_users\n"; }
         }
     }
-    if ($replybodymaxsize == 0) { $replybodymaxsize = 'none'; }
+    if ($proxysettings{'MAX_INCOMING_SIZE'} == 0) {
+        $replybodymaxsize = 'none';
+    }
+    else {
+        $replybodymaxsize = "$proxysettings{'MAX_INCOMING_SIZE'} KB";
+    }
+
     print FILE "reply_body_max_size $replybodymaxsize all\n\n";
 
     print FILE "visible_hostname";
@@ -1211,15 +1237,18 @@
         print FILE "cache_peer $remotehost parent $remoteport 3130 default 
no-query";
 
         # Enter authentication for the parent cache. Option format is
-        # login=user:password   ($proxy1='YES')
-        # login=PASS            ($proxy1='PASS')
-        # login=*:password      ($proxysettings{'FORWARD_USERNAME'} eq 'on')
-        if (($proxy1 eq 'YES') || ($proxy1 eq 'PASS'))
-        {
+        # login=*:password          ($proxysettings{'FORWARD_USERNAME'} eq 
'on')
+        # login=PASS                ($proxysettings{'UPSTREAM_USER'}='PASS')
+        # login=<user>:<password>   ($proxysettings{'UPSTREAM_USER'}='<user>')
+        if ($proxysettings{'FORWARD_USERNAME'} eq 'on') {
+            print FILE " login=*:password";
+        }
+        elsif (($proxysettings{'UPSTREAM_USER'} ne '')) {
             print FILE " login=$proxysettings{'UPSTREAM_USER'}";
-            if ($proxy1 eq 'YES') { print FILE 
":$proxysettings{'UPSTREAM_PASSWORD'}"; }
+            if ($proxysettings{'UPSTREAM_USER'} ne 'PASS') {
+                print FILE ":$proxysettings{'UPSTREAM_PASSWORD'}";
+            }
         }
-        elsif ($proxysettings{'FORWARD_USERNAME'} eq 'on') { print FILE " 
login=*:password"; }
 
         print FILE "\nalways_direct allow IPCop_ips\n";
         print FILE "never_direct  allow all\n\n";

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Ipcop-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to