Handle hostnames with upper-case letters
[webmin.git] / fdisk / edit_hdparm.cgi
1 #!/usr/local/bin/perl
2 # edit_hdparm.cgi
3 # Edit an IDE parameters for some disk
4
5 require './fdisk-lib.pl';
6 &ReadParse();
7 @dlist = &list_disks_partitions();
8 $d = $dlist[$in{'disk'}];
9 &can_edit_disk($d->{'device'}) ||
10         &error($text{'edit_ecannot'});
11
12 &ui_print_header($d->{'desc'}, $text{'hdparm_title'}, "");
13 if ( ! &has_command( "hdparm" ) ) {
14         print "<p>$text{ 'edit_ehdparm' }<p>\n";
15         &ui_print_footer( "", $text{ 'index_return' } );
16         exit;
17         }
18
19 %hdparm = ( 'A', "1", 'K', "0", 'P', "0", 'X', "0", 'W', "0", 'S', "0" );
20 @yesno = ( "1", $text{ 'hdparm_on' }, "0", $text{ 'hdparm_off' } );
21
22 foreach $argument ( 'a', 'd', 'r', 'k', 'u', 'm', 'c' )
23 {
24     $out = `hdparm -$argument $d->{'device'}`;
25     if ($out =~ /\s+=\s+(\S+)/) {
26         $hdparm{ $argument } = $1;
27         }
28     #( $_, $line ) = split( /=/, `hdparm -$argument $d->{'device'}` );
29     #$line =~ s/ {1,}//;
30     #( $hdparm{ $argument } ) = split( / /, $line );
31 }
32
33 # Javascript for slider
34 print(
35 "<script type=\"text/javascript\" src=\"range.js\"></script>
36 <script type=\"text/javascript\" src=\"timer.js\"></script>
37 <script type=\"text/javascript\" src=\"slider.js\"></script>
38 <link type=\"text/css\" rel=\"StyleSheet\" href=\"winclassic.css\" />");
39
40 # Form header
41 print &ui_form_start("apply_hdparm.cgi");
42 print &ui_hidden("drive", $d->{'device'});
43 print &ui_table_start($text{'hdparm_label'}, "width=100%", 4);
44
45 # Transfer mode
46 print &ui_table_row(&hlink($text{'hdparm_conf_X'}, 'X'),
47         &ui_select("X", $hdparm{'X'},
48                 [ [ "0", $text{ 'hdparm_conf_X_defaut' } ], [ "1", $text{ 'hdparm_conf_X_disable' } ], [ "9", "PIO mode 1", ], [ "10", "PIO mode 2" ], [ "11", "PIO mode 3" ], [ "12", "PIO mode 4" ], [ "32", "Multimode DMA 0" ], [ "33", "Multimode DMA 1" ], [ "34", "Multimode DMA 2" ], [ "64", "Ultra DMA 0" ], [ "65", "Ultra DMA 1" ], [ "66", "Ultra DMA 2" ] ], 1, 0, 1));
49
50 # Sector count
51 print &ui_table_row(&hlink($text{'hdparm_conf_a'},"a"),
52         &ui_textbox("a", $hdparm{'a'}, 2));
53
54 # Other yes/no options
55 foreach $o ('d', 'A', 'W', 'u', 'k', 'K', 'r', 'P') {
56         print &ui_table_row(&hlink($text{'hdparm_conf_'.$o}, $o),
57                 &ui_yesno_radio($o, $hdparm{$o}));
58         }
59
60 # Standby timeout (slider)
61 print &ui_table_row(&hlink($text{'hdparm_conf_S'}, 'S'),
62         &p_slider( "S", 0, 251, 0), 3);
63
64 # 32-bit I/O support
65 print &ui_table_row(&hlink($text{'hdparm_conf_c'}, 'c'),
66         &ui_radio('c', $hdparm{'c'},
67                   [ [ 0, $text{'hdparm_disable'} ],
68                     [ 1, $text{'hdparm_enable'} ],
69                     [ 3, $text{'hdparm_enable_special'} ] ]), 3);
70
71 # Sector count for multiple sector I/O
72 print &ui_table_row(&hlink($text{'hdparm_conf_m'}, 'm'),
73         &ui_radio('m', $hdparm{'m'},
74                   [ [ 0, $text{'hdparm_disable'} ],
75                     [ 2 ], [ 4 ], [ 8 ], [ 16 ], [ 32 ] ]), 3);
76
77 print &ui_table_end();
78 print &ui_form_end([ [ 'action', $text{'hdparm_apply'} ],
79                      [ 'action', $text{'hdparm_speed'} ] ]);
80
81 &ui_print_footer( "", $text{ 'index_return' } );
82
83 # Javascript for slider
84 print "<script type=\"text/javascript\">
85
86 var sliderEl = document.getElementById ?
87                   document.getElementById(\"S-slider\") : null;
88 var inputEl = document.forms[0][\"S\"];
89
90 var s = new Slider(sliderEl, inputEl);
91
92 function format_time(t_sec) {
93         
94         if ( t_sec >= 3600 ) {
95                 var t_hour = (t_sec - (t_sec % 3600))/3600;
96                 return t_hour + \" hours \" + format_time(t_sec % 3600);
97         } else if ( t_sec >= 60 ){
98                 var t_min = (t_sec - (t_sec % 60))/60;
99                 return t_min + \" minutes \" + format_time(t_sec % 60);;
100         } else if ( t_sec > 0 ){
101                 return t_sec + \" seconds \";
102         } else {
103                 return \" \";
104         }
105 };
106
107 s.onchange = function () {
108         var flag = s.getValue();
109         var t_sec = 0;
110         if (flag < 241) {
111                 t_sec = flag * 5;
112         } else {
113                 t_sec = (flag -240) * 30 * 60;
114         }
115
116         if (t_sec == 0) {
117                 document.getElementById(\"S-text-id\").value = \"always on\";
118         } else {
119                 document.getElementById(\"S-text-id\").value = format_time(t_sec);
120         }
121 };
122
123 s.setValue(0);
124 s.setMinimum(0);
125 s.setMaximum(251);
126
127 </script>";
128
129 # Returns a slider
130 sub p_slider
131 {
132    my ( $name, $min, $max, $default ) = @_;
133    local $out;
134
135    $out .= "<div class=\"slider\" id=\"". $name ."-slider\" tabIndex=\"1\">";
136    $out .= "<input class=\"slider-input\" id=\"".$name."-slider-input\"";
137    $out .= " name=\"".$name."\"/></div>";
138    $out .= "<input type=text name=\"".$name."-text\" id=\"".$name."-text-id\" readonly value=\"This field is not used\" >";
139
140    return $out;
141 }
142
143