From 6867d110ea5635d603a4adc9a40c960131191d97 Mon Sep 17 00:00:00 2001 From: Joe Cooper Date: Mon, 27 Jun 2016 23:00:09 -0700 Subject: [PATCH] strict/warn, fix #1 --- add.cgi | 26 +++-- delete.cgi | 19 ++-- help.cgi | 13 ++- index.cgi | 32 +++--- log_parser.pl | 4 +- postinstall.pl | 3 + virtual_feature.pl | 240 ++++++++++++++++++++++-------------------- virtualmin-git-lib.pl | 118 +++++++++++---------- 8 files changed, 249 insertions(+), 206 deletions(-) diff --git a/add.cgi b/add.cgi index 1472a18..2a32073 100755 --- a/add.cgi +++ b/add.cgi @@ -1,5 +1,9 @@ #!/usr/local/bin/perl # Create one Git repository +use strict; +use warnings; +our (%access, %text, %in); +our $module_name; require './virtualmin-git-lib.pl'; &ReadParse(); @@ -7,12 +11,13 @@ require './virtualmin-git-lib.pl'; # Validate inputs &error_setup($text{'add_err'}); $in{'rep'} =~ /^[a-z0-9\.\-\_]+$/i || &error($text{'add_erep'}); -$dom = &virtual_server::get_domain($in{'dom'}); +my $dom = &virtual_server::get_domain($in{'dom'}); &can_edit_domain($dom) || &error($text{'add_edom'}); # Check limit on repositories +my @reps; if ($access{'max'}) { - foreach $d (&virtual_server::list_domains()) { + foreach my $d (&virtual_server::list_domains()) { next if (!$d->{$module_name}); next if (!&can_edit_domain($d)); push(@reps, &list_reps($d)); @@ -21,22 +26,23 @@ if ($access{'max'}) { } # Run the create command -$rep = { 'rep' => $in{'rep'} }; -$err = &create_rep($dom, $rep, $in{'desc'}, $in{'anon'}); +my $rep = { 'rep' => $in{'rep'} }; +my $err = &create_rep($dom, $rep, $in{'desc'}, $in{'anon'}); &error("
$err
") if ($err); # Grant selected users -@grants = split(/\r?\n/, $in{'users'}); -%already = map { $_->{'user'}, $_ } &list_users($dom); -@domusers = &virtual_server::list_domain_users($dom, 0, 1, 1, 1); +my @grants = split(/\r?\n/, $in{'users'}); +my %already = map { $_->{'user'}, $_ } &list_users($dom); +my @domusers = &virtual_server::list_domain_users($dom, 0, 1, 1, 1); -foreach $uname (@grants) { +my @repousers; +foreach my $uname (@grants) { if (!$already{$uname}) { # Need to create the user - ($domuser) = grep { &virtual_server::remove_userdom( + my ($domuser) = grep { &virtual_server::remove_userdom( $_->{'user'}, $dom) eq $uname } @domusers; next if (!$domuser); - local $newuser = { 'user' => $uname, + my $newuser = { 'user' => $uname, 'enabled' => 1 }; &set_user_password($newuser, $domuser, $dom); &virtual_server::write_as_domain_user($dom, diff --git a/delete.cgi b/delete.cgi index 4d277dc..862c0b3 100755 --- a/delete.cgi +++ b/delete.cgi @@ -1,19 +1,22 @@ #!/usr/local/bin/perl # Delete one Git repository +use strict; +use warnings; +our (%text, %in); require './virtualmin-git-lib.pl'; &ReadParse(); # Get the domain and repository -($repdom) = grep { $_ ne "confirm" && $_ ne "show" } (keys %in); -($repname, $id) = split(/\@/, $repdom); -$dom = &virtual_server::get_domain($id); +my ($repdom) = grep { $_ ne "confirm" && $_ ne "show" } (keys %in); +my ($repname, $id) = split(/\@/, $repdom); +my $dom = &virtual_server::get_domain($id); &can_edit_domain($dom) || &error($text{'add_edom'}); -@reps = &list_reps($dom); -($rep) = grep { $_->{'rep'} eq $repname } @reps; +my @reps = &list_reps($dom); +my ($rep) = grep { $_->{'rep'} eq $repname } @reps; $rep || &error($text{'delete_erep'}); -$button = $in{$repdom}; +my $button = $in{$repdom}; if ($button eq &entities_to_ascii($text{'delete'})) { # Deleting repo if ($in{'confirm'}) { @@ -29,7 +32,7 @@ if ($button eq &entities_to_ascii($text{'delete'})) { $text{'delete_title'}, ""); print "
\n"; - $size = &disk_usage_kb($rep->{'dir'}); + my $size = &disk_usage_kb($rep->{'dir'}); print &ui_form_start("delete.cgi"); print &ui_hidden($repdom, $in{$repdom}); print &ui_hidden("show", $in{'show'}); @@ -44,7 +47,7 @@ if ($button eq &entities_to_ascii($text{'delete'})) { } elsif ($button eq &entities_to_ascii($text{'index_browse'})) { # Redirect to gitweb - $proto = $dom->{'ssl'} ? "https" : "http"; + my $proto = $dom->{'ssl'} ? "https" : "http"; &redirect("$proto://$dom->{'dom'}/git/gitweb.cgi?p=". &urlize("$rep->{'rep'}.git")); } diff --git a/help.cgi b/help.cgi index 6cc3bea..23a41ba 100644 --- a/help.cgi +++ b/help.cgi @@ -1,17 +1,20 @@ #!/usr/local/bin/perl # Show commands for using some repository +use strict; +use warnings; +our (%text, %in); require './virtualmin-git-lib.pl'; &ReadParse(); # Get the domain and repository -$dom = &virtual_server::get_domain($in{'dom'}); +my $dom = &virtual_server::get_domain($in{'dom'}); &can_edit_domain($dom) || &error($text{'add_edom'}); -@reps = &list_reps($dom); -($rep) = grep { $_->{'rep'} eq $in{'rep'} } @reps; +my @reps = &list_reps($dom); +my ($rep) = grep { $_->{'rep'} eq $in{'rep'} } @reps; $rep || &error($text{'delete_erep'}); -@users = &list_rep_users($dom, $rep); -$user = @users ? $users[0]->{'user'} : "\$username"; +my @users = &list_rep_users($dom, $rep); +my $user = @users ? $users[0]->{'user'} : "\$username"; &ui_print_header(&virtual_server::domain_in($dom), $text{'help_title'}, ""); diff --git a/index.cgi b/index.cgi index f9826f0..9b094ba 100755 --- a/index.cgi +++ b/index.cgi @@ -1,8 +1,13 @@ #!/usr/local/bin/perl # Show all Git repositories for this user +use strict; +use warnings; +our (%access, %text, %in); +our $module_name; require './virtualmin-git-lib.pl'; &ReadParse(); +my $showd; if ($in{'show'}) { $showd = &virtual_server::get_domain_by("dom", $in{'show'}); $showd || &error($text{'index_eshow'}); @@ -11,15 +16,16 @@ if ($in{'show'}) { $text{'index_title'}, "", undef, 1, 1); # Check if Git is installed -$err = &git_check(); +my $err = &git_check(); if ($err) { &ui_print_endpage($err); } # Check if plugin is enabled +no warnings "once"; if (&indexof($module_name, @virtual_server::plugins) < 0) { if (&virtual_server::can_edit_templates()) { - $cgi = $virtual_server::module_info{'version'} >= 3.47 ? + my $cgi = $virtual_server::module_info{'version'} >= 3.47 ? "edit_newfeatures.cgi" : "edit_newplugins.cgi"; &ui_print_endpage(&text('index_eplugin', "../virtual-server/$cgi")); @@ -28,14 +34,16 @@ if (&indexof($module_name, @virtual_server::plugins) < 0) { &ui_print_endpage($text{'index_eplugin2'}); } } +use warnings "once"; # Show repositories for Virtualmin domains visible to the current user -foreach $d ($in{'show'} ? ( $showd ) : &virtual_server::list_domains()) { +my ($domcount, $accesscount); +my (@reps, @mydoms); +foreach my $d ($in{'show'} ? ( $showd ) : &virtual_server::list_domains()) { $domcount++; next if (!&can_edit_domain($d)); $accesscount++; next if (!$d->{$module_name}); - $svncount++; push(@reps, &list_reps($d)); push(@mydoms, $d); } @@ -46,13 +54,13 @@ if (!@mydoms) { } # Build table of repositories -@table = ( ); -foreach $r (@reps) { - $dom = $r->{'dom'}->{'dom'}; - $proto = $r->{'dom'}->{'ssl'} ? "https" : "http"; - $url = "$proto://$r->{'dom'}->{'dom'}/git/gitweb.cgi?p=". +my @table; +foreach my $r (@reps) { + my $dom = $r->{'dom'}->{'dom'}; + my $proto = $r->{'dom'}->{'ssl'} ? "https" : "http"; + my $url = "$proto://$r->{'dom'}->{'dom'}/git/gitweb.cgi?p=". &urlize("$r->{'rep'}.git"); - @actions = ( + my @actions = ( &ui_submit($text{'delete'}, $r->{'rep'}."\@".$r->{'dom'}->{'id'}), &ui_submit($text{'index_browse'}, @@ -115,9 +123,9 @@ else { [ map { [ $_->{'id'}, $_->{'dom'} ] } @mydoms ])); # Users to grant - @unames = ( ); + my @unames; if ($showd) { - foreach $u (&virtual_server::list_domain_users( + foreach my $u (&virtual_server::list_domain_users( $showd, 0, 1, 1, 1)) { push(@unames, &virtual_server::remove_userdom( $u->{'user'}, $showd)); diff --git a/log_parser.pl b/log_parser.pl index 240ceac..a5b393f 100755 --- a/log_parser.pl +++ b/log_parser.pl @@ -1,5 +1,7 @@ # log_parser.pl # Functions for parsing this module's logs +use strict; +use warnings; do 'virtualmin-git-lib.pl'; @@ -7,7 +9,7 @@ # Converts logged information from this module into human-readable form sub parse_webmin_log { -local ($user, $script, $action, $type, $object, $p) = @_; +my ($user, $script, $action, $type, $object, $p) = @_; if ($type eq "repo") { return &text('log_'.$action.'_repo', "".&html_escape($object)."", diff --git a/postinstall.pl b/postinstall.pl index 8f08cd2..b7950a7 100755 --- a/postinstall.pl +++ b/postinstall.pl @@ -1,3 +1,6 @@ +use strict; +use warnings; +our %gconfig; do 'virtualmin-git-lib.pl'; diff --git a/virtual_feature.pl b/virtual_feature.pl index df9f7dd..d8412a1 100755 --- a/virtual_feature.pl +++ b/virtual_feature.pl @@ -1,7 +1,12 @@ # Functions for the Git feature +use strict; +use warnings; +our (%text); +our $module_name; +our $module_config_directory; do 'virtualmin-git-lib.pl'; -$input_name = $module_name; +my $input_name = $module_name; $input_name =~ s/[^A-Za-z0-9]/_/g; &load_theme_library(); @@ -31,7 +36,7 @@ sub feature_disname # editing form sub feature_label { -local ($edit) = @_; +my ($edit) = @_; return $edit ? $text{'feat_label2'} : $text{'feat_label'}; } @@ -76,11 +81,11 @@ sub feature_suitable # Called when this feature is added, with the domain object as a parameter sub feature_setup { -local ($d) = @_; +my ($d) = @_; &$virtual_server::first_print($text{'setup_git'}); &virtual_server::obtain_lock_web($d); -local $phd = &virtual_server::public_html_dir($d); -local $any; +my $phd = &virtual_server::public_html_dir($d); +my $any; $any++ if (&add_git_directives($d, $d->{'web_port'})); $any++ if ($d->{'ssl'} && &add_git_directives($d, $d->{'web_sslport'})); @@ -90,7 +95,7 @@ sub feature_setup } else { # Create needed directories ~/etc/ and ~/public_html/git - local $passwd_file = &passwd_file($d); + my $passwd_file = &passwd_file($d); if (!-d "$phd/git") { &virtual_server::make_dir_as_domain_user( $d, "$phd/git", 02755); @@ -103,10 +108,12 @@ sub feature_setup # Create password files if (!-r $passwd_file) { &lock_file($passwd_file); + no strict "subs"; &virtual_server::open_tempfile_as_domain_user( $d, PASSWD, ">$passwd_file", 0, 1); &virtual_server::close_tempfile_as_domain_user( $d, PASSWD); + use strict "subs"; &virtual_server::set_permissions_as_domain_user( $d, 0755, $passwd_file); &unlock_file($passwd_file); @@ -120,9 +127,9 @@ sub feature_setup ($uinfo = &virtual_server::get_domain_owner($d))) { &$virtual_server::first_print($text{'setup_gituser'}); &foreign_require("htaccess-htpasswd", "htaccess-lib.pl"); - local $un = &virtual_server::remove_userdom( + my $un = &virtual_server::remove_userdom( $uinfo->{'user'}, $d); - local $newuser = { 'user' => $un, + my $newuser = { 'user' => $un, 'enabled' => 1 }; $newuser->{'pass'} = $uinfo->{'pass'}; &virtual_server::write_as_domain_user($d, @@ -135,13 +142,13 @@ sub feature_setup # Setup gitweb if possible &$virtual_server::first_print($text{'feat_gitweb'}); -local $git = &has_command("git") || "git"; -local $gitdir = +my $git = &has_command("git") || "git"; +my $gitdir = -e "/usr/lib/git-core/git-rev-list" ? "/usr/lib/git-core" : -e "/usr/libexec/git-core/git-rev-list" ? "/usr/libexec/git-core" : $git =~ /^(.*)\// ? $1 : "/usr/bin"; -local $src = &find_gitweb(); -local $gitweb = "$phd/git/gitweb.cgi"; +my $src = &find_gitweb(); +my $gitweb = "$phd/git/gitweb.cgi"; &virtual_server::copy_source_dest_as_domain_user($d, $src, $gitweb); &virtual_server::set_permissions_as_domain_user($d, 0755, $gitweb); my $lref = &virtual_server::read_file_lines_as_domain_user($d, $gitweb); @@ -167,7 +174,7 @@ sub feature_setup } &virtual_server::flush_file_lines_as_domain_user($d, $gitweb); foreach my $src (&find_gitweb_data()) { - local $gitfile = $src; + my $gitfile = $src; $gitfile =~ s/^.*\///; $gitfile = "$phd/git/$gitfile"; &virtual_server::copy_source_dest_as_domain_user($d, $src, $gitfile); @@ -176,7 +183,7 @@ sub feature_setup # Set default limit from template if (!exists($d->{$module_name."limit"})) { - local $tmpl = &virtual_server::get_template($d->{'template'}); + my $tmpl = &virtual_server::get_template($d->{'template'}); $d->{$module_name."limit"} = $tmpl->{$module_name."limit"} eq "none" ? "" : $tmpl->{$module_name."limit"}; @@ -195,18 +202,20 @@ sub feature_setup # Add Apache directives for DAV access to /git sub add_git_directives { -local ($d, $port) = @_; -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); +my ($d, $port) = @_; +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); if ($virt) { - local $lref = &read_file_lines($virt->{'file'}); - local ($locstart, $locend) = + my $lref = &read_file_lines($virt->{'file'}); + my ($locstart, $locend) = &find_git_lines($lref, $virt->{'line'}, $virt->{'eline'}); - local @lines; - local $passwd_file = &passwd_file($d); - local @norewrite; + my @lines; + my $passwd_file = &passwd_file($d); + my @norewrite; + no warnings "once"; if ($apache::httpd_modules{'mod_rewrite'}) { @norewrite = ( "RewriteEngine off" ); } + use warnings "once"; if (!$locstart) { push(@lines, "", @@ -236,11 +245,11 @@ sub add_git_directives # Delete Apache directives for the /git location sub remove_git_directives { -local ($d, $port) = @_; -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); +my ($d, $port) = @_; +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); if ($virt) { - local $lref = &read_file_lines($virt->{'file'}); - local ($locstart, $locend) = + my $lref = &read_file_lines($virt->{'file'}); + my ($locstart, $locend) = &find_git_lines($lref, $virt->{'line'}, $virt->{'eline'}); if ($locstart) { splice(@$lref, $locstart, $locend-$locstart+1); @@ -258,8 +267,8 @@ sub remove_git_directives # Returns the start and end lines containing the block sub find_git_lines { -local ($dirs, $start, $end) = @_; -local ($locstart, $locend, $i); +my ($dirs, $start, $end) = @_; +my ($locstart, $locend, $i); for($i=$start; $i<=$end; $i++) { if ($dirs->[$i] =~ /^\s*/i && !$locstart) { $locstart = $i; @@ -275,7 +284,7 @@ sub find_git_lines # Called when a domain with this feature is modified sub feature_modify { -local ($d, $oldd) = @_; +my ($d, $oldd) = @_; &virtual_server::obtain_lock_web($d); &virtual_server::release_lock_web($d); } @@ -284,10 +293,10 @@ sub feature_modify # Called when this feature is disabled, or when the domain is being deleted sub feature_delete { -local ($d) = @_; +my ($d) = @_; &$virtual_server::first_print($text{'delete_git'}); &virtual_server::obtain_lock_web($d); -local $any; +my $any; $any++ if (&remove_git_directives($d, $d->{'web_port'})); $any++ if ($d->{'ssl'} && &remove_git_directives($d, $d->{'web_sslport'})); @@ -302,7 +311,7 @@ sub feature_delete } # Remove gitweb.cgi -local $phd = &virtual_server::public_html_dir($d); +my $phd = &virtual_server::public_html_dir($d); &virtual_server::unlink_file_as_domain_user($d, "$phd/git/gitweb.cgi"); foreach my $gitfile (&find_gitweb_data()) { $gitfile =~ s/^.*\///; @@ -322,7 +331,7 @@ sub feature_delete # the Webmin user when this feature is enabled sub feature_webmin { -local @doms = map { $_->{'dom'} } grep { $_->{$module_name} } @{$_[1]}; +my @doms = map { $_->{'dom'} } grep { $_->{$module_name} } @{$_[1]}; if (@doms) { return ( [ $module_name, { 'dom' => join(" ", @doms), @@ -338,7 +347,7 @@ sub feature_webmin # Returns HTML for editing limits related to this plugin sub feature_limits_input { -local ($d) = @_; +my ($d) = @_; return undef if (!$d->{$module_name}); return &ui_table_row(&hlink($text{'limits_max'}, "limits_max"), &ui_opt_textbox($input_name."limit", $d->{$module_name."limit"}, @@ -350,7 +359,7 @@ sub feature_limits_input # Updates the domain with limit inputs generated by feature_limits_input sub feature_limits_parse { -local ($d, $in) = @_; +my ($d, $in) = @_; return undef if (!$d->{$module_name}); if ($in->{$input_name."limit_def"}) { delete($d->{$module_name."limit"}); @@ -366,7 +375,7 @@ sub feature_limits_parse # Returns an array of link objects for webmin modules for this feature sub feature_links { -local ($d) = @_; +my ($d) = @_; return ( { 'mod' => $module_name, 'desc' => $text{'links_link'}, 'page' => 'index.cgi?show='.$d->{'dom'}, @@ -383,19 +392,19 @@ sub feature_modules # Backup all Git repositories and the users file sub feature_backup { -local ($d, $file, $opts) = @_; +my ($d, $file, $opts) = @_; &$virtual_server::first_print($text{'feat_backup'}); # Copy actual repositories -local $phd = &virtual_server::public_html_dir($d); -local $tar = &virtual_server::get_tar_command(); -local @files = glob("$phd/git/*"); +my $phd = &virtual_server::public_html_dir($d); +my $tar = &virtual_server::get_tar_command(); +my @files = glob("$phd/git/*"); if (!@files) { &$virtual_server::second_print($text{'feat_norepos'}); return 1; } -local $temp = &transname(); -local $out = &backquote_command("cd ".quotemeta("$phd/git")." && ". +my $temp = &transname(); +my $out = &backquote_command("cd ".quotemeta("$phd/git")." && ". "$tar cf ".quotemeta($temp)." . 2>&1"); if ($?) { &$virtual_server::second_print(&text('feat_tar', "
$out
")); @@ -405,7 +414,7 @@ sub feature_backup &unlink_file($temp); # Copy users file -local $pfile = &passwd_file($_[0]); +my $pfile = &passwd_file($_[0]); if (!-r $pfile) { &$virtual_server::second_print($text{'feat_nopfile'}); return 0; @@ -420,14 +429,14 @@ sub feature_backup # Restore Git repositories and the users file sub feature_restore { -local ($d, $file, $opts) = @_; +my ($d, $file, $opts) = @_; &$virtual_server::first_print($text{'feat_restore'}); # Extract tar file of repositories (deleting old ones first) -local $phd = &virtual_server::public_html_dir($d); -local $tar = &virtual_server::get_tar_command(); +my $phd = &virtual_server::public_html_dir($d); +my $tar = &virtual_server::get_tar_command(); &execute_command("rm -rf ".quotemeta("$phd/git")."/*"); -local ($out, $ex) = &virtual_server::run_as_domain_user($d, +my ($out, $ex) = &virtual_server::run_as_domain_user($d, "cd ".quotemeta("$phd/git")." && $tar xf ".quotemeta($file)." 2>&1"); if ($ex) { &$virtual_server::second_print(&text('feat_untar', "
$out
")); @@ -440,11 +449,11 @@ sub feature_restore } # Copy users file -local $pfile = &passwd_file($d); -local ($ok, $out) = &virtual_server::copy_source_dest_as_domain_user( +my $pfile = &passwd_file($d); +my ($ok, $uout) = &virtual_server::copy_source_dest_as_domain_user( $d, $file."_users", $pfile); if (!$ok) { - &$virtual_server::second_print(&text('feat_copypfile2', $out)); + &$virtual_server::second_print(&text('feat_copypfile2', $uout)); return 0; } @@ -462,16 +471,16 @@ sub feature_backup_name # an error message if any problem is found sub feature_validate { -local ($d) = @_; -local $passwd_file = &passwd_file($d); +my ($d) = @_; +my $passwd_file = &passwd_file($d); -r $passwd_file || return &text('feat_evalidatefile', "$passwd_file"); -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}); $virt || return &virtual_server::text('validate_eweb', $d->{'dom'}); -local $lref = &read_file_lines($virt->{'file'}); -local ($locstart, $locend) = +my $lref = &read_file_lines($virt->{'file'}); +my ($locstart, $locend) = &find_git_lines($lref, $virt->{'line'}, $virt->{'eline'}); $locstart || return &text('feat_evalidateloc'); -local $phd = &virtual_server::public_html_dir($d); +my $phd = &virtual_server::public_html_dir($d); -d "$phd/git" || return &text('feat_evalidategit', "$phd/git"); return undef; } @@ -481,25 +490,27 @@ sub feature_validate # formatted to appear inside a table. sub mailbox_inputs { -local ($user, $new, $dom) = @_; +my ($user, $new, $dom) = @_; return undef if (!$dom || !$dom->{$module_name}); -local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); -local $suser; +my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); +my $suser; if (!$new) { - local @users = &list_users($dom); + my @users = &list_users($dom); ($suser) = grep { $_->{'user'} eq $un } @users; } -local $main::ui_table_cols = 2; -local @reps = &list_reps($dom); -local @rwreps; -foreach $r (@reps) { - local @rusers = &list_rep_users($dom, $r); - local ($ruser) = grep { $_->{'user'} eq $un } @rusers; +no warnings "once"; +$main::ui_table_cols = 2; +use warnings "once"; +my @reps = &list_reps($dom); +my @rwreps; +foreach my $r (@reps) { + my @rusers = &list_rep_users($dom, $r); + my ($ruser) = grep { $_->{'user'} eq $un } @rusers; if ($ruser) { push(@rwreps, $r->{'rep'}); } } -local %defs; +my %defs; &read_file("$module_config_directory/defaults.$dom->{'id'}", \%defs); if (!$suser && !@rwreps) { # Use default repositories @@ -507,12 +518,12 @@ sub mailbox_inputs } @rwreps = sort { $a cmp $b } @rwreps; @reps = sort { $a->{'rep'} cmp $b->{'rep'} } @reps; -local @inputs = ( $input_name."_rwreps_opts", $input_name."_rwreps_vals", +my @inputs = ( $input_name."_rwreps_opts", $input_name."_rwreps_vals", $input_name."_rwreps_add", $input_name."_rwreps_remove" ); -local $hasuser = $suser || $new && $defs{'git'}; -local $dis = $hasuser ? 0 : 1; -local $jsenable = &js_disable_inputs([ ], \@inputs, "onClick"); -local $jsdisable = &js_disable_inputs(\@inputs, [ ], "onClick"); +my $hasuser = $suser || $new && $defs{'git'}; +my $dis = $hasuser ? 0 : 1; +my $jsenable = &js_disable_inputs([ ], \@inputs, "onClick"); +my $jsdisable = &js_disable_inputs(\@inputs, [ ], "onClick"); return &ui_table_row(&hlink($text{'mail_git'}, "git"), &ui_radio($input_name, $hasuser ? 1 : 0, [ [ 1, $text{'yes'}, $jsenable ], @@ -531,17 +542,17 @@ sub mailbox_inputs # success or an error message sub mailbox_validate { -local ($user, $olduser, $in, $new, $dom) = @_; +my ($user, $olduser, $in, $new, $dom) = @_; return undef if (!$dom || !$dom->{$module_name}); if ($in->{$input_name}) { - local @users = &list_users($dom); - local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); - local $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); - local ($suser) = grep { $_->{'user'} eq $oun } @users; + my @users = &list_users($dom); + my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); + my $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); + my ($suser) = grep { $_->{'user'} eq $oun } @users; # Make sure Git user doesn't clash if ($new || $user->{'user'} ne $olduser->{'user'}) { - local ($clash) = grep { $_->{'user'} eq $un } @users; + my ($clash) = grep { $_->{'user'} eq $un } @users; return &text('mail_clash', $un) if ($clash); } } @@ -552,14 +563,14 @@ sub mailbox_validate # Updates the user based on inputs generated by mailbox_inputs sub mailbox_save { -local ($user, $olduser, $in, $new, $dom) = @_; +my ($user, $olduser, $in, $new, $dom) = @_; return undef if (!$dom || !$dom->{$module_name}); &foreign_require("htaccess-htpasswd", "htaccess-lib.pl"); -local @users = &list_users($dom); -local $suser; -local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); -local $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); -local $rv; +my @users = &list_users($dom); +my $suser; +my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); +my $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); +my $rv; &lock_file(&passwd_file($dom)); if (!$new) { @@ -567,7 +578,7 @@ sub mailbox_save } if ($in->{$input_name} && !$suser) { # Add the user - local $newuser = { 'user' => $un, + my $newuser = { 'user' => $un, 'enabled' => 1 }; &set_user_password($newuser, $user, $dom); &virtual_server::write_as_domain_user($dom, @@ -596,13 +607,13 @@ sub mailbox_save &unlock_file(&passwd_file($dom)); # Update list of repositories user has access to -local %canrwreps = map { $_, 1 } split(/\r?\n/, $in->{$input_name."_rwreps"}); +my %canrwreps = map { $_, 1 } split(/\r?\n/, $in->{$input_name."_rwreps"}); if (!$in->{$input_name}) { %canrwreps = ( ); } foreach my $r (&list_reps($dom)) { - local @rusers = &list_rep_users($dom, $r); - local ($ruser) = grep { $_->{'user'} eq $oun } @rusers; + my @rusers = &list_rep_users($dom, $r); + my ($ruser) = grep { $_->{'user'} eq $oun } @rusers; @rusers = grep { $_ ne $ruser } @rusers; if ($canrwreps{$r->{'rep'}}) { push(@rusers, { 'user' => $un, @@ -621,13 +632,13 @@ sub mailbox_save # Called when a user is modified by some method other than the edit user form sub mailbox_modify { -local ($user, $olduser, $dom) = @_; +my ($user, $olduser, $dom) = @_; return undef if (!$dom || !$dom->{$module_name}); &foreign_require("htaccess-htpasswd", "htaccess-lib.pl"); -local @users = &list_users($dom); -local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); -local $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); -local ($suser) = grep { $_->{'user'} eq $oun } @users; +my @users = &list_users($dom); +my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); +my $oun = &virtual_server::remove_userdom($olduser->{'user'}, $dom); +my ($suser) = grep { $_->{'user'} eq $oun } @users; return undef if (!$suser); &lock_file(&passwd_file($dom)); @@ -637,8 +648,8 @@ sub mailbox_modify $suser->{'user'} = $un; &htaccess_htpasswd::modify_user($suser); foreach my $r (&list_reps($dom)) { - local @rusers = &list_rep_users($dom, $r->{'rep'}); - local ($ruser) = grep { $_->{'user'} eq $oun } @rusers; + my @rusers = &list_rep_users($dom, $r->{'rep'}); + my ($ruser) = grep { $_->{'user'} eq $oun } @rusers; if ($ruser) { $ruser->{'user'} = $un; &save_rep_users($dom, $r, \@rusers); @@ -661,24 +672,24 @@ sub mailbox_modify # Removes any extra features for this user sub mailbox_delete { -local ($user, $dom) = @_; +my ($user, $dom) = @_; return undef if (!$dom || !$dom->{$module_name}); &foreign_require("htaccess-htpasswd", "htaccess-lib.pl"); &lock_file(&passwd_file($dom)); -local @users = &list_users($dom); -local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); -local ($suser) = grep { $_->{'user'} eq $un } @users; +my @users = &list_users($dom); +my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); +my ($suser) = grep { $_->{'user'} eq $un } @users; if ($suser) { &virtual_server::write_as_domain_user($dom, sub { &htaccess_htpasswd::delete_user($suser) }); } # Remove from all repositories -foreach $r (&list_reps($dom)) { - local @rusers = &list_rep_users($dom, $r->{'rep'}); - local ($ruser) = grep { $_->{'user'} eq $un } @rusers; - local @newrusers = grep { $_ ne $ruser } @rusers; +foreach my $r (&list_reps($dom)) { + my @rusers = &list_rep_users($dom, $r->{'rep'}); + my ($ruser) = grep { $_->{'user'} eq $un } @rusers; + my @newrusers = grep { $_ ne $ruser } @rusers; if (@newrusers != @rusers) { &save_rep_users($dom, $r, \@newrusers); } @@ -689,9 +700,10 @@ sub mailbox_delete # mailbox_header(&domain) # Returns a column header for the user display, or undef for none +my @column_users; # XXX whiff. sub mailbox_header { -local ($d) = @_; +my ($d) = @_; if ($d->{$module_name}) { @column_users = &list_users($d); return $text{'mail_header'}; @@ -705,9 +717,9 @@ sub mailbox_header # Returns the text to display in the column for some user sub mailbox_column { -local ($user, $dom) = @_; -local $un = &virtual_server::remove_userdom($user->{'user'}, $dom); -local ($duser) = grep { $_->{'user'} eq $un } @column_users; +my ($user, $dom) = @_; +my $un = &virtual_server::remove_userdom($user->{'user'}, $dom); +my ($duser) = grep { $_->{'user'} eq $un } @column_users; return $duser ? $text{'yes'} : $text{'no'}; return undef; } @@ -717,11 +729,11 @@ sub mailbox_column # users in this virtual server sub mailbox_defaults_inputs { -local ($defs, $dom) = @_; +my ($defs, $dom) = @_; if ($dom->{$module_name}) { - local %defs; + my %defs; &read_file("$module_config_directory/defaults.$dom->{'id'}", \%defs); - local @reps = &list_reps($dom); + my @reps = &list_reps($dom); return &ui_table_row($text{'mail_git'}, &ui_yesno_radio($input_name, int($defs{'git'})))."\n". &ui_table_row($text{'mail_reps'}, @@ -737,9 +749,9 @@ sub mailbox_defaults_inputs # file internal to this module to store them sub mailbox_defaults_parse { -local ($defs, $dom, $in) = @_; +my ($defs, $dom, $in) = @_; if ($dom->{$module_name}) { - local %defs; + my %defs; &read_file("$module_config_directory/defaults.$dom->{'id'}", \%defs); $defs{'git'} = $in->{$input_name}; $defs{'reps'} = join(" ", split(/\0/, $in->{$input_name."_reps"})); @@ -751,8 +763,8 @@ sub mailbox_defaults_parse # Returns HTML for editing per-template options for this plugin sub template_input { -local ($tmpl) = @_; -local $v = $tmpl->{$module_name."limit"}; +my ($tmpl) = @_; +my $v = $tmpl->{$module_name."limit"}; $v = "none" if (!defined($v) && $tmpl->{'default'}); return &ui_table_row($text{'tmpl_limit'}, &ui_radio($input_name."_mode", @@ -768,7 +780,7 @@ sub template_input # template_input. All template fields must start with the module name. sub template_parse { -local ($tmpl, $in) = @_; +my ($tmpl, $in) = @_; if ($in->{$input_name.'_mode'} == 0) { $tmpl->{$module_name."limit"} = ""; } diff --git a/virtualmin-git-lib.pl b/virtualmin-git-lib.pl index 8e306bc..51f7f3a 100644 --- a/virtualmin-git-lib.pl +++ b/virtualmin-git-lib.pl @@ -1,13 +1,17 @@ +use strict; +use warnings; +our %config; +our $module_root_directory; BEGIN { push(@INC, ".."); }; eval "use WebminCore;"; &init_config(); &foreign_require("virtual-server", "virtual-server-lib.pl"); -%access = &get_module_acl(); +my %access = &get_module_acl(); sub can_edit_domain { -local ($d) = @_; +my ($d) = @_; return &virtual_server::can_edit_domain($d); } @@ -15,20 +19,20 @@ sub can_edit_domain # Returns a list of all repositories in some domain sub list_reps { -local ($d) = @_; -local @rv; -local $dir = &virtual_server::public_html_dir($d)."/git"; -opendir(DIR, $dir); -while(my $f = readdir(DIR)) { +my ($d) = @_; +my @rv; +my $dir = &virtual_server::public_html_dir($d)."/git"; +opendir(my $DIR, $dir); +while(my $f = readdir($DIR)) { if ($f =~ /^(\S+)\.git$/) { - local $rep = { 'dom' => $d, - 'rep' => $1, - 'dir' => "$dir/$f" }; + my $rep = { 'dom' => $d, + 'rep' => $1, + 'dir' => "$dir/$f" }; $rep->{'desc'} = &virtual_server::read_file_contents_as_domain_user($d, $rep->{'dir'}."/description"); push(@rv, $rep); } } -closedir(DIR); +closedir($DIR); return @rv; } @@ -43,7 +47,7 @@ sub git_check # Returns the path to the Git password file for a domain sub passwd_file { -local ($d) = @_; +my ($d) = @_; if ($config{'passfile'}) { return "$d->{'home'}/$config{'passfile'}"; } @@ -56,8 +60,8 @@ sub passwd_file # Creates a new Git repository in some domain sub create_rep { -local ($d, $rep, $desc, $anon) = @_; -local $git = &has_command($config{'git'}); +my ($d, $rep, $desc, $anon) = @_; +my $git = &has_command($config{'git'}); $git || return "Git command $config{'git'} was not found!"; # Make the dir and setup a repo in it @@ -65,8 +69,8 @@ sub create_rep if (!-d $rep->{'dir'}) { &virtual_server::make_dir_as_domain_user($d, $rep->{'dir'}); } -local $cmd = "cd ".quotemeta($rep->{'dir'})." && $git --bare init"; -local ($out, $ex) = &virtual_server::run_as_domain_user($d, $cmd); +my $cmd = "cd ".quotemeta($rep->{'dir'})." && $git --bare init"; +my ($out, $ex) = &virtual_server::run_as_domain_user($d, $cmd); if ($ex) { return $out; } @@ -79,23 +83,25 @@ sub create_rep &virtual_server::release_lock_web($d); # Run update-server-info as Apache -local $webuser = &virtual_server::get_apache_user($d); -local $qdir = quotemeta($rep->{'dir'}); +my $webuser = &virtual_server::get_apache_user($d); +my $qdir = quotemeta($rep->{'dir'}); &system_logged(&command_as_user($webuser, 0, "cd $qdir && $git update-server-info")); # Set description file if ($desc) { - local $descfile = "$rep->{'dir'}/description"; + my $descfile = "$rep->{'dir'}/description"; + no strict "subs"; &virtual_server::open_tempfile_as_domain_user($d, DESC, ">$descfile"); &print_tempfile(DESC, $desc."\n"); &virtual_server::close_tempfile_as_domain_user($d, DESC); + use strict "subs"; } # Set domain owner name in config file -local $cfile = "$rep->{'dir'}/config"; +my $cfile = "$rep->{'dir'}/config"; if (-r $cfile) { - local $lref = &virtual_server::read_file_lines_as_domain_user( + my $lref = &virtual_server::read_file_lines_as_domain_user( $d, $cfile); push(@$lref, "", "[gitweb]", "\towner=$d->{'user'}"); &virtual_server::flush_file_lines_as_domain_user($d, $cfile); @@ -147,7 +153,7 @@ sub find_gitweb # Returns the paths to additional files needed by gitweb sub find_gitweb_data { -local @files = ( "git-favicon.png", "git-logo.png", "gitweb.css" ); +my @files = ( "git-favicon.png", "git-logo.png", "gitweb.css" ); foreach my $p ("/var/www/git", # CentOS "/var/www", # Ubuntu $module_root_directory) { @@ -163,10 +169,10 @@ sub find_gitweb_data # written by SVN sub set_rep_permissions { -local ($d, $rep) = @_; -local $qdir = quotemeta($rep->{'dir'}); -local $webuser = &virtual_server::get_apache_user($d); -local @uinfo = getpwnam($webuser); +my ($d, $rep) = @_; +my $qdir = quotemeta($rep->{'dir'}); +my $webuser = &virtual_server::get_apache_user($d); +my @uinfo = getpwnam($webuser); &virtual_server::run_as_domain_user($d, "chmod -R 770 $qdir"); &system_logged("chown -R $uinfo[2] $qdir"); } @@ -175,7 +181,7 @@ sub set_rep_permissions # Delete a Git repository's directory sub delete_rep { -local ($d, $rep) = @_; +my ($d, $rep) = @_; &unlink_logged($rep->{'dir'}); &virtual_server::obtain_lock_web($d); &remove_git_repo_directives($d, $d->{'web_port'}, $rep); @@ -187,9 +193,9 @@ sub delete_rep # Returns a list of htaccess user hashes for Git in some domain sub list_users { -local ($d) = @_; +my ($d) = @_; &foreign_require("htaccess-htpasswd", "htaccess-lib.pl"); -local $users = &htaccess_htpasswd::list_users(&passwd_file($d)); +my $users = &htaccess_htpasswd::list_users(&passwd_file($d)); return @$users; } @@ -197,20 +203,20 @@ sub list_users # Returns a list of user hashes with access to some repo sub list_rep_users { -local ($d, $rep) = @_; -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, +my ($d, $rep) = @_; +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $d->{'web_port'}); return () if (!$virt); -local @locs = &apache::find_directive_struct("Location", $vconf); -local ($reploc) = grep { $_->{'words'}->[0] eq "/git/".$rep->{'rep'}.".git" } +my @locs = &apache::find_directive_struct("Location", $vconf); +my ($reploc) = grep { $_->{'words'}->[0] eq "/git/".$rep->{'rep'}.".git" } @locs; return () if (!$reploc); -local ($limitloc) = &apache::find_directive_struct("LimitExcept", +my ($limitloc) = &apache::find_directive_struct("LimitExcept", $reploc->{'members'}); -local $req = &apache::find_directive_struct("Require", +my $req = &apache::find_directive_struct("Require", $limitloc ? $limitloc->{'members'} : $reploc->{'members'}); return () if (!$req); -local @usernames = @{$req->{'words'}}; +my @usernames = @{$req->{'words'}}; shift(@usernames); return map { { 'user' => $_ } } @usernames; } @@ -219,19 +225,19 @@ sub list_rep_users # Updates the list of users for some repository sub save_rep_users { -local ($d, $rep, $users) = @_; -local @usernames = map { $_->{'user'} } @$users; -local @ports = ( $d->{'web_port'} ); +my ($d, $rep, $users) = @_; +my @usernames = map { $_->{'user'} } @$users; +my @ports = ( $d->{'web_port'} ); push(@ports, $d->{'web_sslport'}) if ($d->{'ssl'}); foreach my $p (@ports) { - local ($virt, $vconf, $conf) = + my ($virt, $vconf, $conf) = &virtual_server::get_apache_virtual($d->{'dom'}, $p); next if (!$virt); - local @locs = &apache::find_directive_struct("Location", $vconf); - local ($reploc) = grep { $_->{'words'}->[0] eq + my @locs = &apache::find_directive_struct("Location", $vconf); + my ($reploc) = grep { $_->{'words'}->[0] eq "/git/".$rep->{'rep'}.".git" } @locs; next if (!$reploc); - local ($limitloc) = &apache::find_directive_struct( + my ($limitloc) = &apache::find_directive_struct( "LimitExcept", $reploc->{'members'}); &apache::save_directive("Require", [ "user ".join(" ", @usernames) ], $limitloc ? $limitloc->{'members'} @@ -251,13 +257,13 @@ sub restart_apache_null # Add Apache directives for DAV access to some path under /git sub add_git_repo_directives { -local ($d, $port, $rep, $anon) = @_; -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); +my ($d, $port, $rep, $anon) = @_; +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); if ($virt) { - local $lref = &read_file_lines($virt->{'file'}); - local ($locstart, $locend) = + my $lref = &read_file_lines($virt->{'file'}); + my ($locstart, $locend) = &find_git_repo_lines($lref, $virt->{'line'}, $virt->{'eline'}, $rep); - local @lines; + my @lines; if (!$locstart) { push(@lines, "{'rep'}.git>", @@ -284,11 +290,11 @@ sub add_git_repo_directives # Delete Apache directives for the /git/repo location sub remove_git_repo_directives { -local ($d, $port) = @_; -local ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); +my ($d, $port, $rep) = @_; +my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $port); if ($virt) { - local $lref = &read_file_lines($virt->{'file'}); - local ($locstart, $locend) = + my $lref = &read_file_lines($virt->{'file'}); + my ($locstart, $locend) = &find_git_repo_lines($lref, $virt->{'line'}, $virt->{'eline'}, $rep); if ($locstart) { splice(@$lref, $locstart, $locend-$locstart+1); @@ -306,9 +312,9 @@ sub remove_git_repo_directives # Returns the start and end lines containing the block sub find_git_repo_lines { -local ($dirs, $start, $end, $rep) = @_; -local $repname = $rep->{'rep'}; -local ($locstart, $locend, $i); +my ($dirs, $start, $end, $rep) = @_; +my $repname = $rep->{'rep'}; +my ($locstart, $locend, $i); for($i=$start; $i<=$end; $i++) { if ($dirs->[$i] =~ /^\s*/i && !$locstart) { @@ -325,7 +331,7 @@ sub find_git_repo_lines # Sets password fields for a Git user based on their virtualmin user hash sub set_user_password { -local ($newuser, $user, $dom) = @_; +my ($newuser, $user, $dom) = @_; if ($user->{'pass_crypt'}) { # Hashed password is available, use it $newuser->{'pass'} = $user->{'pass_crypt'};