Skip to content

Commit

Permalink
strict/warn
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Jun 30, 2016
1 parent eb8fed2 commit e07c5a7
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 90 deletions.
32 changes: 19 additions & 13 deletions add.cgi
Original file line number Diff line number Diff line change
@@ -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'});
Expand All @@ -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));

Expand All @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions add_form.cgi
Original file line number Diff line number Diff line change
@@ -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'});
Expand All @@ -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,
Expand All @@ -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'});

2 changes: 2 additions & 0 deletions cgi_args.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use strict;
use warnings;

do 'virtualmin-htpasswd-lib.pl';

Expand Down
19 changes: 12 additions & 7 deletions delete.cgi
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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)) {
Expand All @@ -49,4 +55,3 @@ foreach $path (@d) {
&htaccess_htpasswd::save_directories(\@dirs);

&redirect("index.cgi?dom=$in{'dom'}");

27 changes: 15 additions & 12 deletions find.cgi
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
#!/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', "<tt>$d->{'home'}</tt>"),"<p>\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 = <FIND>) {
while(my $f = <$FIND>) {
chop($f);
if ($got{$f}) {
print &text('find_already', "<tt>$f</tt>"),"<br>\n";
next;
}

# Read as the domain user
my ($conf, $currfile, $require);
&virtual_server::write_as_domain_user($d,
sub {
$conf = &apache::get_htaccess_config($f);
$currfile = &apache::find_directive("AuthUserFile", $conf, 1);
sub {
$conf = &apache::get_htaccess_config($f);
$currfile = &apache::find_directive("AuthUserFile", $conf, 1);
$require = &apache::find_directive("require", $conf, 1);
});
if ($currfile && $require) {
local $dir = $f;
my $dir = $f;
$dir =~ s/\/$htaccess_htpasswd::config{'htaccess'}$//;
if (&can_directory($dir, $d)) {
push(@dirs, [ $dir, $currfile ]);
Expand All @@ -48,12 +53,10 @@ while($f = <FIND>) {
print &text('find_noprot', "<tt>$f</tt>"),"<br>\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'});


20 changes: 13 additions & 7 deletions index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down Expand Up @@ -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'});
}

Loading

0 comments on commit e07c5a7

Please sign in to comment.