mirror of
https://github.com/webmin/webmin.git
synced 2026-09-16 10:30:39 +01:00
strict conversion in progress
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
# Functions for configuring squid.conf
|
||||
|
||||
BEGIN { push(@INC, ".."); };
|
||||
#use strict;
|
||||
#use warnings;
|
||||
use WebminCore;
|
||||
&init_config();
|
||||
do 'parser-lib.pl';
|
||||
our ($module_root_directory, %text, %config, %in);
|
||||
|
||||
our %access = &get_module_acl();
|
||||
our $auth_program = "$module_config_directory/squid-auth.pl";
|
||||
@@ -13,11 +16,8 @@ our @caseless_acl_types = ( "url_regex", "urlpath_regex", "proxy_auth_regex",
|
||||
"srcdom_regex", "dstdom_regex", "ident_regex" );
|
||||
|
||||
# Get the squid version
|
||||
our $squid_version;
|
||||
if (open(VERSION, "$module_config_directory/version")) {
|
||||
chop($squid_version = <VERSION>);
|
||||
close(VERSION);
|
||||
}
|
||||
our $squid_version = &read_file_contents("$module_config_directory/version");
|
||||
$squid_version =~ s/\r|\n//g;
|
||||
|
||||
# choice_input(text, name, &config, default, [display, option]+)
|
||||
# Display a number of radio buttons for selecting some option
|
||||
@@ -267,34 +267,37 @@ return $rv;
|
||||
# save_opt_bytes(name, &config)
|
||||
sub save_opt_bytes
|
||||
{
|
||||
local %ss = ( "KB"=> $text{'lib_kb'},
|
||||
"MB"=> $text{'lib_mb'},
|
||||
"GB"=> $text{'lib_gb'} );
|
||||
my ($name, $conf) = @_;
|
||||
my %ss = ( "KB" => $text{'lib_kb'},
|
||||
"MB" => $text{'lib_mb'},
|
||||
"GB" => $text{'lib_gb'} );
|
||||
|
||||
if ($in{"$_[0]_def"}) { &save_directive($_[1], $_[0], [ ]); }
|
||||
elsif ($in{$_[0]} !~ /^[0-9\.]+$/) {
|
||||
&error(&text('lib_emsg3', $in{$_[0]}, $ss{$in{"$_[0]_u"}}) );
|
||||
if ($in{$name."_def"}) {
|
||||
&save_directive($conf, $name, [ ]);
|
||||
}
|
||||
elsif ($in{$name} !~ /^[0-9\.]+$/) {
|
||||
&error(&text('lib_emsg3', $in{$name}, $ss{$in{$name."_u"}}) );
|
||||
}
|
||||
else {
|
||||
local $dir = { 'name' => $_[0],
|
||||
'values' => [ $in{$_[0]}, $in{"$_[0]_u"} ] };
|
||||
&save_directive($_[1], $_[0], [ $dir ]);
|
||||
my $dir = { 'name' => $name,
|
||||
'values' => [ $in{$name}, $in{$name."_u"} ] };
|
||||
&save_directive($conf, $name, [ $dir ]);
|
||||
}
|
||||
}
|
||||
|
||||
%acl_types = ("src", $text{'lib_aclca'},
|
||||
"dst", $text{'lib_aclwsa'},
|
||||
"srcdomain", $text{'lib_aclch'},
|
||||
"dstdomain", $text{'lib_aclwsh'},
|
||||
"time", $text{'lib_acldat'},
|
||||
"url_regex", $text{'lib_aclur'},
|
||||
"urlpath_regex", $text{'lib_aclupr'},
|
||||
"port", $text{'lib_aclup'},
|
||||
"proto", $text{'lib_aclup1'},
|
||||
"method", $text{'lib_aclrm'},
|
||||
"browser", $text{'lib_aclbr'},
|
||||
"user", $text{'lib_aclpl'},
|
||||
"arp", $text{'lib_aclarp'} );
|
||||
our %acl_types = ("src", $text{'lib_aclca'},
|
||||
"dst", $text{'lib_aclwsa'},
|
||||
"srcdomain", $text{'lib_aclch'},
|
||||
"dstdomain", $text{'lib_aclwsh'},
|
||||
"time", $text{'lib_acldat'},
|
||||
"url_regex", $text{'lib_aclur'},
|
||||
"urlpath_regex", $text{'lib_aclupr'},
|
||||
"port", $text{'lib_aclup'},
|
||||
"proto", $text{'lib_aclup1'},
|
||||
"method", $text{'lib_aclrm'},
|
||||
"browser", $text{'lib_aclbr'},
|
||||
"user", $text{'lib_aclpl'},
|
||||
"arp", $text{'lib_aclarp'} );
|
||||
if ($squid_version >= 2.0) {
|
||||
$acl_types{'src_as'} = $text{'lib_aclsan'};
|
||||
$acl_types{'dst_as'} = $text{'lib_acldan'};
|
||||
@@ -328,14 +331,18 @@ if ($squid_version >= 2.5) {
|
||||
sub restart_button
|
||||
{
|
||||
return undef if ($config{'restart_pos'} == 2);
|
||||
local $pid = &is_squid_running();
|
||||
local $args = "redir=".&urlize(&this_url())."&pid=$pid";
|
||||
my $pid = &is_squid_running();
|
||||
my $args = "redir=".&urlize(&this_url())."&pid=$pid";
|
||||
if ($pid) {
|
||||
return ($access{'restart'} ? "<a href=\"restart.cgi?$args\">$text{'lib_buttac'}</a><br>\n" : "").
|
||||
($access{'start'} ? "<a href=\"stop.cgi?$args\">$text{'lib_buttss'}</a>\n" : "");
|
||||
return ($access{'restart'} ?
|
||||
"<a href=\"restart.cgi?$args\">$text{'lib_buttac'}</a><br>\n" :
|
||||
"").
|
||||
($access{'start'} ?
|
||||
"<a href=\"stop.cgi?$args\">$text{'lib_buttss'}</a>\n" : "");
|
||||
}
|
||||
else {
|
||||
return $access{'start'} ? "<a href=\"start.cgi?$args\">$text{'lib_buttss1'}</a>\n" : "";
|
||||
return $access{'start'} ?
|
||||
"<a href=\"start.cgi?$args\">$text{'lib_buttss1'}</a>\n" : "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,13 +350,13 @@ else {
|
||||
# Returns the process ID if squid is running
|
||||
sub is_squid_running
|
||||
{
|
||||
local $conf = &get_config();
|
||||
my $conf = &get_config();
|
||||
|
||||
# Find all possible PID files
|
||||
local @pidfiles;
|
||||
local $pidstruct = &find_config("pid_filename", $conf);
|
||||
my @pidfiles;
|
||||
my $pidstruct = &find_config("pid_filename", $conf);
|
||||
push(@pidfiles, $pidstruct->{'values'}->[0]) if ($pidstruct);
|
||||
local $def_pidstruct = &find_config("pid_filename", $conf);
|
||||
my $def_pidstruct = &find_config("pid_filename", $conf);
|
||||
push(@pidfiles, $def_pidstruct->{'values'}->[0]) if ($def_pidstruct);
|
||||
push(@pidfiles, $config{'pid_file'}) if ($config{'pid_file'});
|
||||
@pidfiles = grep { $_ ne "none" } @pidfiles;
|
||||
@@ -362,7 +369,7 @@ foreach my $pidfile (@pidfiles) {
|
||||
|
||||
if (!@pidfiles) {
|
||||
# Fall back to checking for Squid process
|
||||
local ($pid) = &find_byname("squid");
|
||||
my ($pid) = &find_byname("squid");
|
||||
return $pid;
|
||||
}
|
||||
|
||||
@@ -373,25 +380,29 @@ return 0;
|
||||
# Returns the URL in the apache directory of the current script
|
||||
sub this_url
|
||||
{
|
||||
local($url);
|
||||
$url = $ENV{'SCRIPT_NAME'};
|
||||
if (defined($ENV{'QUERY_STRING'})) { $url .= "?$ENV{'QUERY_STRING'}"; }
|
||||
my $url = $ENV{'SCRIPT_NAME'};
|
||||
if (defined($ENV{'QUERY_STRING'})) {
|
||||
$url .= "?$ENV{'QUERY_STRING'}";
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
# list_auth_users(file)
|
||||
sub list_auth_users
|
||||
{
|
||||
local(@rv, $lnum); $lnum = 0;
|
||||
open(USERS, $_[0]);
|
||||
while(<USERS>) {
|
||||
my ($file) = @_;
|
||||
my @rv;
|
||||
my $lnum = 0;
|
||||
my $fh = "USERS";
|
||||
&open_readfile($fh, $file);
|
||||
while(<$fh>) {
|
||||
if (/^(#*)([^:]+):(\S+)/) {
|
||||
push(@rv, { 'user' => $2, 'pass' => $3,
|
||||
'enabled' => !$1, 'line' => $lnum });
|
||||
}
|
||||
$lnum++;
|
||||
}
|
||||
close(USERS);
|
||||
close($fh);
|
||||
if ($config{'sort_conf'}) {
|
||||
return sort { $a->{'user'} cmp $b->{'user'} } @rv;
|
||||
}
|
||||
@@ -404,14 +415,17 @@ else {
|
||||
# Returns the effective user and group (if any)
|
||||
sub get_squid_user
|
||||
{
|
||||
my ($conf) = @_;
|
||||
if ($squid_version < 2) {
|
||||
local $ceu = &find_config("cache_effective_user", $_[0]);
|
||||
if ($ceu) { return ($ceu->{'values'}->[0], $ceu->{'values'}->[1]); }
|
||||
my $ceu = &find_config("cache_effective_user", $conf);
|
||||
if ($ceu) {
|
||||
return ($ceu->{'values'}->[0], $ceu->{'values'}->[1]);
|
||||
}
|
||||
return (undef, undef);
|
||||
}
|
||||
else {
|
||||
local $ceu = &find_config("cache_effective_user", $_[0]);
|
||||
local $ceg = &find_config("cache_effective_group", $_[0]);
|
||||
my $ceu = &find_config("cache_effective_user", $_[0]);
|
||||
my $ceg = &find_config("cache_effective_group", $_[0]);
|
||||
return ($ceu->{'values'}->[0], $ceg ? $ceg->{'values'}->[0]
|
||||
: $ceu->{'values'}->[1]);
|
||||
}
|
||||
@@ -421,43 +435,49 @@ else {
|
||||
# Change ownership of all squid log and cache directories
|
||||
sub chown_files
|
||||
{
|
||||
local(@list, $pidstruct, $pidfile);
|
||||
@list = ( $config{'log_dir'} );
|
||||
my ($user, $group, $conf) = @_;
|
||||
my @list = ( $config{'log_dir'} );
|
||||
|
||||
# add pidfile
|
||||
if ($str = &find_config("pid_filename", $_[2])) {
|
||||
my $pidfile;
|
||||
if (my $str = &find_config("pid_filename", $conf)) {
|
||||
$pidfile = $str->{'values'}->[0];
|
||||
}
|
||||
else { $pidfile = $config{'pid_file'}; }
|
||||
else {
|
||||
$pidfile = $config{'pid_file'};
|
||||
}
|
||||
push(@list, $pidfile);
|
||||
|
||||
# add other log directories
|
||||
foreach $d ("cache_access_log", "access_log", "cache_log",
|
||||
"cache_store_log", "cache_swap_log") {
|
||||
if (($str = &find_config($d, $_[2])) &&
|
||||
foreach my $d ("cache_access_log", "access_log", "cache_log",
|
||||
"cache_store_log", "cache_swap_log") {
|
||||
my $str;
|
||||
if (($str = &find_config($d, $conf)) &&
|
||||
$str->{'values'}->[0] =~ /^(\S+)\/[^\/]+$/) {
|
||||
push(@list, $1);
|
||||
}
|
||||
}
|
||||
|
||||
# add cache directories
|
||||
if (@str = &find_config("cache_dir", $_[2])) {
|
||||
foreach $str (@str) {
|
||||
if (my @str = &find_config("cache_dir", $conf)) {
|
||||
foreach my $str (@str) {
|
||||
push(@list, $str->{'values'}->[0]);
|
||||
}
|
||||
}
|
||||
else { push(@list, $config{'cache_dir'}); }
|
||||
system("chown -Rf $_[0]:$_[1] ".join(" ",@list)." >/dev/null 2>&1");
|
||||
else {
|
||||
push(@list, $config{'cache_dir'});
|
||||
}
|
||||
system("chown -Rf $user:$group ".join(" ",@list)." >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
# can_access(file)
|
||||
sub can_access
|
||||
{
|
||||
local @f = grep { $_ ne '' } split(/\//, $_[0]);
|
||||
my ($file) = @_;
|
||||
my @f = grep { $_ ne '' } split(/\//, $file);
|
||||
return 1 if ($access{'root'} eq '/');
|
||||
local @a = grep { $_ ne '' } split(/\//, $access{'root'});
|
||||
local $i;
|
||||
for($i=0; $i<@a; $i++) {
|
||||
my @a = grep { $_ ne '' } split(/\//, $access{'root'});
|
||||
for(my $i=0; $i<@a; $i++) {
|
||||
return 0 if ($a[$i] ne $f[$i]);
|
||||
}
|
||||
return 1;
|
||||
@@ -467,13 +487,13 @@ return 1;
|
||||
sub get_auth_file
|
||||
{
|
||||
if ($squid_version >= 2.5) {
|
||||
local @auth = &find_config("auth_param", $_[0]);
|
||||
local ($program) = grep { $_->{'values'}->[0] eq 'basic' &&
|
||||
$_->{'values'}->[1] eq 'program' } @auth;
|
||||
my @auth = &find_config("auth_param", $_[0]);
|
||||
my ($program) = grep { $_->{'values'}->[0] eq 'basic' &&
|
||||
$_->{'values'}->[1] eq 'program' } @auth;
|
||||
return $program ? $program->{'values'}->[3] : undef;
|
||||
}
|
||||
else {
|
||||
local $authprog = &find_value("authenticate_program", $_[0]);
|
||||
my $authprog = &find_value("authenticate_program", $_[0]);
|
||||
return $authprog =~ /(\S+)\s+(\/\S+)$/ ? $2 : undef;
|
||||
}
|
||||
}
|
||||
@@ -481,8 +501,10 @@ else {
|
||||
# parse_external(&external_acl_type)
|
||||
sub parse_external
|
||||
{
|
||||
local @v = @{$_[0]->{'values'}};
|
||||
local $rv = { 'name' => $v[0] };
|
||||
my ($acltype) = @_;
|
||||
my @v = @{$acltype->{'values'}};
|
||||
my $rv = { 'name' => $v[0] };
|
||||
my $i;
|
||||
for($i=1; $v[$i] =~ /^(\S+)=(\S+)$/; $i++) {
|
||||
$rv->{'opts'}->{$1} = $2;
|
||||
}
|
||||
@@ -503,8 +525,9 @@ return $rv;
|
||||
# caches list
|
||||
sub check_cache
|
||||
{
|
||||
local (@cachestruct, @caches, $c, $coss);
|
||||
if (@cachestruct = &find_config("cache_dir", $_[0])) {
|
||||
my ($conf, $cachesrv) = @_;
|
||||
my (@cachestruct, @caches, $coss);
|
||||
if (@cachestruct = &find_config("cache_dir", $conf)) {
|
||||
if ($squid_version >= 2.3) {
|
||||
@caches = map { $_->{'values'}->[1] } @cachestruct;
|
||||
}
|
||||
@@ -516,16 +539,16 @@ if (@cachestruct = &find_config("cache_dir", $_[0])) {
|
||||
else {
|
||||
@caches = ( $config{'cache_dir'} );
|
||||
}
|
||||
@{$_[1]} = @caches;
|
||||
@$cachesrv = @caches;
|
||||
if ($coss) {
|
||||
# Allow COSS files too
|
||||
foreach $c (@caches) {
|
||||
foreach my $c (@caches) {
|
||||
return 0 if (!-f $c && (!-d $c || !-d "$c/00"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Check for dirs only
|
||||
foreach $c (@caches) {
|
||||
foreach my $c (@caches) {
|
||||
return 0 if (!-d $c || !-d "$c/00");
|
||||
}
|
||||
}
|
||||
@@ -536,12 +559,11 @@ return 1;
|
||||
# Returns the port Squid is listening on
|
||||
sub get_squid_port
|
||||
{
|
||||
local $conf = &get_config();
|
||||
local $port;
|
||||
my $conf = &get_config();
|
||||
my $port;
|
||||
if ($squid_version >= 2.3) {
|
||||
local ($p, $v);
|
||||
LOOP: foreach $p (&find_config("http_port", $conf)) {
|
||||
foreach $v (@{$p->{'values'}}) {
|
||||
LOOP: foreach my $p (&find_config("http_port", $conf)) {
|
||||
foreach my $v (@{$p->{'values'}}) {
|
||||
if ($v =~ /^(\d+)$/) {
|
||||
$port = $1;
|
||||
}
|
||||
@@ -563,12 +585,13 @@ return defined($port) ? $port : 3128;
|
||||
sub apply_configuration
|
||||
{
|
||||
if ($config{'squid_restart'}) {
|
||||
local $out = &backquote_logged("$config{'squid_restart'} 2>&1");
|
||||
return "<pre>$out</pre>" if ($?);
|
||||
my $out = &backquote_logged("$config{'squid_restart'} 2>&1");
|
||||
return "<pre>".&html_escape($out)."</pre>" if ($?);
|
||||
}
|
||||
else {
|
||||
$out = &backquote_logged("$config{'squid_path'} -f $config{'squid_conf'} -k reconfigure 2>&1");
|
||||
return "<pre>$out</pre>" if ($? && $out !~ /warning/i);
|
||||
my $out = &backquote_logged("$config{'squid_path'} -f $config{'squid_conf'} -k reconfigure 2>&1");
|
||||
return "<pre>".&html_escape($out)."</pre>"
|
||||
if ($? && $out !~ /warning/i);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user