Skip to content

Commit

Permalink
strict/warn, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Jun 28, 2016
1 parent dd6533f commit 6867d11
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 206 deletions.
26 changes: 16 additions & 10 deletions add.cgi
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/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();

# 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));
Expand All @@ -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("<pre>$err</pre>") 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,
Expand Down
19 changes: 11 additions & 8 deletions delete.cgi
Original file line number Diff line number Diff line change
@@ -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'}) {
Expand All @@ -29,7 +32,7 @@ if ($button eq &entities_to_ascii($text{'delete'})) {
$text{'delete_title'}, "");

print "<center>\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'});
Expand All @@ -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"));
}
Expand Down
13 changes: 8 additions & 5 deletions help.cgi
Original file line number Diff line number Diff line change
@@ -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'}, "");

Expand Down
32 changes: 20 additions & 12 deletions index.cgi
Original file line number Diff line number Diff line change
@@ -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'});
Expand All @@ -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"));
Expand All @@ -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);
}
Expand All @@ -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'},
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion log_parser.pl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# log_parser.pl
# Functions for parsing this module's logs
use strict;
use warnings;

do 'virtualmin-git-lib.pl';

# parse_webmin_log(user, script, action, type, object, &params)
# 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',
"<tt>".&html_escape($object)."</tt>",
Expand Down
3 changes: 3 additions & 0 deletions postinstall.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use strict;
use warnings;
our %gconfig;

do 'virtualmin-git-lib.pl';

Expand Down
Loading

0 comments on commit 6867d11

Please sign in to comment.