-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.cgi
executable file
·66 lines (58 loc) · 1.89 KB
/
add.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/local/bin/perl
# Create one repository
use strict;
use warnings;
our (%access, %text, %in);
our $module_name;
require './virtualmin-svn-lib.pl';
&ReadParse();
# Validate inputs
&error_setup($text{'add_err'});
$in{'rep'} =~ /^[a-z0-9\.\-\_]+$/i || &error($text{'add_erep'});
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 my $d (&virtual_server::list_domains()) {
next if (!$d->{$module_name});
next if (!&can_edit_domain($d));
push(@reps, &list_reps($d));
}
@reps >= $access{'max'} && &error($text{'index_max'});
}
# Run the create command
my $rep = { 'rep' => $in{'rep'} };
my $err = &create_rep($dom, $rep, $in{'type'});
&error("<pre>$err</pre>") if ($err);
my @repousers = &list_rep_users($dom, $rep);
if ($in{'ro'}) {
# Add the anonymous user
push(@repousers, { 'user' => '*', 'perms' => 'r' });
}
# Grant selected users
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 my $uname (@grants) {
if (!$already{$uname}) {
# Need to create the user
my ($domuser) = grep { &virtual_server::remove_userdom(
$_->{'user'}, $dom) eq $uname } @domusers;
next if (!$domuser);
my $newuser = { 'user' => $uname,
'enabled' => 1 };
&set_user_password($newuser, $domuser, $dom);
&virtual_server::write_as_domain_user($dom,
sub { &htaccess_htpasswd::create_user(
$newuser, &passwd_file($dom)) });
&virtual_server::set_permissions_as_domain_user(
$dom, 0755, &passwd_file($dom));
}
# Add to this repo
push(@repousers, { 'user' => $uname,
'perms' => 'rw' });
}
&save_rep_users($dom, $rep, \@repousers);
&webmin_log("add", "repo", $in{'rep'}, { 'dom' => $dom->{'dom'} });
&redirect("index.cgi?show=$in{'show'}");