Handle hostnames with upper-case letters
[webmin.git] / useradmin / gexport_exec.cgi
1 #!/usr/local/bin/perl
2 # Actually output a group creation batch file
3
4 require './user-lib.pl';
5 &error_setup($text{'gexport_err'});
6 $access{'export'} || &error($text{'gexport_ecannot'});
7 &ReadParse();
8
9 # Validate inputs
10 if ($in{'to'}) {
11         $access{'export'} == 2 || &error($text{'export_ecannot'});
12         $in{'file'} =~ /^\/.+$/ || &error($text{'export_efile'});
13         &is_under_directory($access{'home'}, $in{'file'}) ||
14                 &error($text{'export_efile2'});
15         }
16 if ($in{'mode'} == 4) {
17         $in{'gid'} =~ /^\d*$/ || &error($text{'gexport_egid'});
18         $in{'gid2'} =~ /^\d*$/ || &error($text{'gexport_egid2'});
19         }
20
21 # Open the output file
22 if ($in{'to'}) {
23         &open_tempfile(OUT, ">$in{'file'}", 1) ||
24                 &error(&text('export_eopen', $!));
25         $fh = "OUT";
26         &ui_print_header(undef, $text{'gexport_title'}, "");
27         }
28 else {
29         print "Content-type: text/plain\n\n";
30         $fh = "STDOUT";
31         }
32
33 # Work out which groups are allowed and selected
34 @glist = &list_groups();
35 @glist = &list_allowed_groups(\%access, \@glist);
36 $faccess{'gedit_mode'} = $in{'mode'};
37 $faccess{'gedit'} = $in{'mode'} == 2 ? $in{'can'} :
38                    $in{'mode'} == 3 ? $in{'cannot'} :
39                    $in{'mode'} == 4 ? $in{'gid'} : "";
40 $faccess{'gedit2'} = $in{'mode'} == 4 ? $in{'gid2'} : "";
41 @glist = &list_allowed_groups(\%faccess, \@glist);
42
43 # Go through all allowed users
44 $count = 0;
45 foreach $g (@glist) {
46         @line = ( $g->{'group'}, $g->{'pass'}, $g->{'gid'},
47                   $g->{'members'} );
48         if ($fh eq "STDOUT") {
49                 print $fh join(":", "create", @line),"\n";
50                 }
51         else {
52                 &print_tempfile($fh, join(":", "create", @line),"\n");
53                 }
54         $count++;
55         }
56
57 if ($in{'to'}) {
58         # All done
59         &close_tempfile($fh);
60         @st = stat($in{'file'});
61         print "<p>",&text('export_done',
62                   $count, "<tt>$in{'file'}</tt>", &nice_size($st[7])),"<p>\n";
63
64         &ui_print_footer("", $text{'index_return'});
65         }
66