1#!/usr/local/bin/perl
2# edit_mount.cgi
3# Display a form for editing or creating a permanent or temporary mounting.
4
5require './mount-lib.pl';
6&error_setup($text{'edit_err'});
7&ReadParse();
8if (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	}
31else {
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# Start of the form
42print &ui_form_start("save_mount.cgi", "post");
43print &ui_hidden("return", $in{'return'});
44if (!$newm) {
45	print &ui_hidden("old", $in{'index'});
46	print &ui_hidden("temp", $in{'temp'});
47	print &ui_hidden("oldmnow", $mnow);
48	print &ui_hidden("oldmsave", $msave);
49	}
50print &ui_hidden("type", $type);
51print &ui_table_start(&text('edit_header', &fstype_name($type)),
52		      "width=100%", 2, [ "width=20%" ]);
53
54# Mount point
55if ($type eq "swap") {
56	$mfield = "<i>$text{'edit_swap'}</i>";
57	}
58else {
59	local $dir = $minfo[0] || $in{'newdir'};
60	if (@access_fs == 1) {
61		# Make relative to first allowed dir
62		$dir =~ s/^$access_fs[0]\///;
63		}
64	$mfield = &ui_textbox("directory", $dir, 40);
65	if ($access{'browse'}) {
66		$mfield .= " ".&file_chooser_button("directory", 1);
67		}
68	}
69print &ui_table_row(&hlink($text{'edit_dir'}, "edit_dir"),
70		    $mfield);
71
72# Total and free space
73if (!$newm) {
74	($size,$free) = &disk_space($type, $minfo[0]);
75	if ($size) {
76		print &ui_table_row($text{'edit_usage'},
77			"<b>$text{'edit_size'}</b> ".
78			&nice_size($size*1024)." ".
79			"<b>$text{'edit_free'}</b> ".
80			&nice_size($free*1024));
81		}
82	}
83
84# Show save mount options
85if ($mmodes[0] != 0) {
86	@opts = ( [ 2, $text{'edit_boot'} ] );
87	if ($mmodes[0] != 1) {
88		push(@opts, [ 1, $text{'edit_save'} ]);
89		}
90	if (!$newm && $mmodes[1] == 0) {
91		push(@opts, [ 0, $text{'edit_delete'} ]);
92		}
93	else {
94		push(@opts, [ 0, $text{'edit_dont'} ]);
95		}
96	print &ui_table_row($text{'edit_savemount'},
97		&ui_radio("msave", $minfo[5] eq "yes" || $newm ? 2 :
98				   $minfo[5] eq "no" ? 1 :
99				   $minfo[5] eq "" && !$newm ? 0 : undef,
100			  \@opts));
101	}
102
103# Show mount now options
104if ($mmodes[1] == 1 && ($mmodes[3] == 0 || !$mnow)) {
105	print &ui_table_row($text{'edit_now'},
106		&ui_radio("mmount", $mnow || $newm ? 1 : 0,
107			  [ [ 1, $text{'edit_mount'} ],
108			    [ 0, $mmodes[0] == 0 ? $text{'edit_delete'} :
109				 $newm ? $text{'edit_dont2'} :
110					 $text{'edit_unmount'} ] ]));
111	}
112
113# Show fsck order options
114if ($mmodes[2]) {
115	$second = $minfo[4] > 1 ? $minfo[4] : 2;
116	print &ui_table_row($text{'edit_order'},
117		&ui_radio("order", $newm || $minfo[4] == 0 ? 0 :
118				   $minfo[4] == 1 ? 1 :
119				   $second,
120			  [ [ 0, $text{'no'} ],
121			    [ 1, $text{'edit_first'} ],
122			    [ $second, $text{'edit_second'} ] ]));
123	}
124
125# Show filesystem-specific mount source
126&generate_location($type, $minfo[1] || $in{'newdev'});
127print &ui_table_end();
128
129if (!defined($access{'opts'}) || $access{'opts'} =~ /$type/) {
130	# generate mount options
131	print &ui_table_start($text{'edit_adv'}, "width=100%", 4,
132			      [ "width=20%" ]);
133	&parse_options($type, $minfo[3]);
134	&generate_options($type, $newm);
135	print &ui_table_end();
136	}
137
138# Save and other buttons
139if ($newm) {
140	print &ui_form_end([ [ undef, $text{'create'} ] ]);
141	}
142elsif ($mnow && $minfo[2] ne "swap") {
143	&foreign_require("proc");
144	print &ui_hidden("lsoffs", $minfo[0]);
145	print &ui_form_end([ [ undef, $text{'save'} ],
146			     $proc::has_fuser_command ?
147				( [ 'lsof', $text{'edit_list'} ] ) : ( ) ]);
148	}
149else {
150	print &ui_form_end([ [ undef, $text{'save'} ] ]);
151	}
152
153&ui_print_footer($in{'return'}, $text{'index_return'});
154
155