Handle hostnames with upper-case letters
[webmin.git] / file / filesystems.cgi
1 #!/usr/local/bin/perl
2 # filesystems.cgi
3 # List all filesystems and their types
4
5 $trust_unknown_referers = 1;
6 require './file-lib.pl';
7 print "Content-type: text/plain\n\n";
8 if (!&foreign_check("mount") || !$access{'filesystems'}) {
9         print "0\n";
10         exit;
11         }
12 &foreign_require("mount", "mount-lib.pl");
13 @mtab = &mount::list_mounted();
14 %mtab = map { $_->[0], $_ } @mtab;
15 @fstab = &mount::list_mounts();
16 %fstab = map { $_->[0], $_ } @fstab;
17 @mounts = ( @fstab, grep { !$fstab{$_->[0]} } @mtab );
18
19 print "1\n";
20 foreach $m (sort { length($a->[0]) <=> length($b->[0]) } @mounts) {
21         next if ($m->[0] !~ /^\//);
22         local @supp = @{$support{$m->[2]}};
23         if (!@supp) {
24                 # Work out what this filesystem supports
25                 @supp = ( eval $config{$m->[2]."_acl"} ? 1 : 0,
26                           eval $config{$m->[2]."_attr"} ? 1 : 0,
27                           eval $config{$m->[2]."_ext"} ? 1 : 0 );
28                 $support{$m->[2]} = \@supp;
29                 }
30
31         # Check if the filesystem really does support attrs and ACLs
32         local @supp2 = @supp;
33         if ($mtab{$m->[0]}) {
34                 if ($supp2[0]) {
35                         local $out = `$config{'getfacl'} '$m->[0]' 2>/dev/null`;
36                         if ($?) {
37                                 $supp2[0] = 0;
38                                 }
39                         else {
40                                 local $aclcount;
41                                 foreach $l (split(/\n/, $out)) {
42                                         $l =~ s/#.*$//;
43                                         $l =~ s/\s+$//;
44                                         $aclcount++ if ($l =~ /\S/);
45                                         }
46                                 $supp2[0] = 0 if (!$aclcount);
47                                 }
48                         }
49                 if ($supp2[1]) {
50                         local $out = `attr -l '$m->[0]' 2>/dev/null`;
51                         if ($?) {
52                                 $supp2[1] = 0;
53                                 }
54                         }
55                 }
56
57         $m->[1] =~ s/\\/\//g;
58         $chrooted = &make_chroot($m->[0]);
59         if ($chrooted) {
60                 print join(" ", $chrooted, @$m[1..3], @supp2,
61                                 $mtab{$m->[0]} ? 1 : 0,
62                                 $fstab{$m->[0]} ? 1 : 0),"\n";
63                 }
64         }
65