mirror of
https://github.com/webmin/webmin.git
synced 2026-05-04 22:30:33 +01:00
strict and ui-lib conversion
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
# http_access.cgi
|
||||
# A form for editing or creating a proxy access restriction
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our (%text, %in, %access, $squid_version, %config);
|
||||
require './squid-lib.pl';
|
||||
$access{'actrl'} || &error($text{'eacl_ecannot'});
|
||||
&ReadParse();
|
||||
$conf = &get_config();
|
||||
my $conf = &get_config();
|
||||
|
||||
my @http;
|
||||
if (!defined($in{'index'})) {
|
||||
&ui_print_header(undef, $text{'ahttp_header'}, "",
|
||||
undef, 0, 0, 0, &restart_button());
|
||||
@@ -17,49 +21,45 @@ else {
|
||||
@http = @{$conf->[$in{'index'}]->{'values'}};
|
||||
}
|
||||
|
||||
print "<form action=http_access_save.cgi>\n";
|
||||
print &ui_form_start("http_access_save.cgi", "post");
|
||||
if (@http) {
|
||||
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{'ahttp_pr'}</b></td> </tr>\n";
|
||||
print "<tr $cb> <td><table>\n";
|
||||
print &ui_table_start($text{'ahttp_pr'}, 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",
|
||||
$http[0] eq "allow" ? "checked" : "";
|
||||
printf "<input type=radio name=action value=deny %s> $text{'ahttp_d'}</td> </tr>\n",
|
||||
$http[0] eq "allow" ? "" : "checked";
|
||||
# Allow or deny ACLs
|
||||
print &ui_table_row($text{'ahttp_a'},
|
||||
&ui_radio("action", $http[0] || "allow",
|
||||
[ [ "allow", $text{'ahttp_a1'} ],
|
||||
[ "deny", $text{'ahttp_d'} ] ]));
|
||||
|
||||
for($i=1; $i<@http; $i++) { $match{$http[$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<@http; $i++) {
|
||||
if ($http[$i] =~ /^!(.*)/) {
|
||||
push(@no, $1);
|
||||
}
|
||||
else {
|
||||
push(@yes, $http[$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>\n";
|
||||
print "<input type=submit value='$text{'buttsave'}'>\n";
|
||||
if (@http) {
|
||||
print "<input type=submit value='$text{'buttdel'}' name=delete>\n";
|
||||
}
|
||||
print "</form>\n";
|
||||
print &ui_table_end();
|
||||
print &ui_form_end([ [ undef, $text{'buttsave'} ],
|
||||
@http ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]);
|
||||
|
||||
&ui_print_footer("edit_acl.cgi?mode=http", $text{'ahttp_return'},
|
||||
"", $text{'index_return'});
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
# http_access_save.cgi
|
||||
# Save or delete a proxy restriction
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our (%text, %in, %access, $squid_version, %config);
|
||||
require './squid-lib.pl';
|
||||
$access{'actrl'} || &error($text{'eacl_ecannot'});
|
||||
&ReadParse();
|
||||
&lock_file($config{'squid_conf'});
|
||||
$conf = &get_config();
|
||||
$whatfailed = $text{'sahttp_ftspr'};
|
||||
my $conf = &get_config();
|
||||
&error_setup($text{'sahttp_ftspr'});
|
||||
|
||||
@https = &find_config("http_access", $conf);
|
||||
my @https = &find_config("http_access", $conf);
|
||||
my ($http, %used);
|
||||
if (defined($in{'index'})) {
|
||||
$http = $conf->[$in{'index'}];
|
||||
}
|
||||
@@ -19,23 +23,23 @@ if ($in{'delete'}) {
|
||||
}
|
||||
else {
|
||||
# update or create
|
||||
@vals = ( $in{'action'} );
|
||||
foreach $y (split(/\0/, $in{'yes'})) {
|
||||
my @vals = ( $in{'action'} );
|
||||
foreach my $y (split(/\0/, $in{'yes'})) {
|
||||
push(@vals, $y);
|
||||
$used{$y}++;
|
||||
}
|
||||
foreach $n (split(/\0/, $in{'no'})) {
|
||||
foreach my $n (split(/\0/, $in{'no'})) {
|
||||
push(@vals, "!$n");
|
||||
$used{$n}++;
|
||||
}
|
||||
$newhttp = { 'name' => 'http_access', 'values' => \@vals };
|
||||
my $newhttp = { 'name' => 'http_access', 'values' => \@vals };
|
||||
if ($http) { splice(@https, &indexof($http, @https), 1, $newhttp); }
|
||||
else { push(@https, $newhttp); }
|
||||
}
|
||||
|
||||
# Find the last referenced ACL
|
||||
@acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf);
|
||||
$lastacl = @acls ? $acls[$#acls] : undef;
|
||||
my @acls = grep { $used{$_->{'values'}->[0]} } &find_config("acl", $conf);
|
||||
my $lastacl = @acls ? $acls[$#acls] : undef;
|
||||
|
||||
&save_directive($conf, "http_access", \@https, $lastacl);
|
||||
&flush_file_lines();
|
||||
|
||||
Reference in New Issue
Block a user