Handle hostnames with upper-case letters
[webmin.git] / mount / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a list of known filesystems, and indicate which are currently mounted
4
5 require './mount-lib.pl';
6 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
7         &help_search_link("mount fstab vfstab", "man"));
8
9 # List filesystems from fstab and mtab
10 @mounted = &list_mounted();
11 $yes = $text{'yes'};
12 $no = "<font color=#ff0000>$text{'no'}</a>";
13 foreach (&list_fstypes()) { $can_edit{$_}++; }
14 $i = 0;
15 foreach $m (&list_mounts()) {
16         $m->[0] = "swap" if ($m->[2] eq "swap");
17         $mounts{$m->[0],$m->[1]} = $i++;
18         push(@all, $m);
19         }
20 $i = 0;
21 foreach $m (&list_mounted()) {
22         $m->[0] = "swap" if ($m->[2] eq "swap");
23         $mounted{$m->[0],$m->[1]} = $i++;
24         push(@all, $m) if (!defined($mounts{$m->[0],$m->[1]}));
25         }
26
27 # Sort by chosen mode
28 if ($config{'sort_mode'} == 2) {
29         @all = sort { lc($a->[0]) cmp lc($b->[0]) } @all;
30         }
31 elsif ($config{'sort_mode'} == 1) {
32         @all = sort { &fstype_name($a->[2]) cmp &fstype_name($b->[2]) } @all;
33         }
34
35 # Build visible filesystems list
36 foreach $m (@all) {
37         @minfo = @$m;
38         $p = &simplify_mount_path($minfo[0], $minfo[2]);
39         next if ($ignore{$minfo[2]});
40         @mmodes = &mount_modes($minfo[2], $minfo[0], $minfo[1]);
41         $canedit = $can_edit{$minfo[2]} && !$mmodes[4] &&
42                    &can_edit_fs(@minfo);
43         next if (!$canedit && $access{'hide'});
44         push(@visible, $m);
45         }
46
47 if (@visible) {
48         # Show table of all visible filesystems
49         &show_button();
50         print &ui_columns_start([ $text{'index_dir'},
51                                 $text{'index_type'},
52                                 $text{'index_dev'},
53                                 $config{'show_used'} ? ( $text{'index_used'} )
54                                                      : ( ),
55                                 $text{'index_use'},
56                                 $text{'index_perm'} ], 100);
57         foreach $m (@visible) {
58                 @minfo = @$m;
59                 $p = &simplify_mount_path($minfo[0], $minfo[2]);
60
61                 $midx = $mounts{$minfo[0],$minfo[1]};
62                 $medidx = $mounted{$minfo[0],$minfo[1]};
63                 @mmodes = &mount_modes($minfo[2], $minfo[0], $minfo[1]);
64                 $canedit = $can_edit{$minfo[2]} && !$mmodes[4] &&
65                            &can_edit_fs(@minfo);
66                 local @cols;
67                 if ($canedit && !$access{'only'}) {
68                         if (defined($midx)) {
69                                 push(@cols, "<a href=\"edit_mount.cgi?".
70                                             "index=$midx\">$p</a>");
71                                 }
72                         else {
73                                 push(@cols, "<a href=\"edit_mount.cgi?".
74                                             "temp=1&index=$medidx\">$p</a>");
75                                 }
76                         }
77                 else {
78                         push(@cols, $p);
79                         }
80                 local $fsn = &fstype_name($minfo[2]);
81                 $fsn .= " ($minfo[2])" if (uc($fsn) ne uc($minfo[2]));
82                 push(@cols, $minfo[2] eq "*" ? $text{'index_auto'} : $fsn);
83                 push(@cols, &device_name($minfo[1]));
84                 if ($config{'show_used'}) {
85                         # Add disk space used column
86                         ($total, $free) = &disk_space($minfo[2],$minfo[0]);
87                         if ($total > 0 && $total >= $free) {
88                                 $pc = int(100*($total-$free) / $total);
89                                 push(@cols,
90                                  $pc >= 99 ? "<font color=red>$pc %</font>" :
91                                  $pc >= 95 ? "<font color=orange>$pc %</font>" :
92                                              $pc."%");
93                                 }
94                         else {
95                                 push(@cols, "");
96                                 }
97                         }
98                 if (&can_edit_fs(@minfo)) {
99                         push(@cols,
100                                 defined($medidx) ?
101                                 "<a href='unmount.cgi?index=$medidx'>$yes</a>" :
102                                 "<a href='mount.cgi?index=$midx'>$no</a>");
103                         }
104                 else {
105                         push(@cols, defined($medidx) ? $yes : $no);
106                         }
107                 push(@cols, defined($midx) ? $yes : $no);
108                 print &ui_columns_row(\@cols);
109                 }
110         print &ui_columns_end(),"<br>\n";
111         }
112 else {
113         print "<b>$text{'index_none'}</b><p>\n";
114         }
115 &show_button();
116
117 &ui_print_footer("/", $text{'index'});
118
119 sub simplify_mount_path
120 {
121 if ($_[1] eq "swap") {
122         return "<i>$text{'index_swap'}</i>";
123         }
124 elsif (length($_[0]) > 20) {
125         return &html_escape("... ".substr($_[0], length($_[0])-20));
126         }
127 elsif ($_[0] eq "/") {
128         return "/ (<i>$text{'index_root'}</i>)";
129         }
130 else {
131         return &html_escape($_[0]);
132         }
133 }
134
135 sub show_button
136 {
137 return if (!$access{'create'} || $access{'only'});
138 local %donefs;
139 print "<form action=\"edit_mount.cgi\">\n";
140 print "<input type=submit value=\"$text{'index_add'}\"> $text{'index_type'}:\n";
141 print "<select name=type>\n";
142 local $fs;
143 foreach $fs (sort { &fstype_name($a) cmp &fstype_name($b) } &list_fstypes()) {
144         local $nm = &fstype_name($fs);
145         if (!$donefs{$nm}++ && &can_fstype($fs)) {
146                 print "<option value=\"$fs\">$nm ($fs)\n";
147                 }
148         }
149 print "</select></form>\n";
150 }
151