Handle hostnames with upper-case letters
[webmin.git] / quota / user_filesys.cgi
1 #!/usr/local/bin/perl
2 # user_filesys.cgi
3 # List all filesystems for which some user has quotas
4
5 require './quota-lib.pl';
6 &ReadParse();
7 $u = $in{'user'};
8 $u =~ /\S/ || &error($text{'ufilesys_enone'});
9 &can_edit_user($u) ||
10         &error(&text('ufilesys_ecannot', $u));
11 &ui_print_header(undef, $text{'ufilesys_title'}, "", "user_filesys");
12
13 foreach $f (&list_filesystems()) {
14         if ($f->[4]%2 && $f->[5] && &can_edit_filesys($f->[0])) {
15                 push(@fslist, $f->[0]);
16                 $fslist{$f->[0]}++;
17                 }
18         }
19
20 # Make sure all block sizes are the same
21 $n = &user_filesystems($u);
22 for($i=0; $i<$n; $i++) {
23         $bsize = &block_size($filesys{$i,'filesys'});
24         if ($last_bsize && $last_bsize != $bsize) {
25                 $variable_bsize++;
26                 }
27         }
28
29 if ($n) {
30         print &ui_subheading(&text('ufilesys_all', &html_escape($u)));
31
32         # Generate top header (showing blocks/files)
33         @hcols = ( undef, $variable_bsize ? $text{'ufilesys_blocks'}
34                                           : $text{'ufilesys_space'},
35                    $config{'show_grace'} ? ( undef ) : ( ),
36                    $text{'ufilesys_files'},
37                    $config{'show_grace'} ? ( undef ) : ( ) );
38         print &ui_columns_start(\@hcols, 100, 0,
39                 [ undef, "colspan=3 align=center", "colspan=3 align=center" ]);
40
41         # Generate second header
42         @hcols = ( $text{'ufilesys_fs'}, $text{'ufilesys_used'},
43                    $text{'ufilesys_soft'}, $text{'ufilesys_hard'},
44                    $config{'show_grace'} ? ( $text{'ufilesys_grace'} ) : ( ),
45                    $text{'ufilesys_used'},
46                    $text{'ufilesys_soft'}, $text{'ufilesys_hard'},
47                    $config{'show_grace'} ? ( $text{'ufilesys_grace'} ) : ( ),
48                  );
49         print &ui_columns_header(\@hcols);
50
51         # Generate one row per filesystem the user has quota on
52         for($i=0; $i<$n; $i++) {
53                 $f = $filesys{$i,'filesys'};
54                 $bsize = &block_size($f);
55                 local @cols;
56                 if ($fslist{$f} && !$access{'ro'}) {
57                         push(@cols, "<a href=\"edit_user_quota.cgi?filesys=$f&user=$u&source=1\">$f</a>");
58                         }
59                 else {
60                         push(@cols, $f);
61                         }
62                 if ($bsize) {
63                         push(@cols, &nice_size($filesys{$i,'ublocks'}*$bsize));
64                         }
65                 else {
66                         push(@cols, $filesys{$i,'ublocks'});
67                         }
68                 push(@cols, &nice_limit($filesys{$i,'sblocks'}, $bsize));
69                 push(@cols, &nice_limit($filesys{$i,'hblocks'}, $bsize));
70                 push(@cols, $filesys{$i,'gblocks'}) if ($config{'show_grace'});
71                 push(@cols, $filesys{$i,'ufiles'});
72                 push(@cols, &nice_limit($filesys{$i,'sfiles'}, $bsize, 1));
73                 push(@cols, &nice_limit($filesys{$i,'hfiles'}, $bsize, 1));
74                 push(@cols, $filesys{$i,'gfiles'}) if ($config{'show_grace'});
75                 print &ui_columns_row(\@cols);
76                 }
77         print &ui_columns_end();
78         }
79 else {
80         print "<b>",&text('ufilesys_nouquota', $u),"</b><p>\n";
81         }
82
83 if (!$access{'ro'}) {
84         print &ui_hr();
85         print &ui_buttons_start();
86
87         # Form to edit quota on other filesystems
88         print &ui_buttons_row("edit_user_quota.cgi",
89                 $text{'ufilesys_edit'},
90                 $text{'ufilesys_editdesc'},
91                 &ui_hidden("user", $u).&ui_hidden("source", 1),
92                 &ui_select("filesys", undef, \@fslist)
93                 );
94
95         if ($access{'filesys'} eq "*") {
96                 # Button to copy quotas
97                 print &ui_buttons_row("copy_user_form.cgi",
98                         $text{'ufilesys_copy'},
99                         $text{'ufilesys_copydesc'},
100                         &ui_hidden("user", $u));
101                 }
102
103         print &ui_buttons_end();
104         }
105
106 &ui_print_footer("", $text{'ufilesys_return'});
107
108