more strict and ui-lib conversion

This commit is contained in:
Jamie Cameron
2014-01-02 16:04:08 -08:00
parent 67ec52a2c5
commit f267672ae2
4 changed files with 98 additions and 84 deletions

View File

@@ -2,11 +2,15 @@
# always.cgi
# A form for editing or creating http_access directives
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'othercaches'} || &error($text{'eicp_ecannot'});
&ReadParse();
$conf = &get_config();
my $conf = &get_config();
my @always;
if (!defined($in{'index'})) {
&ui_print_header(undef, $text{'always_create'}, "",
undef, 0, 0, 0, &restart_button());
@@ -17,47 +21,46 @@ else {
@always = @{$conf->[$in{'index'}]->{'values'}};
}
print "<form action=always_save.cgi>\n";
print &ui_form_start("always_save.cgi", "post");
if (@always) {
print "<input type=hidden name=index value=$in{'index'}>\n";
print &ui_hidden("index", $in{'index'});
}
print "<table border>\n";
print "<tr $tb> <td><b>$text{'always_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_table_start($text{'always_header'}, undef, 2);
print "<tr> <td><b>$text{'ahttp_a'}</b></td> <td colspan=3>\n";
printf "<input type=radio name=action value=allow %s> $text{'ahttp_a1'}\n",
$always[0] eq "allow" ? "checked" : "";
printf "<input type=radio name=action value=deny %s> $text{'ahttp_d'}</td> </tr>\n",
$always[0] eq "allow" ? "" : "checked";
# Allow or deny this ACL?
print &ui_table_row($text{'ahttp_a'},
&ui_radio("action", $always[0] || "allow",
[ [ "allow", $text{'ahttp_a1'} ],
[ "deny", $text{'ahttp_d'} ] ]));
for($i=1; $i<@always; $i++) { $match{$always[$i]}++; }
@acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf);
# Get list of ACLs being matched, and all ACLs
my (@yes, @no);
for(my $i=1; $i<@always; $i++) {
if ($always[$i] =~ /^!(.*)/) {
push(@no, $1);
}
else {
push(@yes, $always[$i]);
}
}
my %done;
my @acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf);
unshift(@acls, { 'values' => [ 'all' ] }) if ($squid_version >= 3);
$r = @acls; $r = 10 if ($r > 10);
my $r = @acls;
$r = 10 if ($r > 10);
print "<tr> <td valign=top><b>$text{'ahttp_ma'}</b></td>\n";
print "<td valign=top><select name=yes multiple size=$r width=100>\n";
foreach $a (@acls) {
printf "<option %s>%s</option>\n",
$match{$a->{'values'}->[0]} ? "selected" : "",
$a->{'values'}->[0];
}
print "</select></td>\n";
print &ui_table_row($text{'ahttp_ma'},
&ui_select("yes", \@yes, [ map { $_->{'values'}->[0] } @acls ],
$r, 1, 1));
print "<td valign=top><b>$text{'ahttp_dma'}</b></td>\n";
print "<td valign=top><select name=no multiple size=$r width=100>\n";
foreach $a (@acls) {
printf "<option %s>%s</option>\n",
$match{"!$a->{'values'}->[0]"} ? "selected" : "",
$a->{'values'}->[0];
}
print "</select></td> </tr>\n";
print &ui_table_row($text{'ahttp_dma'},
&ui_select("no", \@no, [ map { $_->{'values'}->[0] } @acls ],
$r, 1, 1));
print "</table></td></tr></table><br>\n";
print "<input type=submit value=$text{'buttsave'}>\n";
if (@always) { print "<input type=submit value=$text{'buttdel'} name=delete>\n"; }
print "</form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'buttsave'} ],
@always ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]);
&ui_print_footer("edit_acl.cgi", $text{'ahttp_return'});
&ui_print_footer("edit_icp.cgi", $text{'ahttp_return'});

View File

@@ -2,13 +2,17 @@
# always_save.cgi
# Save or delete an always_direct directive
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'othercaches'} || &error($text{'eicp_ecannot'});
&ReadParse();
&lock_file($config{'squid_conf'});
$conf = &get_config();
my $conf = &get_config();
@always = &find_config("always_direct", $conf);
my @always = &find_config("always_direct", $conf);
my $always;
if (defined($in{'index'})) {
$always = $conf->[$in{'index'}];
}
@@ -18,10 +22,10 @@ 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"); }
$newalways = { 'name' => 'always_direct', 'values' => \@vals };
my @vals = ( $in{'action'} );
foreach my $y (split(/\0/, $in{'yes'})) { push(@vals, $y); }
foreach my $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); }
my $newalways = { 'name' => 'always_direct', 'values' => \@vals };
if ($always) { splice(@always, &indexof($always, @always),
1, $newalways); }
else { push(@always, $newalways); }
@@ -29,6 +33,6 @@ else {
&save_directive($conf, "always_direct", \@always);
&flush_file_lines();
&unlock_file($config{'squid_conf'});
&webmin_log($in{'delete'} ? 'delete' : $always ? 'modify' : 'create', "always");
&webmin_log($in{'delete'} ? 'delete' : $always ? 'modify' : 'create', 'always');
&redirect("edit_icp.cgi");

View File

@@ -2,11 +2,15 @@
# never.cgi
# A form for editing or creating http_access directives
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'othercaches'} || &error($text{'eicp_ecannot'});
&ReadParse();
$conf = &get_config();
my $conf = &get_config();
my @never;
if (!defined($in{'index'})) {
&ui_print_header(undef, $text{'never_create'}, "",
undef, 0, 0, 0, &restart_button());
@@ -17,47 +21,46 @@ else {
@never = @{$conf->[$in{'index'}]->{'values'}};
}
print "<form action=never_save.cgi>\n";
print &ui_form_start("never_save.cgi", "post");
if (@never) {
print "<input type=hidden name=index value=$in{'index'}>\n";
print &ui_hidden("index", $in{'index'});
}
print "<table border>\n";
print "<tr $tb> <td><b>$text{'never_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_table_start($text{'never_header'}, undef, 2);
print "<tr> <td><b>$text{'ahttp_a'}</b></td> <td colspan=3>\n";
printf "<input type=radio name=action value=allow %s> $text{'ahttp_a1'}\n",
$never[0] eq "allow" ? "checked" : "";
printf "<input type=radio name=action value=deny %s> $text{'ahttp_d'}</td> </tr>\n",
$never[0] eq "allow" ? "" : "checked";
# Allow or deny this ACL?
print &ui_table_row($text{'ahttp_a'},
&ui_radio("action", $never[0] || "allow",
[ [ "allow", $text{'ahttp_a1'} ],
[ "deny", $text{'ahttp_d'} ] ]));
for($i=1; $i<@never; $i++) { $match{$never[$i]}++; }
@acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf);
# Get list of ACLs being matched, and all ACLs
my (@yes, @no);
for(my $i=1; $i<@never; $i++) {
if ($never[$i] =~ /^!(.*)/) {
push(@no, $1);
}
else {
push(@yes, $never[$i]);
}
}
my %done;
my @acls = grep { !$done{$_->{'values'}->[0]}++ } &find_config("acl", $conf);
unshift(@acls, { 'values' => [ 'all' ] }) if ($squid_version >= 3);
$r = @acls; $r = 10 if ($r > 10);
my $r = @acls;
$r = 10 if ($r > 10);
print "<tr> <td valign=top><b>$text{'ahttp_ma'}</b></td>\n";
print "<td valign=top><select name=yes multiple size=$r width=100>\n";
foreach $a (@acls) {
printf "<option %s>%s</option>\n",
$match{$a->{'values'}->[0]} ? "selected" : "",
$a->{'values'}->[0];
}
print "</select></td>\n";
print &ui_table_row($text{'ahttp_ma'},
&ui_select("yes", \@yes, [ map { $_->{'values'}->[0] } @acls ],
$r, 1, 1));
print "<td valign=top><b>$text{'ahttp_dma'}</b></td>\n";
print "<td valign=top><select name=no multiple size=$r width=100>\n";
foreach $a (@acls) {
printf "<option %s>%s</option>\n",
$match{"!$a->{'values'}->[0]"} ? "selected" : "",
$a->{'values'}->[0];
}
print "</select></td> </tr>\n";
print &ui_table_row($text{'ahttp_dma'},
&ui_select("no", \@no, [ map { $_->{'values'}->[0] } @acls ],
$r, 1, 1));
print "</table></td></tr></table><br>\n";
print "<input type=submit value=$text{'buttsave'}>\n";
if (@never) { print "<input type=submit value=$text{'buttdel'} name=delete>\n"; }
print "</form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'buttsave'} ],
@never ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]);
&ui_print_footer("edit_acl.cgi", $text{'ahttp_return'});
&ui_print_footer("edit_icp.cgi", $text{'ahttp_return'});

View File

@@ -2,13 +2,17 @@
# never_save.cgi
# Save or delete an never_direct directive
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'othercaches'} || &error($text{'eicp_ecannot'});
&ReadParse();
&lock_file($config{'squid_conf'});
$conf = &get_config();
my $conf = &get_config();
@never = &find_config("never_direct", $conf);
my @never = &find_config("never_direct", $conf);
my $never;
if (defined($in{'index'})) {
$never = $conf->[$in{'index'}];
}
@@ -18,10 +22,10 @@ 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"); }
$newnever = { 'name' => 'never_direct', 'values' => \@vals };
my @vals = ( $in{'action'} );
foreach my $y (split(/\0/, $in{'yes'})) { push(@vals, $y); }
foreach my $n (split(/\0/, $in{'no'})) { push(@vals, "!$n"); }
my $newnever = { 'name' => 'never_direct', 'values' => \@vals };
if ($never) { splice(@never, &indexof($never, @never),
1, $newnever); }
else { push(@never, $newnever); }
@@ -29,6 +33,6 @@ else {
&save_directive($conf, "never_direct", \@never);
&flush_file_lines();
&unlock_file($config{'squid_conf'});
&webmin_log($in{'delete'} ? 'delete' : $never ? 'modify' : 'create', "never");
&webmin_log($in{'delete'} ? 'delete' : $never ? 'modify' : 'create', 'never');
&redirect("edit_icp.cgi");