Handle hostnames with upper-case letters
[webmin.git] / quota / copy_user.cgi
1 #!/usr/local/bin/perl
2 # copy_user.cgi
3 # Copy some user's quota to a number of others
4
5 require './quota-lib.pl';
6 &ReadParse();
7 $whatfailed = $text{'cuser_efail'};
8 $access{'filesys'} eq "*" ||
9         &error($text{'cuser_ecannot'});
10 &can_edit_user($in{'user'}) ||
11         &error($text{'cuser_euallow'});
12 $access{'ro'} && &error($text{'cuser_euallow'});
13
14 if ($in{'dest'} == 0) {
15         # Copy to all users
16         setpwent();
17         while(@uinfo = getpwent()) {
18                 push(@copyto, $uinfo[0]);
19                 }
20         endpwent() if ($gconfig{'os_type'} ne 'hpux');
21         }
22 elsif ($in{'dest'} == 1) {
23         # Copy to selected users
24         @copyto = split(/\s+/, $in{'users'});
25         }
26 elsif ($in{'dest'} == 2) {
27         # Copy to members of groups
28         setpwent();
29         while(@uinfo = getpwent()) { $ingroup{$uinfo[3]} .= "$uinfo[0] "; }
30         endpwent() if ($gconfig{'os_type'} ne 'hpux');
31         foreach $g (split(/\s+/, $in{'groups'})) {
32                 @ginfo = getgrnam($g);
33                 push(@copyto, split(/\s+/, $ingroup{$ginfo[2]}));
34                 push(@copyto, split(/\s+/, $ginfo[3]));
35                 }
36         }
37 @copyto = &unique(@copyto);
38 @copyto = grep { $_ ne $in{'user'} } @copyto;
39 if (!@copyto) { &error($text{'cuser_enouser'}); }
40 foreach $c (@copyto) {
41         &can_edit_user($c) ||
42                 &error(&text('cuser_eallowto', $c));
43         }
44
45 # Do the copy
46 &copy_user_quota($in{'user'}, @copyto);
47 &webmin_log("copy", "user", $in{'user'}, \%in);
48 &redirect("user_filesys.cgi?user=$in{'user'}");
49