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