Handle hostnames with upper-case letters
[webmin.git] / lvm / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a table of all volumne groups and their physical and logical volumes.
4
5 require './lvm-lib.pl';
6 &ReadParse();
7
8 if (!&has_command("vgdisplay")) {
9         &lvm_header();
10         print &text('index_ecommands', "<tt>vgdisplay</tt>"),"<p>\n";
11         &ui_print_footer("/", $text{'index'});
12         exit;
13         }
14 ($lvm_version, $out) = &get_lvm_version();
15 if ($lvm_version && $lvm_version < 2) {
16         # /proc/lvm doesn't exist in LVM 2
17         if (!-d $lvm_proc) {
18                 system("modprobe lvm-mod >/dev/null 2>&1");
19                 }
20         if (!-d $lvm_proc) {
21                 &lvm_header();
22                 print &text('index_emodule', "<tt>$lvm_proc</tt>",
23                                   "<tt>lvm-mod</tt>"),"<p>\n";
24                 &ui_print_footer("/", $text{'index'});
25                 exit;
26                 }
27         }
28 if (!$lvm_version) {
29         &lvm_header();
30         print &text('index_eversion', "<tt>vgdisplay --version</tt>",
31                           "<pre>$out</pre>"),"<p>\n";
32         &ui_print_footer("/", $text{'index'});
33         exit;
34         }
35 &lvm_header();
36
37 @vgs = &list_volume_groups();
38 if (@vgs) {
39         # Start tabs for volume groups, physical volumes and logical volumes
40         @tabs = ( [ 'vgs', $text{'index_vgs'}, 'index.cgi?mode=vgs' ],
41                   [ 'pvs', $text{'index_pvs'}, 'index.cgi?mode=pvs' ],
42                   [ 'lvs', $text{'index_lvs'}, 'index.cgi?mode=lvs' ] );
43         print &ui_tabs_start(\@tabs, "mode", $in{'mode'} || 'vgs', 1);
44
45         # Show volume groups
46         print &ui_tabs_start_tab("mode", "vgs");
47         print $text{'index_vgsdesc'},"<p>\n";
48         @vgs = sort { $a->{'number'} <=> $b->{'number'} } @vgs;
49         @links = ( "<a href='edit_vg.cgi'>$text{'index_add'}</a>" );
50         if ($config{'show_table'}) {
51                 # As table
52                 print &ui_links_row(\@links);
53                 print &ui_columns_start([ $text{'index_vgname'},
54                                           $text{'index_vgsize'},
55                                           $text{'index_vgtotal'},
56                                           $text{'index_vgtotal2'} ], 100);
57                 foreach $v (@vgs) {
58                         print &ui_columns_row([
59                           "<a href='edit_vg.cgi?vg=".
60                             &urlize($v->{'name'})."'>".
61                             &html_escape($v->{'name'})."</a>",
62                           &nice_size($v->{'size'}*1024),
63                           &text('lv_petotals', $v->{'pe_alloc'},
64                                                $v->{'pe_total'}),
65                           &text('lv_petotals',
66                             &nice_size($v->{'pe_alloc'}*$v->{'pe_size'}*1024),
67                             &nice_size($v->{'pe_total'}*$v->{'pe_size'}*1024))
68                           ]);
69                         }
70                 print &ui_columns_end();
71                 }
72         else {
73                 # As icons
74                 print &ui_links_row(\@links);
75                 foreach $v (@vgs) {
76                         push(@vgicons, "edit_vg.cgi?vg=".&urlize($v->{'name'}));
77                         push(@vgtitles, &html_escape($v->{'name'}).
78                                         "<br>".&nice_size($v->{'size'}*1024));
79                         push(@vglinks, "images/vg.gif");
80                         }
81                 &icons_table(\@vgicons, \@vgtitles, \@vglinks);
82                 }
83         print &ui_links_row(\@links);
84         print &ui_tabs_end_tab();
85
86         # Show physical volumes
87         print &ui_tabs_start_tab("mode", "pvs");
88         print $text{'index_pvsdesc'},"<p>\n";
89         foreach $v (@vgs) {
90                 push(@allpvs, &list_physical_volumes($v->{'name'}));
91                 }
92         @allpvs = sort { $a->{'name'} cmp $b->{'name'} } @allpvs;
93         @links = ( );
94         foreach $v (@vgs) {
95                 push(@links, "<a href='edit_pv.cgi?vg=".&urlize($v->{'name'}).
96                              "'>".&text('index_addpv2', $v->{'name'})."</a>");
97                 }
98         if (!@allpvs) {
99                 # None yet
100                 print "<b>$text{'index_nopvs2'}</b><p>\n";
101                 }
102         elsif ($config{'show_table'}) {
103                 # Show table of PVs
104                 print &ui_links_row(\@links);
105                 print &ui_columns_start([ $text{'index_pvname'},
106                                           $text{'index_pvvg'},
107                                           $text{'index_pvsize'},
108                                           $text{'index_pvtotal'},
109                                           $text{'index_pvtotal2'} ], 100);
110                 foreach $p (@allpvs) {
111                         ($v) = grep { $_->{'name'} eq $p->{'vg'} } @vgs;
112                         print &ui_columns_row([
113                           "<a href='edit_pv.cgi?vg=".&urlize($v->{'name'}).
114                             "&pv=".&urlize($p->{'name'})."'>$p->{'name'}</a>",
115                           $v->{'name'},
116                           &nice_size($p->{'size'}*1024),
117                           &text('lv_petotals', $p->{'pe_alloc'},
118                                                $p->{'pe_total'}),
119                           &text('lv_petotals',
120                             &nice_size($p->{'pe_alloc'}*$p->{'pe_size'}*1024),
121                             &nice_size($p->{'pe_total'}*$p->{'pe_size'}*1024)),
122                           ]);
123                         }
124                 print &ui_columns_end();
125                 }
126         else {
127                 # Show PV icons
128                 print &ui_links_row(\@links);
129                 foreach $p (@allpvs) {
130                         ($v) = grep { $_->{'name'} eq $p->{'vg'} } @vgs;
131                         push(@pvicons, "edit_pv.cgi?vg=".&urlize($v->{'name'}).
132                                        "&pv=".&urlize($p->{'name'}));
133                         push(@pvtitles, &html_escape($p->{'name'}).
134                                         "<br>".&nice_size($p->{'size'}*1024));
135                         push(@pvlinks, "images/vg.gif");
136                         }
137                 &icons_table(\@pvicons, \@pvtitles, \@pvlinks);
138                 }
139         print &ui_links_row(\@links);
140         print &ui_tabs_end_tab();
141
142         # Show logical volumes
143         print &ui_tabs_start_tab("mode", "lvs");
144         print $text{'index_lvsdesc'},"<p>\n";
145         foreach $v (@vgs) {
146                 push(@alllvs, &list_logical_volumes($v->{'name'}));
147                 }
148         @alllvs = sort { $a->{'name'} cmp $b->{'name'} } @alllvs;
149         @links = ( );
150         foreach $v (@vgs) {
151                 push(@links, "<a href='edit_lv.cgi?vg=".&urlize($v->{'name'}).
152                              "'>".&text('index_addlv2', $v->{'name'})."</a>");
153                 @lvsin = grep { $_->{'vg'} eq $v->{'name'} } @alllvs;
154                 if (@lvsin) {
155                         push(@links,
156                           "<a href='edit_lv.cgi?vg=".&urlize($v->{'name'}).
157                           "&snap=1'>".&text('index_addlv2s', $v->{'name'}).
158                           "</a>");
159                         }
160                 }
161         if (!@alllvs) {
162                 # None yet
163                 print "<b>$text{'index_nolvs2'}</b><p>\n";
164                 }
165         elsif ($config{'show_table'}) {
166                 # Show table of LVs
167                 print &ui_links_row(\@links);
168                 print &ui_columns_start([ $text{'index_lvname'},
169                                           $text{'index_lvvg'},
170                                           $text{'index_lvsize'},
171                                           $text{'index_lvused'},
172                                           $text{'index_lvuse'} ], 100);
173                 foreach $l (@alllvs) {
174                         ($v) = grep { $_->{'name'} eq $l->{'vg'} } @vgs;
175                         if ($lv->{'is_snap'}) {
176                                 ($snapof) = grep {
177                                         $_->{'size'} == $l->{'size'} &&
178                                         $_->{'vg'} eq $l->{'vg'} &&
179                                         $_->{'has_snap'} } @alllvs;
180                                 }
181                         else {
182                                 $snapof = undef;
183                                 }
184                         @stat = &device_status($l->{'device'});
185                         $usedmsg = "";
186                         if (@stat[2]) {
187                                 ($total, $free) = &mount::disk_space(
188                                         $stat[1], $stat[0]);
189                                 if ($total) {
190                                         $usedmsg = &text('lv_petotals',
191                                                 &nice_size(($total-$free)*1024),
192                                                 &nice_size($total*1024));
193                                         }
194                                 }
195                         print &ui_columns_row([
196                           "<a href='edit_lv.cgi?vg=".&urlize($v->{'name'}).
197                             "&lv=".&urlize($l->{'name'})."'>$l->{'name'}</a>",
198                           $v->{'name'},
199                           &nice_size($l->{'size'}*1024),
200                           $usedmsg,
201                           (@stat ? &device_message(@stat) : undef).
202                           ($snap ? " ".&text('index_snapof', $snap->{'name'})
203                                  : ""),
204                           ]);
205                         }
206                 print &ui_columns_end();
207                 }
208         else {
209                 # Show PV icons
210                 print &ui_links_row(\@links);
211                 foreach $l (@alllvs) {
212                         ($v) = grep { $_->{'name'} eq $l->{'vg'} } @vgs;
213                         push(@lvicons, "edit_lv.cgi?vg=".&urlize($v->{'name'}).
214                                        "&lv=".&urlize($l->{'name'}));
215                         push(@lvtitles, &html_escape($l->{'name'}).
216                                         "<br>".&nice_size($l->{'size'}*1024));
217                         push(@lvlinks, "images/lv.gif");
218                         }
219                 &icons_table(\@lvicons, \@lvtitles, \@lvlinks);
220                 }
221         print &ui_links_row(\@links);
222         print &ui_tabs_end_tab();
223
224         print &ui_tabs_end(1);
225         }
226 else {
227         print "<b>$text{'index_none'}</b> <p>\n";
228         @tab = &list_lvmtab();
229         if (@tab) {
230                 # Maybe LVM needs to be re-started
231                 print &text('index_init', "init.cgi"),"<p>\n";
232                 }
233         print &ui_links_row([
234                 "<a href='edit_vg.cgi'>$text{'index_add'}</a>" ]);
235         }
236
237 &ui_print_footer("/", $text{'index'});
238
239 sub lvm_header
240 {
241 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
242         &help_search_link("lvm", "man", "doc", "google"), undef, undef,
243         $lvm_version ? &text('index_version', $lvm_version) : undef);
244 }
245