Handle hostnames with upper-case letters
[webmin.git] / smart-status / index.cgi
1 #!/usr/local/bin/perl
2 # Show all drives and their SMART status
3
4 require './smart-status-lib.pl';
5 &ReadParse();
6
7 # Make sure SMART commands are installed
8 if (!&has_command($config{'smartctl'})) {
9         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
10         &ui_print_endpage(
11                 &ui_config_link('index_ecmd',
12                         [ "<tt>$config{'smartctl'}</tt>", undef ]));
13         }
14
15 # Show the version
16 $ver = &get_smart_version();
17 if (!$ver) {
18         &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
19         &ui_print_endpage(
20                 &ui_config_link('index_ecmd2',
21                         [ "<tt>$config{'smartctl'}</tt>", undef ]));
22         }
23 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
24                  &help_search_link("smartctl", "man", "doc", "google"),
25                  undef, undef,
26                  &text('index_version', $ver));
27
28 # Get list of drives
29 @drives = &list_smart_disks_partitions();
30 if (!@drives) {
31         &ui_print_endpage($text{'index_eidescsi'});
32         }
33
34 if ($config{'mode'} == 1 || $in{'drive'}) {
35         # Just show one drive, selected from menu
36         print &ui_form_start("index.cgi");
37         print "<b>$text{'index_show'}</b>\n";
38         print &ui_select("drive", $in{'drive'},
39                          [ map { [ $_->{'device'}.":".$_->{'subdisk'},
40                                    $_->{'desc'}.($_->{'model'} ? " ($_->{'model'})" : "") ] } @drives ],
41                          1, 0, 0, 0, "onChange='form.submit()'");
42         print &ui_submit($text{'index_ok'}),"\n";
43         print &ui_form_end();
44
45         if ($in{'drive'}) {
46                 ($device, $subdisk) = split(/:/, $in{'drive'});
47                 ($d) = grep { $_->{'device'} eq $device &&
48                               $_->{'subdisk'} == $subdisk } @drives;
49                 &show_drive($d);
50                 }
51         }
52 else {
53         # Show all IDE drives
54         foreach $d (@drives) {
55                 &show_drive($d);
56                 }
57         }
58
59 &ui_print_footer("/", $text{'index'});
60
61 # show_drive(&drive)
62 sub show_drive
63 {
64 print &ui_form_start("action.cgi");
65 print &ui_hidden("drive", $_[0]->{'device'});
66 print &ui_hidden("subdisk", $_[0]->{'subdisk'});
67 local $h = defined($_[0]->{'subdisk'}) ?
68         &text('index_drivesub', "<tt>$_[0]->{'device'}</tt>",
69                                 $_[0]->{'subdisk'}) :
70         &text('index_drive', "<tt>$_[0]->{'device'}</tt>");
71 print &ui_table_start($h, "width=100%", 4,
72                       [ "width=30%", undef, "width=30%", undef ]);
73 local $st = &get_drive_status($_[0]->{'device'}, $_[0]);
74 print &ui_table_row($text{'index_desc'},
75                     $_[0]->{'desc'});
76 if ($_[0]->{'cylsize'}) {
77         print &ui_table_row($text{'index_size'},
78                     &nice_size($_[0]->{'cylinders'}*$_[0]->{'cylsize'}));
79         }
80 if ($_[0]->{'model'}) {
81         print &ui_table_row($text{'index_model'},
82                             $_[0]->{'model'});
83         }
84 print &ui_table_row($text{'index_support'},
85                     $st->{'support'} ? $text{'yes'} : $text{'no'});
86 print &ui_table_row($text{'index_enabled'},
87                     $st->{'enabled'} ? $text{'yes'} : $text{'no'});
88 if ($st->{'support'} && $st->{'enabled'}) {
89         if ($st->{'errors'}) {
90                 print &ui_table_row($text{'index_errors'},
91                                     "<font color=#ff0000>".
92                                     &text('index_ecount', $st->{'errors'}).
93                                     "</font>");
94                 }
95         print &ui_table_row($text{'index_check'},
96                             $st->{'check'} ? $text{'yes'} :
97                                 "<font color=#ff0000>$text{'no'}</font>");
98         }
99 print &ui_table_end();
100
101 # Show extra attributes
102 if ($config{'attribs'} && @{$st->{'attribs'}}) {
103         $attrs_count++;
104         print &ui_hidden_table_start($text{'index_attrs'}, "width=100%", 2,
105                                      "attrs".$attrs_count, 1, [ "width=30%" ]);
106         foreach my $a (@{$st->{'attribs'}}) {
107                 next if ($a->[0] =~ /UDMA CRC Error Count/i); # too long
108                 print &ui_table_row($a->[0],
109                         $a->[2] =~ /^\s*(seconds|minutes|hours|days|months|years|weeks)\s*/i || !$a->[2] ? $a->[1]." ".$a->[2] : $a->[2]);
110                 }
111         print &ui_hidden_table_end();
112         }
113
114 # Show raw data from smartctl
115 if ($config{'attribs'} && $st->{'raw'}) {
116         $raw_count++;
117         print &ui_hidden_table_start($text{'index_raw'}, "width=100%", 2,
118                              "raw".$raw_count, @{$st->{'attribs'}} ? 0 : 1);
119         print &ui_table_row(undef,
120                 "<pre>".&html_escape($st->{'raw'})."</pre>", 2);
121         print &ui_hidden_table_end();
122         }
123
124 if ($st->{'support'} && $st->{'enabled'}) {
125         print &ui_form_end([ [ "short", $text{'index_short'} ],
126                              [ "ext", $text{'index_ext'} ],
127                              [ "data", $text{'index_data'} ] ]);
128         }
129 else {
130         print &ui_form_end();
131         }
132 }
133