Don't move http_access and icp_access directives unless needed
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 22:58:23 +0000 (22:58 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 22:58:23 +0000 (22:58 +0000)
squid/CHANGELOG
squid/http_access_save.cgi
squid/icp_access_save.cgi
squid/parser-lib.pl

index 721687f..3415899 100644 (file)
@@ -22,3 +22,4 @@ Re-design the Access Control page to use tabs, to better split up the lists of A
 Ensure that HTTP and ICP restrictions are created after ACLs in the config file.
 ---- Changes since 1.390 ----
 The httpd_accel family of directives are no longer shown when using Squid versions 2.6 and above (as they have been deprecated).
+Directives that refer to ACLs like http_access are no longer re-positioned in the configuration file unless necessary.
index 4de353e..0e8c000 100755 (executable)
@@ -20,13 +20,24 @@ if ($in{'delete'}) {
 else {
        # update or create
        @vals = ( $in{'action'} );
-       foreach $y (split(/\0/, $in{'yes'})) { push(@vals, $y); }
-       foreach $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); }
+       foreach $y (split(/\0/, $in{'yes'})) {
+               push(@vals, $y);
+               $used{$y}++;
+               }
+       foreach $n (split(/\0/, $in{'no'})) {
+               push(@vals, "!$n");
+               $used{$n}++;
+               }
        $newhttp = { 'name' => 'http_access', 'values' => \@vals };
        if ($http) { splice(@https, &indexof($http, @https), 1, $newhttp); }
        else { push(@https, $newhttp); }
        }
-&save_directive($conf, "http_access", \@https, "acl");
+
+# Find the last referenced ACL
+@acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf);
+$lastacl = @acls ? $acls[$#acls] : undef;
+
+&save_directive($conf, "http_access", \@https, $lastacl);
 &flush_file_lines();
 &unlock_file($config{'squid_conf'});
 &webmin_log($in{'delete'} ? 'delete' : $http ? 'modify' : 'create', "http");
index ac26107..5eaaaaa 100755 (executable)
@@ -20,13 +20,24 @@ if ($in{'delete'}) {
 else {
        # update or create
        @vals = ( $in{'action'} );
-       foreach $y (split(/\0/, $in{'yes'})) { push(@vals, $y); }
-       foreach $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); }
+       foreach $y (split(/\0/, $in{'yes'})) {
+               push(@vals, $y);
+               $used{$y}++;
+               }
+       foreach $n (split(/\0/, $in{'no'})) {
+               push(@vals, "!$n");
+               $used{$n}++;
+               }
        $newicp = { 'name' => 'icp_access', 'values' => \@vals };
        if ($icp) { splice(@icps, &indexof($icp, @icps), 1, $newicp); }
        else { push(@icps, $newicp); }
        }
-&save_directive($conf, "icp_access", \@icps, "acl");
+
+# Find the last referenced ACL
+@acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf);
+$lastacl = @acls ? $acls[$#acls] : undef;
+
+&save_directive($conf, "icp_access", \@icps, $lastacl);
 &flush_file_lines();
 &unlock_file($config{'squid_conf'});
 &webmin_log($in{'delete'} ? 'delete' : $icp ? 'modify' : 'create', "icp");
index 20cdd46..168892b 100644 (file)
@@ -102,7 +102,8 @@ for($i=0; $i<@oldv || $i<@newv; $i++) {
        if ($i >= @oldv) {
                # a new directive is being added.. 
                $nl = &directive_line($newv[$i]);
-               local @after = $_[3] ? &find_config($_[3], $_[0]) : ( );
+               local @after = ref($_[3]) ? ( $_[3] ) :
+                              $_[3] ? &find_config($_[3], $_[0]) : ( );
                local $after = @after ? @after[$#after] : undef;
                local @comment = &find_config($_[1], $_[0], 3);
                local $comment = @comment ? $comment[$#comment] : undef;
@@ -140,7 +141,8 @@ for($i=0; $i<@oldv || $i<@newv; $i++) {
        else {
                # updating some directive
                $nl = &directive_line($newv[$i]);
-               local @after = $_[3] ? &find_config($_[3], $_[0]) : ( );
+               local @after = ref($_[3]) ? ( $_[3] ) :
+                              $_[3] ? &find_config($_[3], $_[0]) : ( );
                local $after = @after ? @after[$#after] : undef;
                if ($after && $oldv[$i]->{'line'} < $after->{'line'}) {
                        # Need to move it after some directive