Handle hostnames with upper-case letters
[webmin.git] / file / list_exports.cgi
1 #!/usr/local/bin/perl
2 # list_exports.cgi
3 # Output info about NFS exports
4
5 require './file-lib.pl';
6 print "Content-type: text/plain\n\n";
7 if ($access{'uid'}) {
8         # User has no access to NFS
9         print "0\n";
10         exit;
11         }
12
13 &read_acl(\%acl, undef);
14 %einfo = &get_module_info("exports");
15 %dinfo = &get_module_info("dfsadmin");
16 #%binfo = &get_module_info("bsdexports");       # too hard
17
18 if (%einfo && &check_os_support(\%einfo)) {
19         # Linux NFS exports
20         &module_check("exports");
21         if (!&has_command("rpc.nfsd") && !&has_command("nfsd")) {
22                 print "0\n";
23                 exit;
24                 }
25         print "1\n";
26         &foreign_require("exports", "exports-lib.pl");
27         foreach $e (&foreign_call("exports", "list_exports")) {
28                 push(@{$exp{$e->{'dir'}}}, $e)
29                         if ($e->{'dir'} !~ /:/ && $e->{'host'} !~ /:/);
30                 }
31         foreach $d (keys %exp) {
32                 local $host;
33                 foreach $e (@{$exp{$d}}) {
34                         local $o = $e->{'options'};
35                         $host .= sprintf ":%s:%d:%d",
36                                 $e->{'host'} ? $e->{'host'} : '*',
37                                 defined($o->{'ro'}),
38                                 defined($o->{'all_squash'}) ? 0 :
39                                 defined($o->{'no_root_squash'}) ? 2 : 1;
40                         }
41                 print &make_chroot($d),$host,"\n";
42                 }
43         }
44 elsif (%dinfo && &check_os_support(\%dinfo)) {
45         # Solaris NFS shares
46         &module_check("dfsadmin");
47         print "2\n";
48         &foreign_require("dfsadmin", "dfs-lib.pl");
49         foreach $s (&foreign_call("dfsadmin", "list_shares")) {
50                 $opts = &foreign_call("dfsadmin", "parse_options",$s->{'opts'});
51                 $opts->{'ro'} = '-' if (!defined($opts->{'ro'}));
52                 $opts->{'ro'} =~ s/:/ /g;
53                 $opts->{'rw'} = '-' if (!defined($opts->{'rw'}));
54                 $opts->{'rw'} =~ s/:/ /g;
55                 $opts->{'root'} = '-' if (!defined($opts->{'root'}));
56                 $opts->{'root'} =~ s/:/ /g;
57                 printf "%s:%s:%s:%s:%s\n",
58                         &make_chroot($s->{'dir'}), $opts->{'ro'}, $opts->{'rw'},
59                         $opts->{'root'}, $s->{'desc'};
60                 }
61         }
62 elsif (%binfo && &check_os_support(\%binfo)) {
63         # BSD NFS exports
64         &module_check("bsdexports");
65         print "3\n";
66         &foreign_require("bsdexports", "bsdexports-lib.pl");
67         foreach $e (&foreign_call("bsdexports", "list_exports")) {
68                 foreach $d (@{$e->{'dirs'}}) {
69                         printf "%s:%s", $d, $e->{'ro'} ? 1 : 0;
70                         if ($e->{'network'}) {
71                                 printf ":%s/%s\n",
72                                         $e->{'network'}, $e->{'mask'};
73                                 }
74                         else {
75                                 foreach $h (@{$e->{'hosts'}}) {
76                                         print ":$h";
77                                         }
78                                 print "\n";
79                                 }
80                         }
81                 }
82         }
83 else {
84         # No NFS modules installed or supported
85         print "0\n";
86         }
87
88 sub module_check
89 {
90 if (!$acl{$base_remote_user,$_[0]}) {
91         print "0\n";
92         exit;
93         }
94 }
95