more strict and ui-lib conversion

This commit is contained in:
Jamie Cameron
2014-01-07 18:27:13 -08:00
parent 12988ec1b9
commit 82f48c4fa6
5 changed files with 108 additions and 106 deletions

View File

@@ -2,42 +2,49 @@
# acl_save.cgi
# Save or delete an ACL
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config, %acl_types,
@caseless_acl_types);
require './squid-lib.pl';
$access{'actrl'} || &error($text{'eacl_ecannot'});
&ReadParseMime();
&lock_file($config{'squid_conf'});
$conf = &get_config();
$whatfailed = $text{'aclsave_failsave'};
my $conf = &get_config();
&error_setup($text{'aclsave_failsave'});
@acls = &find_config("acl", $conf);
@denys = &find_config("deny_info", $conf);
my @acls = &find_config("acl", $conf);
my @denys = &find_config("deny_info", $conf);
my ($acl, $deny);
if (defined($in{'index'})) {
$acl = $conf->[$in{'index'}];
}
if (defined($in{'dindex'})) {
$deny = $conf->[$in{'dindex'}];
}
my $logacl;
if ($in{'delete'}) {
# Is there more than one ACL with this name?
$name = $acl->{'values'}->[0];
foreach $a (&find_config("acl", $conf)) {
my $name = $acl->{'values'}->[0];
my $count = 0;
foreach my $a (&find_config("acl", $conf)) {
$count++ if ($a->{'values'}->[0] eq $name);
}
# Is this ACL in use?
$whatfailed = $text{'aclsave_faildel'};
&error_setup($text{'aclsave_faildel'});
if ($count == 1) {
foreach $h (&find_config("http_access", $conf)) {
@v = @{$h->{'values'}};
for($i=1; $i<@v; $i++) {
foreach my $h (&find_config("http_access", $conf)) {
my @v = @{$h->{'values'}};
for(my $i=1; $i<@v; $i++) {
if ($v[$i] eq $name || $v[$i] eq "!$name") {
&error($text{'aclsave_epr'});
}
}
}
foreach $h (&find_config("icp_access", $conf)) {
@v = @{$h->{'values'}};
for($i=1; $i<@v; $i++) {
foreach my $h (&find_config("icp_access", $conf)) {
my @v = @{$h->{'values'}};
for(my $i=1; $i<@v; $i++) {
if ($v[$i] eq $in{'name'} ||
$v[$i] eq "!$in{'name'}") {
&error($text{'aclsave_eicpr'});
@@ -46,22 +53,27 @@ if ($in{'delete'}) {
}
}
splice(@acls, &indexof($acl, @acls), 1);
if ($deny) { splice(@denys, &indexof($deny, @denys), 1); }
if ($deny) {
splice(@denys, &indexof($deny, @denys), 1);
}
$logacl = $acl;
}
else {
# Check ACL details
$in{'name'} =~ /^\S+$/ || &error($text{'aclsave_ename'});
my $changed = 0;
$changed++ if ($acl && $in{'name'} ne $acl->{'values'}->[0]);
for($i=0; $i<@acls; $i++) {
for(my $i=0; $i<@acls; $i++) {
if ($changed && $acls[$i]->{'values'}->[0] eq $in{'name'}) {
&error(&text('aclsave_eexists',$in{'name'}));
}
}
my @vals;
if ($in{'type'} eq "src" || $in{'type'} eq "dst") {
for($i=0; defined($from = $in{"from_$i"}); $i++) {
$to = $in{"to_$i"}; $mask = $in{"mask_$i"};
for(my $i=0; defined(my $from = $in{"from_$i"}); $i++) {
my $to = $in{"to_$i"};
my $mask = $in{"mask_$i"};
next if (!$from && !$to && !$mask);
&check_ipaddress($from) ||
&check_ip6address($from) ||
@@ -78,8 +90,8 @@ else {
}
}
elsif ($in{'type'} eq "myip") {
for($i=0; defined($ip = $in{"ip_$i"}); $i++) {
$mask = $in{"mask_$i"};
for(my $i=0; defined(my $ip = $in{"ip_$i"}); $i++) {
my $mask = $in{"mask_$i"};
next if (!$mask || !$ip);
&check_ipaddress($ip) || &check_ip6address($ip) ||
&error(&text('aclsave_eip',$ip));
@@ -125,8 +137,9 @@ else {
elsif ($in{'type'} eq "method") {
push(@vals, split(/\0/, $in{'vals'}));
}
elsif ($in{'type'} eq "browser" || $in{'type'} eq "snmp_community"
|| $in{'type'} eq "req_mime_type" || $in{'type'} eq "rep_mime_type") {
elsif ($in{'type'} eq "browser" || $in{'type'} eq "snmp_community" ||
$in{'type'} eq "req_mime_type" ||
$in{'type'} eq "rep_mime_type") {
push(@vals, $in{'vals'});
}
elsif ($in{'type'} eq "user" || $in{'type'} eq "ident") {
@@ -170,9 +183,9 @@ else {
push(@vals, split(/\s+/, $in{'args'}));
}
elsif ($in{'type'} eq "max_user_ip") {
if($in{'strict'}){
if ($in{'strict'}){
push(@vals, '-s');
}
}
push(@vals, $in{'vals'});
}
@@ -181,6 +194,7 @@ else {
$in{'file'} || &error($text{'aclsave_enofile'});
&can_access($in{'file'}) ||
&error(&text('aclsave_efile', $in{'file'}));
my @notvals;
if ($in{'type'} eq 'external' ||
&indexof($in{'type'}, @caseless_acl_types) >= 0 &&
$vals[0] eq "-i") {
@@ -191,18 +205,20 @@ else {
if (!$acl && -e $in{'file'}) {
&error($text{'aclsave_ealready'});
}
&open_lock_tempfile(FILE, ">$in{'file'}");
foreach $v (@vals) {
&print_tempfile(FILE, $v,"\n");
my $fh = "FILE";
&open_lock_tempfile($fh, ">$in{'file'}");
foreach my $v (@vals) {
&print_tempfile($fh, $v,"\n");
}
&close_tempfile(FILE);
&close_tempfile($fh);
}
@vals = ( $in{'name'}, $in{'type'}, @notvals, "\"$in{'file'}\"" );
@vals = ( $in{'name'}, $in{'type'}, @notvals,
"\"$in{'file'}\"" );
}
else {
# Just saving in Squid config directly
if ($vals[0] =~ /^"(.*)"$/) {
local $f = $1;
my $f = $1;
&can_access($f) ||
&error(&text('aclsave_efile', $f));
if ($f !~ /^\// && $access{'root'} ne '/') {
@@ -212,24 +228,26 @@ else {
}
@vals = ( $in{'name'}, $in{'type'}, @vals );
}
$logacl = $newacl = { 'name' => 'acl', 'values' => \@vals };
my $newacl = { 'name' => 'acl', 'values' => \@vals };
$logacl = $newacl;
if ($acl) { splice(@acls, &indexof($acl, @acls), 1, $newacl); }
else { push(@acls, $newacl); }
$newdeny = { 'name' => 'deny_info',
'values' => [ $in{'deny'}, $vals[0] ] };
$didx = &indexof($deny, @denys);
my $newdeny = { 'name' => 'deny_info',
'values' => [ $in{'deny'}, $vals[0] ] };
my $didx = &indexof($deny, @denys);
if ($deny && $in{'deny'}) { $denys[$didx] = $newdeny; }
elsif ($deny) { splice(@denys, $didx, 1); }
elsif ($in{'deny'}) { push(@denys, $newdeny); }
# Update http_access and icp_access directives if the ACL was renamed
if ($changed) {
@https = &find_config("http_access", $conf);
@icps = &find_config("icp_access", $conf);
$on = $acl->{'values'}->[0];
foreach $c (@https, @icps) {
for($j=1; $j<@{$c->{'values'}}; $j++) {
my @https = &find_config("http_access", $conf);
my @icps = &find_config("icp_access", $conf);
my @replys = &find_config("http_reply_access", $conf);
my $on = $acl->{'values'}->[0];
foreach my $c (@https, @icps, @replys) {
for(my $j=1; $j<@{$c->{'values'}}; $j++) {
if ($c->{'values'}->[$j] eq $on) {
$c->{'values'}->[$j] = $in{'name'};
}

View File

@@ -57,6 +57,7 @@ else {
30)) ] ]),
&ui_select("afmt_$i", $afmt,
[ [ "", "&lt;".$text{'default'}."&gt;" ],
[ "squid", "&lt;".$text{'elogs_squid'}."&gt;" ],
map { [ $_->{'values'}->[0] ] } @logformat ],
1, 0, 1),
&ui_textbox("aacls_$i", join(" ", @aacls), 20)

View File

@@ -1,11 +1,15 @@
#!/usr/local/bin/perl
# A form for editing or creating a refresh pattern rule
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'refresh'} || &error($text{'refresh_ecannot'});
&ReadParse();
$conf = &get_config();
my $conf = &get_config();
my @v;
if (!defined($in{'index'})) {
&ui_print_header(undef, $text{'refresh_create'}, "",
undef, 0, 0, 0, &restart_button());
@@ -16,60 +20,46 @@ else {
@v = @{$conf->[$in{'index'}]->{'values'}};
}
print "<form action=save_refresh.cgi>\n";
print &ui_form_start("save_refresh.cgi", "post");
if (@v) {
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{'refresh_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_table_start($text{'refresh_header'}, undef, 4);
# Show regular expression inputs
my $caseless;
if ($v[0] eq "-i") {
$caseless = shift(@v);
}
print "<tr> <td><b>$text{'refresh_re'}</b></td> <td colspan=3>\n";
printf "<input name=re size=30 value='%s'></td> </tr>\n", $v[0];
print "<tr> <td></td> <td colspan=3>\n";
printf "<input type=checkbox name=caseless value=1 %s> %s</td> </tr>\n",
$caseless ? "checked" : "", $text{'refresh_caseless'};
print &ui_table_row($text{'refresh_re'},
&ui_textbox("re", $v[0], 40)."<br>\n".
&ui_checkbox("caseless", 1, $text{'refresh_caseless'}, $caseless));
# Show min, max and percentage
print "<tr> <td><b>$text{'refresh_min'}</b></td>\n";
printf "<td><input name=min size=6 value='%s'> %s</td>\n",
$v[1], $text{'ec_mins'};
print &ui_table_row($text{'refresh_min'},
&ui_textbox("min", $v[1], 6)." ".$text{'ec_mins'});
print "<td><b>$text{'refresh_max'}</b></td>\n";
printf "<td><input name=max size=6 value='%s'> %s</td> </tr>\n",
$v[3], $text{'ec_mins'};
print &ui_table_row($text{'refresh_max'},
&ui_textbox("max", $v[3], 6)." ".$text{'ec_mins'});
$v[2] =~ s/\%$//;
print "<tr> <td><b>$text{'refresh_pc'}</b></td>\n";
printf "<td><input name=pc size=6 value='%s'> %%</td> </tr>\n",
$v[2];
print &ui_table_row($text{'refresh_pc'},
&ui_textbox("pc", $v[2], 6)." %");
# Show options
%opts = map { $_, 1 } @v[4..$#v];
@known = ( "override-expire", "override-lastmod",
"reload-into-ims", "ignore-reload" );
print "<tr> <td valign=top><b>$text{'refresh_options'}</b></td> <td colspan=3>\n";
foreach $k (@known) {
printf "<input type=checkbox name=options value=%s %s> %s<br>\n",
$k, $opts{$k} ? "checked" : "", $text{'refresh_'.$k};
delete($opts{$k});
my %opts = map { $_, 1 } @v[4..$#v];
my @known = ( "override-expire", "override-lastmod",
"reload-into-ims", "ignore-reload" );
print &ui_table_row($text{'refresh_options'},
join("<br>\n", map { &ui_checkbox("options", $_, $text{'refresh_'.$_},
$opts{$_}) } @known), 3);
foreach my $k (keys %opts) {
print &ui_hidden("options", $k) if (&indexof($k, @known) < 0);
}
foreach $u (keys %opts) {
print "<input type=hidden name=options value=$k>\n";
}
print "</td> </tr>\n";
print "</table></td></tr></table>\n";
print "<input type=submit value='$text{'buttsave'}'>\n";
if (@v) {
print "<input type=submit value='$text{'buttdel'}' name=delete>\n";
}
print "</form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'buttsave'} ],
@v ? ( [ 'delete', $text{'buttdel'} ] ) : ( ) ]);
&ui_print_footer("list_refresh.cgi", $text{'refresh_return'},
"", $text{'index_return'});

View File

@@ -161,13 +161,11 @@ if ($config{'restart_pos'} != 1) {
print &ui_buttons_row("restart.cgi",
$text{'index_restart'},
$text{'index_restartdesc'},
&ui_hidden("pid", $pid).
&ui_hidden("redir", "index.cgi"));
}
if ($access{'start'}) {
print &ui_buttons_row("stop.cgi", $text{'index_stop'},
$text{'index_stopdesc'},
&ui_hidden("pid", $pid).
&ui_hidden("redir", "index.cgi"));
}
}

View File

@@ -2,18 +2,22 @@
# list_refresh.cgi
# Display all refresh patterns
use strict;
use warnings;
our (%text, %in, %access, $squid_version, %config);
require './squid-lib.pl';
$access{'refresh'} || &error($text{'refresh_ecannot'});
&ui_print_header(undef, $text{'refresh_title'}, "", "list_refresh", 0, 0, 0, &restart_button());
$conf = &get_config();
&ui_print_header(undef, $text{'refresh_title'}, "", "list_refresh", 0, 0, 0,
&restart_button());
my $conf = &get_config();
@refresh = &find_config("refresh_pattern", $conf);
@links = ( &select_all_link("d"),
&select_invert_link("d"),
"<a href='edit_refresh.cgi?new=1'>$text{'refresh_add'}</a>" );
my @refresh = &find_config("refresh_pattern", $conf);
my @links = ( &select_all_link("d"),
&select_invert_link("d"),
&ui_link("edit_refresh.cgi?new=1", $text{'refresh_add'}) );
if (@refresh) {
print &ui_form_start("delete_refreshes.cgi", "post");
@tds = ( "width=5", undef, undef, undef, undef, "width=32" );
my @tds = ( "width=5", undef, undef, undef, undef, "width=32" );
print &ui_links_row(\@links);
print &ui_columns_start([ "",
$text{'refresh_re'},
@@ -21,30 +25,21 @@ if (@refresh) {
$text{'refresh_pc'},
$text{'refresh_max'},
$text{'eacl_move'} ], 100, 0, \@tds);
$hc = 0;
foreach $h (@refresh) {
@v = @{$h->{'values'}};
my $hc = 0;
foreach my $h (@refresh) {
my @v = @{$h->{'values'}};
if ($v[0] eq "-i") {
shift(@v);
}
local @cols;
push(@cols, "<a href='edit_refresh.cgi?index=$h->{'index'}'>$v[0]</a>");
my @cols;
push(@cols, &ui_link("edit_refresh.cgi?index=$h->{'index'}",
$v[0]));
push(@cols, @v[1..3]);
local $mover;
if ($hc != @refresh-1) {
$mover .= "<a href=\"move_refresh.cgi?$hc+1\">".
"<img src=images/down.gif border=0></a>";
}
else {
$mover .= "<img src=images/gap.gif>";
}
if ($hc != 0) {
$mover .= "<a href=\"move_refresh.cgi?$hc+-1\">".
"<img src=images/up.gif border=0></a>";
}
else {
$mover .= "<img src=images/gap.gif>";
}
my $mover = &ui_up_down_arrows(
"move_refresh.cgi?$hc+-1",
"move_refresh.cgi?$hc+1",
$hc != 0,
$hc != @refresh-1);
push(@cols, $mover);
print &ui_checked_columns_row(\@cols, \@tds, "d",$h->{'index'});
$hc++;