Handle hostnames with upper-case letters
[webmin.git] / raid / index.cgi
1 #!/usr/local/bin/perl
2 # Display all RAID devices
3
4 require './raid-lib.pl';
5
6 # Check if raid is installed
7 if (!-r $config{'mdstat'}) {
8         &error_exit(&text('index_emdstat', "<tt>$config{'mdstat'}</tt>"));
9         }
10 if (&has_command("mdadm")) {
11         # Using mdadm commands
12         $raid_mode = "mdadm";
13         $raid_ver = &get_mdadm_version();
14         }
15 elsif (&has_command('mkraid') && &has_command('raidstart')) {
16         # Using raid tools commands
17         $raid_mode = "raidtools";
18         }
19 else {
20         &error_exit($text{'index_eprogs'});
21         }
22 &open_tempfile(MODE, ">$module_config_directory/mode");
23 &print_tempfile(MODE, $raid_mode,"\n");
24 &close_tempfile(MODE);
25
26 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
27         &help_search_link("raid", "man", "doc"),
28         undef, undef, &text('index_'.$raid_mode, $raid_ver));
29
30 # Display configured raid devices
31 $conf = &get_raidtab();
32 if (@$conf) {
33         print &ui_columns_start([ $text{'index_name'},
34                                 $text{'index_active'},
35                                 $text{'index_level'},
36                                 $text{'index_size'},
37                                 $text{'index_members'} ]);
38         foreach $c (@$conf) {
39                 $lvl = &find_value('raid-level', $c->{'members'});
40                 @mems = ( );
41                 foreach $d (&find('device', $c->{'members'})) {
42                         if (&find('raid-disk', $d->{'members'}) ||
43                             &find('parity-disk', $d->{'members'})) {
44                                 push(@mems, $d->{'value'});
45                                 }
46                         }
47                 print &ui_columns_row([
48                         "<a href='view_raid.cgi?idx=$c->{'index'}'>".
49                         &html_escape($c->{'value'})."</a>",
50                         $c->{'active'} ?
51                                 "<font color=#00aa00>$text{'yes'}</font>" :
52                                 "<font color=#ff0000>$text{'no'}</font>",
53                         $lvl eq 'linear' ? $text{'linear'} : $text{'raid'.$lvl},
54                         $c->{'size'} ? &nice_size($c->{'size'}*1024) : "",
55                         &ui_links_row(\@mems),
56                         ]);
57                 }
58         print &ui_columns_end();
59         }
60 else {
61         print "<p><b>$text{'index_none'}</b><p>\n";
62         }
63 &show_button();
64
65 # Form for mdadm monitoring options
66 if ($raid_mode eq "mdadm") {
67         $notif = &get_mdadm_notifications();
68         print &ui_hr();
69         print &ui_form_start("save_mdadm.cgi", "post");
70         print &ui_table_start($text{'index_header'}, undef, 2, [ "width=30%" ]);
71
72         # Is monitoring enabled?
73         if (&get_mdadm_action()) {
74                 print &ui_table_row($text{'index_monitor'},
75                    &ui_yesno_radio("monitor", &get_mdadm_monitoring() ? 1 : 0));
76                 }
77
78         # Notification address
79         print &ui_table_row($text{'index_mailaddr'},
80                 &ui_opt_textbox("mailaddr", $notif->{'MAILADDR'}, 40,
81                                 $text{'index_mailaddrnone'}));
82
83         # Notification sender
84         print &ui_table_row($text{'index_mailfrom'},
85                 &ui_opt_textbox("mailfrom", $notif->{'MAILFROM'}, 40,
86                                 $text{'index_mailfromnone'}));
87
88         # Program to call for problems
89         print &ui_table_row($text{'index_program'},
90                 &ui_opt_textbox("program", $notif->{'PROGRAM'}, 40,
91                                 $text{'index_programnone'}));
92
93         print &ui_table_end();
94         print &ui_form_end([ [ undef, $text{'save'} ] ]);
95         }
96
97 &ui_print_footer("/", $text{'index'});
98
99 sub show_button
100 {
101 print &ui_form_start("raid_form.cgi");
102 print &ui_submit($text{'index_add'});
103 local @levels = &get_raid_levels();
104 print &ui_select("level", "linear",
105                  [ [ "linear", $text{'linear'} ],
106                    map { [ $_, $text{'raid'.$_} ] } @levels ]),"\n";
107 print &ui_form_end();
108 }
109
110 sub error_exit
111 {
112 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
113         &help_search_link("raid", "man", "doc"));
114 print "<p><b>",@_,"</b><p>\n";
115 &ui_print_footer("/", $text{'index'});
116 exit;
117 }
118