Handle hostnames with upper-case letters
[webmin.git] / mount / edit_mount.cgi
1 #!/usr/local/bin/perl
2 # edit_mount.cgi
3 # Display a form for editing or creating a permanent or temporary mounting.
4
5 require './mount-lib.pl';
6 &error_setup($text{'edit_err'});
7 &ReadParse();
8 if (defined($in{index})) {
9         if ($in{temp}) {
10                 # Edit a temporary mount, existing only in the mnttab
11                 @mlist = &list_mounted();
12                 @minfo = @{$mlist[$in{index}]};
13                 $mnow = 1; $msave = 0;
14                 }
15         else {
16                 # Edit a permanent mount, which may or may not be currently
17                 # mounted.
18                 @mlist = &list_mounts();
19                 @minfo = @{$mlist[$in{index}]};
20                 $msave = 1; $mnow = (&get_mounted($minfo[0], $minfo[1]) >= 0);
21                 }
22         if ($in{index} >= @mlist) {
23                 &error($text{'edit_egone'});
24                 }
25         &can_edit_fs(@minfo) && !$access{'only'} ||
26                 &error($text{'edit_ecannot'});
27         $type = $minfo[2];
28         &ui_print_header(undef, $text{'edit_title'}, "");
29         $newm = 0;
30         }
31 else {
32         # creating a new mount (temporary or permanent)
33         $type = $in{type};
34         &ui_print_header(undef, $text{'create_title'}, "");
35         $newm = 1;
36         }
37 @mmodes = &mount_modes($type);
38 $msave = ($mmodes[0]==0 ? 0 : $msave);
39 $mnow = ($mmodes[1]==0 ? $msave : $mnow);
40
41 print "<form action=\"save_mount.cgi\">\n";
42 print "<input name=return type=hidden value='$in{'return'}'>\n";
43 if (!$newm) {
44         print "<input type=hidden name=old value=\"$in{index}\">\n";
45         print "<input type=hidden name=temp value=\"$in{temp}\">\n";
46
47         print "<input type=hidden name=oldmnow value=$mnow>\n";
48         print "<input type=hidden name=oldmsave value=$msave>\n";
49         }
50 print "<input type=hidden name=type value=\"$type\">\n";
51 print "<table border width=100%>\n";
52 print "<tr $tb> <td><b>",&text('edit_header', &fstype_name($type)),
53       "</b></td> </tr>\n";
54 print "<tr $cb> <td><table>\n";
55
56 print "<tr> <td>",&hlink("<b>$text{'edit_dir'}</b>", "edit_dir"), "</td>\n";
57 if ($type eq "swap") {
58         print "<td colspan=3><i>$text{'edit_swap'}</i></b>\n";
59         }
60 else {
61         local $dir = $minfo[0] || $in{'newdir'};
62         if (@access_fs == 1) {
63                 # Make relative to first allowed dir
64                 $dir =~ s/^$access_fs[0]\///;
65                 }
66         print "<td colspan=3><input size=30 name=directory value=\"",
67                 $dir,"\">\n";
68         if ($access{'browse'}) {
69                 print &file_chooser_button("directory", 1);
70                 }
71         }
72 if (!$newm && (($size,$free) = &disk_space($type, $minfo[0]))) {
73         print "&nbsp;" x 8;
74         printf "<b>$text{'edit_size'}</b> <i>%s</i> / \n",
75                 &nice_size($size*1024);
76         printf "<b>$text{'edit_free'}</b> <i>%s</i></td>\n",
77                 &nice_size($free*1024);
78         }
79 print "</td> </tr>\n";
80
81 # Show save mount options
82 if ($mmodes[0] != 0 && !$access{'simple'}) {
83         print "<tr> <td><b>$text{'edit_savemount'}</b></td> <td colspan=3>\n";
84         printf "<input type=radio name=msave value=2 %s> $text{'edit_boot'}\n",
85                 $minfo[5] eq "yes" || $newm ? "checked" : "";
86         if ($mmodes[0] != 1) {
87                 printf "<input type=radio name=msave value=1 %s> %s\n",
88                         $minfo[5] eq "no" ? "checked" : "", $text{'edit_save'};
89                 }
90         if (!$newm && $mmodes[1] == 0) {
91                 printf "<input type=radio name=msave value=0 %s> %s\n",
92                         $minfo[5] eq "" && !$newm ? "checked" : "",
93                         $text{'edit_delete'};
94                 }
95         else {
96                 printf "<input type=radio name=msave value=0 %s> %s\n",
97                         $minfo[5] eq "" && !$newm ? "checked" : "",
98                         $text{'edit_dont'};
99                 }
100         print "</td> </tr>\n";
101         }
102
103 # Show mount now options
104 if ($mmodes[1] == 1 && ($mmodes[3] == 0 || !$mnow) && !$access{'simple'}) {
105         print "<tr> <td><b>$text{'edit_now'}</b></td> <td colspan=3>\n";
106         printf "<input type=radio name=mmount value=1 %s> %s\n",
107                 $mnow || $newm ? "checked" : "", $text{'edit_mount'};
108         if ($mmodes[0] == 0) {
109                 printf "<input type=radio name=mmount value=0 %s> %s\n",
110                         $mnow || $newm ? "" : "checked", $text{'edit_delete'};
111                 }
112         else {
113                 printf "<input type=radio name=mmount value=0 %s> %s\n",
114                         $mnow || $newm ? "" : "checked",
115                         $newm ? $text{'edit_dont2'} : $text{'edit_unmount'};
116                 }
117         print "</td> </tr>\n";
118         }
119
120 # Show fsck order options
121 if ($mmodes[2] && !$access{'simple'}) {
122         print "<tr> <td><b>$text{'edit_order'}</b></td>\n";
123         printf "<td colspan=3><input type=radio name=order value=0 %s> %s\n",
124                 $newm || $minfo[4] == 0 ? "checked" : "", $text{'no'};
125         printf "<input type=radio name=order value=1 %s> %s\n",
126                 $minfo[4] == 1 ? "checked" : "", $text{'edit_first'};
127         printf "<input type=radio name=order value=%s %s> %s</td\n",
128                 $minfo[4] > 1 ? $minfo[4] : 2 , $minfo[4] > 1 ? "checked" : "",
129                 $text{'edit_second'};
130         print "</tr>\n";
131         }
132
133 # Show filesystem-specific mount source
134 &generate_location($type, $minfo[1] || $in{'newdev'});
135 print "</table></td> </tr></table><p>\n";
136
137 if (!$access{'simple'} || !defined($access{'opts'}) ||
138     $access{'opts'} =~ /$type/) {
139         # generate mount options
140         if ($in{'advanced'}) {
141                 $access{'simopts'} = 0;
142                 print &ui_hidden("nosimopts", 1),"\n";
143                 }
144         print "<table border width=100%>\n";
145         print "<tr $tb> <td><b>$text{'edit_adv'}</b></td> </tr>\n";
146         print "<tr $cb> <td><table width=100%>\n";
147         &parse_options($type, $minfo[3]);
148         &generate_options($type, $newm);
149         if ($access{'simopts'}) {
150                 print "<tr> <td colspan=4>",
151                         &ui_submit($text{'edit_advanced'}, "advanced"),
152                         "</td> </tr>\n";
153                 }
154         print "</table></td> </tr></table>\n";
155         }
156
157 if ($access{'simple'}) {
158         # buttons for mounting/unmounting
159         print "<table width=100%><tr>\n";
160         if ($newm) {
161                 print "<td><input type=submit ",
162                       "value=\"$text{'edit_create'}\"></td>";
163                 }
164         elsif ($msave && $mnow) {
165                 print "<td width=33%><input type=submit ",
166                       "value=\"$text{'edit_save_apply'}\"></td>\n";
167                 if ($mmodes[1]) {
168                         print "<td align=center width=33%><input type=submit ",
169                            "value=\"$text{'edit_umount'}\" name=umount></td>\n";
170                         }
171                 print "<td align=right width=33%><input type=submit ",
172                       "value=\"$text{'edit_del_umount'}\" name=delete></td>\n";
173                 }
174         elsif ($msave) {
175                 print "<td width=33%><input type=submit ",
176                       "value=\"$text{'save'}\"></td>\n";
177                 print "<td align=center width=33%><input type=submit ",
178                       "value=\"$text{'edit_mount'}\" name=mount></td>\n";
179                 print "<td align=right width=33%><input type=submit ",
180                       "value=\"$text{'edit_delete'}\" name=delete></td>\n";
181                 }
182         else {
183                 print "<td width=33%><input type=submit ",
184                       "value=\"$text{'save'}\"></td>\n";
185                 if ($mmodes[0]) {
186                         print "<td align=middle width=33%><input type=submit ",
187                               "value=\"$text{'edit_perm'}\" name=perm></td>\n";
188                         }
189                 print "<td align=right width=33%><input type=submit ",
190                       "value=\"$text{'edit_umount'}\" name=umount></td>\n";
191                 }
192         print "</tr></table></form>\n";
193         }
194 else {
195         # Save and other buttons
196         print "<table width=100%><tr>\n";
197         if ($newm) {
198                 print "<td><input type=submit value=\"$text{'create'}\"></td>";
199                 }
200         elsif ($mnow && $minfo[2] ne "swap") {
201                 print "<td><input type=submit value=\"$text{'save'}\"></td>\n";
202                 print "</form><form action=../proc/index_search.cgi>\n";
203                 print "<input type=hidden name=mode value=3>\n";
204                 print "<input type=hidden name=fs value=$minfo[0]>\n";
205                 print "<td align=right><input type=submit ",
206                       "value=\"$text{'edit_list'}\"></td>\n";
207                 }
208         else {
209                 print "<td><input type=submit value=\"$text{'save'}\"></td>";
210                 }
211         print "</tr></table></form>\n";
212         }
213 &ui_print_footer($in{'return'}, $text{'index_return'});
214