diff --git a/add.cgi b/add.cgi index b627ae1..a5e8ab6 100755 --- a/add.cgi +++ b/add.cgi @@ -1,21 +1,25 @@ #!/usr/local/bin/perl # Add protection +use strict; +use warnings; +our (%text, %in); require './virtualmin-htpasswd-lib.pl'; &ReadParse(); &error_setup($text{'add_err'}); # Validate inputs -$d = &virtual_server::get_domain($in{'dom'}); +my $d = &virtual_server::get_domain($in{'dom'}); $d && &virtual_server::can_edit_domain($d) || &error($text{'index_ecannot'}); -$pub = &virtual_server::public_html_dir($d); -$cgi = &virtual_server::cgi_bin_dir($d); +my $pub = &virtual_server::public_html_dir($d); +my $cgi = &virtual_server::cgi_bin_dir($d); +my $dir; if ($in{'dir_def'} == 1) { # Whole website $dir = $pub; } else { - $dirname = $in{'dir_def'} == 2 ? $in{'cgi'} : $in{'dir'}; + my $dirname = $in{'dir_def'} == 2 ? $in{'cgi'} : $in{'dir'}; $dirname =~ /\S/ || &error($text{'add_edir'}); $dirname !~ /\.\./ && $dirname !~ /\0/ || &error($text{'add_edir2'}); @@ -33,16 +37,16 @@ else { $in{'desc'} =~ /\S/ && $in{'desc'} !~ /["\0\r\n]/ || &error($text{'add_edesc'}); # Check for existing files -$file = "$dir/$htaccess_htpasswd::config{'htaccess'}"; -$conf = &apache::get_htaccess_config($file); -foreach $clash ("AuthUserFile", "AuthType", "AuthName") { - $dirclash = &apache::find_directive($clash, $conf); +my $file = "$dir/$htaccess_htpasswd::config{'htaccess'}"; +my $conf = &apache::get_htaccess_config($file); +my $htusers = $htaccess_htpasswd::config{'htpasswd'} || "htusers"; +my $usersfile = "$dir/$htusers"; +foreach my $clash ("AuthUserFile", "AuthType", "AuthName") { + my $dirclash = &apache::find_directive($clash, $conf); if ($dirclash) { &error(&text('add_eclash3', $usersfile, $clash)); } } -$htusers = $htaccess_htpasswd::config{'htpasswd'} || "htusers"; -$usersfile = "$dir/$htusers"; -r $usersfile && &error(&text('add_eclash2', $usersfile)); -l $file && &error(&text('add_esymlink', $file)); @@ -67,15 +71,17 @@ $usersfile = "$dir/$htusers"; # Create users file &lock_file($usersfile); +no strict "subs"; # XXX Lexical? &virtual_server::open_tempfile_as_domain_user($d, USERS, ">$usersfile"); &virtual_server::close_tempfile_as_domain_user($d, USERS); -$perms = &virtual_server::apache_in_domain_group($d) ? 0750 : 0755; +use strict "subs"; +my $perms = &virtual_server::apache_in_domain_group($d) ? 0750 : 0755; &virtual_server::set_permissions_as_domain_user($d, $perms, $usersfile); &unlock_file($usersfile); # Add to protected dirs list -@dirs = &htaccess_htpasswd::list_directories(); -$dirstr = [ $dir, $usersfile, 0, 0, undef ]; +my @dirs = &htaccess_htpasswd::list_directories(); +my $dirstr = [ $dir, $usersfile, 0, 0, undef ]; push(@dirs, $dirstr); &htaccess_htpasswd::save_directories(\@dirs); diff --git a/add_form.cgi b/add_form.cgi index 01a79c3..7dd11e4 100755 --- a/add_form.cgi +++ b/add_form.cgi @@ -1,8 +1,12 @@ #!/usr/local/bin/perl # Show a form for adding protection to a directory +use strict; +use warnings; +our (%in, %text); require './virtualmin-htpasswd-lib.pl'; &ReadParse(); +my $d; if ($in{'dom'}) { $d = &virtual_server::get_domain($in{'dom'}); &virtual_server::can_edit_domain($d) || &error($text{'index_ecannot'}); @@ -16,7 +20,7 @@ print &ui_table_start($text{'add_header'}, undef, 2); # Domain selector if (!$d) { - @doms = grep { &virtual_server::can_edit_domain($_) } + my @doms = grep { &virtual_server::can_edit_domain($_) } &virtual_server::list_domains(); print &ui_table_row($text{'add_dom'}, &ui_select("dom", undef, @@ -41,4 +45,3 @@ print &ui_table_end(); print &ui_form_end([ [ "create", $text{'create'} ] ]); &ui_print_footer("index.cgi?dom=$in{'dom'}", $text{'index_return'}); - diff --git a/cgi_args.pl b/cgi_args.pl index bfe8d11..a30a55a 100755 --- a/cgi_args.pl +++ b/cgi_args.pl @@ -1,3 +1,5 @@ +use strict; +use warnings; do 'virtualmin-htpasswd-lib.pl'; diff --git a/delete.cgi b/delete.cgi index 8a4a021..35bb157 100755 --- a/delete.cgi +++ b/delete.cgi @@ -1,27 +1,32 @@ #!/usr/local/bin/perl # Remove protection for several directories +use strict; +use warnings; +our (%text, %in); require './virtualmin-htpasswd-lib.pl'; &ReadParse(); &error_setup($text{'delete_err'}); # Validate inputs -@d = split(/\s+/, $in{'d'}); +my @d = split(/\s+/, $in{'d'}); @d || &error($text{'delete_enone'}); +my $d; if ($in{'dom'}) { $d = &virtual_server::get_domain($in{'dom'}); &virtual_server::can_edit_domain($d) || &error($text{'index_ecannot'}); } -@dirs = &htaccess_htpasswd::list_directories(); -foreach $path (@d) { +my @dirs = &htaccess_htpasswd::list_directories(); +foreach my $path (@d) { &can_directory($path, $d) || &error($text{'delete_ecannot'}); - ($dir) = grep { $_->[0] eq $path } @dirs; + my ($dir) = grep { $_->[0] eq $path } @dirs; if ($dir) { # Remove protection directives - $file = "$dir->[0]/$htaccess_htpasswd::config{'htaccess'}"; + no warnings "once"; + my $file = "$dir->[0]/$htaccess_htpasswd::config{'htaccess'}"; &lock_file($file); - $conf = &apache::get_htaccess_config($file); + my $conf = &apache::get_htaccess_config($file); &apache::save_directive("AuthUserFile", [ ], $conf, $conf); &apache::save_directive("AuthType", [ ], $conf, $conf); &apache::save_directive("AuthName", [ ], $conf, $conf); @@ -30,6 +35,7 @@ foreach $path (@d) { &virtual_server::write_as_domain_user($d, sub { &flush_file_lines($file) }); } + use warnings "once"; # Remove whole file if empty if (&empty_file($file)) { @@ -49,4 +55,3 @@ foreach $path (@d) { &htaccess_htpasswd::save_directories(\@dirs); &redirect("index.cgi?dom=$in{'dom'}"); - diff --git a/find.cgi b/find.cgi index e82a7d3..4f5dc9d 100755 --- a/find.cgi +++ b/find.cgi @@ -1,24 +1,28 @@ #!/usr/local/bin/perl # Find existing protected directories +use strict; +use warnings; +our (%text, %in); require './virtualmin-htpasswd-lib.pl'; &ReadParse(); &error_setup($text{'find_err'}); $in{'dom'} || &error($text{'find_edom'}); -$d = &virtual_server::get_domain($in{'dom'}); +my $d = &virtual_server::get_domain($in{'dom'}); $d && &virtual_server::can_edit_domain($d) || &error($text{'find_ecannot'}); -@dirs = &htaccess_htpasswd::list_directories(); -%got = map { ( "$_->[0]/$htaccess_htpasswd::config{'htaccess'}", 1 ) } @dirs; +my @dirs = &htaccess_htpasswd::list_directories(); +my %got = map { ( "$_->[0]/$htaccess_htpasswd::config{'htaccess'}", 1 ) } @dirs; # Start the search &ui_print_header(&virtual_server::domain_in($d), $text{'find_title'}, ""); print &text('find_doing', "$d->{'home'}"),"
\n";
-open(FIND, "find ".quotemeta($d->{'home'})." -name ".
+# 2XXX Make this use Perl File::Find
+open(my $FIND, "<", "find ".quotemeta($d->{'home'})." -name ".
quotemeta($htaccess_htpasswd::config{'htaccess'}).
" -print 2>/dev/null |");
-while($f =
\n";
@@ -26,14 +30,15 @@ while($f =
\n";
}
}
-close(FIND);
+close($FIND);
&lock_file($htaccess_htpasswd::directories_file);
&htaccess_htpasswd::save_directories(\@dirs);
&unlock_file($htaccess_htpasswd::directories_file);
&ui_print_footer("index.cgi?dom=$in{'dom'}", $text{'index_return'});
-
-
diff --git a/index.cgi b/index.cgi
index 2df787f..999853d 100755
--- a/index.cgi
+++ b/index.cgi
@@ -2,29 +2,34 @@
# Show directories for which web protection is enabled, with a form
# to add a new one. For Virtualmin domain owners, the list is limited to
# a single domain.
+use strict;
+use warnings;
+our (%text, %in);
require './virtualmin-htpasswd-lib.pl';
&ReadParse();
&foreign_require("apache", "apache-lib.pl");
# Get domain and directories
+my $d;
if ($in{'dom'}) {
$d = &virtual_server::get_domain($in{'dom'});
&virtual_server::can_edit_domain($d) || &error($text{'index_ecannot'});
}
-@dirs = &htaccess_htpasswd::list_directories();
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $d) } @dirs;
&ui_print_header($d ? &virtual_server::domain_in($d) : undef,
$text{'index_title'}, "", "intro", 0, 1);
# Build table of directories
-@table = ( );
-foreach $dir (@dirs) {
- $conf = &apache::get_htaccess_config(
+my @table = ( );
+foreach my $dir (@dirs) {
+ no warnings "once";
+ my $conf = &apache::get_htaccess_config(
"$dir->[0]/$htaccess_htpasswd::config{'htaccess'}");
- $desc = &apache::find_directive("AuthName", $conf, 1);
- $users = $dir->[2] == 3 ?
+ my $desc = &apache::find_directive("AuthName", $conf, 1);
+ my $users = $dir->[2] == 3 ?
&htaccess_htpasswd::list_digest_users($dir->[1]) :
&htaccess_htpasswd::list_users($dir->[1]);
push(@table, [
@@ -61,11 +66,12 @@ if ($d) {
}
if ($d) {
+ no warnings "once";
&ui_print_footer($d ? &virtual_server::domain_footer_link($d) : ( ),
"/virtual-server/",
$virtual_server::text{'index_return'});
+ use warnings "once";
}
else {
&ui_print_footer("/", $text{'index'});
}
-
diff --git a/virtual_feature.pl b/virtual_feature.pl
index dab983b..026a0cf 100755
--- a/virtual_feature.pl
+++ b/virtual_feature.pl
@@ -1,7 +1,11 @@
# Defines functions for this feature
+use strict;
+use warnings;
+our (%text);
+our ($module_name, $module_config_directory);
require 'virtualmin-htpasswd-lib.pl';
-$input_name = $module_name;
+my $input_name = $module_name;
$input_name =~ s/[^A-Za-z0-9]/_/g;
&load_theme_library();
@@ -18,7 +22,9 @@ sub feature_name
sub feature_check
{
return $text{'feat_edep'} if (!&foreign_installed("htaccess-htpasswd", 1));
+no warnings "once";
return $text{'feat_eweb'} if (!$virtual_server::config{'web'});
+use warnings "once";
return undef;
}
@@ -26,34 +32,36 @@ sub feature_check
# If any protected directories are defined, returns a list of them for selection
sub mailbox_inputs
{
-local ($user, $new, $dom) = @_;
+my ($user, $new, $dom) = @_;
# Find protected directories
-local @dirs = &htaccess_htpasswd::list_directories();
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $dom) } @dirs;
return undef if (!@dirs);
# Work out which ones this user has access to
-local @indir;
+my @indir;
if (!$new) {
- local %indir = &get_in_dirs(\@dirs, $user->{'user'});
+ my %indir = &get_in_dirs(\@dirs, $user->{'user'});
@indir = keys %indir;
}
else {
- local $lref = &read_file_lines(
+ my $lref = &read_file_lines(
"$module_config_directory/defaults.$dom->{'id'}");
@indir = @$lref;
}
-local $main::ui_table_cols = 2;
-local @opts;
+no warnings "once";
+$main::ui_table_cols = 2;
+use warnings "once";
+my @opts;
foreach my $dir (@dirs) {
- local $reldir = &remove_public_html($dir->[0], $dom);
+ my $reldir = &remove_public_html($dir->[0], $dom);
push(@opts, [ $dir->[0], $reldir ]);
}
-local @vals;
+my @vals;
foreach my $dir (@indir) {
- local $reldir = &remove_public_html($dir, $dom);
+ my $reldir = &remove_public_html($dir, $dom);
push(@vals, [ $dir, $reldir ]);
}
return &ui_table_row(&hlink($text{'user_dirs'}, "dirs"),
@@ -74,19 +82,19 @@ sub mailbox_validate
# Updates the user based on inputs generated by mailbox_inputs
sub mailbox_save
{
-local ($user, $old, $in, $new, $dom) = @_;
+my ($user, $old, $in, $new, $dom) = @_;
# Find protected directories
-local @dirs = &htaccess_htpasswd::list_directories();
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $dom) } @dirs;
return undef if (!@dirs);
-local %indir = &get_in_dirs(\@dirs, $old->{'user'});
-local $count = 0;
+my %indir = &get_in_dirs(\@dirs, $old->{'user'});
+my $count = 0;
# Update them all
-local %seldir = map { $_, 1 } split(/\r?\n/, $in->{$input_name});
+my %seldir = map { $_, 1 } split(/\r?\n/, $in->{$input_name});
foreach my $d (@dirs) {
- local $suser = $indir{$d->[0]};
+ my $suser = $indir{$d->[0]};
if ($suser && !$seldir{$d->[0]}) {
# Take out of this directory
&virtual_server::write_as_domain_user($dom,
@@ -137,16 +145,16 @@ sub mailbox_save
# Adds or removes the user from protected directories
sub mailbox_modify
{
-local ($user, $old, $dom) = @_;
+my ($user, $old, $dom) = @_;
# Find protected directories
-local @dirs = &htaccess_htpasswd::list_directories();
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $dom) } @dirs;
-local %indir = &get_in_dirs(\@dirs, $old->{'user'});
+my %indir = &get_in_dirs(\@dirs, $old->{'user'});
# Update the user
foreach my $d (@dirs) {
- local $suser = $indir{$d->[0]};
+ my $suser = $indir{$d->[0]};
if ($suser) {
if ($user->{'user'} ne $old->{'user'}) {
$suser->{'user'} = $user->{'user'};
@@ -166,16 +174,16 @@ sub mailbox_modify
# Removes any extra features for this user
sub mailbox_delete
{
-local ($user, $dom) = @_;
+my ($user, $dom) = @_;
# Find protected directories
-local @dirs = &htaccess_htpasswd::list_directories();
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $dom) } @dirs;
-local %indir = &get_in_dirs(\@dirs, $user->{'user'});
+my %indir = &get_in_dirs(\@dirs, $user->{'user'});
# Take the user out of them
foreach my $d (@dirs) {
- local $suser = $indir{$d->[0]};
+ my $suser = $indir{$d->[0]};
if ($suser) {
&virtual_server::write_as_domain_user($dom,
sub { &htaccess_htpasswd::delete_user($suser) });
@@ -202,9 +210,9 @@ sub mailbox_column
# users in this virtual server
sub mailbox_defaults_inputs
{
-local ($defs, $dom) = @_;
-local $lref =&read_file_lines("$module_config_directory/defaults.$dom->{'id'}");
-local @dirs = &htaccess_htpasswd::list_directories();
+my ($defs, $dom) = @_;
+my $lref =&read_file_lines("$module_config_directory/defaults.$dom->{'id'}");
+my @dirs = &htaccess_htpasswd::list_directories();
@dirs = grep { &can_directory($_->[0], $dom) } @dirs;
return undef if (!@dirs);
return &ui_table_row($text{'user_dirs'},
@@ -218,8 +226,8 @@ sub mailbox_defaults_inputs
# file internal to this module to store them
sub mailbox_defaults_parse
{
-local ($defs, $dom, $in) = @_;
-local $lref =&read_file_lines("$module_config_directory/defaults.$dom->{'id'}");
+my ($defs, $dom, $in) = @_;
+my $lref =&read_file_lines("$module_config_directory/defaults.$dom->{'id'}");
@$lref = split(/\0/, $in->{$input_name});
&flush_file_lines("$module_config_directory/defaults.$dom->{'id'}");
}
@@ -228,13 +236,13 @@ sub mailbox_defaults_parse
# Returns a list of directories some user has access too, as a hash
sub get_in_dirs
{
-local ($dirs, $username) = @_;
-local %indir;
+my ($dirs, $username) = @_;
+my %indir;
foreach my $d (@$dirs) {
- local $users = $d->[2] == 3 ?
+ my $users = $d->[2] == 3 ?
&htaccess_htpasswd::list_digest_users($d->[1]) :
&htaccess_htpasswd::list_users($d->[1]);
- local ($got) = grep { $_->{'user'} eq $username } @$users;
+ my ($got) = grep { $_->{'user'} eq $username } @$users;
$indir{$d->[0]} = $got if ($got);
}
return %indir;
@@ -244,7 +252,7 @@ sub get_in_dirs
# Returns an array of link objects for webmin modules for this plugin
sub feature_always_links
{
-local ($d) = @_;
+my ($d) = @_;
if ($d->{'web'} && $d->{'dir'} && !$d->{'alias'}) {
return ( { 'mod' => $module_name,
'desc' => $text{'links_link'},
@@ -257,7 +265,7 @@ sub feature_always_links
# Grant this Webmin module only for domain owners who have some web domains
sub feature_webmin
{
-local @doms = grep { $_->{'web'} && $_->{'dir'} && !$_->{'alias'} } @{$_[1]};
+my @doms = grep { $_->{'web'} && $_->{'dir'} && !$_->{'alias'} } @{$_[1]};
if (@doms) {
return ( [ $module_name ] );
}
@@ -267,4 +275,3 @@ sub feature_webmin
}
1;
-
diff --git a/virtualmin-htpasswd-lib.pl b/virtualmin-htpasswd-lib.pl
index d70fb78..a76e49e 100755
--- a/virtualmin-htpasswd-lib.pl
+++ b/virtualmin-htpasswd-lib.pl
@@ -1,4 +1,7 @@
# Common functions for simple protected directory management
+use strict;
+use warnings;
+our (%text);
BEGIN { push(@INC, ".."); };
eval "use WebminCore;";
@@ -11,14 +14,14 @@
# Returns 1 if the current user can edit protection in the given directory
sub can_directory
{
-local ($dir, $d) = @_;
+my ($dir, $d) = @_;
if ($d) {
# Just check specific domain
return &is_under_directory($d->{'home'}, $dir);
}
else {
# Check all of his domains
- local @doms = grep { &virtual_server::can_edit_domain($_) }
+ my @doms = grep { &virtual_server::can_edit_domain($_) }
&virtual_server::list_domains();
foreach my $dd (@doms) {
return 1 if (&is_under_directory($dd->{'home'}, $dir));
@@ -28,19 +31,19 @@ sub can_directory
}
# remove_public_html(dir, &domain)
-# Returns a path relative to public_html, for display. If under cgi-bin,
+# Returns a path relative to public_html, for display. If under cgi-bin,
# path is relative to home. If under another domain's public_html dir, path
# is relative to that.
sub remove_public_html
{
-local ($dir, $dom) = @_;
-local $hdir = &virtual_server::public_html_dir($dom);
+my ($dir, $dom) = @_;
+my $hdir = &virtual_server::public_html_dir($dom);
if ($hdir) {
# Take relative to public_html or cgi-bin dir
if ($hdir eq $dir) {
return "$text{'index_hdir'}";
}
- local $cdir = &virtual_server::cgi_bin_dir($dom);
+ my $cdir = &virtual_server::cgi_bin_dir($dom);
if ($dir =~ /^\Q$hdir\E\/(.*)$/) {
return $1;
}
@@ -49,9 +52,9 @@ sub remove_public_html
}
elsif ($dir =~ /^\Q$dom->{'home'}\E\/domains\/([^\/]+)/) {
# Under a sub-server
- local $sd = &virtual_server::get_domain_by("dom", $1);
+ my $sd = &virtual_server::get_domain_by("dom", $1);
if ($sd) {
- local $rv = &remove_public_html($dir, $sd);
+ my $rv = &remove_public_html($dir, $sd);
if ($rv) {
return $rv." (".$sd->{'dom'}.")";
}
@@ -62,7 +65,7 @@ sub remove_public_html
}
else {
# Take relative to home
- local $hdir = $dom->{'home'};
+ my $hdir = $dom->{'home'};
$dir =~ s/^\Q$hdir\E\///;
return $dir;
}
@@ -72,8 +75,8 @@ sub remove_public_html
# Returns true if a file contains no non-whitespace lines
sub empty_file
{
-local ($file) = @_;
-local $lref = &read_file_lines($file, 1);
+my ($file) = @_;
+my $lref = &read_file_lines($file, 1);
foreach my $l (@$lref) {
return 0 if ($l =~ /\S/);
}
@@ -81,4 +84,3 @@ sub empty_file
}
1;
-