Handle hostnames with upper-case letters
[webmin.git] / zones / save_fs.cgi
1 #!/usr/local/bin/perl
2 # Update, add or delete a filesystem
3
4 require './zones-lib.pl';
5 do 'forms-lib.pl';
6 &ReadParse();
7 $zinfo = &get_zone($in{'zone'});
8 $zinfo || &error($text{'edit_egone'});
9 if (!$in{'new'}) {
10         # Find the filesystem object
11         ($fs) = grep { $_->{'dir'} eq $in{'old'} } @{$zinfo->{'fs'}};
12         $fs || &error($text{'fs_egone'});
13         $mount = &get_active_mount($zinfo, $fs);
14         }
15 else {
16         $fs = { 'keytype' => 'fs',
17                 'type' => $in{'type'} };
18         }
19
20 if ($in{'delete'}) {
21         # Just remove this filesystem
22         &delete_zone_object($zinfo, $fs);
23
24         # Attempt to un-mount it (if mounted)
25         if ($mount) {
26                 &error_setup($text{'fs_err3'});
27                 &mount::unmount_dir(@$mount);
28                 }
29         }
30 else {
31         # Validate inputs
32         $form = &get_fs_form(\%in, $zinfo, $fs, $fs->{'type'});
33         $form->validate_redirect("edit_fs.cgi");
34         $fs->{'dir'} = $form->get_value("dir");
35         if (&indexof($fs->{'type'}, &mount::list_fstypes()) >= 0) {
36                 # Parse friendly filesystem forms
37                 $fs->{'special'} = &mount::check_location($fs->{'type'});
38                 &mount::check_options($fs->{'type'});
39                 $fs->{'options'} = &mount::join_options($fs->{'type'});
40                 }
41         else {
42                 # Just use user-entered device and options
43                 $fs->{'special'} = $form->get_value("special");
44                 $fs->{'options'} = $form->get_value("options");
45                 }
46         if ($fs->{'special'} =~ /^\/dev\/dsk\/(.*)$/) {
47                 $fs->{'raw'} = "/dev/rdsk/$1";
48                 }
49         &find_clash($zinfo, $fs) &&
50                 $form->validate_redirect("edit_fs.cgi",
51                         [ [ "dir", $text{'fs_eclash'} ] ]);
52
53         # Save the filesystem settings
54         $mp = &get_zone_root($zinfo).$fs->{'dir'};
55         if ($in{'new'}) {
56                 &create_zone_object($zinfo, $fs);
57
58                 # Attempt to mount it
59                 if ($in{'mount'}) {
60                         &error_setup($text{'fs_err2'});
61                         &system_logged("mkdir -p ".quotemeta($mp));
62                         &mount::mount_dir($mp,
63                                           $fs->{'special'},
64                                           $fs->{'type'},
65                                           $fs->{'options'});
66                         }
67                 }
68         else {
69                 &modify_zone_object($zinfo, $fs);
70
71                 # Attempt to re-mount it
72                 if ($mount) {
73                         &error_setup($text{'fs_err4'});
74                         &mount::unmount_dir(@$mount);
75                         if ($fs->{'dir'} ne $in{'old'}) {
76                                 &system_logged("mkdir -p ".quotemeta($mp));
77                                 }
78                         print STDERR "mounting $fs->{'special'} on $mp with type $fs->{'type'} and options $fs->{'options'}\n";
79                         &mount::mount_dir($mp,
80                                           $fs->{'special'},
81                                           $fs->{'type'},
82                                           $fs->{'options'});
83                         }
84                 }
85         }
86
87 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
88             "fs", $in{'old'} || $fs->{'dir'}, $fs);
89 &redirect("edit_zone.cgi?zone=$in{'zone'}");
90